From f527cad141eeafd154017240503193c2a11f89bc Mon Sep 17 00:00:00 2001 From: Antoine ELIAS Date: Tue, 3 Feb 2015 15:34:13 +0100 Subject: [PATCH] fix sprintf to take care of %% Change-Id: I84e3171303e6289444b6bcdfb9096290133bbc9d --- .../output_stream/sci_gateway/cpp/sci_msprintf.cpp | 11 ++++++----- .../output_stream/src/cpp/scilab_sprintf.cpp | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scilab/modules/output_stream/sci_gateway/cpp/sci_msprintf.cpp b/scilab/modules/output_stream/sci_gateway/cpp/sci_msprintf.cpp index a1356c2..1b8221a 100644 --- a/scilab/modules/output_stream/sci_gateway/cpp/sci_msprintf.cpp +++ b/scilab/modules/output_stream/sci_gateway/cpp/sci_msprintf.cpp @@ -54,7 +54,8 @@ types::Callable::ReturnValue sci_msprintf(types::typed_list &in, int _iRetCount, wchar_t* pwstInput = in[0]->getAs()->get()[0]; int iNumberPercent = 0; - for (int i = 0 ; i < wcslen(pwstInput) ; i++) + int iNumberPercentPercent = 0; + for (int i = 0; i < wcslen(pwstInput); i++) { if (pwstInput[i] == L'%') { @@ -62,7 +63,7 @@ types::Callable::ReturnValue sci_msprintf(types::typed_list &in, int _iRetCount, if (pwstInput[i + 1] == L'%') { //it is a %%, not a %_ - iNumberPercent--; + iNumberPercentPercent++; //force incremantation to bypass the second % of %% i++; } @@ -70,7 +71,7 @@ types::Callable::ReturnValue sci_msprintf(types::typed_list &in, int _iRetCount, } //Input values must be less or equal than excepted - if ((in.size() - 1) > iNumberPercent) + if ((in.size() - 1) > iNumberPercent - iNumberPercentPercent) { Scierror(999, _("%s: Wrong number of input arguments: at most %d expected.\n"), "msprintf", iNumberPercent); return types::Function::Error; @@ -94,7 +95,7 @@ types::Callable::ReturnValue sci_msprintf(types::typed_list &in, int _iRetCount, } } - if (iNumberCols != iNumberPercent) + if (iNumberCols != iNumberPercent - iNumberPercentPercent) { Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), "msprintf"); return types::Function::Error; @@ -102,7 +103,7 @@ types::Callable::ReturnValue sci_msprintf(types::typed_list &in, int _iRetCount, //fill ArgumentPosition structure - pArgs = new ArgumentPosition[iNumberPercent]; + pArgs = new ArgumentPosition[iNumberPercent - iNumberPercentPercent]; int idx = 0; for (int i = 1 ; i < in.size() ; i++) { diff --git a/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp b/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp index 7b89650..4548a8f 100644 --- a/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp +++ b/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp @@ -117,6 +117,7 @@ wchar_t** scilab_sprintf(const char* _pstName, const wchar_t* _pwstInput, typed_ pToken[iToken].pwstToken = new wchar_t[iEnd - iStart + 1]; wcsncpy(pToken[iToken].pwstToken, pwstFirstOutput + iStart, iEnd - iStart); pToken[iToken].pwstToken[iEnd - iStart] = L'\0'; + pToken[iToken].outputType = InternalType::ScilabNull; //identify destination type //format : %[flags][width][.precision][length]specifier -- 1.7.9.5