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); } }
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 expand(unsigned char *as, int rcnt) { int count; DIR *dirf; BOOL dir = 0; unsigned char *rescan = 0; unsigned char *slashsav = 0; register unsigned char *s, *cs; unsigned char *s2 = 0; struct argnod *schain = gchain; BOOL slash; int len; wchar_t wc; if (trapnote & SIGSET) return (0); s = cs = as; /* * check for meta chars */ { register BOOL open; slash = 0; open = 0; do { if ((len = nextc(&wc, (char *)cs)) <= 0) { len = 1; wc = (unsigned char)*cs; } cs += len; switch (wc) { case 0: if (rcnt && slash) break; else return (0); case '/': slash++; open = 0; continue; case '[': open++; continue; case ']': if (open == 0) continue; case '?': case '*': if (rcnt > slash) continue; else cs--; break; case '\\': cs++; default: continue; } break; } while (TRUE); } for (;;) { if (cs == s) { s = (unsigned char *)nullstr; break; } else if (*--cs == '/') { *cs = 0; if (s == cs) s = (unsigned char *)"/"; else { /* * push trimmed copy of directory prefix * onto stack */ s2 = cpystak(s); trim(s2); s = s2; } break; } } if ((dirf = opendir(*s ? (char *)s : (char *)".")) != 0) dir++; /* Let s point to original string because it will be trimmed later */ if (s2) s = as; count = 0; if (*cs == 0) slashsav = cs++; /* remember where first slash in as is */ /* check for rescan */ if (dir) { register unsigned char *rs; struct dirent *e; rs = cs; do /* find next / in as */ { if (*rs == '/') { rescan = rs; *rs = 0; gchain = 0; } } while (*rs++); while ((e = readdir(dirf)) && (trapnote & SIGSET) == 0) { if (e->d_name[0] == '.' && *cs != '.') continue; if (gmatch(e->d_name, cs)) { addg(s, e->d_name, rescan, slashsav); count++; } } closedir(dirf); if (rescan) { register struct argnod *rchain; rchain = gchain; gchain = schain; if (count) { count = 0; while (rchain) { count += expand(rchain->argval, slash + 1); rchain = rchain->argnxt; } } *rescan = '/'; } } if (slashsav) *slashsav = '/'; return (count); }