void copy(IOPTR ioparg) { CHAR c, *ends; register CHAR *cline, *clinep; int fd; register IOPTR iop; if (iop = ioparg) { copy(iop->iolst); ends = mactrim(iop->ioname); if (nosubst) iop->iofile &= ~IODOC; fd = tmpfil(); iop->ioname = cpystak(tmpout); iop->iolst = iotemp; iotemp = iop; cline = locstak(); for (;;) { clinep = cline; chkpr(NL); while ((c = (nosubst ? readc() : nextc(*ends)),!eolchar(c))) { *clinep++ = c; } *clinep = 0; if (eof || eq(cline, ends)) break; *clinep++ = NL; write(fd, cline, clinep - cline); } close(fd); } }
int word(void) { register unsigned int c, d, cc; struct argnod *arg = (struct argnod *)locstak(); register 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); }
int word(void) { register char c, d; register char *argp = locstak() + BYTESPERWORD; int alpha = 1; wdnum = 0; wdset = 0; while (1) { while (c = nextc(0), space(c)) /* skipc() */ ; if (c == COMCHAR) { while ((c = readc()) != NL && c != EOF); peekc = c; } else { break; /* out of comment - white space loop */ } } if (!eofmeta(c)) { do { if (c == LITERAL) { *argp++ = (DQUOTE); while ((c = readc()) && c != LITERAL) { *argp++ = (c | QUOTE); chkpr(c); } *argp++ = (DQUOTE); } else { *argp++ = (c); if (c == '=') wdset |= alpha; if (!alphanum(c)) alpha = 0; if (qotchar(c)) { d = c; while ((*argp++ = (c = nextc(d))) && c != d) chkpr(c); } } } while ((c = nextc(0), !eofmeta(c))); argp = endstak(argp); if (!letter(((ARGPTR) argp)->argval[0])) wdset = 0; peekc = c | MARK; if (((ARGPTR) argp)->argval[1] == 0 && (d = ((ARGPTR) argp)->argval[0], digit(d)) && (c == '>' || c == '<')) { word(); wdnum = d - '0'; } else { /*check for reserved words */ if (reserv == FALSE || (wdval = syslook(((ARGPTR) argp)->argval, reserved)) == 0) { wdarg = (ARGPTR) argp; wdval = 0; } } } else if (dipchar(c)) { if ((d = nextc(0)) == c) wdval = c | SYMREP; else { peekc = d | MARK; wdval = c; } } else { if ((wdval = c) == EOF) wdval = EOFSYM; if (iopend && eolchar(c)) { copy(iopend); iopend = 0; } } reserv = FALSE; return wdval; }
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)); }