static void printcmdnamnode(HashNode hn, int printflags) { Cmdnam cn = (Cmdnam) hn; if (printflags & PRINT_WHENCE_WORD) { printf("%s: %s\n", cn->node.nam, (cn->node.flags & HASHED) ? "hashed" : "command"); return; } if ((printflags & PRINT_WHENCE_CSH) || (printflags & PRINT_WHENCE_SIMPLE)) { if (cn->node.flags & HASHED) { zputs(cn->u.cmd, stdout); putchar('\n'); } else { zputs(*(cn->u.name), stdout); putchar('/'); zputs(cn->node.nam, stdout); putchar('\n'); } return; } if (printflags & PRINT_WHENCE_VERBOSE) { if (cn->node.flags & HASHED) { nicezputs(cn->node.nam, stdout); printf(" is hashed to "); nicezputs(cn->u.cmd, stdout); putchar('\n'); } else { nicezputs(cn->node.nam, stdout); printf(" is "); nicezputs(*(cn->u.name), stdout); putchar('/'); nicezputs(cn->node.nam, stdout); putchar('\n'); } return; } if (printflags & PRINT_LIST) { printf("hash "); if(cn->node.nam[0] == '-') printf("-- "); } if (cn->node.flags & HASHED) { quotedzputs(cn->node.nam, stdout); putchar('='); quotedzputs(cn->u.cmd, stdout); putchar('\n'); } else { quotedzputs(cn->node.nam, stdout); putchar('='); quotedzputs(*(cn->u.name), stdout); putchar('/'); quotedzputs(cn->node.nam, stdout); putchar('\n'); } }
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'); }
static void printaliasnode(HashNode hn, int printflags) { Alias a = (Alias) hn; if (printflags & PRINT_NAMEONLY) { zputs(a->node.nam, stdout); putchar('\n'); return; } if (printflags & PRINT_WHENCE_WORD) { printf("%s: alias\n", a->node.nam); return; } if (printflags & PRINT_WHENCE_SIMPLE) { zputs(a->text, stdout); putchar('\n'); return; } if (printflags & PRINT_WHENCE_CSH) { nicezputs(a->node.nam, stdout); printf(": "); if (a->node.flags & ALIAS_SUFFIX) printf("suffix "); else if (a->node.flags & ALIAS_GLOBAL) printf("globally "); printf ("aliased to "); nicezputs(a->text, stdout); putchar('\n'); return; } if (printflags & PRINT_WHENCE_VERBOSE) { nicezputs(a->node.nam, stdout); printf(" is a"); if (a->node.flags & ALIAS_SUFFIX) printf(" suffix"); else if (a->node.flags & ALIAS_GLOBAL) printf(" global"); else printf("n"); printf(" alias for "); nicezputs(a->text, stdout); putchar('\n'); return; } if (printflags & PRINT_LIST) { printf("alias "); if (a->node.flags & ALIAS_SUFFIX) printf("-s "); else if (a->node.flags & ALIAS_GLOBAL) printf("-g "); /* If an alias begins with `-', then we must output `-- ' * * first, so that it is not interpreted as an option. */ if(a->node.nam[0] == '-') printf("-- "); } quotedzputs(a->node.nam, stdout); putchar('='); quotedzputs(a->text, stdout); putchar('\n'); }
static int bin_zpty(char *nam, char **args, Options ops, UNUSED(int func)) { if ((OPT_ISSET(ops,'r') && OPT_ISSET(ops,'w')) || ((OPT_ISSET(ops,'r') || OPT_ISSET(ops,'w')) && (OPT_ISSET(ops,'d') || OPT_ISSET(ops,'e') || OPT_ISSET(ops,'b') || OPT_ISSET(ops,'L'))) || (OPT_ISSET(ops,'w') && (OPT_ISSET(ops,'t') || OPT_ISSET(ops,'m'))) || (OPT_ISSET(ops,'n') && (OPT_ISSET(ops,'b') || OPT_ISSET(ops,'e') || OPT_ISSET(ops,'r') || OPT_ISSET(ops,'t') || OPT_ISSET(ops,'d') || OPT_ISSET(ops,'L') || OPT_ISSET(ops,'m'))) || (OPT_ISSET(ops,'d') && (OPT_ISSET(ops,'b') || OPT_ISSET(ops,'e') || OPT_ISSET(ops,'L') || OPT_ISSET(ops,'t') || OPT_ISSET(ops,'m'))) || (OPT_ISSET(ops,'L') && (OPT_ISSET(ops,'b') || OPT_ISSET(ops,'e') || OPT_ISSET(ops,'m')))) { zwarnnam(nam, "illegal option combination"); return 1; } if (OPT_ISSET(ops,'r') || OPT_ISSET(ops,'w')) { Ptycmd p; if (!*args) { zwarnnam(nam, "missing pty command name"); return 1; } else if (!(p = getptycmd(*args))) { zwarnnam(nam, "no such pty command: %s", *args); return 1; } if (p->fin) return 2; return (OPT_ISSET(ops,'r') ? ptyread(nam, p, args + 1, OPT_ISSET(ops,'t'), OPT_ISSET(ops, 'm')) : ptywrite(p, args + 1, OPT_ISSET(ops,'n'))); } else if (OPT_ISSET(ops,'d')) { Ptycmd p; int ret = 0; if (*args) { while (*args) if ((p = getptycmd(*args++))) deleteptycmd(p); else { zwarnnam(nam, "no such pty command: %s", args[-1]); ret = 1; } } else deleteallptycmds(); return ret; } else if (OPT_ISSET(ops,'t')) { Ptycmd p; if (!*args) { zwarnnam(nam, "missing pty command name"); return 1; } else if (!(p = getptycmd(*args))) { zwarnnam(nam, "no such pty command: %s", *args); return 1; } checkptycmd(p); return p->fin; } else if (*args) { if (!args[1]) { zwarnnam(nam, "missing command"); return 1; } if (getptycmd(*args)) { zwarnnam(nam, "pty command name already used: %s", *args); return 1; } return newptycmd(nam, *args, args + 1, OPT_ISSET(ops,'e'), OPT_ISSET(ops,'b')); } else { Ptycmd p; char **a; for (p = ptycmds; p; p = p->next) { checkptycmd(p); if (OPT_ISSET(ops,'L')) printf("%s %s%s%s ", nam, (p->echo ? "-e " : ""), (p->nblock ? "-b " : ""), p->name); else if (p->fin) printf("(finished) %s: ", p->name); else printf("(%d) %s: ", p->pid, p->name); for (a = p->args; *a; ) { quotedzputs(*a++, stdout); if (*a) putchar(' '); } putchar('\n'); } return 0; } }