evas@euraiv1.UUCP (Eelco van Asperen) (10/02/87)
Here is part 9 of 9: Eelco van Asperen.
# This is a shar archive. Extract with sh, not csh.
# This archive ends with exit, so do not worry about trailing junk.
# --------------------------- cut here --------------------------
echo Extracting commands/rm.dif
sed 's/^X//' > commands/rm.dif << '+ END-OF-FILE 'commands/rm.dif
X107,109c107,109
X< stderr3 ("rm: remove ", name, " with mode ");
X< octal(s.st_mode & 0777);
X< std_err("? ");
X---
X> stderr3 ("rm: remove ", name, " (mode = ");
X> octal(s.st_mode & 0777);
X> std_err(") ? ");
X132,133c132,133
X< execl ("/bin/rmdir", "rmdir", name, 0);
X< execl ("/usr/bin/rmdir", "rmdir", name, 0);
X---
X> execl ("/bin/rmdir", "rmdir", name, (char*) 0);
X> execl ("/usr/bin/rmdir", "rmdir", name, (char*) 0);
+ END-OF-FILE commands/rm.dif
chmod u=rw,g=r,o=r commands/rm.dif
set `sum commands/rm.dif`
sum=$1
case $sum in
31036) :;;
*) echo 'Bad sum in 'commands/rm.dif >&2
esac
echo Extracting commands/rmdir.dif
sed 's/^X//' > commands/rmdir.dif << '+ END-OF-FILE 'commands/rmdir.dif
X1c1,3
X< /* rmdir - remove a directory Author: Adri Koppes */
X---
X> /* rmdir - remove a directory Author: Adri Koppes
X> * (modified by Paul Polderman)
X> */
X29a32,33
X> extern char *rindex();
X>
X37a42
X> register char *p;
X49,55c54,60
X< strcpy (dots, dirname);
X< while (dirname[fd])
X< if (dirname[fd++] == '/')
X< sl = fd;
X< dots[sl] = '\0';
X< if (access (dots, 2)) {
X< stderr2(dirname, " no permission\n");
X---
X> if (p = rindex(dirname, '/'))
X> p++;
X> else
X> p = dirname;
X>
X> if (strcmp(p, ".") == 0 || strcmp(p, "..") == 0) {
X> stderr2(dirname, " will not remove \".\" or \"..\"\n");
X59,61c64,71
X< stat ("", &cwd);
X< if ((s.st_ino == cwd.st_ino) && (s.st_dev == cwd.st_dev)) {
X< std_err ("rmdir: can't remove current directory\n");
X---
X>
X> strcpy (dots, dirname);
X> while (dirname[fd])
X> if (dirname[fd++] == '/')
X> sl = fd;
X> dots[sl] = '\0';
X> if (access (dots, 2)) {
X> stderr2(dirname, " no permission\n");
X65,67c75,77
X< if ((fd = open (dirname, 0)) < 0) {
X< stderr2("can't read ", dirname);
X< std_err("\n");
X---
X> stat ("", &cwd);
X> if ((s.st_ino == cwd.st_ino) && (s.st_dev == cwd.st_dev)) {
X> std_err ("rmdir: can't remove current directory\n");
X70a81,86
X> if ((fd = open (dirname, 0)) < 0) {
X> stderr2("can't read ", dirname);
X> std_err("\n");
X> error++;
X> return;
X> }
X81,86c97,106
X< strcat (dots, "/.");
X< unlink (dots);
X< strcat (dots, ".");
X< unlink (dots);
X< if (unlink (dirname)) {
X< stderr2("can't remove ", dirname);
X---
X> strcat (dots, "/..");
X> patch_path(dots);
X> for (p = dots; *p; p++) /* find end of dots */
X> ;
X> unlink(dots); /* dirname/.. */
X> *(p - 1) = '\0';
X> unlink(dots); /* dirname/. */
X> *(p - 3) = '\0';
X> if (unlink(dots)) { /* dirname */
X> stderr2("can't remove ", dots);
X99a120,148
X>
X> patch_path(dir)
X> char *dir; /* pathname ending with "/.." */
X> {
X> register char *p, *s;
X> struct stat pst, st;
X>
X> if (stat(dir, &pst) < 0)
X> return;
X> p = dir;
X> while (*p == '/') p++;
X> while (1) {
X> s = p; /* remember start of new pathname part */
X> while (*p && *p != '/')
X> p++; /* find next slash */
X> if (*p == '\0')
X> return; /* if end of pathname, return */
X>
X> /* check if this part of pathname == the original pathname */
X> *p = '\0';
X> stat(dir, &st);
X> if (st.st_ino == pst.st_ino && st.st_dev == pst.st_dev
X> && strcmp(s, "..") == 0)
X> return;
X> /* if not, try next part */
X> *p++ = '/';
X> while (*p == '/') p++;
X> }
X> }
+ END-OF-FILE commands/rmdir.dif
chmod u=rw,g=r,o=r commands/rmdir.dif
set `sum commands/rmdir.dif`
sum=$1
case $sum in
48972) :;;
*) echo 'Bad sum in 'commands/rmdir.dif >&2
esac
echo Extracting commands/roff.dif
sed 's/^X//' > commands/roff.dif << '+ END-OF-FILE 'commands/roff.dif
X1c1,16
X< /* roff - text justifier Author: George Sicherman */
X---
X> /* roff - text justifier Author: George L. Sicherman */
X>
X> /*
X> * roff - C version.
X> * the Colonel. 19 May 1983.
X> *
X> * Copyright 1983 by G. L. Sicherman.
X> * You may use and alter this software freely for noncommercial ends
X> * so long as you leave this message alone.
X> *
X> * Fix by Tim Maroney, 31 Dec 1984.
X> * .hc implemented, 8 Feb 1985.
X> * Fix to hyphenating with underlining, 12 Feb 1985.
X> * Fixes to long-line hang and .bp by Dave Tutelman, 30 Mar 1985.
X> * Fix to centering valve with long input lines, 4 May 1987.
X> */
X14,16c29,32
X< #define UNDERL 0200
X<
X< char cumbuf[BUFSIZ];
X---
X> #define UNDERL '\200'
X>
X> char cumbuf[BUFSIZ];
X>
X48d63
X< int center = 0;
X67d81
X<
X128,130c142,144
X< char *ttyname();
X<
X< /* This routine is not needed --
X---
X> /* This routine is not needed.
X> char *ttyname();
X>
X138c152
X< */
X---
X> * ------- end of mesg */
X145,147c159,162
X< if (center || !o_fi) {
X< if (assylen) writeline(0,1);
X< else blankline();
X---
X> if (o_ce || !o_fi) {
X> if (assylen) writeline(0,1);
X> else blankline();
X> if (o_ce) o_ce--;
X213,214d227
X< center=o_ce;
X< if (o_ce) o_ce--;
X227a241,244
X> * Tutelman's fix #1, modified by the Colonel.
X> */
X> if (!o_fi || o_ce) goto giveup;
X> /*
X242c259
X< if (*hc!=o_hc) continue;
X---
X> if ((*hc&~UNDERL)!=o_hc) continue;
X293c310
X< for (t=s; *s; s++) if (*s != o_hc) *t++ = *s;
X---
X> for (t=s; *s; s++) if ((*s&~UNDERL) != o_hc) *t++ = *s;
X307c324
X< while (*s) n += (o_hc != *s++);
X---
X> while (*s) n += (o_hc != (~UNDERL & *s++));
X372,373c389,393
X< if (s>0) o_bp=page_no-r;
X< else if (s<0) o_bp=page_no+r;
X---
X> /*
X> * Tutelman's fix #2 - the signs were reversed!
X> */
X> if (s>0) o_bp=page_no+r;
X> else if (s<0) o_bp=page_no-r;
X388,389c408,413
X< nread(&o_ce);
X< writebreak();
X---
X> /*
X> * Fix to centering. Set counter _after_ breaking! --G.L.S.
X> */
X> nread(&r);
X> writebreak();
X> o_ce = r;
X735c759
X< if (c==EOF || c=='\n') break;;
X---
X> if (c==EOF || c=='\n') break;
X836c860
X< if (center) for (j=0; j<(o_ll-assylen+1)/2; j++) spit(' ');
X---
X> if (o_ce) for (j=0; j<(o_ll-assylen+1)/2; j++) spit(' ');
X1085c1109,1112
X< c = *t;
X---
X> /*
X> * fix - last char translates to space.
X> */
X> c = *t? *t: ' ';
X1123,1125c1150
X< * strhas - does string have character?
X< * USG and BSD both have this in their libraries. Now, if
X< * they could just agree on the name of the function ...
X---
X> * strhas - does string have character? Allow UNDERL flag.
X1132c1157
X< for (; *p; p++) if (*p==c) return p;
X---
X> for (; *p; p++) if ((*p&~UNDERL)==c) return p;
+ END-OF-FILE commands/roff.dif
chmod u=rw,g=r,o=r commands/roff.dif
set `sum commands/roff.dif`
sum=$1
case $sum in
57369) :;;
*) echo 'Bad sum in 'commands/roff.dif >&2
esac
if test -f commands/sh
then echo Removing commands/sh
rm commands/sh
fi
if test -d commands/sh
then :
else echo Creating commands/sh
mkdir commands/sh
fi
echo Extracting commands/sh/sh-h.dif
sed 's/^X//' > commands/sh/sh-h.dif << '+ END-OF-FILE 'commands/sh/sh-h.dif
X88,98c88,98
X< char **dolv;
X< int dolc;
X< int exstat;
X< char gflg;
X< int talking; /* interactive (talking-type wireless) */
X< int execflg;
X< int multiline; /* \n changed to ; */
X< struct op *outtree; /* result from parser */
X<
X< xint *failpt;
X< xint *errpt;
X---
X> Extern char **dolv;
X> Extern int dolc;
X> Extern int exstat;
X> Extern char gflg;
X> Extern int talking; /* interactive (talking-type wireless) */
X> Extern int execflg;
X> Extern int multiline; /* \n changed to ; */
X> Extern struct op *outtree; /* result from parser */
X>
X> Extern xint *failpt;
X> Extern xint *errpt;
X103,104c103,105
X< } *brklist;
X< int isbreak;
X---
X> } ;
X> Extern struct brkcon *brklist;
X> Extern int isbreak;
X127,128c128,129
X< struct wdblock *wdlist;
X< struct wdblock *iolist;
X---
X> Extern struct wdblock *wdlist;
X> Extern struct wdblock *iolist;
X152,166c153,167
X< char *flag;
X<
X< char *null; /* null value for variable */
X< int intr; /* interrupt pending */
X<
X< char *trap[NSIG];
X< char ourtrap[NSIG];
X< int trapset; /* trap pending */
X<
X< int inword; /* defer traps and interrupts */
X<
X< int yynerrs; /* yacc */
X<
X< char line[LINELIM];
X< char *elinep;
X---
X> extern char *flag;
X>
X> extern char *null; /* null value for variable */
X> extern int intr; /* interrupt pending */
X>
X> Extern char *trap[NSIG];
X> Extern char ourtrap[NSIG];
X> Extern int trapset; /* trap pending */
X>
X> extern int inword; /* defer traps and interrupts */
X>
X> Extern int yynerrs; /* yacc */
X>
X> Extern char line[LINELIM];
X> extern char *elinep;
X219,226c220,227
X< struct var *vlist; /* dictionary */
X<
X< struct var *homedir; /* home directory */
X< struct var *prompt; /* main prompt */
X< struct var *cprompt; /* continuation prompt */
X< struct var *path; /* search path for commands */
X< struct var *shell; /* shell to interpret command files */
X< struct var *ifs; /* field separators */
X---
X> Extern struct var *vlist; /* dictionary */
X>
X> Extern struct var *homedir; /* home directory */
X> Extern struct var *prompt; /* main prompt */
X> Extern struct var *cprompt; /* continuation prompt */
X> Extern struct var *path; /* search path for commands */
X> Extern struct var *shell; /* shell to interpret command files */
X> Extern struct var *ifs; /* field separators */
X256c257
X< struct io iostack[NPUSH];
X---
X> Extern struct io iostack[NPUSH];
X260,263c261,266
X< #define XIO 3 /* file IO */
X<
X< /* in substitution */
X< #define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL)
X---
X> #define XIO 4 /* file IO */
X> #define XHERE 0x80 /* Any of the above inside a here document */
X> #define XMASK 0x7f /* Get the actual task */
X>
X> /* in substitution */
X> #define INSUB() ((e.iop->task&XMASK)==XGRAVE||(e.iop->task&XMASK)==XDOLL)
X300c303
X< struct ioarg temparg; /* temporary for PUSHIO */
X---
X> Extern struct ioarg temparg; /* temporary for PUSHIO */
X330c333
X< int areanum; /* current allocation area */
X---
X> Extern int areanum; /* current allocation area */
+ END-OF-FILE commands/sh/sh-h.dif
chmod u=rw,g=r,o=r commands/sh/sh-h.dif
set `sum commands/sh/sh-h.dif`
sum=$1
case $sum in
37516) :;;
*) echo 'Bad sum in 'commands/sh/sh-h.dif >&2
esac
echo Extracting commands/sh/sh1.dif
sed 's/^X//' > commands/sh/sh1.dif << '+ END-OF-FILE 'commands/sh/sh1.dif
X0a1
X> #define Extern extern
X21c22
X< char **environ; /* environment pointer */
X---
X> extern char **environ; /* environment pointer */
X40a42
X> initarea();
X163c165
X< setval(lookup("#"), putn(dolc));
X---
X> setval(lookup("#"), putn(dolc-1));
X205d206
X< register char *cp;
X213,215c214
X< cp = getcell(258);
X< garbage();
X< DELETE(cp);
X---
X> garbage();
X522c521
X< if (vp == 0 || (vp->name = space(cp-n+2)) == 0) {
X---
X> if (vp == 0 || (vp->name = space((int)(cp-n)+2)) == 0) {
X669c668
X< write(out, vp->name, findeq(vp->name) - vp->name);
X---
X> write(out, vp->name, (int)(findeq(vp->name) - vp->name));
X772,773c771,773
X< #define GROWBY 1024
X< #define SHRINKBY 256
X---
X> #define REGSIZE sizeof(struct region)
X> #define GROWBY 256
X> #undef SHRINKBY 64
X786,792c786,793
X< /*initial empty arena*/
X< extern struct region area1;
X< static struct region area2 = {&area1, BUSY};
X< static struct region area1 = {&area2, BUSY};
X< static struct region *areap = &area1;
X< static struct region *areatop = &area1;
X< static struct region *areabrk;
X---
X> /*
X> * All memory between (char *)areabot and (char *)(areatop+1) is
X> * exclusively administered by the area management routines.
X> * It is assumed that sbrk() and brk() manipulate the high end.
X> */
X> static struct region *areabot; /* bottom of area */
X> static struct region *areatop; /* top of area */
X> static struct region *areanxt; /* starting point of scan */
X795a797,807
X> initarea()
X> {
X> while ((int)sbrk(0) & ALIGN)
X> sbrk(1);
X> areabot = (struct region *)sbrk(REGSIZE);
X> areabot->next = areabot;
X> areabot->area = BUSY;
X> areatop = areabot;
X> areanxt = areabot;
X> }
X>
X800,836c812,868
X< register int rbytes;
X< register struct region *p, *q;
X< struct region *newbrk;
X<
X< if (areabrk == NULL)
X< areabrk = (struct region *)(((int)sbrk(0)+ALIGN)&~ALIGN);
X<
X< rbytes = (nbytes+sizeof(struct region)-1)/sizeof(struct region) + 1;
X< p=areap;
X< for (;;) {
X< do {
X< if (p->area > areanum) {
X< while ((q = p->next)->area > areanum)
X< p->next = q->next;
X< if (q >= p+rbytes) {
X< areap = p+rbytes;
X< if (q > areap) {
X< areap->next = p->next;
X< areap->area = FREE;
X< }
X< p->next = areap;
X< p->area = areanum;
X< return((char *)(p+1));
X< }
X< }
X< q = p; p = p->next;
X< } while (q >= areap || p < areap);
X< newbrk = (struct region *)sbrk(rbytes>=GROWBY? rbytes: GROWBY);
X< if ((int)newbrk == -1)
X< return(NULL);
X< newbrk = (struct region *)sbrk(0);
X< areatop->next = areabrk;
X< areatop->area = ((q=areabrk)!=areatop+1)? BUSY: FREE;
X< areatop = areabrk->next = newbrk-1;
X< areabrk->area = FREE; areabrk = newbrk;
X< areatop->next = &area2; areatop->area=BUSY;
X< }
X---
X> register int nregio;
X> register struct region *p, *q;
X> register i;
X>
X> if (nbytes == 0)
X> abort(); /* silly and defeats the algorithm */
X> /*
X> * round upwards and add administration area
X> */
X> nregio = (nbytes+(REGSIZE-1))/REGSIZE + 1;
X> for (p = areanxt;;) {
X> if (p->area > areanum) {
X> /*
X> * merge free cells
X> */
X> while ((q = p->next)->area > areanum)
X> p->next = q->next;
X> /*
X> * exit loop if cell big enough
X> */
X> if (q >= p + nregio)
X> goto found;
X> }
X> p = p->next;
X> if (p == areanxt)
X> break;
X> }
X> i = nregio >= GROWBY ? nregio : GROWBY;
X> p = (struct region *)sbrk(i * REGSIZE);
X> if ((int)p == -1)
X> return(NULL);
X> p--;
X> if (p != areatop)
X> abort(); /* allocated areas are contiguous */
X> q = p + i;
X> p->next = q;
X> p->area = FREE;
X> q->next = areabot;
X> q->area = BUSY;
X> areatop = q;
X> found:
X> /*
X> * we found a FREE area big enough, pointed to by 'p', and up to 'q'
X> */
X> areanxt = p + nregio;
X> if (areanxt < q) {
X> /*
X> * split into requested area and rest
X> */
X> if (areanxt+1 > q)
X> abort(); /* insufficient space left for admin */
X> areanxt->next = q;
X> areanxt->area = FREE;
X> p->next = areanxt;
X> }
X> p->area = areanum;
X> return((char *)(p+1));
X847,848c879,880
X< if (p < areap)
X< areap = p;
X---
X> if (p < areanxt)
X> areanxt = p;
X860,865c892,894
X< p = &area1;
X< do {
X< if (p->area >= a)
X< p->area = FREE;
X< p = p->next;
X< } while (p != top);
X---
X> for (p = areabot; p != top; p = p->next)
X> if (p->area >= a)
X> p->area = FREE;
X883,907c912,929
X< register int nu;
X<
X< top = areatop;
X<
X< areap = p = &area1;
X< do {
X< if (p->area>areanum) {
X< while ((q = p->next)->area > areanum)
X< p->next = q->next;
X< areap = p;
X< }
X< q = p; p = p->next;
X< } while (p != top);
X< #if STOPSHRINK == 0
X< nu = (SHRINKBY+sizeof(struct region)-1)/sizeof(struct region);
X< if (areatop >= q+nu &&
X< q->area > areanum) {
X< brk((char *)(areabrk -= nu));
X< q->next = areatop = areabrk-1;
X< areatop->next = &area2;
X< areatop->area = BUSY;
X< }
X< #endif
X< }
X<
X---
X>
X> top = areatop;
X> for (p = areabot; p != top; p = p->next) {
X> if (p->area > areanum) {
X> while ((q = p->next)->area > areanum)
X> p->next = q->next;
X> areanxt = p;
X> }
X> }
X> #ifdef SHRINKBY
X> if (areatop >= q + SHRINKBY && q->area > areanum) {
X> brk((char *)(q+1));
X> q->next = areabot;
X> q->area = BUSY;
X> areatop = q;
X> }
X> #endif
X> }
+ END-OF-FILE commands/sh/sh1.dif
chmod u=rw,g=r,o=r commands/sh/sh1.dif
set `sum commands/sh/sh1.dif`
sum=$1
case $sum in
49975) :;;
*) echo 'Bad sum in 'commands/sh/sh1.dif >&2
esac
echo Extracting commands/sh/sh2.dif
sed 's/^X//' > commands/sh/sh2.dif << '+ END-OF-FILE 'commands/sh/sh2.dif
X0a1
X> #define Extern extern
+ END-OF-FILE commands/sh/sh2.dif
chmod u=rw,g=r,o=r commands/sh/sh2.dif
set `sum commands/sh/sh2.dif`
sum=$1
case $sum in
2318) :;;
*) echo 'Bad sum in 'commands/sh/sh2.dif >&2
esac
echo Extracting commands/sh/sh3.dif
sed 's/^X//' > commands/sh/sh3.dif << '+ END-OF-FILE 'commands/sh/sh3.dif
X0a1
X> #define Extern extern
X529,530c530,531
X< *v = "/bin/sh";
X< execve(*v, v, envp);
X---
X> *v = e.linep;
X> execve("/bin/sh", v, envp);
+ END-OF-FILE commands/sh/sh3.dif
chmod u=rw,g=r,o=r commands/sh/sh3.dif
set `sum commands/sh/sh3.dif`
sum=$1
case $sum in
9698) :;;
*) echo 'Bad sum in 'commands/sh/sh3.dif >&2
esac
echo Extracting commands/sh/sh4.dif
sed 's/^X//' > commands/sh/sh4.dif << '+ END-OF-FILE 'commands/sh/sh4.dif
X0a1
X> #define Extern extern
X348a350,353
X>
X> /* jrp debug */
X> scraphere();
X>
X454c459
X< for (dp = cp = space(pp-np+3); np < pp;)
X---
X> for (dp = cp = space((int)(pp-np)+3); np < pp;)
X512c517
X< p = op = space(end1-start1+strlen(middle)+strlen(end)+2);
X---
X> p = op = space((int)(end1-start1)+strlen(middle)+strlen(end)+2);
X631c636
X< if ((n=lim-base) <= v2)
X---
X> if ((n=(int)(lim-base)) <= v2)
+ END-OF-FILE commands/sh/sh4.dif
chmod u=rw,g=r,o=r commands/sh/sh4.dif
set `sum commands/sh/sh4.dif`
sum=$1
case $sum in
28634) :;;
*) echo 'Bad sum in 'commands/sh/sh4.dif >&2
esac
echo Extracting commands/sh/sh5.dif
sed 's/^X//' > commands/sh/sh5.dif << '+ END-OF-FILE 'commands/sh/sh5.dif
X0a1
X> #define Extern extern
X28c29
X< if (ec != '\'') {
X---
X> if ((ec != '"') && (ec != '\'')) {
X402d402
X< char *memcpy();
X416,419c416,419
X< char *b_start;
X< char *b_next;
X< char *b_line;
X< int b_size;
X---
X> char *b_linebuf;
X> char *b_next;
X> char b_tmpfile[50];
X> int b_fd;
X424c424
X< #define NCPB 100 /* here text block allocation unit */
X---
X> #define NCPB 2048 /* here text block allocation unit */
X438a439
X> h->h_iop->io_un.io_here = NULL;
X461,462c462,466
X< for (h = herelist; h != NULL; h = h->h_next)
X< h->h_iop->io_un.io_here = readhere(h->h_tag, h->h_dosub? 0: '\'');
X---
X> for (h = herelist; h != NULL; h = h->h_next) {
X> h->h_iop->io_un.io_here =
X> readhere(h->h_tag, h->h_dosub? 0: '\'',
X> h->h_iop->io_flag & IOXHERE);
X> }
X467c471
X< readhere(s, ec)
X---
X> readhere(s, ec, nolit)
X476a481,485
X> bp->b_linebuf = (char *)space(NCPB);
X> if (bp->b_linebuf == 0) {
X> /* jrp - should release bp here... */
X> return(0);
X> }
X482,485c491,496
X< bp->b_size = 0;
X< bp->b_line = 0;
X< bp->b_next = 0;
X< bp->b_start = 0;
X---
X>
X> /* jrp changes */
X> bp->b_linebuf[0] = 0;
X> bp->b_next = bp->b_linebuf;
X> bp->b_tmpfile[0] = 0;
X> bp->b_fd = -1;
X490c501
X< if (savec(c, bp) == 0) {
X---
X> if (savec(c, bp, nolit) == 0) {
X495,501c506,511
X< savec(0, bp);
X< if (strcmp(s, bp->b_line) == 0 || c == 0)
X< break;
X< bp->b_next[-1] = '\n';
X< bp->b_line = bp->b_next;
X< }
X< *bp->b_line = 0;
X---
X> savec(0, bp, nolit);
X> if (strcmp(s, bp->b_linebuf) == 0 || c == 0)
X> break;
X> savec('\n', bp, nolit);
X> }
X> *bp->b_linebuf = 0;
X511,586c521,681
X< savec(c, bp)
X< register struct block *bp;
X< {
X< register char *np;
X<
X< if (bp->b_start == NULL || bp->b_next+1 >= bp->b_start+bp->b_size) {
X< np = space(bp->b_size + NCPB);
X< if (np == 0)
X< return(0);
X< memcpy(np, bp->b_start, bp->b_size);
X< bp->b_size += NCPB;
X< bp->b_line = np + (bp->b_line-bp->b_start);
X< bp->b_next = np + (bp->b_next-bp->b_start);
X< xfree(bp->b_start);
X< bp->b_start = np;
X< }
X< *bp->b_next++ = c;
X< return(1);
X< }
X<
X< herein(bp, xdoll)
X< struct block *bp;
X< {
X< register tf;
X< char tname[50];
X< static int inc;
X< register char *cp, *lp;
X<
X< if (bp == 0)
X< return(-1);
X< for (cp = tname, lp = "/tmp/shtm"; (*cp = *lp++) != '\0'; cp++)
X< ;
X< lp = putn(getpid()*100 + inc++);
X< for (; (*cp = *lp++) != '\0'; cp++)
X< ;
X< if ((tf = creat(tname, 0666)) >= 0) {
X< if (xdoll) {
X< char c;
X< jmp_buf ev;
X<
X< if (newenv(setjmp(errpt = ev)) == 0) {
X< PUSHIO(aword, bp->b_start, strchar);
X< setbase(e.iop);
X< while ((c = subgetc(0, 0)) != 0) {
X< c &= ~ QUOTE;
X< write(tf, &c, sizeof c);
X< }
X< quitenv();
X< } else
X< unlink(tname);
X< } else
X< write(tf, bp->b_start, bp->b_line-bp->b_start);
X< close(tf);
X< tf = open(tname, 0);
X< unlink(tname);
X< }
X< return(tf);
X< }
X<
X< scraphere()
X< {
X< herelist = NULL;
X< }
X<
X< char *
X< memcpy(ato, from, nb)
X< register char *ato, *from;
X< register int nb;
X< {
X< register char *to;
X<
X< to = ato;
X< while (--nb >= 0)
X< *to++ = *from++;
X< return(ato);
X< }
X---
X> savec(c, bp, nolit)
X> register struct block *bp;
X> {
X> /* jrp - gutted routine completely, modified to use temp file. */
X>
X> /* If the file is not open, see if a filename needs to be
X> * created. If so, create one. Then create the file.
X> */
X> char * lp;
X> char * cp;
X> static int inc;
X> int len;
X>
X> if(bp->b_fd < 0) {
X> if(bp->b_tmpfile[0] == 0) {
X> /* Key this by the PID plus a tag... */
X> for (cp = bp->b_tmpfile, lp = "/tmp/shtm";
X> (*cp = *lp++) != '\0'; cp++)
X> ;
X>
X> inc = (inc + 1) % 100;
X> lp = putn(getpid()*100 + inc);
X> for (; (*cp = *lp++) != '\0'; cp++)
X> ;
X> }
X>
X> /* Create the file, then open it for
X> * read/write access. After opening the
X> * file, unlink it to it'll go away when
X> * we're through using it.
X> */
X> bp->b_fd = creat(bp->b_tmpfile, 0600);
X> close(bp->b_fd);
X> bp->b_fd = open(bp->b_tmpfile, 2);
X> unlink(bp->b_tmpfile);
X> if(bp->b_fd < 0) {
X> return(0);
X> }
X> }
X>
X> /* Stuff the character into the line buffer. If it's a
X> * newline, then insert it before the trailing null, write
X> * out the line, and reset the line buffer.
X> */
X> if(c == '\n') {
X> bp->b_next[-1] = '\n';
X> bp->b_next[0] = '\0';
X> len = strlen(bp->b_linebuf);
X>
X> /* Write this out, unless the line ended
X> * with a backslash...
X> */
X> if((len > 1) && (bp->b_next[-2] != '\\')) {
X> write_linebuf(bp, nolit);
X> }
X>
X> return(1);
X> }
X> else {
X> if(bp->b_next == &(bp->b_linebuf[NCPB - 1])) {
X> prs("here: line buffer full\n");
X> return(0);
X> }
X> *(bp->b_next++) = c;
X> return(1);
X> }
X> }
X>
X> write_linebuf(bp, nolit)
X> struct block * bp;
X> {
X>
X> char c;
X> jmp_buf ev;
X>
X> if(nolit) {
X> if (newenv(setjmp(errpt = ev)) == 0) {
X> PUSHIO(aword, bp->b_linebuf, strchar);
X> setbase(e.iop);
X> e.iop->task |= XHERE;
X> while ((c = subgetc(0, 0)) != 0) {
X> c &= ~ QUOTE;
X> write(bp->b_fd, &c, sizeof c);
X> }
X> quitenv();
X>
X> }
X> }
X> else {
X> write(bp->b_fd, bp->b_linebuf, strlen(bp->b_linebuf));
X> }
X>
X> /* Zap the line buffer for next time... */
X> bp->b_next = bp->b_linebuf;
X> bp->b_linebuf[0] = 0;
X> }
X>
X> herein(bp, xdoll)
X> struct block *bp;
X> {
X> int ret_fd;
X>
X> if (bp == 0)
X> return(-1);
X>
X> /* If we have a temp file, then rewind it to the beginning */
X> if(bp->b_fd < 0) {
X> return(-1);
X> }
X>
X> lseek(bp->b_fd, 0L, 0);
X>
X> /* Free up this block pointer, as we're
X> * not going to need it anymore.
X> */
X> xfree(bp->b_linebuf);
X> xfree(bp);
X>
X> return(bp->b_fd);
X> }
X>
X> scraphere()
X> {
X> struct here * h;
X> struct here * nexth;
X> struct block * bp;
X>
X>
X> /* Close and unlink any files associated with
X> * heres in progress, and free up all the
X> * associated structures.
X> */
X> h = herelist;
X> while(h != NULL) {
X> nexth = h->h_next;
X> bp = (struct block *)h->h_iop->io_un.io_here;
X> if(bp != NULL) {
X> if(bp->b_fd >= 0) { close(bp->b_fd); }
X> if(*bp->b_tmpfile) { unlink(bp->b_tmpfile); }
X> xfree(bp->b_linebuf);
X> xfree(bp);
X> }
X> xfree(h);
X> h = nexth;
X> }
X>
X> herelist = NULL;
X> }
X>
X> char *
X> memcpy(ato, from, nb)
X> register char *ato, *from;
X> register int nb;
X> {
X> register char *to;
X>
X> to = ato;
X> while (--nb >= 0)
X> *to++ = *from++;
X> return(ato);
X> }
+ END-OF-FILE commands/sh/sh5.dif
chmod u=rw,g=r,o=r commands/sh/sh5.dif
set `sum commands/sh/sh5.dif`
sum=$1
case $sum in
1505) :;;
*) echo 'Bad sum in 'commands/sh/sh5.dif >&2
esac
echo Extracting commands/sh/sh6.c
sed 's/^X//' > commands/sh/sh6.c << '+ END-OF-FILE 'commands/sh/sh6.c
X#define Extern
X
X#include <signal.h>
X#include <errno.h>
X#include <setjmp.h>
X#include "sh.h"
X
+ END-OF-FILE commands/sh/sh6.c
chmod u=rw,g=r,o=r commands/sh/sh6.c
set `sum commands/sh/sh6.c`
sum=$1
case $sum in
7714) :;;
*) echo 'Bad sum in 'commands/sh/sh6.c >&2
esac
echo Extracting commands/split.dif
sed 's/^X//' > commands/split.dif << '+ END-OF-FILE 'commands/split.dif
X66c66
X< if (write(fd, base, index-base) != index-base)
X---
X> if (write(fd,base,(int)(index-base)) != (int)(index-base))
X73c73
X< if (write(fd, base, index - base) != index - base) quit();
X---
X> if (write(fd, base, (int) (index-base)) != (int) (index-base)) quit();
+ END-OF-FILE commands/split.dif
chmod u=rw,g=r,o=r commands/split.dif
set `sum commands/split.dif`
sum=$1
case $sum in
20492) :;;
*) echo 'Bad sum in 'commands/split.dif >&2
esac
echo Extracting commands/tar.dif
sed 's/^X//' > commands/tar.dif << '+ END-OF-FILE 'commands/tar.dif
X60a61,62
X> char path[NAME_SIZE];
X> char pathname[NAME_SIZE];
X111,112c113,116
X< for (i = 3; i < argc; i++)
X< add_file(argv[i]);
X---
X> for (i = 3; i < argc; i++) {
X> add_file(argv[i]);
X> path[0] = '\0';
X> }
X158,163c162,167
X< string_print(NIL_PTR, "linked to %s",
X< header.member.m_link);
X< else
X< string_print(NIL_PTR, "%d tape blocks", block_size());
X< print("\n");
X< skip_entry();
X---
X> string_print(NIL_PTR, "linked to %s\n",
X> header.member.m_link);
X> else {
X> string_print(NIL_PTR, "%d tape blocks\n", block_size());
X> skip_entry();
X> }
X248c252
X< execl(MKDIR, "mkdir", dir_name, 0);
X---
X> execl(MKDIR, "mkdir", dir_name, (char *) 0);
X281,283c285
X< char path[NAME_SIZE];
X<
X< char pathname[NAME_SIZE];
X---
X>
+ END-OF-FILE commands/tar.dif
chmod u=rw,g=r,o=r commands/tar.dif
set `sum commands/tar.dif`
sum=$1
case $sum in
54112) :;;
*) echo 'Bad sum in 'commands/tar.dif >&2
esac
echo Extracting commands/test.c
sed 's/^X//' > commands/test.c << '+ END-OF-FILE 'commands/test.c
X/* test(1); version 7-like -- author Erik Baalbergen */
X#include <stat.h>
X#include <sgtty.h>
X
X/* test(1) accepts the following grammar:
X expr ::= bexpr | bexpr "-o" expr ;
X bexpr ::= primary | primary "-a" bexpr ;
X primary ::= unary-operator operand
X | operand binary-operator operand
X | operand
X | "(" expr ")"
X | "!" expr
X ;
X unary-operator ::= "-r"|"-w"|"-f"|"-d"|"-s"|"-t"|"-z"|"-n";
X binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt";
X operand ::= <any legal UNIX file name>
X*/
X
X#define EOI 0
X#define FILRD 1
X#define FILWR 2
X#define FILND 3
X#define FILID 4
X#define FILGZ 5
X#define FILTT 6
X#define STZER 7
X#define STNZE 8
X#define STEQL 9
X#define STNEQ 10
X#define INTEQ 11
X#define INTNE 12
X#define INTGE 13
X#define INTGT 14
X#define INTLE 15
X#define INTLT 16
X#define UNEGN 17
X#define BAND 18
X#define BOR 19
X#define LPAREN 20
X#define RPAREN 21
X#define OPERAND 22
X
X#define UNOP 1
X#define BINOP 2
X#define BUNOP 3
X#define BBINOP 4
X#define PAREN 5
X
Xstruct op {
X char *op_text;
X short op_num, op_type;
X} ops[] = {
X {"-r", FILRD, UNOP},
X {"-w", FILWR, UNOP},
X {"-f", FILND, UNOP},
X {"-d", FILID, UNOP},
X {"-s", FILGZ, UNOP},
X {"-t", FILTT, UNOP},
X {"-z", STZER, UNOP},
X {"-n", STNZE, UNOP},
X {"=", STEQL, BINOP},
X {"!=", STNEQ, BINOP},
X {"-eq", INTEQ, BINOP},
X {"-ne", INTNE, BINOP},
X {"-ge", INTGE, BINOP},
X {"-gt", INTGT, BINOP},
X {"-le", INTLE, BINOP},
X {"-lt", INTLT, BINOP},
X {"!", UNEGN, BUNOP},
X {"-a", BAND, BBINOP},
X {"-o", BOR, BBINOP},
X {"(", LPAREN, PAREN},
X {")", RPAREN, PAREN},
X {0, 0, 0}
X};
X
Xlong num();
Xchar **ip;
Xchar *prog;
Xstruct op *ip_op;
X
Xmain(argc, argv)
X char *argv[];
X{
X prog = argv[0];
X ip = &argv[1];
X exit(!(expr(lex(*ip)) && *++ip == 0));
X}
X
Xexpr(n)
X{
X int res;
X
X if (n == EOI)
X syntax();
X res = bexpr(n);
X if (lex(*++ip) == BOR)
X return expr(lex(*++ip)) || res;
X ip--;
X return res;
X}
X
Xbexpr(n)
X{
X int res;
X
X if (n == EOI)
X syntax();
X res = primary(n);
X if (lex(*++ip) == BAND)
X return bexpr(lex(*++ip)) && res;
X ip--;
X return res;
X}
X
Xprimary(n)
X{
X register char *opnd1, *opnd2;
X int res;
X
X if (n == EOI)
X syntax();
X if (n == UNEGN)
X return !expr(lex(*++ip));
X if (n == LPAREN) {
X res = expr(lex(*++ip));
X if (lex(*++ip) != RPAREN)
X syntax();
X return res;
X }
X if (n == OPERAND) {
X opnd1 = *ip;
X (void) lex(*++ip);
X if (ip_op && ip_op->op_type == BINOP) {
X struct op *op = ip_op;
X
X if ((opnd2 = *++ip) == (char *)0)
X syntax();
X
X switch (op->op_num) {
X case STEQL:
X return strcmp(opnd1, opnd2) == 0;
X case STNEQ:
X return strcmp(opnd1, opnd2) != 0;
X case INTEQ:
X return num(opnd1) == num(opnd2);
X case INTNE:
X return num(opnd1) != num(opnd2);
X case INTGE:
X return num(opnd1) >= num(opnd2);
X case INTGT:
X return num(opnd1) > num(opnd2);
X case INTLE:
X return num(opnd1) <= num(opnd2);
X case INTLT:
X return num(opnd1) < num(opnd2);
X }
X }
X ip--;
X return strlen(opnd1) > 0;
X }
X /* unary expression */
X if (ip_op->op_type != UNOP || *++ip == 0)
X syntax();
X if (n == STZER)
X return strlen(*ip) == 0;
X if (n == STNZE)
X return strlen(*ip) != 0;
X return filstat(*ip, n);
X}
X
Xfilstat(nm, mode)
X char *nm;
X{
X struct stat s;
X struct sgttyb t;
X
X switch (mode) {
X case FILRD:
X return access(nm, 4) == 0;
X case FILWR:
X return access(nm, 2) == 0;
X case FILND:
X return stat(nm, &s) == 0 && ((s.st_mode & S_IFMT) != S_IFDIR);
X case FILID:
X return stat(nm, &s) == 0 && ((s.st_mode & S_IFMT) == S_IFDIR);
X case FILGZ:
X return stat(nm, &s) == 0 && (s.st_size > 0L);
X case FILTT:
X return ioctl((int)num(nm), TIOCGETP, &t) == 0;
X }
X}
X
Xint
Xlex(s)
X register char *s;
X{
X register struct op *op = ops;
X
X if (s == 0)
X return EOI;
X while (op->op_text) {
X if (strcmp(s, op->op_text) == 0) {
X ip_op = op;
X return op->op_num;
X }
X op++;
X }
X ip_op = (struct op *)0;
X return OPERAND;
X}
X
Xlong
Xnum(s)
X register char *s;
X{
X long l = 0;
X long sign = 1;
X
X if (*s == '\0')
X syntax();
X if (*s == '-') {
X sign = -1;
X s++;
X }
X while (*s >= '0' && *s <= '9')
X l = l * 10 + *s++ - '0';
X if (*s != '\0')
X syntax();
X return sign * l;
X}
X
Xsyntax()
X{
X write(2, prog, strlen(prog));
X write(2, ": syntax error\n", 15);
X exit(1);
X}
+ END-OF-FILE commands/test.c
chmod u=rw,g=r,o=r commands/test.c
set `sum commands/test.c`
sum=$1
case $sum in
29713) :;;
*) echo 'Bad sum in 'commands/test.c >&2
esac
echo Extracting commands/uudecode.c
sed 's/^X//' > commands/uudecode.c << '+ END-OF-FILE 'commands/uudecode.c
X/* uudecode - decode a uuencoded file */
X
X/* call: uudecode [input_file] */
X
X#include "stdio.h"
X#include "pwd.h"
X#include "stat.h"
X
Xextern FILE *fopen();
Xchar *fgets();
X#define NULLF (FILE *) 0
X#define NULLP (char *) 0
X
X/* single character decode */
X#define DEC(c) (((c) - ' ') & 077)
X
Xmain(argc, argv)
Xchar **argv;
X{
X FILE *in, *out;
X struct stat sbuf;
X int mode;
X char dest[128];
X char buf[80];
X
X /* optional input arg */
X if (argc > 1) {
X if ((in = fopen(argv[1], "r")) == NULLF) {
X perror(argv[1]);
X exit(1);
X }
X argv++; argc--;
X } else
X in = stdin;
X
X if (argc != 1) {
X printf("Usage: uudecode [infile]\n");
X exit(2);
X }
X
X /* search for header line */
X for (;;) {
X if (fgets(buf, sizeof buf, in) == NULLP) {
X fprintf(stderr, "No begin line\n");
X exit(3);
X }
X if (strncmp(buf, "begin ", 6) == 0)
X break;
X }
X sscanf(buf, "begin %o %s", &mode, dest);
X
X /* handle ~user/file format */
X if (dest[0] == '~') {
X char *sl;
X struct passwd *getpwnam();
X char *index();
X struct passwd *user;
X char dnbuf[100];
X
X sl = index(dest, '/');
X if (sl == NULLP) {
X fprintf(stderr, "Illegal ~user\n");
X exit(3);
X }
X *sl++ = 0;
X user = getpwnam(dest+1);
X if (user == NULL) {
X fprintf(stderr, "No such user as %s\n", dest);
X exit(4);
X }
X strcpy(dnbuf, user->pw_dir);
X strcat(dnbuf, "/");
X strcat(dnbuf, sl);
X strcpy(dest, dnbuf);
X }
X
X /* create output file */
X out = fopen(dest, "w");
X if (out == NULLF) {
X perror(dest);
X exit(4);
X }
X chmod(dest, mode);
X
X decode(in, out);
X
X if (fgets(buf, sizeof buf, in) == NULLP || strcmp(buf, "end\n")) {
X fprintf(stderr, "No end line\n");
X exit(5);
X }
X exit(0);
X}
X
X/*
X * copy from in to out, decoding as you go along.
X */
Xdecode(in, out)
XFILE *in;
XFILE *out;
X{
X char buf[80];
X char *bp;
X int n;
X
X for (;;) {
X /* for each input line */
X if (fgets(buf, sizeof buf, in) == NULLP) {
X printf("Short file\n");
X exit(10);
X }
X n = DEC(buf[0]);
X if (n <= 0)
X break;
X
X bp = &buf[1];
X while (n > 0) {
X outdec(bp, out, n);
X bp += 4;
X n -= 3;
X }
X }
X}
X
X/*
X * output a group of 3 bytes (4 input characters).
X * the input chars are pointed to by p, they are to
X * be output to file f. n is used to tell us not to
X * output all of them at the end of the file.
X */
Xoutdec(p, f, n)
Xchar *p;
XFILE *f;
X{
X int c1, c2, c3;
X
X c1 = DEC(*p) << 2 | DEC(p[1]) >> 4;
X c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
X c3 = DEC(p[2]) << 6 | DEC(p[3]);
X if (n >= 1)
X putc(c1, f);
X if (n >= 2)
X putc(c2, f);
X if (n >= 3)
X putc(c3, f);
X}
X
X
X/* fr: like read but stdio */
Xint
Xfr(fd, buf, cnt)
XFILE *fd;
Xchar *buf;
Xint cnt;
X{
X int c, i;
X
X for (i=0; i<cnt; i++) {
X c = getc(fd);
X if (c == EOF)
X return(i);
X buf[i] = c;
X }
X return (cnt);
X}
X
X/*
X * Return the ptr in sp at which the character c appears;
X * NULL if not found
X */
X
X
Xchar *
Xindex(sp, c)
Xregister char *sp, c;
X{
X do {
X if (*sp == c)
X return(sp);
X } while (*sp++);
X return(NULL);
X}
+ END-OF-FILE commands/uudecode.c
chmod u=rw,g=r,o=r commands/uudecode.c
set `sum commands/uudecode.c`
sum=$1
case $sum in
12023) :;;
*) echo 'Bad sum in 'commands/uudecode.c >&2
esac
echo Extracting commands/uuencode.c
sed 's/^X//' > commands/uuencode.c << '+ END-OF-FILE 'commands/uuencode.c
X/* uuencode - encode a file for mailing to a remote system */
X
X/* Call: uuencode [input] output
X * encodes a file to pure ASCII, with 3 bytes in the original file becoming
X * 4 bytes in the encoded file. Uudecode decodes encoded files.
X */
X
X#include "stdio.h"
X#include "stat.h"
X
Xextern FILE *fopen();
X
X/* ENC is the basic 1 character encoding function to make a char printing */
X#define ENC(c) (((c) & 077) + ' ')
X
Xmain(argc, argv)
Xchar **argv;
X{
X FILE *in;
X struct stat sbuf;
X int mode;
X
X /* optional 1st argument */
X if (argc > 2) {
X if ((in = fopen(argv[1], "r")) == (FILE *) NULL) {
X perror(argv[1]);
X exit(1);
X }
X argv++; argc--;
X } else
X in = stdin;
X
X if (argc != 2) {
X printf("Usage: uuencode [infile] remotefile\n");
X exit(2);
X }
X
X /* figure out the input file mode */
X fstat(fileno(in), &sbuf);
X mode = sbuf.st_mode & 0777;
X printf("begin %o %s\n", mode, argv[1]);
X
X encode(in, stdout);
X
X printf("end\n");
X exit(0);
X}
X
X/*
X * copy from in to out, encoding as you go along.
X */
Xencode(in, out)
XFILE *in;
XFILE *out;
X{
X char buf[80];
X int i, n;
X
X for (;;) {
X /* 1 (up to) 45 character line */
X n = fr(in, buf, 45);
X putc(ENC(n), out);
X
X for (i=0; i<n; i += 3)
X outdec(&buf[i], out);
X
X putc('\n', out);
X if (n <= 0)
X break;
X }
X}
X
X/*
X * output one group of 3 bytes, pointed at by p, on file f.
X */
Xoutdec(p, f)
Xchar *p;
XFILE *f;
X{
X int c1, c2, c3, c4;
X
X c1 = *p >> 2;
X c2 = (*p << 4) & 060 | (p[1] >> 4) & 017;
X c3 = (p[1] << 2) & 074 | (p[2] >> 6) & 03;
X c4 = p[2] & 077;
X putc(ENC(c1), f);
X putc(ENC(c2), f);
X putc(ENC(c3), f);
X putc(ENC(c4), f);
X}
X
X/* fr: like read but stdio */
Xint
Xfr(fd, buf, cnt)
XFILE *fd;
Xchar *buf;
Xint cnt;
X{
X int c, i;
X
X for (i=0; i<cnt; i++) {
X c = getc(fd);
X if (c == EOF)
X return(i);
X buf[i] = c;
X }
X return (cnt);
X}
+ END-OF-FILE commands/uuencode.c
chmod u=rw,g=r,o=r commands/uuencode.c
set `sum commands/uuencode.c`
sum=$1
case $sum in
63186) :;;
*) echo 'Bad sum in 'commands/uuencode.c >&2
esac
echo Extracting commands/wc.dif
sed 's/^X//' > commands/wc.dif << '+ END-OF-FILE 'commands/wc.dif
X4c4
X< #define isdigit(c) (c >= '0' && c <= '9)
X---
X> #define isdigit(c) (c >= '0' && c <= '9')
X55c55
X< if (*cp++ == '-') {
X---
X> if (argc >1 && *cp++ == '-') {
+ END-OF-FILE commands/wc.dif
chmod u=rw,g=r,o=r commands/wc.dif
set `sum commands/wc.dif`
sum=$1
case $sum in
9665) :;;
*) echo 'Bad sum in 'commands/wc.dif >&2
esac
exit 0
echo byebyebyebyebyebyebyebyebyebyebyebyebyebyebyebyebyebyebyebyebyebey