Deleted Added
full compact
history.c (256281) history.c (278411)
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 *
32 * $NetBSD: history.c,v 1.34 2009/09/07 21:24:33 christos Exp $
33 */
34
35#if !defined(lint) && !defined(SCCSID)
36static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
37#endif /* not lint && not SCCSID */
38#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 *
32 * $NetBSD: history.c,v 1.34 2009/09/07 21:24:33 christos Exp $
33 */
34
35#if !defined(lint) && !defined(SCCSID)
36static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
37#endif /* not lint && not SCCSID */
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: stable/10/lib/libedit/history.c 237448 2012-06-22 18:01:22Z pfg $");
39__FBSDID("$FreeBSD: stable/10/lib/libedit/history.c 278411 2015-02-08 22:11:24Z bapt $");
40
41/*
42 * hist.c: History access functions
43 */
44#include "sys.h"
45
46#include <string.h>
47#include <stdlib.h>

--- 50 unchanged lines hidden (view full) ---

98
99private int history_setsize(History *, HistEvent *, int);
100private int history_getsize(History *, HistEvent *);
101private int history_setunique(History *, HistEvent *, int);
102private int history_getunique(History *, HistEvent *);
103private int history_set_fun(History *, History *);
104private int history_load(History *, const char *);
105private int history_save(History *, const char *);
40
41/*
42 * hist.c: History access functions
43 */
44#include "sys.h"
45
46#include <string.h>
47#include <stdlib.h>

--- 50 unchanged lines hidden (view full) ---

98
99private int history_setsize(History *, HistEvent *, int);
100private int history_getsize(History *, HistEvent *);
101private int history_setunique(History *, HistEvent *, int);
102private int history_getunique(History *, HistEvent *);
103private int history_set_fun(History *, History *);
104private int history_load(History *, const char *);
105private int history_save(History *, const char *);
106private int history_save_fp(History *, FILE*);
106private int history_prev_event(History *, HistEvent *, int);
107private int history_next_event(History *, HistEvent *, int);
108private int history_next_string(History *, HistEvent *, const char *);
109private int history_prev_string(History *, HistEvent *, const char *);
110
111
112/***********************************************************************/
113

--- 654 unchanged lines hidden (view full) ---

768 }
769oomem:
770 h_free((ptr_t)ptr);
771done:
772 (void) fclose(fp);
773 return (i);
774}
775
107private int history_prev_event(History *, HistEvent *, int);
108private int history_next_event(History *, HistEvent *, int);
109private int history_next_string(History *, HistEvent *, const char *);
110private int history_prev_string(History *, HistEvent *, const char *);
111
112
113/***********************************************************************/
114

--- 654 unchanged lines hidden (view full) ---

769 }
770oomem:
771 h_free((ptr_t)ptr);
772done:
773 (void) fclose(fp);
774 return (i);
775}
776
776
777/* history_save():
778 * History save function
777/* history_save_fp():
778 * History save with open FILE*
779 */
779 */
780private int
781history_save(History *h, const char *fname)
780private int history_save_fp(History *h, FILE* fp)
782{
781{
783 FILE *fp;
784 HistEvent ev;
785 int i = -1, retval;
786 size_t len, max_size;
787 char *ptr;
788
782 HistEvent ev;
783 int i = -1, retval;
784 size_t len, max_size;
785 char *ptr;
786
789 if ((fp = fopen(fname, "w")) == NULL)
790 return (-1);
791
792 if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1)
793 goto done;
794 if (fputs(hist_cookie, fp) == EOF)
795 goto done;
796 ptr = h_malloc(max_size = 1024);
797 if (ptr == NULL)
798 goto done;
799 for (i = 0, retval = HLAST(h, &ev);

--- 11 unchanged lines hidden (view full) ---

811 ptr = nptr;
812 }
813 (void) strvis(ptr, ev.str, VIS_WHITE);
814 (void) fprintf(fp, "%s\n", ptr);
815 }
816oomem:
817 h_free((ptr_t)ptr);
818done:
787 if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1)
788 goto done;
789 if (fputs(hist_cookie, fp) == EOF)
790 goto done;
791 ptr = h_malloc(max_size = 1024);
792 if (ptr == NULL)
793 goto done;
794 for (i = 0, retval = HLAST(h, &ev);

--- 11 unchanged lines hidden (view full) ---

806 ptr = nptr;
807 }
808 (void) strvis(ptr, ev.str, VIS_WHITE);
809 (void) fprintf(fp, "%s\n", ptr);
810 }
811oomem:
812 h_free((ptr_t)ptr);
813done:
814 return (i);
815
816}
817
818
819/* history_save():
820 * History save function
821 */
822private int
823history_save(History *h, const char *fname)
824{
825 FILE *fp;
826 int i;
827
828 if ((fp = fopen(fname, "w")) == NULL)
829 return (-1);
830
831 i = history_save_fp(h, fp);
832
833done:
819 (void) fclose(fp);
820 return (i);
821}
822
823
824/* history_prev_event():
825 * Find the previous event, with number given
826 */

--- 169 unchanged lines hidden (view full) ---

996 break;
997
998 case H_SAVE:
999 retval = history_save(h, va_arg(va, const char *));
1000 if (retval == -1)
1001 he_seterrev(ev, _HE_HIST_WRITE);
1002 break;
1003
834 (void) fclose(fp);
835 return (i);
836}
837
838
839/* history_prev_event():
840 * Find the previous event, with number given
841 */

--- 169 unchanged lines hidden (view full) ---

1011 break;
1012
1013 case H_SAVE:
1014 retval = history_save(h, va_arg(va, const char *));
1015 if (retval == -1)
1016 he_seterrev(ev, _HE_HIST_WRITE);
1017 break;
1018
1019 case H_SAVE_FP:
1020 retval = history_save_fp(h, va_arg(va, FILE*));
1021 if (retval == -1)
1022 he_seterrev(ev, _HE_HIST_WRITE);
1023 break;
1024
1004 case H_PREV_EVENT:
1005 retval = history_prev_event(h, ev, va_arg(va, int));
1006 break;
1007
1008 case H_NEXT_EVENT:
1009 retval = history_next_event(h, ev, va_arg(va, int));
1010 break;
1011

--- 74 unchanged lines hidden ---
1025 case H_PREV_EVENT:
1026 retval = history_prev_event(h, ev, va_arg(va, int));
1027 break;
1028
1029 case H_NEXT_EVENT:
1030 retval = history_next_event(h, ev, va_arg(va, int));
1031 break;
1032

--- 74 unchanged lines hidden ---