1: /* @(#)sh.hist.c 2.1 SCCS id keyword */
2: /* Copyright (c) 1980 Regents of the University of California */
3: #include "sh.h"
4:
5: /*
6: * C shell
7: */
8:
9: savehist(sp)
10: struct wordent *sp;
11: {
12: register struct Hist *hp, *np;
13: int histlen;
14: register char *cp;
15:
16: cp = value("history");
17: if (*cp == 0)
18: histlen = 0;
19: else {
20: while (*cp && digit(*cp))
21: cp++;
22: /* avoid a looping snafu */
23: if (*cp)
24: set("history", "10");
25: histlen = getn(value("history"));
26: }
27: /* throw away null lines */
28: if (sp->next->word[0] == '\n')
29: return;
30: for (hp = &Histlist; np = hp->Hnext;)
31: if (eventno - np->Href >= histlen || histlen == 0)
32: hp->Hnext = np->Hnext, hfree(np);
33: else
34: hp = np;
35: enthist(++eventno, sp, 1);
36: }
37:
38: struct Hist *
39: enthist(event, lp, docopy)
40: int event;
41: register struct wordent *lp;
42: bool docopy;
43: {
44: register struct Hist *np;
45:
46: np = (struct Hist *) calloc(1, sizeof *np);
47: np->Hnum = np->Href = event;
48: if (docopy)
49: copylex(&np->Hlex, lp);
50: else {
51: np->Hlex.next = lp->next;
52: lp->next->prev = &np->Hlex;
53: np->Hlex.prev = lp->prev;
54: lp->prev->next = &np->Hlex;
55: }
56: np->Hnext = Histlist.Hnext;
57: Histlist.Hnext = np;
58: return (np);
59: }
60:
61: hfree(hp)
62: register struct Hist *hp;
63: {
64:
65: freelex(&hp->Hlex);
66: xfree(hp);
67: }
68:
69: dohist()
70: {
71:
72: if (getn(value("history")) == 0)
73: return;
74: dohist1(Histlist.Hnext);
75: }
76:
77: dohist1(hp)
78: register struct Hist *hp;
79: {
80:
81: if (hp == 0)
82: return;
83: hp->Href++;
84: dohist1(hp->Hnext);
85: phist(hp);
86: }
87:
88: phist(hp)
89: register struct Hist *hp;
90: {
91:
92: printf("%6d\t", hp->Hnum);
93: prlex(&hp->Hlex);
94: }
Defined functions
hfree
defined in line
61; used 1 times
phist
defined in line
88; used 1 times