1 /* hist_erasedups -- remove all duplicate entries from history file */
3 /* Copyright (C) 2011 Free Software Foundation, Inc.
5 This file is part of the GNU Readline Library (Readline), a library for
6 reading lines of text with interactive input and history editing.
8 Readline is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Readline is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Readline. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef READLINE_LIBRARY
22 #define READLINE_LIBRARY 1
29 #ifdef READLINE_LIBRARY
32 # include <readline/history.h>
37 #define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0)
38 #define STREQN(a, b, n) ((n == 0) ? (1) \
39 : ((a)[0] == (b)[0] && strncmp(a, b, n) == 0))
41 int hist_erasedups (void);
46 fprintf (stderr
, "hist_erasedups: usage: hist_erasedups [-t] [filename]\n");
58 while ((r
= getopt (argc
, argv
, "t")) != -1)
63 history_write_timestamps
= 1;
72 fn
= argc
? argv
[0] : getenv ("HISTFILE");
75 fprintf (stderr
, "hist_erasedups: no history file\n");
79 if ((r
= read_history (fn
)) != 0)
81 fprintf (stderr
, "hist_erasedups: read_history: %s: %s\n", fn
, strerror (r
));
87 if ((r
= write_history (fn
)) != 0)
89 fprintf (stderr
, "hist_erasedups: write_history: %s: %s\n", fn
, strerror (r
));
100 HIST_ENTRY
*h
, *temp
;
103 while (h
= previous_history ())
105 r
= where_history ();
106 for (n
= 0; n
< r
; n
++)
108 temp
= history_get (n
+history_base
);
109 if (STREQ (h
->line
, temp
->line
))
112 r
--; /* have to get one fewer now */
113 n
--; /* compensate for above increment */
114 history_offset
--; /* moving backwards in history list */
This page took 0.039005 seconds and 4 git commands to generate.