summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine ELIAS <antoine.elias@scilab-enterprises.com>2016-11-10 08:33:02 +0100
committerAntoine ELIAS <antoine.elias@scilab-enterprises.com>2016-11-10 08:33:02 +0100
commita6141cd95ba3e0a377937cff09ae3e028b593133 (patch)
tree5fe65259b3cf6654642c3774e0970eb7f14467fb
parent43c5939684ac89f5aa998b72ccdf5e55fccdcf24 (diff)
downloadscilab-a6141cd95ba3e0a377937cff09ae3e028b593133.zip
scilab-a6141cd95ba3e0a377937cff09ae3e028b593133.tar.gz
utf: output_stream 3
Change-Id: I7d7e2cfc5ae1e6ce23f014d4a35847ed58d53eff
-rw-r--r--scilab/modules/output_stream/sci_gateway/cpp/sci_mprintf.cpp2
-rw-r--r--scilab/modules/output_stream/src/cpp/Diary.cpp24
-rw-r--r--scilab/modules/output_stream/src/cpp/getDiaryDate.cpp6
-rw-r--r--scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp40
4 files changed, 15 insertions, 57 deletions
diff --git a/scilab/modules/output_stream/sci_gateway/cpp/sci_mprintf.cpp b/scilab/modules/output_stream/sci_gateway/cpp/sci_mprintf.cpp
index c55074b..e0335cd 100644
--- a/scilab/modules/output_stream/sci_gateway/cpp/sci_mprintf.cpp
+++ b/scilab/modules/output_stream/sci_gateway/cpp/sci_mprintf.cpp
@@ -29,8 +29,6 @@ extern "C"
29#include "os_wtoi.h" 29#include "os_wtoi.h"
30} 30}
31 31
32int new_sprintf(const std::string& funcname, const wchar_t* _pwstInput, types::typed_list &in, int* _piOutputRows, int* _piNewLine, wchar_t*** output);
33
34/*--------------------------------------------------------------------------*/ 32/*--------------------------------------------------------------------------*/
35types::Callable::ReturnValue sci_mprintf(types::typed_list &in, int _iRetCount, types::typed_list &out) 33types::Callable::ReturnValue sci_mprintf(types::typed_list &in, int _iRetCount, types::typed_list &out)
36{ 34{
diff --git a/scilab/modules/output_stream/src/cpp/Diary.cpp b/scilab/modules/output_stream/src/cpp/Diary.cpp
index 5d4d42e..482cbfa 100644
--- a/scilab/modules/output_stream/src/cpp/Diary.cpp
+++ b/scilab/modules/output_stream/src/cpp/Diary.cpp
@@ -115,14 +115,7 @@ void Diary::write(const std::string& _str, bool bInput)
115 { 115 {
116 if ((PrefixIoModeFilter == PREFIX_FILTER_INPUT_AND_OUTPUT) || (PrefixIoModeFilter == PREFIX_FILTER_ONLY_INPUT)) 116 if ((PrefixIoModeFilter == PREFIX_FILTER_INPUT_AND_OUTPUT) || (PrefixIoModeFilter == PREFIX_FILTER_ONLY_INPUT))
117 { 117 {
118 char *timeInfo = wide_string_to_UTF8((wchar_t *) getDiaryDate(PrefixTimeFormat).c_str()); 118 fileDiary << getDiaryDate(PrefixTimeFormat) << " ";
119
120 if (timeInfo)
121 {
122 fileDiary << timeInfo << " ";
123 FREE(timeInfo);
124 timeInfo = NULL;
125 }
126 } 119 }
127 if (line) 120 if (line)
128 { 121 {
@@ -136,14 +129,7 @@ void Diary::write(const std::string& _str, bool bInput)
136 { 129 {
137 if ((PrefixIoModeFilter == PREFIX_FILTER_INPUT_AND_OUTPUT) || (PrefixIoModeFilter == PREFIX_FILTER_ONLY_OUTPUT)) 130 if ((PrefixIoModeFilter == PREFIX_FILTER_INPUT_AND_OUTPUT) || (PrefixIoModeFilter == PREFIX_FILTER_ONLY_OUTPUT))
138 { 131 {
139 char *timeInfo = wide_string_to_UTF8((wchar_t *) getDiaryDate(PrefixTimeFormat).c_str()); 132 fileDiary << getDiaryDate(PrefixTimeFormat) << " ";
140
141 if (timeInfo)
142 {
143 fileDiary << timeInfo << " ";
144 FREE(timeInfo);
145 timeInfo = NULL;
146 }
147 } 133 }
148 if (line) 134 if (line)
149 { 135 {
@@ -151,12 +137,6 @@ void Diary::write(const std::string& _str, bool bInput)
151 } 137 }
152 } 138 }
153 } 139 }
154
155 if (line)
156 {
157 FREE(line);
158 line = NULL;
159 }
160 } 140 }
161 fileDiary.close(); 141 fileDiary.close();
162 } 142 }
diff --git a/scilab/modules/output_stream/src/cpp/getDiaryDate.cpp b/scilab/modules/output_stream/src/cpp/getDiaryDate.cpp
index f5631d3..164aac1 100644
--- a/scilab/modules/output_stream/src/cpp/getDiaryDate.cpp
+++ b/scilab/modules/output_stream/src/cpp/getDiaryDate.cpp
@@ -55,9 +55,9 @@ std::string getDiaryDate(int format_mode)
55 unsigned int MINUTES = nowstruct->tm_min; 55 unsigned int MINUTES = nowstruct->tm_min;
56 unsigned int SECONDS = nowstruct->tm_sec; 56 unsigned int SECONDS = nowstruct->tm_sec;
57 57
58 StrStream << YEAR << L"-" << MONTH << L"-" << DAY_OF_MONTH; 58 StrStream << YEAR << "-" << MONTH << "-" << DAY_OF_MONTH;
59 StrStream << L" "; 59 StrStream << " ";
60 StrStream << HOUR_OF_DAY << L":" << MINUTES << L":" << SECONDS; 60 StrStream << HOUR_OF_DAY << ":" << MINUTES << ":" << SECONDS;
61 strdate = StrStream.str(); 61 strdate = StrStream.str();
62 } 62 }
63 break; 63 break;
diff --git a/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp b/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp
index 80850c3..036de68 100644
--- a/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp
+++ b/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp
@@ -32,8 +32,7 @@ extern "C"
32} 32}
33 33
34static char* replaceAndCountLines(const char* _pstInput, int* _piLines, int* _piNewLine); 34static char* replaceAndCountLines(const char* _pstInput, int* _piLines, int* _piNewLine);
35static char* addl(TokenDef* token); 35static char* replacebys(TokenDef* token);
36static void updatel(TokenDef* token);
37 36
38#define NanString "Nan" 37#define NanString "Nan"
39#define InfString "Inf" 38#define InfString "Inf"
@@ -341,11 +340,6 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types
341 return nullptr; 340 return nullptr;
342 } 341 }
343 342
344 if (tok->length == false)
345 {
346 updatel(tok);
347 }
348
349 tok->outputType = types::InternalType::ScilabString; 343 tok->outputType = types::InternalType::ScilabString;
350 tok->pos = p; 344 tok->pos = p;
351 tok->col = c; 345 tok->col = c;
@@ -438,7 +432,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types
438 } 432 }
439 else 433 else
440 { 434 {
441 char* newToken = addl(tok); 435 char* newToken = replacebys(tok);
442 436
443 if (std::isnan(dblVal)) 437 if (std::isnan(dblVal))
444 { 438 {
@@ -453,7 +447,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types
453 os_sprintf(pstTemp, bsiz, newToken, InfString); 447 os_sprintf(pstTemp, bsiz, newToken, InfString);
454 } 448 }
455 449
456 delete[] newToken; 450 FREE(newToken);
457 } 451 }
458 452
459 oFirstOutput << pstTemp; 453 oFirstOutput << pstTemp;
@@ -491,7 +485,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types
491 } 485 }
492 else 486 else
493 { 487 {
494 char* newToken = addl(tok); 488 char* newToken = replacebys(tok);
495 489
496 if (std::isnan(dblVal)) 490 if (std::isnan(dblVal))
497 { 491 {
@@ -509,7 +503,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types
509 } 503 }
510 } 504 }
511 505
512 delete[] newToken; 506 FREE(newToken);
513 } 507 }
514 508
515 oFirstOutput << pstTemp; 509 oFirstOutput << pstTemp;
@@ -548,7 +542,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types
548 } 542 }
549 else 543 else
550 { 544 {
551 char* newToken = addl(tok); 545 char* newToken = replacebys(tok);
552 546
553 if (std::isnan(dblVal)) 547 if (std::isnan(dblVal))
554 { 548 {
@@ -566,7 +560,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types
566 } 560 }
567 } 561 }
568 562
569 delete[] newToken; 563 FREE(newToken);
570 } 564 }
571 565
572 oFirstOutput << pstTemp; 566 oFirstOutput << pstTemp;
@@ -779,25 +773,11 @@ static char* replaceAndCountLines(const char* _pstInput, int* _piLines, int* _pi
779 return pstFirstOutput; 773 return pstFirstOutput;
780} 774}
781/*--------------------------------------------------------------------------*/ 775/*--------------------------------------------------------------------------*/
782char* addl(TokenDef* token) 776char* replacebys(TokenDef* token)
783{ 777{
784 //replace %s or %c by %ls or %lc to wide char compatibility
785 int iPos = token->typePos; 778 int iPos = token->typePos;
786 int sizeTotal = (int)strlen(token->pstToken); 779 char* pstToken = os_strdup(token->pstToken);
787 char* pstToken = new char[sizeTotal + 2]; 780 pstToken[iPos] = 's';
788
789 strncpy(pstToken, token->pstToken, iPos);
790 pstToken[iPos] = 'l';
791 pstToken[iPos + 1] = 's';
792 strncpy(&pstToken[iPos + 2], token->pstToken + iPos + 1, sizeTotal - (iPos + 1));
793 pstToken[sizeTotal + 1] = '\0';
794
795 return pstToken; 781 return pstToken;
796} 782}
797/*--------------------------------------------------------------------------*/ 783/*--------------------------------------------------------------------------*/
798void updatel(TokenDef* token)
799{
800 char* newToken = addl(token);
801 delete[] token->pstToken;
802 token->pstToken = newToken;
803}