From octave-maintainers-request at bevo dot che dot wisc dot edu Wed Mar 8 08:44:33 2000 Subject: interface to readline From: Thomas Walter To: octave-maintainers at bevo dot che dot wisc dot edu Date: Wed, 8 Mar 2000 15:49:27 +0100 Hello, I updated my local changes to the interface between readline and octave from the '2.0.xx' to the '2.1.xx' version. This little patch disables double entries in the history list. This means if you re-enter the previous line it NOT added to the history list. The octave internal organization has changed. Currently I included the readline headers again at the point where I needed them. The missing interface function of octave is a wrapper to the readline function 'using_history()'. For reference I add my patch at the end. Bye Thomas ==== patch start ============== Index: octave-2_1_28CVS.2/liboctave/ChangeLog --- octave-2_1_28CVS.2/liboctave/ChangeLog Thu, 24 Feb 2000 13:35:53 +0100 twalter (octave_devel/p/32_ChangeLog 1.2.1.1.1.1.1.1.1.1.1.1 640) +++ octave-2_1_28CVS.2(w)/liboctave/ChangeLog Thu, 24 Feb 2000 14:42:28 +0100 twalter (octave_devel/p/32_ChangeLog 1.2.1.1.1.1.1.1.1.1.1.1 640) at @ -1,3 +1,8 @@ +2000-02-24 Thomas Walter + + * cmd-hist.cc (compare_history_entries): New function. + (do_add): Apply my changes to ignore duplicate history entries. + 2000-02-18 John W. Eaton * oct-rl-hist.c (octave_history_list): Do something when not Index: octave-2_1_28CVS.2/liboctave/cmd-hist.cc --- octave-2_1_28CVS.2/liboctave/cmd-hist.cc Wed, 09 Feb 2000 10:43:09 +0100 twalter (octave_devel/r/6_cmd-hist.c 1.1.4.1 640) +++ octave-2_1_28CVS.2(w)/liboctave/cmd-hist.cc Thu, 24 Feb 2000 14:07:11 +0100 twalter (octave_devel/r/6_cmd-hist.c 1.1.4.1 640) at @ -115,18 +115,72 @@ private: int mark; }; +#define READLINE_SHALL_IGNORE_DUPLICATES 1 +#if defined(READLINE_SHALL_IGNORE_DUPLICATES) +#include + +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); +} + +#endif // READLINE_SHALL_IGNORE_DUPLICATES + void gnu_history::do_add (const std::string& s) { if (! do_ignoring_entries ()) { +#if defined(READLINE_SHALL_IGNORE_DUPLICATES) + HIST_ENTRY *p_h_entry; + +#endif // READLINE_SHALL_IGNORE_DUPLICATES if (s.empty () || (s.length () == 1 && (s[0] == '\r' || s[0] == '\n'))) return; +#if defined(READLINE_SHALL_IGNORE_DUPLICATES) + 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)) + { + ::octave_add_history (s.c_str ()); + + lines_this_session++; + } +#else // !READLINE_SHALL_IGNORE_DUPLICATES ::octave_add_history (s.c_str ()); lines_this_session++; +#endif // !READLINE_SHALL_IGNORE_DUPLICATES } } ==== patch end ============== -- Warum hat eine Leiterbahn keine 90 Grad Winkel sondern 2 mal 45 Grad? Weil die Elektronen sonst immer gegen die Wand laufen 8-))) ---------------------------------------------- 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