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