summaryrefslogtreecommitdiff
path: root/util/fbrun
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbrun')
-rw-r--r--util/fbrun/FbRun.cc37
1 files changed, 30 insertions, 7 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc
index 9c4d1d5..6c7a53a 100644
--- a/util/fbrun/FbRun.cc
+++ b/util/fbrun/FbRun.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: FbRun.cc,v 1.13 2003/06/25 12:01:23 fluxgen Exp $ 22// $Id: FbRun.cc,v 1.14 2003/07/10 10:18:08 fluxgen Exp $
23 23
24#include "FbRun.hh" 24#include "FbRun.hh"
25 25
@@ -86,12 +86,35 @@ void FbRun::run(const std::string &command) {
86 86
87 // save command history to file 87 // save command history to file
88 if (m_runtext.size() != 0) { // no need to save empty command 88 if (m_runtext.size() != 0) { // no need to save empty command
89 // open file in append mode 89
90 ofstream outfile(m_history_file.c_str(), ios::app); 90 // don't allow duplicates into the history file, first
91 if (outfile) 91 // look for a duplicate
92 outfile<<m_runtext<<endl; 92 if (m_current_history_item < m_history.size()
93 else 93 && m_runtext == m_history[m_current_history_item]) {
94 cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; 94 // m_current_history_item is the duplicate
95 } else {
96 int i;
97 for (i = 0; i < m_history.size(); i++)
98 if (m_runtext == m_history[i]) break;
99 m_current_history_item = i;
100 }
101
102 // now m_current_history_item points at the duplicate, or
103 // at m_history.size() if no duplicate
104 fstream inoutfile(m_history_file.c_str(), ios::in|ios::out);
105 if (inoutfile) {
106 int i = 0;
107 // read past history items before current
108 for (string line; !inoutfile.eof() && i < m_current_history_item; i++)
109 getline(inoutfile, line);
110 // write the history items that come after current
111 for (i++; i < m_history.size(); i++)
112 inoutfile<<m_history[i]<<endl;
113 // and append the current one back to the end
114 inoutfile<<m_runtext<<endl;
115 inoutfile.close();
116 } else
117 cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl;
95 } 118 }
96 FbTk::App::instance()->end(); // end application 119 FbTk::App::instance()->end(); // end application
97 m_end = true; // mark end of processing 120 m_end = true; // mark end of processing