C roff is now even closer to B: for loops are now while loops.

This commit is contained in:
Warren Toomey
2016-03-29 08:12:46 +10:00
parent fd5c06efab
commit bf1914f388
+315 -135
View File
@@ -1,5 +1,3 @@
/* roff - text justifier Author: George L. Sicherman */
/* /*
* roff - C version. * roff - C version.
* the Colonel. 19 May 1983. * the Colonel. 19 May 1983.
@@ -14,6 +12,12 @@
* Fixes to long-line hang and .bp by Dave Tutelman, 30 Mar 1985. * Fixes to long-line hang and .bp by Dave Tutelman, 30 Mar 1985.
* Fix to centering valve with long input lines, 4 May 1987. * Fix to centering valve with long input lines, 4 May 1987.
*/ */
/*
* This version from ftp://minnie.tuhs.org/minix/1.5/Source/commands/roff.c
* and then modified to be closer to the functionality of the B language
* so that it can be translated into B for the PDP-7 version of Unix.
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -23,6 +27,7 @@
#define UNDERL '\200' #define UNDERL '\200'
int spacechars[] = { ' ', '\t', '\n', 0 }; int spacechars[] = { ' ', '\t', '\n', 0 };
int holdword[MAXLENGTH], *holdp; int holdword[MAXLENGTH], *holdp;
int assyline[MAXLENGTH]; int assyline[MAXLENGTH];
int assylen; int assylen;
@@ -37,7 +42,9 @@ int o_in = 0; /* INDENT SIZE */
int o_ix = -1; /* NEXT INDENT SIZE */ int o_ix = -1; /* NEXT INDENT SIZE */
int o_ta[20] = { int o_ta[20] = {
9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105,
113, 121, 129, 137, 145, 153, 161}; 113, 121, 129, 137, 145, 153, 161
};
int n_ta = 20; /* #TAB STOPS */ int n_ta = 20; /* #TAB STOPS */
int o_ll = 65, o_ad = 1, o_po = 0, o_ls = 1, o_ig = 0, o_fi = 1; int o_ll = 65, o_ad = 1, o_po = 0, o_ls = 1, o_ig = 0, o_fi = 1;
int o_pl = 66, o_ro = 0, o_hx = 0, o_sp = 0, o_sk = 0; int o_pl = 66, o_ro = 0, o_hx = 0, o_sp = 0, o_sk = 0;
@@ -91,6 +98,7 @@ int *request[]= {
(int[]){'u', 'l', 0}, (int[]){'u', 'l', 0},
NULL NULL
}; };
int c; /* LAST CHAR READ */ int c; /* LAST CHAR READ */
int main(int argc, char **argv); int main(int argc, char **argv);
@@ -142,7 +150,8 @@ int main(argc, argv)
int argc; int argc;
char **argv; char **argv;
{ {
while (--argc) switch (**++argv) { while (--argc)
switch (**++argv) {
default: default:
argc++; argc++;
goto endargs; goto endargs;
@@ -166,21 +175,26 @@ endargs:
} }
writebreak(); writebreak();
endpage(); endpage();
for (; o_sk; o_sk--) blankpage(); while (o_sk) {
blankpage();
o_sk--;
}
return (0); return (0);
} }
void readfile() void readfile()
{ {
startwhile1:
while (readline()) { while (readline()) {
if (isrequest) continue; if (isrequest)
goto startwhile1;
if (o_ce || !o_fi) { if (o_ce || !o_fi) {
if (assylen) if (assylen)
writeline(0, 1); writeline(0, 1);
else else
blankline(); blankline();
if (o_ce) o_ce--; if (o_ce)
o_ce--;
} }
} }
} }
@@ -198,14 +212,17 @@ int readline()
goto out; goto out;
} else if (isspace(c)) } else if (isspace(c))
writebreak(); writebreak();
for (;;) { startfor1:
while (1) {
if (c == EOF) { if (c == EOF) {
if (doingword) bumpword(); if (doingword)
break; bumpword();
goto out;
} }
if (c != o_cc && o_ig) { if (c != o_cc && o_ig) {
while (c != '\n' && c != EOF) c = suck(); while (c != '\n' && c != EOF)
break; c = suck();
goto out;
} }
if (isspace(c) && !doingword) { if (isspace(c) && !doingword) {
startline = 0; startline = 0;
@@ -213,11 +230,14 @@ int readline()
case ' ': case ' ':
assyline[assylen++] = ' '; assyline[assylen++] = ' ';
break; break;
case '\t': tabulate(); break; case '\t':
case '\n': goto out; tabulate();
break;
case '\n':
goto out;
} }
c = suck(); c = suck();
continue; goto startfor1;
} }
if (isspace(c) && doingword) { if (isspace(c) && doingword) {
bumpword(); bumpword();
@@ -226,7 +246,8 @@ int readline()
else if (assylen) else if (assylen)
assyline[assylen++] = ' '; assyline[assylen++] = ' ';
doingword = 0; doingword = 0;
if (c == '\n') break; if (c == '\n')
goto out;
} }
if (!isspace(c)) { if (!isspace(c)) {
if (doingword) if (doingword)
@@ -244,8 +265,10 @@ int readline()
c = suck(); c = suck();
} }
out: out:
if (o_ul) o_ul--; if (o_ul)
if (o_li) o_li--; o_ul--;
if (o_li)
o_li--;
return c != EOF; return c != EOF;
} }
@@ -262,7 +285,8 @@ void bumpword()
/* /*
* Tutelman's fix #1, modified by the Colonel. * Tutelman's fix #1, modified by the Colonel.
*/ */
if (!o_fi || o_ce) goto giveup; if (!o_fi || o_ce)
goto giveup;
/* /*
* We use a while-loop in case of ridiculously long words with * We use a while-loop in case of ridiculously long words with
* multiple hyphenation indicators. * multiple hyphenation indicators.
@@ -279,12 +303,12 @@ void bumpword()
/* /*
* There are hyphenation marks. Use them! * There are hyphenation marks. Use them!
*/ */
for (hc = strend(holdword); hc >= holdword; hc--) { hc = strend(holdword);
while (hc >= holdword) {
if ((*hc & ~UNDERL) != o_hc) if ((*hc & ~UNDERL) != o_hc)
continue; continue;
*hc = '\0'; *hc = '\0';
if (assylen + reallen(holdword) + 1 > if (assylen + reallen(holdword) + 1 > o_ll - IDTLEN) {
o_ll - IDTLEN) {
*hc = o_hc; *hc = o_hc;
continue; continue;
} }
@@ -297,13 +321,17 @@ void bumpword()
Strcat(assyline, minus); Strcat(assyline, minus);
assylen += Strlen(holdword) + 1; assylen += Strlen(holdword) + 1;
Strcpy(holdword, ++hc); Strcpy(holdword, ++hc);
break; /* STOP LOOKING */ goto out2; /* STOP LOOKING */
hc--; /* How do we get here? */
} /* for */ } /* for */
out2:
/* /*
* It won't fit, or we've succeeded in breaking the word. * It won't fit, or we've succeeded in breaking the word.
*/ */
writeline(o_ad, 0); writeline(o_ad, 0);
if (hc < holdword) goto giveup; if (hc < holdword)
goto giveup;
} else { } else {
/* /*
* If no hyphenation marks, give up. * If no hyphenation marks, give up.
@@ -318,7 +346,8 @@ giveup:
/* /*
* remove hyphenation marks, even if hyphenation is disabled. * remove hyphenation marks, even if hyphenation is disabled.
*/ */
if (o_hc) dehyph(holdword); if (o_hc)
dehyph(holdword);
Strcpy(&assyline[assylen], holdword); Strcpy(&assyline[assylen], holdword);
assylen += Strlen(holdword); assylen += Strlen(holdword);
holdp = holdword; holdp = holdword;
@@ -332,8 +361,12 @@ void dehyph(s)
int *s; int *s;
{ {
int *t; int *t;
for (t = s; *s; s++) t = s;
if ((*s & ~UNDERL) != o_hc) *t++ = *s; while (*s) {
if ((*s & ~UNDERL) != o_hc)
*t++ = *s;
s++;
}
*t = '\0'; *t = '\0';
} }
@@ -346,19 +379,25 @@ int *s;
{ {
int n; int n;
n = 0; n = 0;
while (*s) n += (o_hc != (~UNDERL & *s++)); while (*s)
n += (o_hc != (~UNDERL & *s++));
return n; return n;
} }
void tabulate() void tabulate()
{ {
int j; int j;
for (j = 0; j < n_ta; j++) j = 0;
while (j < n_ta) {
if (o_ta[j] - 1 > assylen + IDTLEN) { if (o_ta[j] - 1 > assylen + IDTLEN) {
for (; assylen + IDTLEN < o_ta[j] - 1; assylen++) while (assylen + IDTLEN < o_ta[j] - 1) {
assyline[assylen] = o_tc; assyline[assylen] = o_tc;
assylen++;
}
return; return;
} }
j++;
}
/* NO TAB STOPS REMAIN */ /* NO TAB STOPS REMAIN */
assyline[assylen++] = o_tc; assyline[assylen++] = o_tc;
@@ -368,9 +407,11 @@ int readreq()
{ {
int req[3]; int req[3];
int r, s; int r, s;
if (skipsp()) return c != EOF; if (skipsp())
return c != EOF;
c = suck(); c = suck();
if (c == EOF || c == '\n') return c != EOF; if (c == EOF || c == '\n')
return c != EOF;
if (c == '.') { if (c == '.') {
o_ig = 0; o_ig = 0;
do do
@@ -379,7 +420,8 @@ int readreq()
return c != EOF; return c != EOF;
} }
if (o_ig) { if (o_ig) {
while (c != EOF && c != '\n') c = suck(); while (c != EOF && c != '\n')
c = suck();
return c != EOF; return c != EOF;
} }
req[0] = c; req[0] = c;
@@ -389,9 +431,13 @@ int readreq()
else else
req[1] = c; req[1] = c;
req[2] = '\0'; req[2] = '\0';
for (r = 0; request[r]; r++) { r = 0;
if (!Strcmp(request[r], req)) break; while (request[r]) {
if (!Strcmp(request[r], req))
goto out3;
r++;
} }
out3:
if (!request[r]) { if (!request[r]) {
do do
(c = suck()); (c = suck());
@@ -403,7 +449,9 @@ int readreq()
o_ad = 1; o_ad = 1;
writebreak(); writebreak();
break; break;
case 1: /* ar */ o_ro = 0; break; case 1: /* ar */
o_ro = 0;
break;
case 2: /* bp */ case 2: /* bp */
case 27: /* pa */ case 27: /* pa */
c = snread(&r, &s, 1); c = snread(&r, &s, 1);
@@ -422,7 +470,9 @@ int readreq()
beginpage(); beginpage();
} }
break; break;
case 3: /* br */ writebreak(); break; case 3: /* br */
writebreak();
break;
case 4: /* cc */ case 4: /* cc */
c = cread(&o_cc); c = cread(&o_cc);
break; break;
@@ -459,9 +509,15 @@ int readreq()
c = tread(ehead); c = tread(ehead);
Strcpy(ohead, ehead); Strcpy(ohead, ehead);
break; break;
case 13: /* hx */ o_hx = 1; break; case 13: /* hx */
case 14: /* hy */ nread(&o_hy); break; o_hx = 1;
case 15: /* ig */ o_ig = 1; break; break;
case 14: /* hy */
nread(&o_hy);
break;
case 15: /* ig */
o_ig = 1;
break;
case 16: /* in */ case 16: /* in */
writebreak(); writebreak();
snset(&o_in); snset(&o_in);
@@ -471,9 +527,15 @@ int readreq()
snset(&o_ix); snset(&o_ix);
o_in = o_ix; o_in = o_ix;
break; break;
case 18: /* li */ nread(&o_li); break; case 18: /* li */
case 19: /* ll */ snset(&o_ll); break; nread(&o_li);
case 20: /* ls */ snset(&o_ls); break; break;
case 19: /* ll */
snset(&o_ll);
break;
case 20: /* ls */
snset(&o_ls);
break;
case 21: /* na */ case 21: /* na */
o_ad = 0; o_ad = 0;
writebreak(); writebreak();
@@ -490,17 +552,27 @@ int readreq()
o_fi = 0; o_fi = 0;
writebreak(); writebreak();
break; break;
case 24: /* nn */ snset(&o_nn); break; case 24: /* nn */
snset(&o_nn);
break;
case 25: /* of */ case 25: /* of */
c = tread(ofoot); c = tread(ofoot);
break; break;
case 26: /* oh */ case 26: /* oh */
c = tread(ohead); c = tread(ohead);
break; break;
case 28: /* pl */ snset(&o_pl); break; case 28: /* pl */
case 29: /* po */ snset(&o_po); break; snset(&o_pl);
case 30: /* ro */ o_ro = 1; break; break;
case 31: /* sk */ nread(&o_sk); break; case 29: /* po */
snset(&o_po);
break;
case 30: /* ro */
o_ro = 1;
break;
case 31: /* sk */
nread(&o_sk);
break;
case 32: /* sp */ case 32: /* sp */
nread(&o_sp); nread(&o_sp);
writebreak(); writebreak();
@@ -509,7 +581,9 @@ int readreq()
writebreak(); writebreak();
o_ls = 1; o_ls = 1;
break; break;
case 34: /* ta */ do_ta(); break; case 34: /* ta */
do_ta();
break;
case 35: /* tc */ case 35: /* tc */
c = cread(&o_tc); c = cread(&o_tc);
break; break;
@@ -523,10 +597,15 @@ int readreq()
else else
o_ti = r; o_ti = r;
break; break;
case 37: /* tr */ do_tr(); break; case 37: /* tr */
case 38: /* ul */ nread(&o_ul); break; do_tr();
break;
case 38: /* ul */
nread(&o_ul);
break;
} }
while (c != EOF && c != '\n') c = suck(); while (c != EOF && c != '\n')
c = suck();
return c != EOF; return c != EOF;
} }
@@ -548,9 +627,11 @@ int *s;
{ {
int leadbl; int leadbl;
leadbl = 0; leadbl = 0;
for (;;) { startfor2:
while (1) {
c = suck(); c = suck();
if (c == ' ' && !leadbl) continue; if (c == ' ' && !leadbl)
goto startfor2;
if (c == EOF || c == '\n') { if (c == EOF || c == '\n') {
*s = '\0'; *s = '\0';
return c; return c;
@@ -566,17 +647,22 @@ int *i;
int f; int f;
f = 0; f = 0;
*i = 0; *i = 0;
if (!skipsp()) for (;;) { if (!skipsp())
while (1) {
c = suck(); c = suck();
if (c == EOF) break; if (c == EOF)
if (isspace(c)) break; goto out4;
if (isspace(c))
goto out4;
if (isdigit(c)) { if (isdigit(c)) {
f++; f++;
*i = *i * 10 + c - '0'; *i = *i * 10 + c - '0';
} else } else
break; goto out4;
} }
if (!f) *i = 1; out4:
if (!f)
*i = 1;
} }
int snread(i, s, sdef) int snread(i, s, sdef)
@@ -584,14 +670,16 @@ int *i, *s, sdef;
{ {
int f; int f;
f = *i = *s = 0; f = *i = *s = 0;
for (;;) { startfor3:
while (1) {
c = suck(); c = suck();
if (c == EOF || c == '\n') break; if (c == EOF || c == '\n')
goto out5;
if (isspace(c)) { if (isspace(c)) {
if (f) if (f)
break; goto out5;
else else
continue; goto startfor3;
} }
if (isdigit(c)) { if (isdigit(c)) {
f++; f++;
@@ -600,9 +688,11 @@ int *i, *s, sdef;
f++; f++;
*s = c == '+' ? 1 : -1; *s = c == '+' ? 1 : -1;
} else } else
break; goto out5;
} }
while (c != EOF && c != '\n') c = suck(); out5:
while (c != EOF && c != '\n')
c = suck();
if (!f) { if (!f) {
*i = 1; *i = 1;
*s = sdef; *s = sdef;
@@ -615,11 +705,15 @@ int *k;
{ {
int u; int u;
*k = -1; *k = -1;
for (;;) { startfor4:
while (1) {
u = suck(); u = suck();
if (u == EOF || u == '\n') return u; if (u == EOF || u == '\n')
if (isspace(u)) continue; return u;
if (*k < 0) *k = u; if (isspace(u))
goto startfor4;
if (*k < 0)
*k = u;
} }
} }
@@ -627,13 +721,14 @@ void do_ta()
{ {
int v; int v;
n_ta = 0; n_ta = 0;
for (;;) { while (1) {
nread(&v); nread(&v);
if (v == 1) if (v == 1)
return; return;
else else
o_ta[n_ta++] = v; o_ta[n_ta++] = v;
if (c == '\n' || c == EOF) break; if (c == '\n' || c == EOF)
return;
} }
} }
@@ -642,24 +737,29 @@ void do_tr()
int *t; int *t;
t = &o_tr[0][0]; t = &o_tr[0][0];
*t = '\0'; *t = '\0';
if (skipsp()) return; if (skipsp())
for (;;) { return;
while (1) {
c = suck(); c = suck();
if (c == EOF || c == '\n') break; if (c == EOF || c == '\n')
goto out6;
*t++ = c; *t++ = c;
} }
out6:
*t = '\0'; *t = '\0';
} }
int skipsp() int skipsp()
{ {
for (;;) switch (c = suck()) { startfor5:
while (1)
switch (c = suck()) {
case EOF: case EOF:
case '\n': case '\n':
return 1; return 1;
case ' ': case ' ':
case '\t': case '\t':
continue; goto startfor5;
default: default:
ungetc(c, File); ungetc(c, File);
return 0; return 0;
@@ -669,19 +769,25 @@ int skipsp()
void writebreak() void writebreak()
{ {
int q; int q;
if (assylen) writeline(0, 1); if (assylen)
writeline(0, 1);
q = TXTLEN; q = TXTLEN;
if (o_sp) { if (o_sp) {
if (o_sp + line_no > q) if (o_sp + line_no > q)
newpage(); newpage();
else if (line_no) else if (line_no) {
for (; o_sp; o_sp--) blankline(); while (o_sp) {
blankline();
o_sp--;
}
}
} }
} }
void blankline() void blankline()
{ {
if (line_no >= TXTLEN) newpage(); if (line_no >= TXTLEN)
newpage();
spit('\n'); spit('\n');
line_no++; line_no++;
} }
@@ -691,36 +797,65 @@ int adflag, flushflag;
{ {
int j, q; int j, q;
int lnstring[7]; int lnstring[7];
for (j = assylen - 1; j; j--) { j = assylen - 1;
while (j) {
if (assyline[j] == ' ') if (assyline[j] == ' ')
assylen--; assylen--;
else else
break; goto out7;
j--;
} }
out7:
q = TXTLEN; q = TXTLEN;
if (line_no >= q) newpage(); if (line_no >= q)
for (j = 0; j < o_po; j++) spit(' '); newpage();
if (o_nn) o_nn--; j = 0;
if (o_ce) for (j = 0; j < (o_ll - assylen + 1) / 2; j++) while (j < o_po) {
spit(' '); spit(' ');
else j++;
for (j = 0; j < IDTLEN; j++) spit(' '); }
if (adflag && !flushflag) fillline(); if (o_nn)
for (j = 0; j < assylen; j++) spit(assyline[j]); o_nn--;
if (o_ce) {
j = 0;
while (j < (o_ll - assylen + 1) / 2) {
spit(' ');
j++;
}
} else {
j = 0;
while (j < IDTLEN) {
spit(' ');
j++;
}
}
if (adflag && !flushflag)
fillline();
j = 0;
while (j < assylen) {
spit(assyline[j]);
j++;
}
spit('\n'); spit('\n');
assylen = 0; assylen = 0;
assyline[0] = '\0'; assyline[0] = '\0';
line_no++; line_no++;
for (j = 1; j < o_ls; j++) j = 1;
if (line_no <= q) blankline(); while (j < o_ls) {
if (line_no <= q)
blankline();
j++;
}
if (!flushflag) { if (!flushflag) {
if (o_hc) dehyph(holdword); if (o_hc)
dehyph(holdword);
Strcpy(assyline, holdword); Strcpy(assyline, holdword);
assylen = Strlen(holdword); assylen = Strlen(holdword);
*holdword = '\0'; *holdword = '\0';
holdp = holdword; holdp = holdword;
} }
if (o_ix >= 0) o_in = o_ix; if (o_ix >= 0)
o_in = o_ix;
o_ix = o_ti = -1; o_ix = o_ti = -1;
} }
@@ -728,12 +863,14 @@ void fillline()
{ {
int excess, j, s, inc, spaces; int excess, j, s, inc, spaces;
adjtoggle ^= 1; adjtoggle ^= 1;
if (!(excess = o_ll - IDTLEN - assylen)) return; if (!(excess = o_ll - IDTLEN - assylen))
return;
if (excess < 0) { if (excess < 0) {
fprintf(stderr, "roff: internal error #2 [%d]\n", excess); fprintf(stderr, "roff: internal error #2 [%d]\n", excess);
exit(1); exit(1);
} }
for (j = 2;; j++) { j = 2;
while (1) {
if (adjtoggle) { if (adjtoggle) {
s = 0; s = 0;
inc = 1; inc = 1;
@@ -748,13 +885,16 @@ void fillline()
else { else {
if (0 < spaces && spaces < j) { if (0 < spaces && spaces < j) {
insrt(s - inc); insrt(s - inc);
if (inc > 0) s++; if (inc > 0)
if (!--excess) return; s++;
if (!--excess)
return;
} }
spaces = 0; spaces = 0;
} }
s += inc; s += inc;
} }
j++;
} }
} }
@@ -762,7 +902,11 @@ void insrt(p)
int p; int p;
{ {
int i; int i;
for (i = assylen; i > p; i--) assyline[i] = assyline[i - 1]; i = assylen;
while (i > p) {
assyline[i] = assyline[i - 1];
i--;
}
assylen++; assylen++;
} }
@@ -772,7 +916,10 @@ void newpage()
endpage(); endpage();
else else
page_no = 1; page_no = 1;
for (; o_sk; o_sk--) blankpage(); while (o_sk) {
blankpage();
o_sk--;
}
beginpage(); beginpage();
} }
@@ -780,14 +927,22 @@ void beginpage()
{ {
int i; int i;
writetitle(page_no & 1 ? ohead : ehead); writetitle(page_no & 1 ? ohead : ehead);
for (i = 0; i < o_m2; i++) spit('\n'); i = 0;
while (i < o_m2) {
spit('\n');
i++;
}
line_no = 0; line_no = 0;
} }
void endpage() void endpage()
{ {
int i; int i;
for (i = line_no; i < TXTLEN; i++) blankline(); i = line_no;
while (i < TXTLEN) {
blankline();
i++;
}
writetitle(page_no & 1 ? ofoot : efoot); writetitle(page_no & 1 ? ofoot : efoot);
if (o_bp < 0) if (o_bp < 0)
page_no++; page_no++;
@@ -801,13 +956,16 @@ void blankpage()
{ {
int i; int i;
writetitle(page_no & 1 ? ohead : ehead); writetitle(page_no & 1 ? ohead : ehead);
for (i = 0; i < TXTLEN; i++) spit('\n'); i = 0;
while (i < TXTLEN) {
spit('\n');
i++;
}
writetitle(page_no & 1 ? ofoot : efoot); writetitle(page_no & 1 ? ofoot : efoot);
page_no++; page_no++;
line_no = 0; line_no = 0;
} }
void writetitle(t) void writetitle(t)
int *t; int *t;
{ {
@@ -819,7 +977,11 @@ int *t;
return; return;
} }
pst = pgform(); pst = pgform();
for (j = 0; j < o_po; j++) spit(' '); j = 0;
while (j < o_po) {
spit(' ');
j++;
}
l = titlen(++t, d, Strlen(pst)); l = titlen(++t, d, Strlen(pst));
while (*t && *t != d) { while (*t && *t != d) {
if (*t == '%') if (*t == '%')
@@ -833,7 +995,11 @@ int *t;
return; return;
} }
m = titlen(++t, d, Strlen(pst)); m = titlen(++t, d, Strlen(pst));
for (j = l; j < (o_ll - m) / 2; j++) spit(' '); j = l;
while (j < (o_ll - m) / 2) {
spit(' ');
j++;
}
while (*t && *t != d) { while (*t && *t != d) {
if (*t == '%') if (*t == '%')
spits(pst); spits(pst);
@@ -850,7 +1016,11 @@ int *t;
else else
m += l; m += l;
n = titlen(++t, d, Strlen(pst)); n = titlen(++t, d, Strlen(pst));
for (j = m; j < o_ll - n; j++) spit(' '); j = m;
while (j < o_ll - n) {
spit(' ');
j++;
}
while (*t && *t != d) { while (*t && *t != d) {
if (*t == '%') if (*t == '%')
spits(pst); spits(pst);
@@ -872,8 +1042,7 @@ int s_v[]= {'v', 0 };
int s_iv[] = { 'i', 'v', 0 }; int s_iv[] = { 'i', 'v', 0 };
int s_i[] = { 'i', 0 }; int s_i[] = { 'i', 0 };
int * int *pgform()
pgform()
{ {
static int pst[11]; static int pst[11];
int i; int i;
@@ -916,7 +1085,8 @@ int *
Strcat(pst, s_iv); Strcat(pst, s_iv);
i -= 4; i -= 4;
} }
while (i--) Strcat(pst, s_i); while (i--)
Strcat(pst, s_i);
} else } else
printn(pst, page_no, 11); printn(pst, page_no, 11);
return pst; return pst;
@@ -928,14 +1098,16 @@ int k;
{ {
int q; int q;
q = 0; q = 0;
while (*t && *t != c) q += *t++ == '%' ? k : 1; while (*t && *t != c)
q += *t++ == '%' ? k : 1;
return q; return q;
} }
void spits(s) void spits(s)
int *s; int *s;
{ {
while (*s) spit(*s++); while (*s)
spit(*s++);
} }
void spit(c) void spit(c)
@@ -946,21 +1118,27 @@ int c;
int *t; int *t;
ulflag = c & UNDERL; ulflag = c & UNDERL;
c &= ~UNDERL; c &= ~UNDERL;
for (t = (int *) o_tr; *t; t++) t = (int *)o_tr;
while (*t) {
if (*t++ == c) { if (*t++ == c) {
/* /*
* fix - last int translates to space. * fix - last int translates to space.
*/ */
c = *t ? *t : ' '; c = *t ? *t : ' ';
break; goto out8;
} }
t++;
}
out8:
if (c != ' ' && c != '\n' && n_blanks) { if (c != ' ' && c != '\n' && n_blanks) {
for (; n_blanks; n_blanks--) { while (n_blanks) {
putc(' ', stdout); putc(' ', stdout);
col_no++; col_no++;
n_blanks--;
} }
} }
if (ulflag && isalnum(c)) fputs("_\b", stdout); if (ulflag && isalnum(c))
fputs("_\b", stdout);
if (c == ' ') if (c == ' ')
n_blanks++; n_blanks++;
else { else {
@@ -975,7 +1153,7 @@ int c;
int suck() int suck()
{ {
for (;;) { while (1) {
c = getc(File); c = getc(File);
if (islegal(c)) { if (islegal(c)) {
return c; return c;
@@ -987,12 +1165,14 @@ int suck()
* strhas - does string have character? Allow UNDERL flag. * strhas - does string have character? Allow UNDERL flag.
*/ */
int * int *strhas(p, c)
strhas(p, c)
int *p, c; int *p, c;
{ {
for (; *p; p++) while (*p) {
if ((*p & ~UNDERL) == c) return p; if ((*p & ~UNDERL) == c)
return p;
p++;
}
return NULL; return NULL;
} }
@@ -1000,8 +1180,7 @@ int *p, c;
* strend - find NULL at end of string. * strend - find NULL at end of string.
*/ */
int * int *strend(p)
strend(p)
int *p; int *p;
{ {
while (*p++) ; while (*p++) ;
@@ -1020,15 +1199,20 @@ int isspace(c)
int c; int c;
{ {
int *s; int *s;
for (s = spacechars; *s; s++) s = spacechars;
if (*s == c) return 1; while (*s) {
if (*s == c)
return 1;
s++;
}
return 0; return 0;
} }
int isalnum(c) int isalnum(c)
int c; int c;
{ {
return(c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'); return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0'
&& c <= '9');
} }
int isdigit(c) int isdigit(c)
@@ -1056,23 +1240,19 @@ int *s1, *s2;
int *os1; int *os1;
os1 = s1; os1 = s1;
while ((*s1++ = *s2++)) while ((*s1++ = *s2++)) ;
;
return (os1); return (os1);
} }
int * int *Strcat(s1, s2)
Strcat(s1, s2)
int *s1, *s2; int *s1, *s2;
{ {
int *os1; int *os1;
os1 = s1; os1 = s1;
while (*s1++) while (*s1++) ;
;
--s1; --s1;
while ((*s1++ = *s2++)) while ((*s1++ = *s2++)) ;
;
return (os1); return (os1);
} }