2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley Software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
18 #include "sh.tconst.h"
20 struct Hist
*enthist(int, struct wordent
*, bool);
21 void hfree(struct Hist
*);
22 void dohist1(struct Hist
*, int *, int, int);
23 void phist(struct Hist
*, int);
30 savehist(struct wordent
*sp
)
37 tprintf("TRACE- savehist()\n");
39 /* throw away null lines */
40 if (sp
->next
->word
[0] == '\n')
42 cp
= value(S_history
/*"history"*/);
51 histlen
= histlen
* 10 + *p
++ - '0';
54 for (hp
= &Histlist
; np
= hp
->Hnext
;)
55 if (eventno
- np
->Href
>= histlen
|| histlen
== 0)
56 hp
->Hnext
= np
->Hnext
, hfree(np
);
59 (void) enthist(++eventno
, sp
, 1);
63 enthist(int event
, struct wordent
*lp
, bool docopy
)
68 tprintf("TRACE- enthist()\n");
70 np
= (struct Hist
*) xalloc(sizeof *np
);
71 np
->Hnum
= np
->Href
= event
;
73 copylex(&np
->Hlex
, lp
);
75 np
->Hlex
.next
= lp
->next
;
76 lp
->next
->prev
= &np
->Hlex
;
77 np
->Hlex
.prev
= lp
->prev
;
78 lp
->prev
->next
= &np
->Hlex
;
80 np
->Hnext
= Histlist
.Hnext
;
86 hfree(struct Hist
*hp
)
89 tprintf("TRACE- hfree()\n");
99 int n
, rflg
= 0, hflg
= 0;
101 tprintf("TRACE- dohist()\n");
103 if (getn(value(S_history
/*"history"*/)) == 0)
106 (void) sigsetmask(sigblock(0) & ~sigmask(SIGINT
));
107 while (*++vp
&& **vp
== '-') {
118 case '-': /* ignore multiple '-'s */
121 printf("Unknown flag: -%c\n", *vp2
);
122 error("Usage: history [-rh] [# number of events]");
128 n
= getn(value(S_history
/*"history"*/));
130 dohist1(Histlist
.Hnext
, &n
, rflg
, hflg
);
134 dohist1(struct Hist
*hp
, int *np
, int rflg
, int hflg
)
136 bool print
= (*np
) > 0;
138 tprintf("TRACE- dohist1()\n");
146 dohist1(hp
->Hnext
, np
, rflg
, hflg
);
158 phist(struct Hist
*hp
, int hflg
)
161 tprintf("TRACE- phist()\n");
165 printf("%6d\t", hp
->Hnum
);