UNIX — универсальная среда программирования - Керниган Брайан Уилсон
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] = ' ';
fputs(buf, stdout);
fflush(stdout);
ttyin();
lines = 0;
}
}
#include "ttyin2.c"
#include "efopen.c"
#include "spname.c"
3.8.42 pick1
# pick: select arguments
PATH=/bin:/usr/bin
for i # for each argument
do
echo -n "$i? " >/dev/tty
read response
case $response in
y*) echo $i ;;
q*) break
esac
done </dev/tty
3.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] = ' '; /* 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("%sn", s);
}
#include "ttyin2.c"
#include "efopen.c"
3.8.44 prpages
# prpages: compute number of pages that pr will print
wc $* |
awk '!/ total$/ { n += int(($1+55) / 56) }
END { print n }'
3.8.45 put
# put: install file into history
PATH=/bin:/usr/bin
case $# in
1) HIST=$1.H ;;
*) echo 'Usage: put file' 1>&2; exit 1 ;;
esac
if test ! -r $1
then
echo "put: can't open $1" 1>&2
exit 1
fi
trap 'rm -f /tmp/put.[ab]$$; exit 1 12 15
echo -n 'Summary: '
read Summary
if get -o /tmp/put.a$$ $1 # previous version
then # 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 back
else # make a new one
echo "put: creating $HIST"
cp $1 $HIST
echo "@@@ `getname` `date` $Summary" >>$HIST
fi