From 45964d3df9a076f515cdc43b4edaa6391d444c83 Mon Sep 17 00:00:00 2001 From: Bill Joy Date: Fri, 15 Dec 1978 01:32:54 -0800 Subject: [PATCH] BSD 3 development Work on file usr/src/cmd/apropos.c Work on file usr/src/cmd/expand.c Work on file usr/src/cmd/iul.c Work on file usr/src/cmd/fold.c Work on file usr/src/cmd/ssp.c Work on file usr/src/cmd/soelim.c Synthesized-from: 3bsd --- usr/src/cmd/apropos.c | 96 +++++++++++++++++++++++++++++ usr/src/cmd/expand.c | 111 +++++++++++++++++++++++++++++++++ usr/src/cmd/fold.c | 94 ++++++++++++++++++++++++++++ usr/src/cmd/iul.c | 139 ++++++++++++++++++++++++++++++++++++++++++ usr/src/cmd/soelim.c | 100 ++++++++++++++++++++++++++++++ usr/src/cmd/ssp.c | 71 +++++++++++++++++++++ 6 files changed, 611 insertions(+) create mode 100644 usr/src/cmd/apropos.c create mode 100644 usr/src/cmd/expand.c create mode 100644 usr/src/cmd/fold.c create mode 100644 usr/src/cmd/iul.c create mode 100644 usr/src/cmd/soelim.c create mode 100644 usr/src/cmd/ssp.c diff --git a/usr/src/cmd/apropos.c b/usr/src/cmd/apropos.c new file mode 100644 index 0000000000..4b4a83400b --- /dev/null +++ b/usr/src/cmd/apropos.c @@ -0,0 +1,96 @@ +#include +#include + +main(argc, argv) + int argc; + char *argv[]; +{ + + argc--, argv++; + if (argc == 0) { +usage: + fprintf(stderr, "apropos word ...\n"); + exit(1); + } + if (freopen("/usr/lib/whatis", "r", stdin) == NULL) { + perror("/usr/lib/whatis"); + exit (1); + } + argv[argc] = 0; + apropos(argv); + exit(0); +} + +apropos(argv) + char **argv; +{ + char buf[BUFSIZ]; + char *gotit; + register char **vp; + + gotit = (char *) calloc(1, blklen(argv)); + while (fgets(buf, sizeof buf, stdin) != NULL) + for (vp = argv; *vp; vp++) + if (match(buf, *vp)) { + printf("%s", buf); + gotit[vp - argv] = 1; + for (vp++; *vp; vp++) + if (match(buf, *vp)) + gotit[vp - argv] = 1; + break; + } + for (vp = argv; *vp; vp++) + if (gotit[vp - argv] == 0) + printf("%s: nothing apropriate\n", *vp); +} + +match(buf, str) + char *buf, *str; +{ + register char *bp, *cp; + + bp = buf; + for (;;) { + if (*bp == 0) + return (0); + if (amatch(bp, str)) + return (1); + bp++; + } +} + +amatch(cp, dp) + register char *cp, *dp; +{ + + while (*cp && *dp && lmatch(*cp, *dp)) + cp++, dp++; + if (*dp == 0) + return (1); + return (0); +} + +lmatch(c, d) + char c, d; +{ + + if (c == d) + return (1); + if (!isalpha(c) || !isalpha(d)) + return (0); + if (islower(c)) + c = toupper(c); + if (islower(d)) + d = toupper(d); + return (c == d); +} + +blklen(ip) + register int *ip; +{ + register int i = 0; + + while (*ip++) + i++; + return (i); +} diff --git a/usr/src/cmd/expand.c b/usr/src/cmd/expand.c new file mode 100644 index 0000000000..4dc6d8718b --- /dev/null +++ b/usr/src/cmd/expand.c @@ -0,0 +1,111 @@ +#include +/* + * expand - expand tabs to equivalent spaces + */ +char obuf[BUFSIZ]; +int nstops; +int tabstops[100]; + +main(argc, argv) + int argc; + char *argv[]; +{ + register int c, column; + register int n; + + setbuf(stdout, obuf); + argc--, argv++; + do { + while (argc > 0 && argv[0][0] == '-') { + getstops(argv[0]); + argc--, argv++; + } + if (argc > 0) { + if (freopen(argv[0], "r", stdin) == NULL) { + perror(argv[0]); + exit(1); + } + argc--, argv++; + } + column = 0; + for (;;) { + c = getc(stdin); + if (c == -1) + break; + switch (c) { + + case '\t': + if (nstops == 0) { + do { + putchar(' '); + column++; + } while (column & 07); + continue; + } + if (nstops == 1) { + do { + putchar(' '); + column++; + } while (((column - 1) % tabstops[0]) != (tabstops[0] - 1)); + continue; + } + for (n = 0; n < nstops; n++) + if (tabstops[n] > column) + break; + if (n == nstops) { + putchar(' '); + column++; + continue; + } + while (column < tabstops[n]) { + putchar(' '); + column++; + } + continue; + + case '\b': + if (column) + column--; + putchar('\b'); + continue; + + default: + putchar(c); + column++; + continue; + + case '\n': + putchar(c); + column = 0; + continue; + } + } + } while (argc > 0); + exit(0); +} + +getstops(cp) + register char *cp; +{ + register int i; + + nstops = 0; + cp++; + for (;;) { + i = 0; + while (*cp >= '0' && *cp <= '9') + i = i * 10 + *cp++ - '0'; + if (i <= 0 || i > 256) { +bad: + fprintf(stderr, "Bad tab stop spec\n"); + exit(1); + } + if (nstops > 0 && i <= tabstops[nstops]) + goto bad; + tabstops[nstops++] = i; + if (*cp == 0) + break; + if (*cp++ != ',') + goto bad; + } +} diff --git a/usr/src/cmd/fold.c b/usr/src/cmd/fold.c new file mode 100644 index 0000000000..ab968ee0fd --- /dev/null +++ b/usr/src/cmd/fold.c @@ -0,0 +1,94 @@ +#include +/* + * fold - fold long lines for finite output devices + * + * Bill Joy UCB June 28, 1977 + */ + +int fold = 80; + +main(argc, argv) + int argc; + char *argv[]; +{ + register c; + FILE *f; + char obuf[BUFSIZ]; + + argc--, argv++; + setbuf(stdout, obuf); + if (argc > 0 && argv[0][0] == '-') { + fold = 0; + argv[0]++; + while (*argv[0] >= '0' && *argv[0] <= '9') + fold =* 10, fold =+ *argv[0]++ - '0'; + if (*argv[0]) { + printf("Bad number for fold\n"); + exit(1); + } + argc--, argv++; + } + do { + if (argc > 0) { + if (freopen(argv[0], "r", stdin) == NULL) { + perror(argv[0]); + exit(1); + } + argc--, argv++; + } + for (;;) { + c = getc(stdin); + if (c == -1) + break; + putch(c); + } + } while (argc > 0); + exit(0); +} + +int col; + +putch(c) + register c; +{ + register ncol; + + switch (c) { + case '\n': + ncol = 0; + break; + case '\t': + ncol = (col + 8) &~ 7; + break; + case '\b': + ncol = col ? col - 1 : 0; + break; + case '\r': + ncol = 0; + break; + default: + ncol = col + 1; + } + if (ncol > fold) + putchar('\n'), col = 0; + putchar(c); + switch (c) { + case '\n': + col = 0; + break; + case '\t': + col =+ 8; + col =& ~7; + break; + case '\b': + if (col) + col--; + break; + case '\r': + col = 0; + break; + default: + col++; + break; + } +} diff --git a/usr/src/cmd/iul.c b/usr/src/cmd/iul.c new file mode 100644 index 0000000000..dd534aed14 --- /dev/null +++ b/usr/src/cmd/iul.c @@ -0,0 +1,139 @@ +#include + +#define BACKSPACE 0 +#define QUOTE 0200 +/* + * iul - a cat like program to indicate underlining for graphic terminals + * + * Bill Joy UCB June 22, 1977 + * + * This program was a piece of the editor ex. + */ + +#define LBSIZE 512 + +char linebuf[LBSIZE], genbuf[LBSIZE]; +char *strcpy(); + +main(argc, argv) + int argc; + char *argv[]; +{ + register c; + register char *lp; + char obuf[BUFSIZ]; + + setbuf(stdout, obuf); + argc--; + argv++; + do { + if (argc > 0) { + if (freopen(argv[0], "r", stdin) == NULL) { + perror(argv[0]); + exit(1); + } + argc--; argv++; + } + while (fgets(linebuf, sizeof linebuf, stdin) != 0) { + for (lp = linebuf; *lp; lp++) + continue; + *--lp = 0; + doulg(); + dographic(); + if (genbuf[0]) + printf("\n%s", genbuf); + putchar('\n'); + fflush(stdout); + } + } while (argc > 0); + exit(0); +} + +dographic() +{ + register char *lp; + register c; + + for (lp = linebuf; c = *lp++;) { + switch (c) { + case '\b': + if (BACKSPACE == 0) + c = '?'; + break; + default: + if (c < ' ' || c == 0177) + c = '?'; + break; + case '\t': + break; + } + putchar(c); + } +} + +doulg() +{ + register char *lp, *gp; + char *maxgp; + register c; + char csw; + int col; + + gp = genbuf; + *gp = 0; + maxgp = gp; + col = 0; + for (lp = linebuf; c = *lp++;) { + switch (c) { + case '\t': + while ((col & 7) != 7) { + *gp++ = ' '; + if (gp >= &genbuf[LBSIZE - 2]) + goto ovflo; + col++; + } + break; + default: + if (gp >= maxgp) + break; + c =| (*gp & QUOTE); + break; + case '_': + if (gp >= maxgp) + c = QUOTE; + else + c = *gp | QUOTE; + break; + case '\b': + if (gp > genbuf) { + gp--; + col--; + } + continue; + } + if (gp >= &genbuf[LBSIZE - 2]) { +ovflo: + fprintf(stderr, "Line too long\n"); + exit(1); + } + *gp++ = c; + if (gp > maxgp) + maxgp = gp; + col++; + } + *maxgp = 0; + strcpy(linebuf, genbuf); + for (lp = linebuf, gp = genbuf; c = *lp; gp++, lp++) + if (c & QUOTE) { + c =& 0177; + if (c == 0) + *lp = '_', *gp = ' '; + else + *lp = c, *gp = '-'; + } else + *gp = ' '; + --gp; + while (gp >= genbuf && *gp == ' ') + --gp; + gp[1] = 0; +} diff --git a/usr/src/cmd/soelim.c b/usr/src/cmd/soelim.c new file mode 100644 index 0000000000..39699b5710 --- /dev/null +++ b/usr/src/cmd/soelim.c @@ -0,0 +1,100 @@ +#include +/* + * soelim - a filter to process n/troff input eliminating .so's + * + * Author: Bill Joy UCB July 8, 1977 + * + * This program eliminates .so's from a n/troff input stream. + * It can be used to prepare safe input for submission to the + * phototypesetter since the software supporting the operator + * doesn't let him do chdir. + * + * This is a kludge and the operator should be given the + * ability to do chdir. + * + * This program is more generally useful, it turns out, because + * the program tbl doesn't understand ".so" directives. + */ + +main(argc, argv) + int argc; + char *argv[]; +{ + + argc--; + argv++; + if (argc == 0) { + fprintf(stderr, "Usage: %s file [ file ... ]\n", argv[-1]); + exit(1); + } + do { + process(argv[0]); + argv++; + argc--; + } while (argc > 0); + exit(0); +} + +process(file) + char *file; +{ + register char *cp; + register int c; + char fname[BUFSIZ]; + FILE *soee; + + soee = fopen(file, "r"); + if (soee == NULL) { + perror(file); + return; + } + for (;;) { + c = getc(soee); + if (c < 0) + break; + if (c != '.') + goto simple; + c = getc(soee); + if (c != 's') { + putchar('.'); + goto simple; + } + c = getc(soee); + if (c != 'o') { + printf(".s"); + goto simple; + } + do + c = getc(soee); + while (c == ' ' || c == '\t'); + cp = fname; + for (;;) { + switch (c) { + + case ' ': + case '\t': + case '\n': + case EOF: + goto donename; + + default: + *cp++ = c; + c = getc(soee); + continue; + } + } +donename: + if (cp == fname) { + printf(".so"); + goto simple; + } + *cp++ = 0; + process(fname); + continue; +simple: + if (c == EOF) + break; + putchar(c); + } + fclose(soee); +} diff --git a/usr/src/cmd/ssp.c b/usr/src/cmd/ssp.c new file mode 100644 index 0000000000..b85e3c6645 --- /dev/null +++ b/usr/src/cmd/ssp.c @@ -0,0 +1,71 @@ +#include +/* + * ssp - single space output + * + * Bill Joy UCB August 25, 1977 + * + * Compress multiple empty lines to a single empty line. + * Option - compresses to nothing. + */ + +char poof, hadsome; + +int ibuf[256]; + + +main(argc, argv) + int argc; + char *argv[]; +{ + register int c; + FILE *f; + + argc--, argv++; + do { + while (argc > 0 && argv[0][0] == '-') { + poof = 1; + argc--, argv++; + } + f = stdin; + if (argc > 0) { + if ((f=fopen(argv[0], "r")) == NULL) { + fflush(f); + perror(argv[0]); + exit(1); + } + argc--, argv++; + } + for (;;) { + c = getc(f); + if (c == -1) + break; + if (c != '\n') { + hadsome = 1; + putchar(c); + continue; + } + /* + * Eat em up + */ + if (hadsome) + putchar('\n'); + c = getc(f); + if (c == -1) + break; + if (c != '\n') { + putchar(c); + hadsome = 1; + continue; + } + do + c = getc(f); + while (c == '\n'); + if (!poof && hadsome) + putchar('\n'); + if (c == -1) + break; + putchar(c); + hadsome = 1; + } + } while (argc > 0); +} -- 2.20.1