* Bug #9305 fixed - In the optimisation help page, new chapter "Least Squares functions"
created.
+* Bug #10415 fixed - Remove a session line in history causes the removal
+ of the session node in history browser
+
* Bug #10606 fixed - unix_g did not return stdout in somes cases.
* Bug #10661 fixed - xmltopdf & xmltopdf were failing in the binary version.
void resetScilabHistory(void)
{
if (ScilabHistory)
+ {
ScilabHistory->reset();
+ }
}
/*------------------------------------------------------------------------*/
char **lines = NULL;
if (ScilabHistory)
+ {
lines = ScilabHistory->getAllLines(&nbElements);
+ }
freeArrayOfString(lines, nbElements);
char *line = NULL;
if (ScilabHistory)
+ {
line = ScilabHistory->getLastLine();
+ }
return line;
}
char *line = NULL;
if (ScilabHistory)
+ {
line = ScilabHistory->getPreviousLine();
+ }
return line;
}
char *line = NULL;
if (ScilabHistory)
+ {
line = ScilabHistory->getNextLine();
+ }
return line;
}
int val = 0;
if (ScilabHistory)
+ {
val = ScilabHistory->getNumberOfLines();
+ }
return val;
}
void setSaveConsecutiveDuplicateLinesInScilabHistory(BOOL doit)
{
if (ScilabHistory)
+ {
ScilabHistory->setSaveConsecutiveDuplicateLines(doit);
+ }
}
/*------------------------------------------------------------------------*/
BOOL getSaveConsecutiveDuplicateLinesInScilabHistory(void)
{
if (ScilabHistory)
+ {
return ScilabHistory->getSaveConsecutiveDuplicateLines();
+ }
return FALSE;
}
void setAfterHowManyLinesScilabHistoryIsSaved(int num)
{
if (ScilabHistory)
+ {
ScilabHistory->setAfterHowManyLinesHistoryIsSaved(num);
+ }
}
/*------------------------------------------------------------------------*/
int val = 0;
if (ScilabHistory)
+ {
val = ScilabHistory->getAfterHowManyLinesHistoryIsSaved();
+ }
return val;
}
char *getNthLineInScilabHistory(int N)
{
if (ScilabHistory)
+ {
return ScilabHistory->getNthLine(N);
+ }
return NULL;
}
int val = 0;
if (ScilabHistory)
+ {
val = ScilabHistory->getNumberOfLines() - 1;
+ }
return val;
}
BOOL setSizeMaxScilabHistory(int nbLinesMax)
{
BOOL bOK = FALSE;
- if (ScilabHistory) bOK = ScilabHistory->setNumberOfLinesMax(nbLinesMax);
+ if (ScilabHistory)
+ {
+ bOK = ScilabHistory->setNumberOfLinesMax(nbLinesMax);
+ }
return bOK;
}
/*------------------------------------------------------------------------*/
int getSizeMaxScilabHistory(void)
{
int val = 0;
- if (ScilabHistory) val = ScilabHistory->getNumberOfLinesMax();
+ if (ScilabHistory)
+ {
+ val = ScilabHistory->getNumberOfLinesMax();
+ }
return val;
}
/*------------------------------------------------------------------------*/
for (i = 0; i < nbrlines; i++)
{
if ((lines[i] == NULL) || (!appendLine(lines[i])))
+ {
bOK = FALSE;
+ }
}
return bOK;
}
*numberoflines = 0;
if (CommandsList.empty())
+ {
return lines;
+ }
else
{
list < CommandLine >::iterator it_commands;
char *line = NULL;
if (N < 0)
+ {
N = getNumberOfLines() + N;
+ }
if ((N >= 0) && (N <= getNumberOfLines()))
{
/*--------------------------------------------------------------------------*/
BOOL HistoryManager::deleteNthLine(int N)
{
- BOOL bOK = FALSE;
-
if ((N >= 0) && (N <= getNumberOfLines()))
{
int i = 0;
- list < CommandLine >::iterator it_commands;
- for (it_commands = CommandsList.begin(); it_commands != CommandsList.end(); ++it_commands)
+ list<CommandLine>::iterator it_start, it_end;
+ for (it_start = CommandsList.begin(); it_start != CommandsList.end(); ++it_start)
{
if (i == N)
{
- if (it_commands != CommandsList.end())
+ it_end = it_start;
+ it_end++;
+ if (isBeginningSessionLine(*it_start))
{
- std::string str;
- str.erase();
- CommandsList.erase(it_commands);
- // After a remove , we update search
- my_search.setHistory(CommandsList);
- my_search.setToken(str);
-
- CommandHistoryDeleteLine(N);
- return TRUE;
+ for (; it_end != CommandsList.end(); ++it_end)
+ {
+ if (isBeginningSessionLine(*it_end))
+ {
+ break;
+ }
+ }
}
+
+ CommandsList.erase(it_start, it_end);
+
+ my_search.setHistory(CommandsList);
+ my_search.setToken(std::string());
+
+ CommandHistoryDeleteLine(N);
+ return TRUE;
}
i++;
}
}
- return bOK;
+ return FALSE;
}
/*--------------------------------------------------------------------------*/
{
std::string Token;
if (token)
+ {
Token.assign(token);
+ }
my_search.setHistory(CommandsList);
return my_search.setToken(Token);
}
return my_search.reset();
}
+BOOL HistoryManager::isBeginningSessionLine(CommandLine& line)
+{
+ std::string str = line.get();
+ return isBeginningSessionLine(str.c_str());
+}
+
/*--------------------------------------------------------------------------*/
-BOOL HistoryManager::isBeginningSessionLine(char *line)
+BOOL HistoryManager::isBeginningSessionLine(const char *line)
{
if (line)
{
- if (strlen(line) > strlen(SESSION_PRAGMA_BEGIN) + strlen(SESSION_PRAGMA_END))
- {
-#define STR_LEN_MAX 64
- char str_start[STR_LEN_MAX];
- char str_end[STR_LEN_MAX];
+ size_t len_begin = strlen(SESSION_PRAGMA_BEGIN);
+ size_t len_end = strlen(SESSION_PRAGMA_END);
+ size_t len_line = strlen(line);
- strncpy(str_start, line, (int)strlen(SESSION_PRAGMA_BEGIN));
- strncpy(str_end, &line[strlen(line) - strlen(SESSION_PRAGMA_END)], (int)strlen(SESSION_PRAGMA_END));
- if ((strcmp(str_start, SESSION_PRAGMA_BEGIN) == 0) && (strcmp(str_end, SESSION_PRAGMA_END) == 0))
+ if (len_line > len_begin + len_end)
+ {
+ if ((strncmp(line, SESSION_PRAGMA_BEGIN, len_begin) == 0) &&
+ (strncmp(line + len_line - len_end, SESSION_PRAGMA_END, len_end) == 0))
{
return TRUE;
}
return FALSE;
}
+
+
/*--------------------------------------------------------------------------*/
void HistoryManager::fixHistorySession(void)
{
* @param size of the array of string
* @return TRUE or FALSE
*/
- BOOL appendLines(char **lines,int nbrlines);
+ BOOL appendLines(char **lines, int nbrlines);
/**
* Display history
int numberoflinesbeforehistoryissaved;
/**
- * search if line is a beginning of a session
+ * indicates if command line is a beginning of a session
* @return TRUE or FALSE
*/
- BOOL isBeginningSessionLine(char *line);
+ BOOL isBeginningSessionLine(CommandLine& line);
+
+ /**
+ * indicates if a string has the pattern "beginning of a session"
+ * @return TRUE or FALSE
+ */
+ BOOL isBeginningSessionLine(const char *line);
/**
* add as first line beginning session info
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Simon MARCHETTO
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- Non-regression test for bug 10415 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=10415
+//
+// <-- Short Description -->
+// The removal of an history session line does not remove
+// all the children command lines
+
+resethistory();
+
+// a session line will be added at the front of this history
+addhistory("lineA");
+addhistory("lineB");
+addhistory("lineC");
+
+// we check the removal of current session line remove all history
+removelinehistory(0);
+h = gethistory();
+assert_checkequal(h, []);
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+function [] = check_history(expected)
+ actual = gethistory();
+ // ignore first line of history which indicates the current session
+ actual(1,1) = []
+ assert_checkequal(actual, expected);
+endfunction
+// checking removing simple lines
+resethistory()
+// warning: a session line will be added at the front of this history
+addhistory("lineA");
+addhistory("lineB");
+addhistory("lineC");
+addhistory("lineD");
+removelinehistory(1);
+check_history(['lineB';'lineC';'lineD']);
+removelinehistory(2);
+h = gethistory();
+check_history(['lineB';'lineD']);
+removelinehistory(2);
+h = gethistory();
+check_history(['lineB']);
+removelinehistory(1);
+check_history([]);
+// check removing of session lines
+resethistory()
+// warning: a session line will be added at the front of this history
+expected_history = ["// -- 26/02/2013 10:00:00 -- //";
+ "lineA";
+ "lineB";
+ "// -- 26/02/2013 11:00:00 -- //";
+ "lineC";
+ "// -- 26/02/2013 12:00:00 -- //";
+ "// -- 26/02/2013 13:00:00 -- //"];
+addhistory(expected_history);
+removelinehistory(1);
+expected_history(1:3,1) = [];
+check_history(expected_history);
+removelinehistory(3);
+expected_history(3,1) = [];
+check_history(expected_history);
+removelinehistory(3);
+expected_history(3,1) = [];
+check_history(expected_history);
+removelinehistory(1);
+expected_history(1:2,1) = [];
+check_history(expected_history);
+// check error messages
+resethistory()
+ierr = execstr("removelinehistory(10)", "errcatch");
+assert_checkequal(ierr, 999);
+
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Simon MARCHETTO
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+function [] = check_history(expected)
+ actual = gethistory();
+ // ignore first line of history which indicates the current session
+ actual(1,1) = []
+ assert_checkequal(actual, expected);
+endfunction
+
+// checking removing simple lines
+
+resethistory()
+// warning: a session line will be added at the front of this history
+addhistory("lineA");
+addhistory("lineB");
+addhistory("lineC");
+addhistory("lineD");
+
+removelinehistory(1);
+check_history(['lineB';'lineC';'lineD']);
+
+removelinehistory(2);
+h = gethistory();
+check_history(['lineB';'lineD']);
+
+removelinehistory(2);
+h = gethistory();
+check_history(['lineB']);
+
+removelinehistory(1);
+check_history([]);
+
+// check removing of session lines
+
+resethistory()
+// warning: a session line will be added at the front of this history
+expected_history = ["// -- 26/02/2013 10:00:00 -- //";
+ "lineA";
+ "lineB";
+ "// -- 26/02/2013 11:00:00 -- //";
+ "lineC";
+ "// -- 26/02/2013 12:00:00 -- //";
+ "// -- 26/02/2013 13:00:00 -- //"];
+addhistory(expected_history);
+
+removelinehistory(1);
+expected_history(1:3,1) = [];
+check_history(expected_history);
+
+removelinehistory(3);
+expected_history(3,1) = [];
+check_history(expected_history);
+
+removelinehistory(3);
+expected_history(3,1) = [];
+check_history(expected_history);
+
+removelinehistory(1);
+expected_history(1:2,1) = [];
+check_history(expected_history);
+
+// check error messages
+
+resethistory()
+ierr = execstr("removelinehistory(10)", "errcatch");
+assert_checkequal(ierr, 999);
+