void curlyexpand (char *head, char *tail) { char buf2[NSTRBUF]; char *s, *t; int depth; if (*tail++ != '{') goto syntax; for (s = tail, depth = 1; *tail; tail++) if (*tail == '{') depth++; else if (*tail == '}' && --depth <= 0) break; if (*tail++ != '}') goto syntax; for (depth = 1;; s++) { for (t = buf2;; *t++ = *s++) if (*s == '{') depth++; else if (*s == ',' && depth <= 1 || *s == '}' && depth-- <= 1) break; (void) strcpy (t, tail); doexpand (head, buf2); if (*s == '}') return; } syntax: error ("{} syntax"); }
int squarexpand (char *head, char *tail) { char *t; int hi, incr, lo; if (*tail++ != '[') goto syntax; for (t = tail; *tail && *tail != ']'; tail++); if (*tail++ != ']') goto syntax; for (; *t != ']'; t++) { lo = *t; if (t[1] == '-' && t[2] != ']') hi = *(t += 2); else hi = lo; incr = lo > hi ? -1 : 1; for (; lo - incr != hi; lo += incr) { *head = lo; doexpand (head + 1, tail); } } return; syntax: error ("[] syntax"); return; }
int expand (char *s, char ***v, int msk) { int i; mask = msk; nstrs = nstrbuf = 0; *v = 0; doexpand (buf, s); if (nstrs <= 0) error ("%s: empty expanse", s); for (i = 0; i < nstrs; i++) numify(strs[i]); /* bart bit vector hack */ *v = strs; return (nstrs); }
int anglexpand (char *head, char *tail) { int hi = 0, hilen = 0, incr, len, lo = 0, lolen = 0, n; if (*tail++ != '<') goto syntax; for (; isdigit (*tail); lolen++, lo = 10 * lo + *tail++ - '0'); if (*tail++ != ':') goto syntax; for (; isdigit (*tail); hilen++, hi = 10 * hi + *tail++ - '0'); if (*tail == ':') { incr = hi; for (hi = hilen = 0, tail++; isdigit (*tail); hilen++) hi = 10 * hi + *tail++ - '0'; } else incr = 1; if (*tail++ != '>' || lolen <= 0 || hilen <= 0 || incr < 0) goto syntax; if (lo > hi) incr = -incr; if (hilen < lolen) hilen = lolen; for (;; lo += incr) { for (len = hilen-1, n = lo; len >= 0; len--, n /= 10) head[len] = n % 10 + '0'; doexpand (head + hilen, tail); if (incr > 0 && lo >= hi || incr < 0 && lo <= hi) break; } return; syntax: error ("<> syntax"); }
void dotranslate(char *from, char *topath) { char frompath[128],fromname[14]; char to[128],toname[14]; char *nptr; char ans; char buf[256]; int handle; FILE *infile; int doad; if (!split(from,frompath,fromname)) { fprintf(stderr,"Couldn't parse filename %s.\n",from); return; } ans=0; nptr=fromname+strlen(fromname)-1; // lose the extension while (nptr>fromname) if (*nptr=='.') { *nptr=0; break; } else nptr--; if (!fiadordoad(topath,&doad,to,toname)) { fprintf(stderr,"Can't access %s\n",topath); return; } else if (!doad) { dos2ti(fromname,toname); // get 10-char name dochop(toname); strcat(toname,ext); // strcpy(fromname,toname); // copy // ti2dos(fromname,toname); // make DOS name } else { dos2ti(fromname,toname); // get 10-char name dochop(toname); strcat(toname,ext); strcpy(fromname,toname); } strcpy(to,topath); strcat(to,toname); while ((!overwrite) && tiexists(to) && ans!='O' && ans!='S') { fprintf(stderr,"File %s exists. (O)verwrite, (R)ename, or (S)kip? ",to); buf[0]=4; cgets(buf); fprintf(stderr,"\n"); ans=toupper(*(buf+2)); if (ans=='R') { fprintf(stderr,"Enter new filename in the form %s: ",toname); buf[0]=14; cgets(buf); fprintf(stderr,"\n"); strcpy(toname,buf+2); strcpy(to,topath); strcat(to,toname); } } if (ans!='S') { if ((infile=openbufferread(from))==NULL) // if (!openfoad(from, &handle)) { if (!ignore) fprintf(stderr,"File %s does not exist (?), skipping.\n",from); } else { { if (!createti(to,type,reclen,&handle)) { fprintf(stderr,"Could not create %s !\n",to); tierror(to); } else { if (verbose) fprintf(stderr,"Converting %s to %s\n",from,to); while (!feof(infile)) { getstring(buf,reclen,infile,!(type&F_VARIABLE), (type&F_INTERNAL) ? 0 : 0x20); if (chop) dochop(buf); if (expandtabs) doexpand(buf); if (!writeti(handle,buf,strlen(buf))) { fprintf(stderr,"\tWrite error on %s !\n",to); break; } } closeti(handle); } } closebufferread(infile); } } }