break; argv[i] = buf; /* fall through... */ case 0: /* exact match */ fp = efopen(argv[i], "r"); print(fp, pagesize); fclose(fp); } exit(0);}print(fp, pagesize) /* print fp in pagesize chunks */ FILE *fp; int pagesize;{ static int lines = 0; /* number of lines so far */ char buf[BUFSIZ]; while (fgets(buf, sizeof buf, fp) != NULL) if (++lines < pagesize) fputs(buf, stdout); else { buf[strlen(buf)-1] = '\0'; fputs(buf, stdout); fflush(stdout); ttyin(); lines = 0; }}#include "ttyin2.c"#include "efopen.c"#include "spname.c"3.8.42
pick1# pick: select argumentsPATH=/bin:/usr/binfor i # for each argumentdo echo -n "$i? " >/dev/tty read response case $response in y*) echo $i ;; q*) break esacdone </dev/tty3.8.43
pick.c/* pick: offer choice on each argument */#include <stdio.h>char *progname; /* program name for error message */main(argc, argv) int argc; char *argv[];{ int i; char buf[BUFSIZ]; progname = argv[0]; if (argc == 2 && strcmp(argv[1], "-") == 0) /* pick - */ while (fgets(buf, sizeof buf, stdin) != NULL) { buf[strlen(buf)-1] = '\0'; /* drop newline */ pick(buf); } for (i = 1; i < argc; i++) pick(argv[i]); exit(0);}pick(s) /* offer choice of s */ char *s;{ fprintf(stderr, "%s? ", s); if (ttyin() == 'y') printf("%s\n", s);}#include "ttyin2.c"#include "efopen.c"3.8.44
prpages# prpages: compute number of pages that pr will printwc $* |awk '!/ total$/ { n += int(($1+55) / 56) } END { print n }'3.8.45
put# put: install file into historyPATH=/bin:/usr/bincase $# in1) HIST=$1.H ;;*) echo 'Usage: put file' 1>&2; exit 1 ;;esacif test ! -r $1then echo "put: can't open $1" 1>&2 exit 1fitrap 'rm -f /tmp/put.[ab]$$; exit 1 12 15echo -n 'Summary: 'read Summaryif get -o /tmp/put.a$$ $1 # previous versionthen # merge pieces cp $1 /tmp/put.b$$ # current version echo `getname` `date` $Summary" >>/tmp/put.b$$ diff -e $1 /tmp/put.a$$ >>/tmp/put.b$$ # latest diffs sed -n '/^@@@/,$р' <$HIST >>/tmp/put.b$$ # old diffs overwrite $HIST cat /tmp/put.b$$ # put it backelse # make a new one echo "put: creating $HIST" cp $1 $HIST echo "@@@ `getname` `date` $Summary" >>$HISTfi