From octave-sources-request at bevo dot che dot wisc dot edu Wed Apr 28 03:25:36 1999 Subject: octave readline, no double entries in history anymore From: Thomas Walter To: octave-sources at bevo dot che dot wisc dot edu Date: Wed, 28 Apr 1999 10:25:38 +0200 Hi, I solved the tast to avoid double entries in the octave coammand history. Some small additions in 'liboctave/cmd-hist.cc' and it works. After applying the patch below you can re-enter the previous command in octave and it is not added to the command history. Hints are welcome Bye Thomas ===================== patch start =================== Index: octave-2_0_14.1/liboctave/ChangeLog --- octave-2_0_14.1/liboctave/ChangeLog Mon, 19 Apr 1999 10:14:55 +0200 twalter (octave/p/4_ChangeLog 1.5 640) +++ octave-2_0_14-loc.2/liboctave/ChangeLog Tue, 27 Apr 1999 12:28:25 +0200 twalter (octave/p/4_ChangeLog 1.7 640) at @ -1,3 +1,9 @@ +1999-04-27 Thomas Walter + + * cmd-hist.cc (add): First simple version to avoid double history entries. + (compare_history_entries): New function. + (add): Use the new function to compare history two entries. + Wed Apr 14 12:55:42 1999 John W. Eaton * Version 2.0.14 released. Index: octave-2_0_14.1/liboctave/cmd-hist.cc --- octave-2_0_14.1/liboctave/cmd-hist.cc Tue, 26 Jan 1999 13:07:01 +0100 twalter (octave/q/26_cmd-hist.c 1.1 640) +++ octave-2_0_14-loc.2/liboctave/cmd-hist.cc Tue, 27 Apr 1999 12:28:25 +0200 twalter (octave/q/26_cmd-hist.c 1.3 640) at @ -114,17 +114,57 @@ command_history::ignoring_entries (void) return ignoring_additions; } +static bool +compare_history_entries (const char* previous, const char* current) +{ + // Compare two strings from a command history + // Return 'false' if they are different + // Return 'true' if they are equal + + if (previous[0] != current[0]) + { + return (false); + } + + if (((long *)previous)[0] != ((long *)current)[0]) + { + return (false); + } + + if (strlen (previous) != strlen (current)) + { + return (false); + } + + if (strcmp (previous, current) == 0) + { + return (true); + } + + // In the case something fails be conservative and say they are different. + // And make the compiler happy to see always a return value. + return (false); +} + void command_history::add (const string& s) { if (! ignoring_entries ()) { + HIST_ENTRY *p_h_entry; + if (s.empty () || (s.length () == 1 && (s[0] == '\r' || s[0] == '\n'))) return; - ::add_history (s.c_str ()); - lines_this_session++; + using_history (); // Must be called always at this point or 'p_h_entry' has the wrong value. + p_h_entry = previous_history (); + // cout << p_h_entry->line << endl; // Simple debugging + if ((p_h_entry == 0) || (compare_history_entries (p_h_entry->line, s.c_str ()) == false)) + { + ::add_history (s.c_str ()); + lines_this_session++; + } } } ===================== patch end =================== -- Platzangst: Der dauerhafte Zustand eines Luftballons. ---------------------------------------------- Dipl. Phys. Thomas Walter Inst. f. Physiklische Chemie II Egerlandstr. 3 Tel.: ++9131-85 27326 / 27330 91058 Erlangen, Germany email: walter at pctc dot chemie dot uni-erlangen dot de