/*------------------------------------------------------------------------*/ BOOL HistoryManager::appendLine(char *cline) { BOOL bOK = FALSE; if (cline) { if (!saveconsecutiveduplicatelines) { char *previousline = getLastLine(); if ((previousline) && (strcmp(previousline, cline) == 0)) { bOK = FALSE; } else { CommandLine Line(cline); CommandsList.push_back(Line); numberoflinesbeforehistoryissaved++; bOK = TRUE; CommandHistoryAppendLine(cline); } if (previousline) { FREE(previousline); previousline = NULL; } } else { CommandLine Line(cline); CommandsList.push_back(Line); numberoflinesbeforehistoryissaved++; bOK = TRUE; CommandHistoryAppendLine(cline); } } if (afterhowmanylineshistoryissaved != 0) { if (afterhowmanylineshistoryissaved == numberoflinesbeforehistoryissaved) { my_file.setHistory(CommandsList); my_file.writeToFile(); numberoflinesbeforehistoryissaved = 0; } } else { numberoflinesbeforehistoryissaved = 0; } return bOK; }
/*------------------------------------------------------------------------*/ BOOL HistoryManager::appendLine(char* _pstLine) { BOOL bOK = FALSE; if (_pstLine) { int i = 0; int len = 0; char* pstCleanedLine = NULL; /* remove space & carriage return at the end of line */ len = (int)strlen(_pstLine); pstCleanedLine = (char*) MALLOC(len + 1); memcpy(pstCleanedLine, _pstLine, len + 1); /* remove carriage return at the end of line */ for (i = len ; i > 0 ; i--) { if (pstCleanedLine[i] == '\n') { pstCleanedLine[i] = '\0'; len = i - 1; break; } } /* remove spaces at the end of line */ i = len; while (i >= 0) { if (pstCleanedLine[i] == ' ') { pstCleanedLine[i] = '\0'; } else { break; } i--; } if (strlen(pstCleanedLine) == 0) { FREE(pstCleanedLine); return TRUE; } // append if (m_bAllowConsecutiveCommand) { m_Commands.push_back(pstCleanedLine); m_iSavedLines++; bOK = TRUE; CommandHistoryAppendLine(pstCleanedLine); } else { char* pstPreviousLine = getLastLine(); if (pstPreviousLine && strcmp(pstPreviousLine, pstCleanedLine) == 0) { bOK = TRUE; } else { m_Commands.push_back(pstCleanedLine); m_iSavedLines++; bOK = TRUE; CommandHistoryAppendLine(pstCleanedLine); } if (pstPreviousLine) { FREE(pstPreviousLine); pstPreviousLine = NULL; } } if (m_iSaveLimit != 0) { if (m_iSavedLines >= m_iSaveLimit) { m_HF.setHistory(m_Commands); m_HF.writeToFile(); m_iSavedLines = 0; } } else { m_iSavedLines = 0; } if (pstCleanedLine) { FREE(pstCleanedLine); pstCleanedLine = NULL; } } return bOK; }