n = to1-from1 + to2-from2 + 1; /* #lines from diff */
if (cmd == 'c')
n += 2;
else if (cmd == 'a')
from1++;
else if (cmd == 'd')
from2++;
printf("%s", buf);
while (n-- 0) {
fgets(buf, sizeof buf, fin);
printf("%s", buf);
}
do {
printf("? ");
fflush(stdout);
fgets(buf, sizeof buf, stdin);
switch (buf[0]) {
case '':
nskip(f1, to1-nf1);
ncopy(f2, to2-nf2, fout);
break;
case '':
nskip(f2, to2-nf2);
ncopy(f1, to1-nf1, fout);
break;
case 'e':
ncopy(f1, from1-1-nf1, fout);
nskip(f2, from2-1-nf2);
ft = efopen(tempfile, "w");
ncopy(f1, to1+1-from1, ft);
fprintf(ft, "--- \n");
ncopy(f2, to2+1-from2, ft);
fclose(ft);
sprintf(buf2, "ed %s", tempfile);
system(buf2);
ft = efopen(tempfile, "r");
ncopy(ft, HUGE, fout);
fclose(ft);
break;
case '!':
system(buf+1);
printf("!\n");
break;
default:
printf(" or or e or !\n");
break;
}
} while (buf[0]!= '' buf[0]!= '' buf[0]! = 'e');
nf1 = to1;
nf2 = to2;
}
ncopy(f1, HUGE, fout); /* can fail on very long files */
unlink(tempfile);
}
parse(s, pfrom1, pto1, pcmd, pfrom2, pto2)
char *s;
int *pcmd, *pfrom1, *pto1, *pfrom2, *pto2;
{
#define a2i(p) while (isdigit(*s)) \
p = 10*(p) + *s++ - '0'
*pfrom1 = *pto1 = *pfrom2 = *pto2 = 0;
a2i(*pfrom1);
if (*s == ',') {
s++;
a2i(*pto1);
} else
*pto1 = *pfrom1;
*pcmd = *s++;
a2i(*pfrom2);
if (*s == ',') {
s++;
a2i(*pto2);
} else
*pto2 = *pfrom2;
}
nskip(fin, n) /* skip n lines of file fin */
FILE *fin;
{
char buf[BUFSIZ];
while (n-- 0)
fgets(buf, sizeof buf, fin);
}
ncopy(fin, n, fout) /* copy n lines from fin to fout */
FILE *fin, *fout;
{
char buf[BUFSIZ];
while (n-- 0) {
if (fgets(buf, sizeof buf, fin) == NULL)
return;
fputs(buf, fout);
}
}
#include "efopen.c"
3.8.28 makefile
files: files.o files1.o directory.o
cc files.o files1.o directory.o -o files
p0: p0.c ttyin0.c
cc p0.c ttyin0.c
clean:
rm -f *.o a.out
3.8.29 newer
# newer f: list files newer than f
ls -t | sed '/^'$1'$/q'
3.8.30 news1
# news: print news files, version 1
HOME=. # debugging only
cd . # place holder for /usr/news
for i in `ls -t * $HOME/.news_time`
do
case $i in
*/.news_time) break ;;
*) echo news: $i
esac
done
touch $HOME/.news_time
3.8.31 news2
# news: print news files, version 2
HOME=. # debugging only
cd . # place holder for /usr/news
IFS='
' # just a newline
for i in `ls -t * $HOME/.news_time 21`
do
case $i in
*' not found') ;;
*/.news_time) break ;;
*) echo news: $i ;;
esac
done
touch $HOME/.news_time
3.8.32 news3
# news: print news files, final version
PATH=/bin:/usr/bin
IFS='
' # just a newline
cd /usr/news
for i in `ls -t * $HOME/.news_time 21`
do
IFS=' '
case $i in
*' not found') ;;
*/.news_time) break ;;
*) set X`ls -l $i`
echo "
$i: ($3) $5 $6 $7
"