add ``history -h >file'' and ``source -h file'' to
[unix-history] / usr / src / bin / csh / hist.c
index 79e6c43..5d8a379 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)hist.c 4.1 %G%";
+static char *sccsid = "@(#)hist.c 4.3 %G%";
 
 #include "sh.h"
 
 
 #include "sh.h"
 
@@ -69,27 +69,33 @@ hfree(hp)
 dohist(vp)
        char **vp;
 {
 dohist(vp)
        char **vp;
 {
-       int n, rflg = 0;
-
+       int n, rflg = 0, hflg = 0;
        if (getn(value("history")) == 0)
                return;
        if (setintr)
                sigrelse(SIGINT);
        vp++;
        if (getn(value("history")) == 0)
                return;
        if (setintr)
                sigrelse(SIGINT);
        vp++;
-       if (*vp && eq(*vp, "-r")) {
-               rflg++;
-               vp++;
+       while (*vp[0] == '-') {
+               if (*vp && eq(*vp, "-h")) {
+                       hflg++;
+                       vp++;
+               }
+               if (*vp && eq(*vp, "-r")) {
+                       rflg++;
+                       vp++;
+               }
        }
        if (*vp)
                n = getn(*vp);
        }
        if (*vp)
                n = getn(*vp);
-       else
-               n = 1000;
-       dohist1(Histlist.Hnext, &n, rflg);
+       else {
+               n = getn(value("history"));
+       }
+       dohist1(Histlist.Hnext, &n, rflg, hflg);
 }
 
 }
 
-dohist1(hp, np, rflg)
+dohist1(hp, np, rflg, hflg)
        struct Hist *hp;
        struct Hist *hp;
-       int *np;
+       int *np, rflg, hflg;
 {
        bool print = (*np) > 0;
 top:
 {
        bool print = (*np) > 0;
 top:
@@ -98,21 +104,23 @@ top:
        (*np)--;
        hp->Href++;
        if (rflg == 0) {
        (*np)--;
        hp->Href++;
        if (rflg == 0) {
-               dohist1(hp->Hnext, np, rflg);
+               dohist1(hp->Hnext, np, rflg, hflg);
                if (print)
                if (print)
-                       phist(hp);
+                       phist(hp, hflg);
                return;
        }
        if (*np >= 0)
                return;
        }
        if (*np >= 0)
-               phist(hp);
+               phist(hp, hflg);
        hp = hp->Hnext;
        goto top;
 }
 
        hp = hp->Hnext;
        goto top;
 }
 
-phist(hp)
+phist(hp, hflg)
        register struct Hist *hp;
        register struct Hist *hp;
+       int hflg;
 {
 
 {
 
-       printf("%6d\t", hp->Hnum);
+       if (hflg == 0)
+               printf("%6d\t", hp->Hnum);
        prlex(&hp->Hlex);
 }
        prlex(&hp->Hlex);
 }