int argc;
char *argv[];
{
struct stat buf;
char *name, *getlogin();
int lastsize = 0;
progname = argv[0];
if ((name = getlogin()) == NULL)
error("can't get login name", (char*)0);
if (chdir(maildir) == -1)
error("can't cd to %s", maildir);
for (;;) {
if (stat(name, &buf) == -1) /* no mailbox */
buf.st_size = 0;
if (buf.st_size > lastsize)
fprintf(stderr, "\nYou have mail\007\n");
lastsize = buf.st_size;
sleep(60);
}
}
#include "error.c"
3.8.13
checkmail.sh
# checkmail: watch mailbox for growth
PATH=/bin:/usr/bin
MAIL=/usr/spool/mail/`getname` # system dependent
t=${1-60}
x="`ls -l $MAIL`"
while :
do
y="`ls -l $MAIL`"
echo $x $y x="$y"
sleep $t
done | awk '$4 < $12 { print "You have mail" }'
3.8.14
cp.c
/* cp: minimal version */
#include <stdio.h>
#define PERMS 0644 /* RW for owner, R for group, others */
char *progname;
main(argc, argv) /* cp: copy f1 to f2 */
int argc;
char *argv[];
{
char buf[BUFSIZ];
progname = argv[0];
if (argc != 3)
error("Usage: %s from to", progname);
if ((f1 = open(argv[1], 0)) == -1)
error("can't open %s", argv[1]);
if ((f2 = creat(argv[2] , PERMS)) == -1)
error("can't create %s", argv[2]);
while ((n = read(f1, buf, BUFSIZ)) > 0)
if (write(f2, buf, n) != n)
error("write error", (char*)0);
exit(0);
}
#include "error.c"
3.8.15
doctype
# doctype: synthesize proper command line for troff
echo -n "cat $* | "
egrep -h '^\.(EQ|TS|\[|PS|IS|PP)' $* |
sort -u | awk '
/^\.PP/ { ms++ }
/^\.EQ/ { eqn++ }
/^\.TS/ { tbl++ }
/^\.PS/ { pic++ }
/^\.IS/ { ideal++ }
/^\.\[/ { refer++ }
END {
if (refer > 0) printf "refer | "
if (pic > 0) printf "pic | "
if (ideal > 0) printf "ideal | "
if (tbl > 0) printf "tbl | "
if (eqn > 0) printf "eqn | "
printf "troff "
if (ms > 0) printf "-ms"
printf "\n"
}'
3.8.16
double
awk '
FILENAME != prevfile { # new file
NR = 1 # reset line number
prevfile = FILENAME
}
NF > 0 {
if ($1 == lastword)
printf "double %s, file %s, line %d\n" ,$1,FILENAME,NR
for (i = 2; i <= NF; i++)
if ($i == $(i-1))
printf "double %s, file %s, line %d\n" ,$i, FILENAME ,NR
if (NF > 0)
lastword = $NF
}' $*
3.8.17
efopen.c
FILE *efopen(file, mode) /* fopen file, die if can't */
char *file, *mode;
{
FILE *fp, *fopen();
extern char *progname;
if ((fp = fopen(file, mode)) != NULL)