Annotation of 41BSD/cmd/oldcsh/sh.hist.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.