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 readvar(unsigned char **names) { struct fileblk fb; register struct fileblk *f = &fb; unsigned char c[MULTI_BYTE_MAX+1]; register int rc = 0; struct namnod *n; unsigned char *rel; unsigned char *oldstak; register unsigned char *pc, *rest; int d; unsigned int (*newwc)(void); extern const char badargs[]; if (eq(*names, "-r")) { if (*++names == NULL) error(badargs); newwc = readwc; } else newwc = nextwc; n = lookup(*names++); /* done now to avoid storage mess */ rel = (unsigned char *)relstak(); push(f); initf(dup(0)); /* * If stdin is a pipe then this lseek(2) will fail with ESPIPE, so * the read buffer size is set to 1 because we will not be able * lseek(2) back towards the beginning of the file, so we have * to read a byte at a time instead * */ if (lseek(0, (off_t)0, SEEK_CUR) == -1) f->fsiz = 1; #ifdef __sun /* * If stdin is a socket then this isastream(3C) will return 1, so * the read buffer size is set to 1 because we will not be able * lseek(2) back towards the beginning of the file, so we have * to read a byte at a time instead * */ if (isastream(0) == 1) f->fsiz = 1; #endif /* * strip leading IFS characters */ for (;;) { d = newwc(); if(eolchar(d)) break; rest = readw(d); pc = c; while(*pc++ = *rest++); if(!anys(c, ifsnod.namval)) break; } oldstak = curstak(); for (;;) { if ((*names && anys(c, ifsnod.namval)) || eolchar(d)) { if (staktop >= brkend) growstak(staktop); zerostak(); assign(n, absstak(rel)); setstak(rel); if (*names) n = lookup(*names++); else n = 0; if (eolchar(d)) { break; } else /* strip imbedded IFS characters */ while(1) { d = newwc(); if(eolchar(d)) break; rest = readw(d); pc = c; while(*pc++ = *rest++); if(!anys(c, ifsnod.namval)) break; } } else { if(d == '\\' && newwc == nextwc) { d = newwc(); rest = readw(d); while(d = *rest++) { if (staktop >= brkend) growstak(staktop); pushstak(d); } oldstak = staktop; } else { pc = c; while(d = *pc++) { if (staktop >= brkend) growstak(staktop); pushstak(d); } if(!anys(c, ifsnod.namval)) oldstak = staktop; } d = newwc(); if (eolchar(d)) staktop = oldstak; else { rest = readw(d); pc = c; while(*pc++ = *rest++); } } } while (n) { assign(n, nullstr); if (*names) n = lookup(*names++); else n = 0; } if (eof) rc = 1; #ifdef __sun if (isastream(0) != 1) #endif /* * If we are reading on a stream do not attempt to * lseek(2) back towards the start because this is * logically meaningless, but there is nothing in * the standards to pervent the stream implementation * from attempting it and breaking our code here * */ lseek(0, (off_t)(f->nxtoff - f->endoff), SEEK_CUR); pop(); return(rc); }
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 */ } }
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; }