fix the no-writing-history issue for fbrun
This commit is contained in:
parent
d39897f19d
commit
1910d5af46
1 changed files with 19 additions and 12 deletions
|
@ -140,20 +140,27 @@ void FbRun::run(const std::string &command) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now m_current_history_item points at the duplicate, or
|
|
||||||
// at m_history.size() if no duplicate
|
|
||||||
fstream inoutfile(m_history_file.c_str(), ios::in|ios::out);
|
fstream inoutfile(m_history_file.c_str(), ios::in|ios::out);
|
||||||
if (inoutfile) {
|
if (inoutfile) {
|
||||||
int i = 0;
|
// now m_current_history_item points at the duplicate, or
|
||||||
// read past history items before current
|
// at m_history.size() if no duplicate
|
||||||
for (string line; !inoutfile.eof() && i < m_current_history_item; i++)
|
if (m_current_history_item != m_history.size()) {
|
||||||
getline(inoutfile, line);
|
int i = 0;
|
||||||
// write the history items that come after current
|
// read past history items before current
|
||||||
for (i++; i < m_history.size(); i++)
|
for (; inoutfile.good() && i < m_current_history_item; i++)
|
||||||
inoutfile<<m_history[i]<<endl;
|
inoutfile.ignore(1, '\n');
|
||||||
|
|
||||||
// and append the current one back to the end
|
// write the history items that come after current
|
||||||
inoutfile<<text()<<endl;
|
for (i++; i < m_history.size(); i++)
|
||||||
|
inoutfile<<m_history[i]<<endl;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// set put-pointer at end of file
|
||||||
|
inoutfile.seekp(0, ios::end);
|
||||||
|
}
|
||||||
|
// append current command to the file
|
||||||
|
inoutfile<<command<<endl;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl;
|
cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue