Deleted Added
full compact
16,20c16
< * 3. All advertising materials mentioning features or use of this software
< * must display the following acknowledgement:
< * This product includes software developed by the University of
< * California, Berkeley and its contributors.
< * 4. Neither the name of the University nor the names of its contributors
---
> * 3. Neither the name of the University nor the names of its contributors
36c32
< * $NetBSD: history.c,v 1.16 2000/09/04 22:06:30 lukem Exp $
---
> * $NetBSD: history.c,v 1.31 2005/08/01 14:34:06 christos Exp $
43c39
< __FBSDID("$FreeBSD: head/lib/libedit/history.c 105095 2002-10-14 10:42:38Z tjr $");
---
> __FBSDID("$FreeBSD: head/lib/libedit/history.c 148834 2005-08-07 20:55:59Z stefanf $");
73a70
> history_sfun_t h_del; /* Set the given element */
77a75
>
86a85
> #define HDEL(h, ev, n) (*(h)->h_del)((h)->h_ref, ev, n)
87a87
> #define h_strdup(a) strdup(a)
91a92,95
> typedef struct {
> int num;
> char *str;
> } HistEventPrivate;
92a97,98
>
>
94a101,102
> private int history_setunique(History *, HistEvent *, int);
> private int history_getunique(History *, HistEvent *);
113c121
< } hentry_t;
---
> } hentry_t;
116,119c124,127
< hentry_t list; /* Fake list header element */
< hentry_t *cursor; /* Current element in the list */
< int max; /* Maximum number of events */
< int cur; /* Current number of events */
---
> hentry_t list; /* Fake list header element */
> hentry_t *cursor; /* Current element in the list */
> int max; /* Maximum number of events */
> int cur; /* Current number of events */
121c129,131
< } history_t;
---
> int flags; /* History flags */
> #define H_UNIQUE 1 /* Store only unique elements */
> } history_t;
123,124d132
< private int history_def_first(ptr_t, HistEvent *);
< private int history_def_last(ptr_t, HistEvent *);
125a134
> private int history_def_first(ptr_t, HistEvent *);
126a136
> private int history_def_last(ptr_t, HistEvent *);
128c138,139
< private int history_def_set(ptr_t, HistEvent *, const int n);
---
> private int history_def_set(ptr_t, HistEvent *, const int);
> private void history_def_clear(ptr_t, HistEvent *);
131,132c142,144
< private void history_def_init(ptr_t *, HistEvent *, int);
< private void history_def_clear(ptr_t, HistEvent *);
---
> private int history_def_del(ptr_t, HistEvent *, const int);
>
> private int history_def_init(ptr_t *, HistEvent *, int);
136,137c148,155
< #define history_def_setsize(p, num)(void) (((history_t *) p)->max = (num))
< #define history_def_getsize(p) (((history_t *) p)->cur)
---
> #define history_def_setsize(p, num)(void) (((history_t *)p)->max = (num))
> #define history_def_getsize(p) (((history_t *)p)->cur)
> #define history_def_getunique(p) (((((history_t *)p)->flags) & H_UNIQUE) != 0)
> #define history_def_setunique(p, uni) \
> if (uni) \
> (((history_t *)p)->flags) |= H_UNIQUE; \
> else \
> (((history_t *)p)->flags) &= ~H_UNIQUE
230,232c248
< if (h->cursor != &h->list)
< h->cursor = h->cursor->next;
< else {
---
> if (h->cursor == &h->list) {
237,239c253
< if (h->cursor != &h->list)
< *ev = h->cursor->ev;
< else {
---
> if (h->cursor->next == &h->list) {
243a258,260
> h->cursor = h->cursor->next;
> *ev = h->cursor->ev;
>
256,258c273
< if (h->cursor != &h->list)
< h->cursor = h->cursor->prev;
< else {
---
> if (h->cursor == &h->list) {
264,266c279
< if (h->cursor != &h->list)
< *ev = h->cursor->ev;
< else {
---
> if (h->cursor->prev == &h->list) {
270a284,286
> h->cursor = h->cursor->prev;
> *ev = h->cursor->ev;
>
330a347
> HistEventPrivate *evp = (void *)&h->cursor->ev;
334c351
< len = strlen(h->cursor->ev.str) + strlen(str) + 1;
---
> len = strlen(evp->str) + strlen(str) + 1;
336c353
< if (!s) {
---
> if (s == NULL) {
342,344c359,360
< /* LINTED const cast */
< h_free((ptr_t) h->cursor->ev.str);
< h->cursor->ev.str = s;
---
> h_free((ptr_t)evp->str);
> evp->str = s;
349a366,383
> /* history_def_del():
> * Delete element hp of the h list
> */
> /* ARGSUSED */
> private int
> history_def_del(ptr_t p, HistEvent *ev __unused,
> const int num)
> {
> history_t *h = (history_t *) p;
> if (history_def_set(h, ev, num) != 0)
> return (-1);
> ev->str = strdup(h->cursor->ev.str);
> ev->num = h->cursor->ev.num;
> history_def_delete(h, ev, h->cursor);
> return (0);
> }
>
>
355c389,390
< history_def_delete(history_t *h, HistEvent *ev, hentry_t *hp)
---
> history_def_delete(history_t *h,
> HistEvent *ev __unused, hentry_t *hp)
357c392
<
---
> HistEventPrivate *evp = (void *)&hp->ev;
359a395,396
> if (h->cursor == hp)
> h->cursor = hp->prev;
362,363c399
< /* LINTED const cast */
< h_free((ptr_t) hp->ev.str);
---
> h_free((ptr_t) evp->str);
377,381c413,417
< if (h->cursor)
< h->cursor->ev.str = strdup(str);
< if (!h->cursor || !h->cursor->ev.str) {
< he_seterrev(ev, _HE_MALLOC_FAILED);
< return (-1);
---
> if (h->cursor == NULL)
> goto oomem;
> if ((h->cursor->ev.str = h_strdup(str)) == NULL) {
> h_free((ptr_t)h->cursor);
> goto oomem;
391a428,430
> oomem:
> he_seterrev(ev, _HE_MALLOC_FAILED);
> return (-1);
402a442,445
> if ((h->flags & H_UNIQUE) != 0 && h->list.next != &h->list &&
> strcmp(h->list.next->ev.str, str) == 0)
> return (0);
>
410c453
< while (h->cur - 1 > h->max)
---
> while (h->cur > h->max && h->cur > 0)
413c456
< return (0);
---
> return (1);
421,422c464,465
< private void
< history_def_init(ptr_t *p, HistEvent *ev, int n)
---
> private int
> history_def_init(ptr_t *p, HistEvent *ev __unused, int n)
424a468,469
> if (h == NULL)
> return -1;
434a480
> h->flags = 0;
435a482
> return 0;
464d510
< History *h = (History *) h_malloc(sizeof(History));
465a512,514
> History *h = (History *) h_malloc(sizeof(History));
> if (h == NULL)
> return NULL;
467c516,519
< history_def_init(&h->h_ref, &ev, 0);
---
> if (history_def_init(&h->h_ref, &ev, 0) == -1) {
> h_free((ptr_t)h);
> return NULL;
> }
477a530
> h->h_del = history_def_del;
492a546
> h_free(h);
523,524d576
< int retval = 0;
<
529,530c581,582
< retval = history_def_getsize(h->h_ref);
< if (retval < -1) {
---
> ev->num = history_def_getsize(h->h_ref);
> if (ev->num < -1) {
534d585
< ev->num = retval;
538a590,620
> /* history_setunique():
> * Set if adjacent equal events should not be entered in history.
> */
> private int
> history_setunique(History *h, HistEvent *ev, int uni)
> {
>
> if (h->h_next != history_def_next) {
> he_seterrev(ev, _HE_NOT_ALLOWED);
> return (-1);
> }
> history_def_setunique(h->h_ref, uni);
> return (0);
> }
>
>
> /* history_getunique():
> * Get if adjacent equal events should not be entered in history.
> */
> private int
> history_getunique(History *h, HistEvent *ev)
> {
> if (h->h_next != history_def_next) {
> he_seterrev(ev, _HE_NOT_ALLOWED);
> return (-1);
> }
> ev->num = history_def_getunique(h->h_ref);
> return (0);
> }
>
>
550c632
< nh->h_ref == NULL) {
---
> nh->h_del == NULL || nh->h_ref == NULL) {
561a644
> h->h_del = history_def_del;
577a661
> h->h_del = nh->h_del;
605a690,691
> if (ptr == NULL)
> goto done;
615,616c701,708
< max_size = (sz + 1023) & ~1023;
< ptr = h_realloc(ptr, max_size);
---
> char *nptr;
> max_size = (sz + 1024) & ~1023;
> nptr = h_realloc(ptr, max_size);
> if (nptr == NULL) {
> i = -1;
> goto oomem;
> }
> ptr = nptr;
620c712,715
< HENTER(h, &ev, ptr);
---
> if (HENTER(h, &ev, ptr) == -1) {
> h_free((ptr_t)ptr);
> return -1;
> }
622,623c717,718
< h_free(ptr);
<
---
> oomem:
> h_free((ptr_t)ptr);
638c733
< int i = 0, retval;
---
> int i = -1, retval;
645,646c740,743
< (void) fchmod(fileno(fp), S_IRUSR|S_IWUSR);
< (void) fputs(hist_cookie, fp);
---
> if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1)
> goto done;
> if (fputs(hist_cookie, fp) == EOF)
> goto done;
648c745,747
< for (retval = HLAST(h, &ev);
---
> if (ptr == NULL)
> goto done;
> for (i = 0, retval = HLAST(h, &ev);
653,654c752,759
< max_size = (len + 1023) & 1023;
< ptr = h_realloc(ptr, max_size);
---
> char *nptr;
> max_size = (len + 1024) & ~1023;
> nptr = h_realloc(ptr, max_size);
> if (nptr == NULL) {
> i = -1;
> goto oomem;
> }
> ptr = nptr;
659c764,766
< h_free(ptr);
---
> oomem:
> h_free((ptr_t)ptr);
> done:
757a865,872
> case H_GETUNIQUE:
> retval = history_getunique(h, ev);
> break;
>
> case H_SETUNIQUE:
> retval = history_setunique(h, ev, va_arg(va, int));
> break;
>
762a878,881
> case H_DEL:
> retval = HDEL(h, ev, va_arg(va, const int));
> break;
>
846a966
> hf.h_del = va_arg(va, history_sfun_t);