void copy(struct ionod *ioparg) { unsigned char *cline; unsigned char *clinep; struct ionod *iop; unsigned int c; unsigned char *ends; unsigned char *start; int fd; int i; int stripflg; unsigned char *pc; if (iop = ioparg) { struct tempblk tb; copy(iop->iolst); ends = mactrim(iop->ioname); stripflg = iop->iofile & IOSTRIP; if (nosubst) iop->iofile &= ~IODOC; fd = tmpfil(&tb); if (fndef) iop->ioname = (char *) make(tmpout); else iop->ioname = (char *) cpystak(tmpout); iop->iolst = iotemp; iotemp = iop; cline = clinep = start = locstak(); if (stripflg) { iop->iofile &= ~IOSTRIP; while (*ends == '\t') ends++; } for (;;) { chkpr(); if (nosubst) { c = readwc(); if (stripflg) while (c == '\t') c = readwc(); while (!eolchar(c)) { pc = readw(c); while (*pc) { if (clinep >= brkend) growstak(clinep); *clinep++ = *pc++; } c = readwc(); } }else{ c = nextwc(); if (stripflg) while (c == '\t') c = nextwc(); while (!eolchar(c)) { pc = readw(c); while (*pc) { if (clinep >= brkend) growstak(clinep); *clinep++ = *pc++; } if (c == '\\') { pc = readw(readwc()); /* *pc might be NULL */ if (*pc) { while (*pc) { if (clinep >= brkend) growstak(clinep); *clinep++ = *pc++; } } else { if (clinep >= brkend) growstak(clinep); *clinep++ = *pc; } } c = nextwc(); } } if (clinep >= brkend) growstak(clinep); *clinep = 0; if (eof || eq(cline, ends)) { if ((i = cline - start) > 0) write(fd, start, i); break; }else{ if (clinep >= brkend) growstak(clinep); *clinep++ = NL; } if ((i = clinep - start) < CPYSIZ) cline = clinep; else { write(fd, start, i); cline = clinep = start; } } poptemp(); /* * pushed in tmpfil -- bug fix for problem * deleting in-line scripts */ } }
static void addg(unsigned char *as1, unsigned char *as2, unsigned char *as3, unsigned char *as4) { register unsigned char *s1, *s2; register int c; int len; wchar_t wc; s2 = locstak() + BYTESPERWORD; s1 = as1; if (as4) { while (c = *s1++) { if (s2 >= brkend) growstak(s2); *s2++ = c; } /* * Restore first slash before the first metacharacter * if as1 is not "/" */ if (as4 + 1 == s1) { if (s2 >= brkend) growstak(s2); *s2++ = '/'; } } /* add matched entries, plus extra \\ to escape \\'s */ s1 = as2; for (;;) { if ((len = nextc(&wc, (char *)s1)) <= 0) { len = 1; wc = (unsigned char)*s1; } if (s2 >= brkend) growstak(s2); if (wc == 0) { *s2 = *s1++; break; } if (wc == '\\') { *s2++ = '\\'; if (s2 >= brkend) growstak(s2); *s2++ = '\\'; s1++; continue; } if ((s2 + len) >= brkend) growstak(s2 + len); memcpy(s2, s1, len); s2 += len; s1 += len; } if (s1 = as3) { if (s2 >= brkend) growstak(s2); *s2++ = '/'; do { if (s2 >= brkend) growstak(s2); } while (*s2++ = *++s1); } makearg((struct argnod *)endstak(s2)); }
void addblok(unsigned int reqd) { if (stakbot == 0) { brkbegin = setbrk(3 * BRKINCR); /* * setbrk() returns 8 byte aligned address * but we could need larger align in future */ brkbegin = (unsigned char *)round(brkbegin, ALIGNSIZ); bloktop = (struct blk *)brkbegin; } if (stakbas != staktop) { unsigned char *rndstak; struct blk *blokstak; if (staktop >= brkend) growstak(staktop); pushstak(0); rndstak = (unsigned char *)round(staktop, ALIGNSIZ); blokstak = (struct blk *)(stakbas) - 1; blokstak->word = stakbsy; stakbsy = blokstak; bloktop->word = (struct blk *)(Rcheat(rndstak) | BUSY); bloktop = (struct blk *)(rndstak); } reqd += brkincr; reqd &= ~(brkincr - 1); blokp = bloktop; /* * brkend points to the first invalid address. * make sure bloktop is valid. */ if ((unsigned char *)&bloktop->word >= brkend) { if (setbrk((unsigned)((unsigned char *) (&bloktop->word) - brkend + sizeof (struct blk))) == (unsigned char *)-1) error(nospace); } bloktop = bloktop->word = (struct blk *)(Rcheat(bloktop) + reqd); if ((unsigned char *)&bloktop->word >= brkend) { if (setbrk((unsigned)((unsigned char *) (&bloktop->word) - brkend + sizeof (struct blk))) == (unsigned char *)-1) error(nospace); } bloktop->word = (struct blk *)(brkbegin + 1); { unsigned char *stakadr = (unsigned char *) (bloktop + 2); unsigned char *sp = stakadr; if (reqd = (staktop-stakbot)) { if (stakadr + reqd >= brkend) growstak(stakadr + reqd); while (reqd-- > 0) *sp++ = *stakbot++; sp--; } staktop = sp; if (staktop >= brkend) growstak(staktop); stakbas = stakbot = stakadr; } }
int word(void) { unsigned int c, d, cc; struct argnod *arg = (struct argnod *)locstak(); unsigned char *argp = arg->argval; unsigned char *oldargp; int alpha = 1; unsigned char *pc; wdnum = 0; wdset = 0; while (1) { while (c = nextwc(), space(c)) /* skipc() */ ; if (c == COMCHAR) { while ((c = readwc()) != NL && c != EOF); peekc = c; } else { break; /* out of comment - white space loop */ } } if (!eofmeta(c)) { do { if (c == LITERAL) { oldargp = argp; while ((c = readwc()) && c != LITERAL){ /* * quote each character within * single quotes */ pc = readw(c); if (argp >= brkend) growstak(argp); *argp++='\\'; /* Pick up rest of multibyte character */ if (c == NL) chkpr(); while (c = *pc++) { if (argp >= brkend) growstak(argp); *argp++ = (unsigned char)c; } } if (argp == oldargp) { /* null argument - '' */ /* * Word will be represented by quoted null * in macro.c if necessary */ if (argp >= brkend) growstak(argp); *argp++ = '"'; if (argp >= brkend) growstak(argp); *argp++ = '"'; } } else { if (c == 0) { if (argp >= brkend) growstak(argp); *argp++ = 0; } else { pc = readw(c); while (*pc) { if (argp >= brkend) growstak(argp); *argp++ = *pc++; } } if (c == '\\') { if ((cc = readwc()) == 0) { if (argp >= brkend) growstak(argp); *argp++ = 0; } else { pc = readw(cc); while (*pc) { if (argp >= brkend) growstak(argp); *argp++ = *pc++; } } } if (c == '=') wdset |= alpha; if (!alphanum(c)) alpha = 0; if (qotchar(c)) { d = c; for (;;) { if ((c = nextwc()) == 0) { if (argp >= brkend) growstak(argp); *argp++ = 0; } else { pc = readw(c); while (*pc) { if (argp >= brkend) growstak(argp); *argp++ = *pc++; } } if (c == 0 || c == d) break; if (c == NL) chkpr(); /* * don't interpret quoted * characters */ if (c == '\\') { if ((cc = readwc()) == 0) { if (argp >= brkend) growstak(argp); *argp++ = 0; } else { pc = readw(cc); while (*pc) { if (argp >= brkend) growstak(argp); *argp++ = *pc++; } } } } } } } while ((c = nextwc(), !eofmeta(c))); argp = endstak(argp); if (!letter(arg->argval[0])) wdset = 0; peekn = c | MARK; if (arg->argval[1] == 0 && (d = arg->argval[0], digit(d)) && (c == '>' || c == '<')) { word(); wdnum = d - '0'; }else{ /* check for reserved words */ if (reserv == FALSE || (wdval = syslook(arg->argval, reserved, no_reserved)) == 0) { wdval = 0; } /* set arg for reserved words too */ wdarg = arg; } }else if (dipchar(c)){ if ((d = nextwc()) == c) { wdval = c | SYMREP; if (c == '<') { if ((d = nextwc()) == '-') wdnum |= IOSTRIP; else peekn = d | MARK; } } else { peekn = d | MARK; wdval = c; } } else { if ((wdval = c) == EOF) wdval = EOFSYM; if (iopend && eolchar(c)) { struct ionod *tmp_iopend; tmp_iopend = iopend; iopend = 0; copy(tmp_iopend); } } reserv = FALSE; return (wdval); }