static void printshfuncnode(HashNode hn, int printflags) { Shfunc f = (Shfunc) hn; char *t = 0; if ((printflags & PRINT_NAMEONLY) || ((printflags & PRINT_WHENCE_SIMPLE) && !(printflags & PRINT_WHENCE_FUNCDEF))) { zputs(f->nam, stdout); putchar('\n'); return; } if ((printflags & (PRINT_WHENCE_VERBOSE|PRINT_WHENCE_WORD)) && !(printflags & PRINT_WHENCE_FUNCDEF)) { nicezputs(f->nam, stdout); printf((printflags & PRINT_WHENCE_WORD) ? ": function\n" : " is a shell function\n"); return; } quotedzputs(f->nam, stdout); if (f->funcdef || f->flags & PM_UNDEFINED) { printf(" () {\n\t"); if (f->flags & PM_UNDEFINED) printf("%c undefined\n\t", hashchar); else t = getpermtext(f->funcdef, NULL); if (f->flags & PM_TAGGED) printf("%c traced\n\t", hashchar); if (!t) { char *fopt = "Utkz"; int flgs[] = { PM_UNALIASED, PM_TAGGED, PM_KSHSTORED, PM_ZSHSTORED, 0 }; int fl;; zputs("builtin autoload -X", stdout); for (fl=0;fopt[fl];fl++) if (f->flags & flgs[fl]) putchar(fopt[fl]); } else { zputs(t, stdout); zsfree(t); if (f->funcdef->flags & EF_RUN) { printf("\n\t"); quotedzputs(f->nam, stdout); printf(" \"$@\""); } } printf("\n}\n"); } else { printf(" () { }\n"); } }
void printshfuncnode(HashNode hn, int printflags) { Shfunc f = (Shfunc) hn; char *t; if ((printflags & PRINT_NAMEONLY) || ((printflags & PRINT_WHENCE_SIMPLE) && !(printflags & PRINT_WHENCE_FUNCDEF))) { zputs(f->nam, stdout); putchar('\n'); return; } if ((printflags & PRINT_WHENCE_VERBOSE) && !(printflags & PRINT_WHENCE_FUNCDEF)) { nicezputs(f->nam, stdout); printf(" is a shell function\n"); return; } if (f->flags & PM_UNDEFINED) printf("undefined "); if (f->flags & PM_TAGGED) printf("traced "); if (!f->funcdef) { nicezputs(f->nam, stdout); printf(" () { }\n"); return; } t = getpermtext((void *) dupstruct((void *) f->funcdef)); quotedzputs(f->nam, stdout); printf(" () {\n\t"); zputs(t, stdout); printf("\n}\n"); zsfree(t); }
enum loop_return loop(int toplevel, int justonce) { Eprog prog; int err, non_empty = 0; queue_signals(); pushheap(); if (!toplevel) zcontext_save(); for (;;) { freeheap(); if (stophist == 3) /* re-entry via preprompt() */ hend(NULL); hbegin(1); /* init history mech */ if (isset(SHINSTDIN)) { setblock_stdin(); if (interact && toplevel) { int hstop = stophist; stophist = 3; /* * Reset all errors including the interrupt error status * immediately, so preprompt runs regardless of what * just happened. We'll reset again below as a * precaution to ensure we get back to the command line * no matter what. */ errflag = 0; preprompt(); if (stophist != 3) hbegin(1); else stophist = hstop; /* * Reset all errors, including user interupts. * This is what allows ^C in an interactive shell * to return us to the command line. */ errflag = 0; } } use_exit_printed = 0; intr(); /* interrupts on */ lexinit(); /* initialize lexical state */ if (!(prog = parse_event(ENDINPUT))) { /* if we couldn't parse a list */ hend(NULL); if ((tok == ENDINPUT && !errflag) || (tok == LEXERR && (!isset(SHINSTDIN) || !toplevel)) || justonce) break; if (exit_pending) { /* * Something down there (a ZLE function?) decided * to exit when there was stuff to clear up. * Handle that now. */ stopmsg = 1; zexit(exit_pending >> 1, 0); } if (tok == LEXERR && !lastval) lastval = 1; continue; } if (hend(prog)) { enum lextok toksav = tok; non_empty = 1; if (toplevel && (getshfunc("preexec") || paramtab->getnode(paramtab, "preexec" HOOK_SUFFIX))) { LinkList args; char *cmdstr; /* * As we're about to freeheap() or popheap() * anyway, there's no gain in using permanent * storage here. */ args = newlinklist(); addlinknode(args, "preexec"); /* If curline got dumped from the history, we don't know * what the user typed. */ if (hist_ring && curline.histnum == curhist) addlinknode(args, hist_ring->node.nam); else addlinknode(args, ""); addlinknode(args, dupstring(getjobtext(prog, NULL))); addlinknode(args, cmdstr = getpermtext(prog, NULL, 0)); callhookfunc("preexec", args, 1, NULL); /* The only permanent storage is from getpermtext() */ zsfree(cmdstr); /* * Note this does *not* remove a user interrupt error * condition, even though we're at the top level loop: * that would be inconsistent with the case where * we didn't execute a preexec function. This is * an implementation detail that an interrupting user * does't care about. */ errflag &= ~ERRFLAG_ERROR; } if (stopmsg) /* unset 'you have stopped jobs' flag */ stopmsg--; execode(prog, 0, 0, toplevel ? "toplevel" : "file"); tok = toksav; if (toplevel) noexitct = 0; } if (ferror(stderr)) { zerr("write error"); clearerr(stderr); } if (subsh) /* how'd we get this far in a subshell? */ exit(lastval); if (((!interact || sourcelevel) && errflag) || retflag) break; if (isset(SINGLECOMMAND) && toplevel) { dont_queue_signals(); if (sigtrapped[SIGEXIT]) dotrap(SIGEXIT); exit(lastval); } if (justonce) break; }
static void printshfuncnode(HashNode hn, int printflags) { Shfunc f = (Shfunc) hn; char *t = 0; if ((printflags & PRINT_NAMEONLY) || ((printflags & PRINT_WHENCE_SIMPLE) && !(printflags & PRINT_WHENCE_FUNCDEF))) { zputs(f->node.nam, stdout); putchar('\n'); return; } if ((printflags & (PRINT_WHENCE_VERBOSE|PRINT_WHENCE_WORD)) && !(printflags & PRINT_WHENCE_FUNCDEF)) { nicezputs(f->node.nam, stdout); printf((printflags & PRINT_WHENCE_WORD) ? ": function" : (f->node.flags & PM_UNDEFINED) ? " is an autoload shell function" : " is a shell function"); if (f->filename && (printflags & PRINT_WHENCE_VERBOSE) && strcmp(f->filename, f->node.nam) != 0) { printf(" from "); quotedzputs(f->filename, stdout); } putchar('\n'); return; } quotedzputs(f->node.nam, stdout); if (f->funcdef || f->node.flags & PM_UNDEFINED) { printf(" () {\n"); zoutputtab(stdout); if (f->node.flags & PM_UNDEFINED) { printf("%c undefined\n", hashchar); zoutputtab(stdout); } else t = getpermtext(f->funcdef, NULL, 1); if (f->node.flags & (PM_TAGGED|PM_TAGGED_LOCAL)) { printf("%c traced\n", hashchar); zoutputtab(stdout); } if (!t) { char *fopt = "UtTkz"; int flgs[] = { PM_UNALIASED, PM_TAGGED, PM_TAGGED_LOCAL, PM_KSHSTORED, PM_ZSHSTORED, 0 }; int fl;; zputs("builtin autoload -X", stdout); for (fl=0;fopt[fl];fl++) if (f->node.flags & flgs[fl]) putchar(fopt[fl]); } else { zputs(t, stdout); zsfree(t); if (f->funcdef->flags & EF_RUN) { printf("\n"); zoutputtab(stdout); quotedzputs(f->node.nam, stdout); printf(" \"$@\""); } } printf("\n}"); } else { printf(" () { }"); } if (f->redir) { t = getpermtext(f->redir, NULL, 1); if (t) { zputs(t, stdout); zsfree(t); } } putchar('\n'); }
enum loop_return loop(int toplevel, int justonce) { Eprog prog; int err, non_empty = 0; pushheap(); if (!toplevel) lexsave(); for (;;) { freeheap(); if (stophist == 3) /* re-entry via preprompt() */ hend(NULL); hbegin(1); /* init history mech */ if (isset(SHINSTDIN)) { setblock_stdin(); if (interact && toplevel) { int hstop = stophist; stophist = 3; preprompt(); if (stophist != 3) hbegin(1); else stophist = hstop; errflag = 0; } } use_exit_printed = 0; intr(); /* interrupts on */ lexinit(); /* initialize lexical state */ if (!(prog = parse_event())) { /* if we couldn't parse a list */ hend(NULL); if ((tok == ENDINPUT && !errflag) || (tok == LEXERR && (!isset(SHINSTDIN) || !toplevel)) || justonce) break; if (exit_pending) { /* * Something down there (a ZLE function?) decided * to exit when there was stuff to clear up. * Handle that now. */ stopmsg = 1; zexit(exit_pending >> 1, 0); } if (tok == LEXERR && !lastval) lastval = 1; continue; } if (hend(prog)) { int toksav = tok; non_empty = 1; if (toplevel && (getshfunc("preexec") || paramtab->getnode(paramtab, "preexec" HOOK_SUFFIX))) { LinkList args; char *cmdstr; /* * As we're about to freeheap() or popheap() * anyway, there's no gain in using permanent * storage here. */ args = newlinklist(); addlinknode(args, "preexec"); /* If curline got dumped from the history, we don't know * what the user typed. */ if (hist_ring && curline.histnum == curhist) addlinknode(args, hist_ring->node.nam); else addlinknode(args, ""); addlinknode(args, dupstring(getjobtext(prog, NULL))); addlinknode(args, cmdstr = getpermtext(prog, NULL, 0)); callhookfunc("preexec", args, 1, NULL); /* The only permanent storage is from getpermtext() */ zsfree(cmdstr); errflag = 0; } if (stopmsg) /* unset 'you have stopped jobs' flag */ stopmsg--; execode(prog, 0, 0, toplevel ? "toplevel" : "file"); tok = toksav; if (toplevel) noexitct = 0; } if (ferror(stderr)) { zerr("write error"); clearerr(stderr); } if (subsh) /* how'd we get this far in a subshell? */ exit(lastval); if (((!interact || sourcelevel) && errflag) || retflag) break; if (isset(SINGLECOMMAND) && toplevel) { if (sigtrapped[SIGEXIT]) dotrap(SIGEXIT); exit(lastval); } if (justonce) break; }