Annotation of 3BSD/cmd/sh/print.c, revision 1.1.1.1

1.1       root        1: #
                      2: /*
                      3:  * UNIX shell
                      4:  *
                      5:  * S. R. Bourne
                      6:  * Bell Telephone Laboratories
                      7:  *
                      8:  */
                      9: 
                     10: #include       "defs.h"
                     11: 
                     12: CHAR           numbuf[6];
                     13: 
                     14: 
                     15: /* printing and io conversion */
                     16: 
                     17: newline()
                     18: {      prc(NL);
                     19: }
                     20: 
                     21: blank()
                     22: {      prc(SP);
                     23: }
                     24: 
                     25: prp()
                     26: {
                     27:        IF (flags&prompt)==0 ANDF cmdadr
                     28:        THEN    prs(cmdadr); prs(colon);
                     29:        FI
                     30: }
                     31: 
                     32: VOID   prs(as)
                     33:        STRING          as;
                     34: {
                     35:        REG STRING      s;
                     36: 
                     37:        IF s=as
                     38:        THEN    write(output,s,length(s)-1);
                     39:        FI
                     40: }
                     41: 
                     42: VOID   prc(c)
                     43:        CHAR            c;
                     44: {
                     45:        IF c
                     46:        THEN    write(output,&c,1);
                     47:        FI
                     48: }
                     49: 
                     50: prt(t)
                     51:        L_INT           t;
                     52: {
                     53:        REG INT hr, min, sec;
                     54: 
                     55:        t += 30; t /= 60;
                     56:        sec=t%60; t /= 60;
                     57:        min=t%60;
                     58:        IF hr=t/60
                     59:        THEN    prn(hr); prc('h');
                     60:        FI
                     61:        prn(min); prc('m');
                     62:        prn(sec); prc('s');
                     63: }
                     64: 
                     65: prn(n)
                     66:        INT             n;
                     67: {
                     68:        itos(n); prs(numbuf);
                     69: }
                     70: 
                     71: itos(n)
                     72: {
                     73:        REG char *abuf; REG POS a, i; INT pr, d;
                     74:        abuf=numbuf; pr=FALSE; a=n;
                     75:        FOR i=10000; i!=1; i/=10
                     76:        DO      IF (pr |= (d=a/i)) THEN *abuf++=d+'0' FI
                     77:                a %= i;
                     78:        OD
                     79:        *abuf++=a+'0';
                     80:        *abuf++=0;
                     81: }
                     82: 
                     83: stoi(icp)
                     84: STRING icp;
                     85: {
                     86:        REG CHAR        *cp = icp;
                     87:        REG INT         r = 0;
                     88:        REG CHAR        c;
                     89: 
                     90:        WHILE (c = *cp, digit(c)) ANDF c ANDF r>=0
                     91:        DO r = r*10 + c - '0'; cp++ OD
                     92:        IF r<0 ORF cp==icp
                     93:        THEN    failed(icp,badnum);
                     94:        ELSE    return(r);
                     95:        FI
                     96: }
                     97: 

unix.superglobalmegacorp.com

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