📄 front.c
字号:
return (i); } else if (*i != NORMAL) { *num = nn; return (i); } } } break; case CO_FOREACH: for (wl = cp_variablesubst(cp_bquote(cp_doglob(wl_copy(bl-> co_text)))); wl; wl = wl->wl_next) { cp_vset(bl->co_foreachvar, VT_STRING, wl->wl_word); for (ch = bl->co_children; ch; ch = cn) { cn = ch->co_next; i = doblock(ch, &nn); switch (*i) { case NORMAL: break; case BROKEN: /* Break. */ if (nn < 2) return (NORMAL_STR); else { *num = nn - 1; return (BROKEN_STR); } case CONTINUED: /* Continue. */ if (nn < 2) { cn = NULL; break; } else { *num = nn - 1; return (CONTINUED_STR); } default: cn = findlabel(i, bl->co_children); if (!cn) return (i); } } } break; case CO_BREAK: if (bl->co_numtimes > 0) { *num = bl->co_numtimes; return (BROKEN_STR); } else { fprintf(cp_err, "Warning: break %d a no-op\n", bl->co_numtimes); return (NORMAL_STR); } case CO_CONTINUE: if (bl->co_numtimes > 0) { *num = bl->co_numtimes; return (CONTINUED_STR); } else { fprintf(cp_err, "Warning: continue %d a no-op\n", bl->co_numtimes); return (NORMAL_STR); } case CO_GOTO: wl = cp_variablesubst(cp_bquote(cp_doglob( wl_copy(bl->co_text)))); return (wl->wl_word); case CO_LABEL: /* Do nothing. */ break; case CO_STATEMENT: docommand(wl_copy(bl->co_text)); break; case CO_UNFILLED: /* There was probably an error here... */ fprintf(cp_err, "Warning: ignoring previous error\n"); break; default: fprintf(cp_err, "doblock: Internal Error: bad block type %d\n", bl->co_type); return (NORMAL_STR); } return (NORMAL_STR);}static struct control *findlabel(s, ct) char *s; struct control *ct;{ while (ct) { if ((ct->co_type == CO_LABEL) && eq(s, ct->co_text->wl_word)) break; ct = ct->co_next; } return (ct);}/* This blows away the control structures... */voidcp_resetcontrol(){ if (cend[stackp] && cend[stackp]->co_parent) fprintf(cp_err, "Warning: EOF before block terminated\n"); /* We probably should free the control structures... */ control[0] = cend[0] = NULL; stackp = 0; (void) cp_kwswitch(CT_LABEL, (char *) NULL); return;}/* Push or pop a new control structure set... */voidcp_popcontrol(){ if (cp_debug) fprintf(cp_err, "pop: stackp: %d -> %d\n", stackp, stackp - 1); if (stackp < 1) fprintf(cp_err, "cp_popcontrol: Internal Error: stack empty\n"); else stackp--; return;}voidcp_pushcontrol(){ if (cp_debug) fprintf(cp_err, "push: stackp: %d -> %d\n", stackp, stackp + 1); if (stackp > CONTROLSTACKSIZE - 2) { fprintf(cp_err, "Error: stack overflow -- max depth = %d\n", CONTROLSTACKSIZE); stackp = 0; } else { stackp++; control[stackp] = cend[stackp] = NULL; } return;}/* And this returns to the top level (for use in the interrupt handlers). */voidcp_toplevel(){ stackp = 0; if (cend[stackp]) while (cend[stackp]->co_parent) cend[stackp] = cend[stackp]->co_parent; return;}/* Note that we only do io redirection when we get to here - we also * postpone some other things until now. */static voiddocommand(wlist) register wordlist *wlist;{ register char *r, *s, *t; char *lcom; int nargs; register int i; struct comm *command; wordlist *wl, *nextc, *ee, *rwlist; if (cp_debug) { printf("docommand "); wl_print(wlist, stdout); (void) putc('\n', stdout); } /* Do all the things that used to be done by cshpar when the line * was read... */ wlist = cp_variablesubst(wlist); pwlist(wlist, "After variable substitution"); wlist = cp_bquote(wlist); pwlist(wlist, "After backquote substitution"); wlist = cp_doglob(wlist); pwlist(wlist, "After globbing"); if (!wlist || !wlist->wl_word) return; /* Now loop through all of the commands given. */ rwlist = wlist; do { for (nextc = wlist; nextc; nextc = nextc->wl_next) if (eq(nextc->wl_word, cp_csep)) break; /* Temporarily hide the rest of the command... */ if (nextc && nextc->wl_prev) nextc->wl_prev->wl_next = NULL; ee = wlist->wl_prev; if (ee) wlist->wl_prev = NULL; if (nextc == wlist) { /* There was no text... */ goto out; } /* And do the redirection. */ cp_ioreset(); for (i = 0; noredirect[i]; i++) if (eq(wlist->wl_word, noredirect[i])) break; if (!noredirect[i]) { if (!(wlist = cp_redirect(wlist))) { cp_ioreset(); return; } } /* Get rid of all the 8th bits now... */ cp_striplist(wlist); s = wlist->wl_word; /* Look for the command in the command list. */ for (i = 0; cp_coms[i].co_comname; i++) { /* strcmp(cp_coms[i].co_comname, s) ... */ for (t = cp_coms[i].co_comname, r = s; *t && *r; t++, r++) if (*t != *r) break; if (!*t && !*r) break; } /* Now give the user-supplied command routine a try... */ if (!cp_coms[i].co_func && cp_oddcomm(s, wlist->wl_next)) goto out; /* If it's not there, try it as a unix command. */ if (!cp_coms[i].co_comname) { if (cp_dounixcom && cp_unixcom(wlist)) goto out; fprintf(cp_err,"%s: no such command available in %s\n", s, cp_program); goto out; /* If it's there but spiceonly, and this is nutmeg, error. */ } else if (!cp_coms[i].co_func && ft_nutmeg && (cp_coms[i].co_spiceonly)) { fprintf(cp_err,"%s: command available only in spice\n", s); goto out; } /* The command was a valid spice/nutmeg command. */ command = &cp_coms[i]; nargs = 0; for (wl = wlist->wl_next; wl; wl = wl->wl_next) nargs++; if (command->co_stringargs) { lcom = wl_flatten(wlist->wl_next); (*command->co_func) (lcom); } else { if (nargs < command->co_minargs) { if (command->co_argfn) { (*command->co_argfn) (wlist->wl_next, command); } else { fprintf(cp_err, "%s: too few args.\n", s); } } else if (nargs > command->co_maxargs) { fprintf(cp_err, "%s: too many args.\n", s); } else (*command->co_func) (wlist->wl_next); } /* Now fix the pointers and advance wlist. */out: wlist->wl_prev = ee; if (nextc) { if (nextc->wl_prev) nextc->wl_prev->wl_next = nextc; wlist = nextc->wl_next; } } while (nextc && wlist); wl_free(rwlist); /* Do periodic sorts of things... */ cp_periodic(); cp_ioreset(); return;}/* Get a command. This does all the bookkeeping things like turning * command completion on and off... */static wordlist *getcommand(string) char *string;{ wordlist *wlist; int i = 0, j; static char buf[64]; struct control *c; if (cp_debug) fprintf(cp_err, "calling getcommand %s\n", string ? string : ""); if (cend[stackp]) { for (c = cend[stackp]->co_parent; c; c = c->co_parent) i++; if (i) { for (j = 0; j < i; j++) buf[j] = '>'; buf[j] = ' '; buf[j + 1] = '\0'; cp_altprompt = buf; } else cp_altprompt = NULL; } else cp_altprompt = NULL; cp_cwait = true; wlist = cp_parse(string); cp_cwait = false; if (cp_debug) { printf("getcommand "); wl_print(wlist, stdout); (void) putc('\n', stdout); } return (wlist);}/* This is also in cshpar.c ... */static voidpwlist(wlist, name) wordlist *wlist; char *name;{ wordlist *wl; if (!cp_debug) return; fprintf(cp_err, "%s : [ ", name); for (wl = wlist; wl; wl = wl->wl_next) fprintf(cp_err, "%s ", wl->wl_word); fprintf(cp_err, "]\n"); return;}static int indent;/* ARGSUSED */voidcom_cdump(wl) wordlist *wl;{ struct control *c; indent = 0; for (c = control[stackp]; c; c = c->co_next) dodump(c); return;}#define tab(num) for (i = 0; i < num; i++) (void) putc(' ', cp_out);static voiddodump(cc) struct control *cc;{ int i; struct control *tc; switch (cc->co_type) { case CO_UNFILLED: tab(indent); fprintf(cp_out, "(unfilled)\n"); break; case CO_STATEMENT: tab(indent); wl_print(cc->co_text, cp_out); (void) putc('\n', cp_out); break; case CO_WHILE: tab(indent); fprintf(cp_out, "while "); wl_print(cc->co_cond, cp_out); (void) putc('\n', cp_out); indent += 8; for (tc = cc->co_children; tc; tc = tc->co_next) dodump(tc); indent -= 8; tab(indent); fprintf(cp_out, "end\n"); break; case CO_REPEAT: tab(indent); fprintf(cp_out, "repeat "); if (cc->co_numtimes != -1) fprintf(cp_out, "%d\n", cc->co_numtimes); else (void) putc('\n', cp_out); indent += 8; for (tc = cc->co_children; tc; tc = tc->co_next) dodump(tc); indent -= 8; tab(indent); fprintf(cp_out, "end\n"); break; case CO_DOWHILE: tab(indent); fprintf(cp_out, "dowhile "); wl_print(cc->co_cond, cp_out); (void) putc('\n', cp_out); indent += 8; for (tc = cc->co_children; tc; tc = tc->co_next) dodump(tc); indent -= 8; tab(indent); fprintf(cp_out, "end\n"); break; case CO_IF: tab(indent); fprintf(cp_out, "if "); wl_print(cc->co_cond, cp_out); (void) putc('\n', cp_out); indent += 8; for (tc = cc->co_children; tc; tc = tc->co_next) dodump(tc); indent -= 8; tab(indent); fprintf(cp_out, "end\n"); break; case CO_FOREACH: tab(indent); fprintf(cp_out, "foreach %s ", cc->co_foreachvar); wl_print(cc->co_text, cp_out); (void) putc('\n', cp_out); indent += 8; for (tc = cc->co_children; tc; tc = tc->co_next) dodump(tc); indent -= 8; tab(indent); fprintf(cp_out, "end\n"); break; case CO_BREAK: tab(indent); if (cc->co_numtimes != 1) fprintf(cp_out, "break %d\n", cc->co_numtimes); else fprintf(cp_out, "break\n"); break; case CO_CONTINUE: tab(indent); if (cc->co_numtimes != 1) fprintf(cp_out, "continue %d\n", cc->co_numtimes); else fprintf(cp_out, "continue\n"); break; case CO_LABEL: tab(indent); fprintf(cp_out, "label %s\n", cc->co_text->wl_word); break; case CO_GOTO: tab(indent); fprintf(cp_out, "goto %s\n", cc->co_text->wl_word); break; default: tab(indent); fprintf(cp_out, "bad type %d\n", cc->co_type); break; } return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -