/*ARGSUSED*/ void dolet(Char **v, struct command *dummy) { Char *p; Char *vp, c, op; int hadsub; int subscr; USE(dummy); v++; p = *v++; if (p == 0) { prvars(); return; } do { hadsub = 0; vp = p; if (letter(*p)) for (; alnum(*p); p++) continue; if (vp == p || !letter(*vp)) stderror(ERR_NAME | ERR_VARBEGIN); if (*p == '[') { hadsub++; p = getinx(p, &subscr); } if (*p == 0 && *v) p = *v++; if ((op = *p) != 0) *p++ = 0; else stderror(ERR_NAME | ERR_ASSIGN); /* * if there is no expression after the '=' then print a "Syntax Error" * message - strike */ if (*p == '\0' && *v == NULL) stderror(ERR_NAME | ERR_ASSIGN); vp = Strsave(vp); cleanup_push(vp, xfree); if (op == '=') { c = '='; p = xset(p, &v); } else { c = *p++; if (any("+-", c)) { if (c != op || *p) stderror(ERR_NAME | ERR_UNKNOWNOP); p = Strsave(STR1); } else { if (any("<>", op)) { if (c != op) stderror(ERR_NAME | ERR_UNKNOWNOP); stderror(ERR_NAME | ERR_SYNTAX); } if (c != '=') stderror(ERR_NAME | ERR_UNKNOWNOP); p = xset(p, &v); } } cleanup_push(p, xfree); if (op == '=') { if (hadsub) asx(vp, subscr, p); else setv(vp, p, VAR_READWRITE); cleanup_ignore(p); } else if (hadsub) { struct varent *gv = getvx(vp, subscr); Char *val; val = operate(op, gv->vec[subscr - 1], p); cleanup_push(val, xfree); asx(vp, subscr, val); cleanup_ignore(val); cleanup_until(val); } else { Char *val; val = operate(op, varval(vp), p); cleanup_push(val, xfree); setv(vp, val, VAR_READWRITE); cleanup_ignore(val); cleanup_until(val); } update_vars(vp); cleanup_until(vp); } while ((p = *v++) != NULL); }
/*ARGSUSED*/ void doset(Char **v, struct command *c) { Char *p; Char *vp; Char **vecp; int hadsub; int subscr; int flags = VAR_READWRITE; int first_match = 0; int last_match = 0; int changed = 0; USE(c); v++; do { changed = 0; /* * Readonly addition From: Tim P. Starrin <*****@*****.**> */ if (*v && eq(*v, STRmr)) { flags = VAR_READONLY; v++; changed = 1; } if (*v && eq(*v, STRmf) && !last_match) { first_match = 1; v++; changed = 1; } if (*v && eq(*v, STRml) && !first_match) { last_match = 1; v++; changed = 1; } } while(changed); p = *v++; if (p == 0) { plist(&shvhed, flags); return; } do { hadsub = 0; vp = p; if (!letter(*p)) stderror(ERR_NAME | ERR_VARBEGIN); do { p++; } while (alnum(*p)); if (*p == '[') { hadsub++; p = getinx(p, &subscr); } if (*p != '\0' && *p != '=') stderror(ERR_NAME | ERR_VARALNUM); if (*p == '=') { *p++ = '\0'; if (*p == '\0' && *v != NULL && **v == '(') p = *v++; } else if (*v && eq(*v, STRequal)) { if (*++v != NULL) p = *v++; } if (eq(p, STRLparen)) { Char **e = v; if (hadsub) stderror(ERR_NAME | ERR_SYNTAX); for (;;) { if (!*e) stderror(ERR_NAME | ERR_MISSING, ')'); if (**e == ')') break; e++; } p = *e; *e = 0; vecp = saveblk(v); if (first_match) flags |= VAR_FIRST; else if (last_match) flags |= VAR_LAST; set1(vp, vecp, &shvhed, flags); *e = p; v = e + 1; } else if (hadsub) { Char *copy; copy = Strsave(p); cleanup_push(copy, xfree); asx(vp, subscr, copy); cleanup_ignore(copy); cleanup_until(copy); } else setv(vp, Strsave(p), flags); update_vars(vp); } while ((p = *v++) != NULL); }
void /*ARGSUSED*/ doset(Char **v, struct command *t) { Char *p; Char *vp, op; Char **vecp; bool hadsub; int subscr; v++; p = *v++; if (p == 0) { prvars(); return; } do { hadsub = 0; vp = p; if (letter(*p)) for (; alnum(*p); p++) continue; if (vp == p || !letter(*vp)) stderror(ERR_NAME | ERR_VARBEGIN); if ((p - vp) > MAXVARLEN) { stderror(ERR_NAME | ERR_VARTOOLONG); return; } if (*p == '[') { hadsub++; p = getinx(p, &subscr); } if ((op = *p) != '\0') { *p++ = 0; if (*p == 0 && *v && **v == '(') p = *v++; } else if (*v && eq(*v, STRequal)) { op = '=', v++; if (*v) p = *v++; } if (op && op != '=') stderror(ERR_NAME | ERR_SYNTAX); if (eq(p, STRLparen)) { Char **e = v; if (hadsub) stderror(ERR_NAME | ERR_SYNTAX); for (;;) { if (!*e) stderror(ERR_NAME | ERR_MISSING, ')'); if (**e == ')') break; e++; } p = *e; *e = 0; vecp = saveblk(v); set1(vp, vecp, &shvhed); *e = p; v = e + 1; } else if (hadsub) asx(vp, subscr, Strsave(p)); else set(vp, Strsave(p)); if (eq(vp, STRpath)) { exportpath(adrof(STRpath)->vec); dohash(NULL, NULL); } else if (eq(vp, STRhistchars)) { Char *pn = value(STRhistchars); HIST = *pn++; HISTSUB = *pn; } else if (eq(vp, STRuser)) { Setenv(STRUSER, value(vp)); Setenv(STRLOGNAME, value(vp)); } else if (eq(vp, STRwordchars)) { word_chars = value(vp); } else if (eq(vp, STRterm)) Setenv(STRTERM, value(vp)); else if (eq(vp, STRhome)) { Char *cp; cp = Strsave(value(vp)); /* get the old value back */ /* * convert to canonical pathname (possibly resolving symlinks) */ cp = dcanon(cp, cp); set(vp, Strsave(cp)); /* have to save the new val */ /* and now mirror home with HOME */ Setenv(STRHOME, cp); /* fix directory stack for new tilde home */ dtilde(); free(cp); } else if (eq(vp, STRfilec)) filec = 1; } while ((p = *v++) != NULL); }
void /*ARGSUSED*/ dolet(Char **v, struct command *t) { Char *p; Char *vp, c, op; bool hadsub; int subscr; v++; p = *v++; if (p == 0) { prvars(); return; } do { hadsub = 0; vp = p; if (letter(*p)) for (; alnum(*p); p++) continue; if (vp == p || !letter(*vp)) stderror(ERR_NAME | ERR_VARBEGIN); if ((p - vp) > MAXVARLEN) stderror(ERR_NAME | ERR_VARTOOLONG); if (*p == '[') { hadsub++; p = getinx(p, &subscr); } if (*p == 0 && *v) p = *v++; if ((op = *p) != '\0') *p++ = 0; else stderror(ERR_NAME | ERR_ASSIGN); if (*p == '\0' && *v == NULL) stderror(ERR_NAME | ERR_ASSIGN); vp = Strsave(vp); if (op == '=') { c = '='; p = xset(p, &v); } else { c = *p++; if (any("+-", c)) { if (c != op || *p) stderror(ERR_NAME | ERR_UNKNOWNOP); p = Strsave(STR1); } else { if (any("<>", op)) { if (c != op) stderror(ERR_NAME | ERR_UNKNOWNOP); c = *p++; stderror(ERR_NAME | ERR_SYNTAX); } if (c != '=') stderror(ERR_NAME | ERR_UNKNOWNOP); p = xset(p, &v); } } if (op == '=') if (hadsub) asx(vp, subscr, p); else set(vp, p); else if (hadsub) { struct varent *gv = getvx(vp, subscr); asx(vp, subscr, operate(op, gv->vec[subscr - 1], p)); } else set(vp, operate(op, value(vp), p)); if (eq(vp, STRpath)) { exportpath(adrof(STRpath)->vec); dohash(NULL, NULL); } free(vp); if (c != '=') free(p); } while ((p = *v++) != NULL); }
void doset(tchar **v) { tchar *p; tchar *vp, op; tchar **vecp; bool hadsub; int subscr; tchar *retp; #ifdef TRACE tprintf("TRACE- doset()\n"); #endif v++; p = *v++; if (p == 0) { prvars(); return; } do { hadsub = 0; /* * check for proper variable syntax * must be alphanumeric, start with a letter and * be at most 20 characters */ for (vp = p; alnum(*p); p++) continue; if (vp == p || !letter(*vp)) goto setsyn; if ((p - vp) > MAX_VAR_LEN) bferr("Variable name too long"); if (*p == '[') { hadsub++; p = getinx(p, &subscr); } if (op = *p) { *p++ = 0; if (*p == 0 && *v && **v == '(') p = *v++; } else if (*v && eq(*v, S_EQ /* "=" */)) { op = '=', v++; if (*v) p = *v++; } if (op && op != '=') setsyn: bferr("Syntax error"); if (eq(p, S_LPAR /* "(" */)) { tchar **e = v; if (hadsub) goto setsyn; for (;;) { if (!*e) bferr("Missing )"); if (**e == ')') break; e++; } p = *e; *e = 0; vecp = saveblk(v); set1(vp, vecp, &shvhed); *e = p; v = e + 1; } else if (hadsub) { retp = savestr(p); asx(vp, subscr, retp); xfree(retp); retp = 0; } else set(vp, savestr(p)); if (eq(vp, S_path /* "path" */)) { exportpath(adrof(S_path /* "path" */)->vec); dohash(xhash); } else if (eq(vp, S_histchars /* "histchars" */)) { tchar *p = value(S_histchars /* "histchars" */); HIST = *p++; HISTSUB = *p; } else if (eq(vp, S_user /* "user" */)) local_setenv(S_USER /* "USER" */, value(vp)); else if (eq(vp, S_term /* "term" */)) local_setenv(S_TERM /* "TERM" */, value(vp)); else if (eq(vp, S_home /* "home" */)) local_setenv(S_HOME /* "HOME" */, value(vp)); #ifdef FILEC else if (eq(vp, S_filec /* "filec" */)) filec = 1; else if (eq(vp, S_cdpath /* "cdpath" */)) dohash(xhash2); #endif } while (p = *v++); }
void dolet(tchar **v) { tchar *p; tchar *vp, c, op; bool hadsub; int subscr; v++; p = *v++; if (p == 0) { prvars(); return; } do { hadsub = 0; for (vp = p; alnum(*p); p++) continue; if (vp == p || !letter(*vp)) goto letsyn; if (*p == '[') { hadsub++; p = getinx(p, &subscr); } if (*p == 0 && *v) p = *v++; if (op = *p) *p++ = 0; else goto letsyn; vp = savestr(vp); if (op == '=') { c = '='; p = xset(p, &v); } else { c = *p++; /* if (any(c, "+-")) { */ if (c == '+' || c == '-') { if (c != op || *p) goto letsyn; p = plusplus; } else { /* if (any(op, "<>")) { */ if (op == '<' || op == '>') { if (c != op) goto letsyn; c = *p++; letsyn: bferr("Syntax error"); } if (c != '=') goto letsyn; p = xset(p, &v); } } if (op == '=') if (hadsub) asx(vp, subscr, p); else set(vp, p); else if (hadsub) #ifndef V6 /* avoid bug in vax CC */ { struct varent *gv = getvx(vp, subscr); asx(vp, subscr, operate(op, gv->vec[subscr - 1], p)); } #else asx(vp, subscr, operate(op, getvx(vp, subscr)->vec[subscr - 1], p)); #endif else set(vp, operate(op, value(vp), p)); if (eq(vp, S_path /* "path" */)) { exportpath(adrof(S_path /* "path" */)->vec); dohash(xhash); } if (eq(vp, S_cdpath /* "cdpath" */)) dohash(xhash2); xfree(vp); if (c != '=') xfree(p); } while (p = *v++);