aboutsummaryrefslogtreecommitdiff
path: root/util/fbrun/FbRun.cc
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbrun/FbRun.cc')
-rw-r--r--util/fbrun/FbRun.cc31
1 files changed, 19 insertions, 12 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc
index 4b51c4b..da3ee6b 100644
--- a/util/fbrun/FbRun.cc
+++ b/util/fbrun/FbRun.cc
@@ -140,20 +140,27 @@ void FbRun::run(const std::string &command) {
140 } 140 }
141 } 141 }
142 142
143 // now m_current_history_item points at the duplicate, or
144 // at m_history.size() if no duplicate
145 fstream inoutfile(m_history_file.c_str(), ios::in|ios::out); 143 fstream inoutfile(m_history_file.c_str(), ios::in|ios::out);
146 if (inoutfile) { 144 if (inoutfile) {
147 int i = 0; 145 // now m_current_history_item points at the duplicate, or
148 // read past history items before current 146 // at m_history.size() if no duplicate
149 for (string line; !inoutfile.eof() && i < m_current_history_item; i++) 147 if (m_current_history_item != m_history.size()) {
150 getline(inoutfile, line); 148 int i = 0;
151 // write the history items that come after current 149 // read past history items before current
152 for (i++; i < m_history.size(); i++) 150 for (; inoutfile.good() && i < m_current_history_item; i++)
153 inoutfile<<m_history[i]<<endl; 151 inoutfile.ignore(1, '\n');
154 152
155 // and append the current one back to the end 153 // write the history items that come after current
156 inoutfile<<text()<<endl; 154 for (i++; i < m_history.size(); i++)
155 inoutfile<<m_history[i]<<endl;
156
157 } else {
158 // set put-pointer at end of file
159 inoutfile.seekp(0, ios::end);
160 }
161 // append current command to the file
162 inoutfile<<command<<endl;
163
157 } else 164 } else
158 cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; 165 cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl;
159 } 166 }