Deleted Added
full compact
53a54,55
> static const char hist_cookie[] = "_HiStOrY_V1_\n";
>
57a60
> typedef void (*history_vfun_t) __P((ptr_t));
65a69
> history_vfun_t h_clear; /* Clear the history list */
74a79
> #define HCLEAR(h) (*(h)->h_clear)((h)->h_ref)
83,89c88,90
< private int history_set_fun __P((History *, history_gfun_t,
< history_gfun_t,
< history_gfun_t,
< history_gfun_t,
< history_gfun_t,
< history_efun_t,
< history_efun_t, ptr_t));
---
> private int history_set_fun __P((History *, History *));
> private int history_load __P((History *, const char *));
> private int history_save __P((History *, const char *));
123c124
< private void history_def_end __P((ptr_t));
---
> private void history_def_clear __P((ptr_t));
234,235c235,236
< (void) strcpy(s, h->cursor->ev.str);
< (void) strcat(s, str);
---
> (void)strcpy(s, h->cursor->ev.str); /* XXX strcpy is safe */
> (void)strcat(s, str); /* XXX strcat is safe */
327c328
< /* history_def_end():
---
> /* history_def_clear():
331c332
< history_def_end(p)
---
> history_def_clear(p)
337a339,340
> h->eventno = 0;
> h->cur = 0;
356a360
> h->h_clear = history_def_clear;
372c376
< history_def_end(h->h_ref);
---
> history_def_clear(h->h_ref);
396,400c400,401
< history_set_fun(h, first, next, last, prev, curr, enter, add, ptr)
< History *h;
< history_gfun_t first, next, last, prev, curr;
< history_efun_t enter, add;
< ptr_t ptr;
---
> history_set_fun(h, nh)
> History *h, *nh;
402,405c403,406
< if (first == NULL || next == NULL ||
< last == NULL || prev == NULL || curr == NULL ||
< enter == NULL || add == NULL ||
< ptr == NULL ) {
---
> if (nh->h_first == NULL || nh->h_next == NULL ||
> nh->h_last == NULL || nh->h_prev == NULL || nh->h_curr == NULL ||
> nh->h_enter == NULL || nh->h_add == NULL || nh->h_clear == NULL ||
> nh->h_ref == NULL) {
412a414
> h->h_clear = history_def_clear;
420c422
< history_def_end(h->h_ref);
---
> history_def_clear(h->h_ref);
422,425c424,431
< h->h_next = next;
< h->h_first = first;
< h->h_enter = enter;
< h->h_add = add;
---
> h->h_first = nh->h_first;
> h->h_next = nh->h_next;
> h->h_last = nh->h_last;
> h->h_prev = nh->h_prev;
> h->h_curr = nh->h_curr;
> h->h_clear = nh->h_clear;
> h->h_enter = nh->h_enter;
> h->h_add = nh->h_add;
429a436,493
> /* history_load():
> * History load function
> */
> private int
> history_load(h, fname)
> History *h;
> const char *fname;
> {
> FILE *fp;
> char *line;
> size_t sz;
> int i = -1;
>
> if ((fp = fopen(fname, "r")) == NULL)
> return i;
>
> if ((line = fgetln(fp, &sz)) == NULL)
> goto done;
>
> if (strncmp(line, hist_cookie, sz) != 0)
> goto done;
>
> for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) {
> char c = line[sz];
> line[sz] = '\0';
> HENTER(h, line);
> line[sz] = c;
> }
>
> done:
> (void) fclose(fp);
> return i;
> }
>
>
> /* history_save():
> * History save function
> */
> private int
> history_save(h, fname)
> History *h;
> const char *fname;
> {
> FILE *fp;
> const HistEvent *ev;
> int i = 0;
>
> if ((fp = fopen(fname, "w")) == NULL)
> return -1;
>
> (void) fputs(hist_cookie, fp);
> for (ev = HLAST(h); ev != NULL; ev = HPREV(h), i++)
> (void) fprintf(fp, "%s", ev->str);
> (void) fclose(fp);
> return i;
> }
>
>
512c576
< static const HistEvent sev = { 0, "" };
---
> static HistEvent sev = { 0, "" };
554a619,632
> case H_CLEAR:
> HCLEAR(h);
> break;
>
> case H_LOAD:
> sev.num = history_load(h, va_arg(va, const char *));
> ev = &sev;
> break;
>
> case H_SAVE:
> sev.num = history_save(h, va_arg(va, const char *));
> ev = &sev;
> break;
>
572c650,651
< if (history_set_num(h, va_arg(va, int)) == 0)
---
> if (history_set_num(h, va_arg(va, int)) == 0) {
> sev.num = -1;
573a653
> }
578,585c658,667
< history_gfun_t first = va_arg(va, history_gfun_t);
< history_gfun_t next = va_arg(va, history_gfun_t);
< history_gfun_t last = va_arg(va, history_gfun_t);
< history_gfun_t prev = va_arg(va, history_gfun_t);
< history_gfun_t curr = va_arg(va, history_gfun_t);
< history_efun_t enter = va_arg(va, history_efun_t);
< history_efun_t add = va_arg(va, history_efun_t);
< ptr_t ptr = va_arg(va, ptr_t);
---
> History hf;
> hf.h_ref = va_arg(va, ptr_t);
> hf.h_first = va_arg(va, history_gfun_t);
> hf.h_next = va_arg(va, history_gfun_t);
> hf.h_last = va_arg(va, history_gfun_t);
> hf.h_prev = va_arg(va, history_gfun_t);
> hf.h_curr = va_arg(va, history_gfun_t);
> hf.h_clear = va_arg(va, history_vfun_t);
> hf.h_enter = va_arg(va, history_efun_t);
> hf.h_add = va_arg(va, history_efun_t);
587,588c669,670
< if (history_set_fun(h, first, next, last, prev,
< curr, enter, add, ptr) == 0)
---
> if (history_set_fun(h, &hf) == 0) {
> sev.num = -1;
589a672
> }