/*ARGSUSED*/ void douniverse(Char **v, struct command *c) { Char *cp = v[1]; Char *cp2; /* dunno how many elements v comes in with */ char ubuf[100]; if (cp == 0) { (void) getuniverse(ubuf); xprintf("%s\n", ubuf); } else { cp2 = v[2]; if (cp2 == 0) { if (*cp == '\0' || setuniverse(short2str(cp)) != 0) stderror(ERR_NAME | ERR_STRING, CGETS(23, 12, "Illegal universe")); } else { (void) getuniverse(ubuf); if (*cp == '\0' || setuniverse(short2str(cp)) != 0) stderror(ERR_NAME | ERR_STRING, CGETS(23, 12, "Illegal universe")); cleanup_push(ubuf, setuniverse_cleanup); if (setintr) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } lshift(v, 2); if (setintr) cleanup_until(&pintr_disabled); reexecute(c); cleanup_until(ubuf); } } }
static int migratepid(pit_t pid, siteno_t new_site) { struct sf *st; int need_local; need_local = (pid == 0) || (pid == getpid()); if (kill3(pid, SIGMIGRATE, new_site) < 0) { xprintf("%d: %s\n", pid, strerror(errno)); return (-1); } if (need_local) { if ((new_site = site(0)) == -1) { xprintf(CGETS(23, 4, "site: %s\n"), strerror(errno)); return (-1); } if ((st = sfnum(new_site)) == NULL) { xprintf(CGETS(23, 5, "%d: Site not found\n"), new_site); return (-1); } if (setlocal(st->sf_local, strlen(st->sf_local)) == -1) { xprintf(CGETS(23, 6, "setlocal: %s: %s\n"), st->sf_local, strerror(errno)); return (-1); } } return (0); }
void AddXkey(const CStr *Xkey, XmapVal *val, int ntype) { CStr cs; cs.buf = Xkey->buf; cs.len = Xkey->len; if (Xkey->len == 0) { xprintf("%s", CGETS(9, 1, "AddXkey: Null extended-key not allowed.\n")); return; } if (ntype == XK_CMD && val->cmd == F_XKEY) { xprintf("%s", CGETS(9, 2, "AddXkey: sequence-lead-in command not allowed\n")); return; } if (Xmap == NULL) /* tree is initially empty. Set up new node to match Xkey[0] */ Xmap = GetFreeNode(&cs); /* it is properly initialized */ /* Now recurse through Xmap */ (void) TryNode(Xmap, &cs, val, ntype); return; }
int xgethostname(char *name, int namlen) { # if !defined(_MINIX) && !defined(__EMX__) && !defined(WINNT_NATIVE) int i, retval; struct utsname uts; retval = uname(&uts); # ifdef DEBUG xprintf(CGETS(23, 14, "sysname: %s\n"), uts.sysname); xprintf(CGETS(23, 15, "nodename: %s\n"), uts.nodename); xprintf(CGETS(23, 16, "release: %s\n"), uts.release); xprintf(CGETS(23, 17, "version: %s\n"), uts.version); xprintf(CGETS(23, 18, "machine: %s\n"), uts.machine); # endif /* DEBUG */ i = strlen(uts.nodename) + 1; (void) strncpy(name, uts.nodename, i < namlen ? i : namlen); return retval; # else /* !_MINIX && !__EMX__ */ if (namlen > 0) { # ifdef __EMX__ (void) strncpy(name, "OS/2", namlen); # else /* _MINIX */ (void) strncpy(name, "minix", namlen); # endif /* __EMX__ */ name[namlen-1] = '\0'; } return(0); #endif /* _MINIX && !__EMX__ */ } /* end xgethostname */
void dodmmode(Char **v, struct command *c) { Char *cp = v[1]; USE(c); if ( !cp ) { int mode; mode = dmmode(0); dmmode(mode); xprintf("%d\n",mode); } else { if (cp[1] != '\0') stderror(ERR_NAME | ERR_STRING, CGETS(23, 30, "Too many arguments")); else switch(*cp) { case '0': dmmode(0); break; case '1': dmmode(1); break; default: stderror(ERR_NAME | ERR_STRING, CGETS(23, 31, "Invalid argument")); } } }
/* Puts terminal in insert character mode, or inserts num characters in the line */ void Insert_write(register Char *cp, register int num) { UNREFERENCED_PARAMETER(cp); if (num <= 0) return; if (!T_CanIns) { #ifdef DEBUG_EDIT xprintf(CGETS(7, 18, "ERROR: cannot insert\r\n")); #endif /* DEBUG_EDIT */ flush(); return; } if (num > TermH) { #ifdef DEBUG_SCREEN xprintf(CGETS(7, 19, "StartInsert: num is riduculous: %d\r\n"), num); flush(); #endif /* DEBUG_SCREEN */ return; } }
/*ARGSUSED*/ void dowarp(Char **v, struct command *c) { int warp, oldwarp; struct warpent *we; volatile struct sigaction old_sigsys_handler; char *newwarp; if (setjmp(sigsys_buf)) { sigaction(SIGSYS, &old_sigsys_handler, NULL); stderror(ERR_NAME | ERR_STRING, CGETS(23, 8, "You're trapped in a universe you never made")); return; } sigaction(SIGSYS, NULL, &old_sigsys_handler); signal(SIGSYS, catch_sigsys); warp = getwarp(); v++; if (*v == 0) { /* display warp value */ if (warp < 0) stderror(ERR_NAME | ERR_STRING, CGETS(23, 9, "Getwarp failed")); we = getwarpbyvalue(warp); if (we) printf("%s\n", we->w_name); else printf("%d\n", warp); } else { /* set warp value */ oldwarp = warp; newwarp = short2str(*v); if (Isdigit(*v[0])) warp = atoi(newwarp); else { we = getwarpbyname(newwarp); if (we) warp = we->w_value; else warp = -1; } if ((warp < 0) || (warp >= WARP_MAXLINK)) stderror(ERR_NAME | ERR_STRING, CGETS(23, 10, "Invalid warp")); if ((setwarp(warp) < 0) || (getwarp() != warp)) { (void) setwarp(oldwarp); stderror(ERR_NAME | ERR_STRING, CGETS(23, 11, "Setwarp failed")); } } sigaction(SIGSYS, &old_sigsys_handler, NULL); }
/* PrintOne(): * Print the specified key and its associated * function specified by val */ void printOne(const Char *key, const XmapVal *val, int ntype) { struct KeyFuncs *fp; static const char *fmt = "%s\n"; xprintf("%-15S-> ", key); if (val != NULL) switch (ntype) { case XK_STR: case XK_EXE: { unsigned char *p; p = unparsestring(&val->str, ntype == XK_STR ? STRQQ : STRBB); cleanup_push(p, xfree); xprintf(fmt, p); cleanup_until(p); break; } case XK_CMD: for (fp = FuncNames; fp->name; fp++) if (val->cmd == fp->func) xprintf(fmt, fp->name); break; default: abort(); break; } else xprintf(fmt, CGETS(9, 7, "no input")); }
static void Enumerate(struct Strbuf *buf, const XmapNode *ptr) { size_t old_len; if (ptr == NULL) { #ifdef DEBUG_EDIT xprintf(CGETS(9, 6, "Enumerate: BUG!! Null ptr passed\n!")); #endif return; } old_len = buf->len; unparsech(buf, ptr->ch); /* put this char at end of string */ if (ptr->next == NULL) { /* print this Xkey and function */ Strbuf_append1(buf, '"'); Strbuf_terminate(buf); printOne(buf->s, &ptr->val, ptr->type); } else Enumerate(buf, ptr->next); /* go to sibling if there is one */ if (ptr->sibling) { buf->len = old_len; Enumerate(buf, ptr->sibling); } }
/* PrintXKey(): * Print the binding associated with Xkey key. * Print entire Xmap if null */ void PrintXkey(const CStr *key) { struct Strbuf buf = Strbuf_INIT; CStr cs; if (key) { cs.buf = key->buf; cs.len = key->len; } else { cs.buf = STRNULL; cs.len = 0; } /* do nothing if Xmap is empty and null key specified */ if (Xmap == NULL && cs.len == 0) return; Strbuf_append1(&buf, '"'); cleanup_push(&buf, Strbuf_cleanup); if (Lookup(&buf, &cs, Xmap) <= -1) /* key is not bound */ xprintf(CGETS(9, 4, "Unbound extended key \"%S\"\n"), cs.buf); cleanup_until(&buf); }
/* The dowhich() is by: * Andreas Luik <*****@*****.**> * I S A GmbH - Informationssysteme fuer computerintegrierte Automatisierung * Azenberstr. 35 * D-7000 Stuttgart 1 * West-Germany * Thanks!! */ int cmd_expand(Char *cmd, Char **str) { struct wordent lexp[3]; struct varent *vp; int rv = TRUE; lexp[0].next = &lexp[1]; lexp[1].next = &lexp[2]; lexp[2].next = &lexp[0]; lexp[0].prev = &lexp[2]; lexp[1].prev = &lexp[0]; lexp[2].prev = &lexp[1]; lexp[0].word = STRNULL; lexp[2].word = STRret; if ((vp = adrof1(cmd, &aliases)) != NULL && vp->vec != NULL) { if (str == NULL) { xprintf(CGETS(22, 1, "%S: \t aliased to "), cmd); blkpr(vp->vec); xputchar('\n'); } else *str = blkexpand(vp->vec); } else { lexp[1].word = cmd; rv = tellmewhat(lexp, str); } return rv; }
/* * Karl Kleinpaste, 18 Jan 1984. * Added period_cmd(), which executes the alias "periodic" every * $tperiod minutes. Useful for occasional checking of msgs and such. */ void period_cmd(void) { Char *vp; time_t t, interval; pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); if (periodic_active) { /* an error must have been caught */ aliasrun(2, STRunalias, STRperiodic); xprintf("%s", CGETS(22, 6, "Faulty alias 'periodic' removed.\n")); goto leave; } periodic_active = 1; if (!whyles && adrof1(STRperiodic, &aliases)) { vp = varval(STRtperiod); if (vp == STRNULL) { aliasrun(1, STRperiodic, NULL); goto leave; } interval = getn(vp); (void) time(&t); if (t - t_period >= interval * 60) { t_period = t; aliasrun(1, STRperiodic, NULL); } } leave: periodic_active = 0; cleanup_until(&pintr_disabled); }
/* sitename(): * Return the site name where the process is running */ char * sitename(pid_t pid) { siteno_t ss; struct sf *st; if ((ss = site(pid)) == -1 || (st = sfnum(ss)) == NULL) return CGETS(23, 3, "unknown"); else return st->sf_sname; }
/*ARGSUSED*/ void dosetspath(Char **v, struct command *c) { int i; short j; char *s; sitepath_t p[MAXSITE]; struct sf *st; /* * sfname() on AIX G9.9 at least, mallocs too pointers p, q * then does the equivalent of while (*p++ == *q++) continue; * and then tries to free(p,q) them! Congrats to the wizard who * wrote that one. I bet he tested it really well too. * Sooo, we set dont_free :-) */ dont_free = 1; for (i = 0, v++; *v && *v[0] != '\0'; v++, i++) { s = short2str(*v); if (isdigit(*s)) p[i] = atoi(s); else if (strcmp(s, "LOCAL") == 0) p[i] = NULLSITE; else if ((st = sfctype(s)) != NULL) p[i] = SPATH_CPU | st->sf_ccode; else if ((j = getxid(s)) != -1) p[i] = SPATH_CPU | j; else if ((st = sfname(s)) != NULL) p[i] = st->sf_id; else { setname(s); stderror(ERR_NAME | ERR_STRING, CGETS(23, 1, "Bad cpu/site name")); } if (i == MAXSITE - 1) stderror(ERR_NAME | ERR_STRING, CGETS(23, 2, "Site path too long")); } if (setspath(p, i) == -1) stderror(ERR_SYSTEM, "setspath", strerror(errno)); dont_free = 0; }
int getv(Char *v) { if (eq(v, STRbsd43)) return(1); else if (eq(v, STRsys53)) return(0); else stderror(ERR_NAME | ERR_SYSTEM, short2str(v), CGETS(23, 28, "Invalid system type")); /*NOTREACHED*/ return(0); }
char * xstrerror(int i) { if (i >= 0 && i < sys_nerr) { return sys_errlist[i]; } else { static char *errbuf; /* = NULL; */ xfree(errbuf); errbuf = xasprintf(CGETS(23, 13, "Unknown Error: %d"), i); return errbuf; } }
void DeleteChars(int num) /* deletes <num> characters */ { if (num <= 0) return; if (!T_CanDel) { #ifdef DEBUG_EDIT xprintf(CGETS(7, 16, "ERROR: cannot delete\r\n")); #endif /* DEBUG_EDIT */ flush(); return; } if (num > TermH) { #ifdef DEBUG_SCREEN xprintf(CGETS(7, 17, "DeletChars: num is riduculous: %d\r\n"), num); flush(); #endif /* DEBUG_SCREEN */ return; } }
/* * Joachim Hoenig 07/16/91 Added beep_cmd, run every time tcsh wishes * to beep the terminal bell. Useful for playing nice sounds instead. */ void beep_cmd(void) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); if (beepcmd_active) { /* an error must have been caught */ aliasrun(2, STRunalias, STRbeepcmd); xprintf("%s", CGETS(22, 5, "Faulty alias 'beepcmd' removed.\n")); } else { beepcmd_active = 1; if (!whyles && adrof1(STRbeepcmd, &aliases)) aliasrun(1, STRbeepcmd, NULL); } beepcmd_active = 0; cleanup_until(&pintr_disabled); }
/*ARGSUSED*/ void dover(Char **v, struct command *c) { Char *p; setname(short2str(*v++)); if (!*v) { if (!(p = tgetenv(STRSYSTYPE))) stderror(ERR_NAME | ERR_STRING, CGETS(23, 29, "System type is not set")); xprintf("%S\n", p); } else { tsetenv(STRSYSTYPE, getv(*v) ? STRbsd43 : STRsys53); dohash(NULL, NULL); } }
/* * Paul Placeway 11/24/87 Added cwd_cmd by hacking precmd() into * submission... Run every time $cwd is set (after it is set). Useful * for putting your machine and cwd (or anything else) in an xterm title * space. */ void cwd_cmd(void) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); if (cwdcmd_active) { /* an error must have been caught */ aliasrun(2, STRunalias, STRcwdcmd); xprintf("%s", CGETS(22, 4, "Faulty alias 'cwdcmd' removed.\n")); goto leave; } cwdcmd_active = 1; if (!whyles && adrof1(STRcwdcmd, &aliases)) aliasrun(1, STRcwdcmd, NULL); leave: cwdcmd_active = 0; cleanup_until(&pintr_disabled); }
int DeleteXkey(const CStr *Xkey) { CStr s; s = *Xkey; if (s.len == 0) { xprintf("%s", CGETS(9, 3, "DeleteXkey: Null extended-key not allowed.\n")); return (-1); } if (Xmap == NULL) return (0); (void) TryDeleteNode(&Xmap, &s); return (0); }
/* * GrP Greg Parker May 2001 * Added job_cmd(), which is run every time a job is started or * foregrounded. The command is passed a single argument, the string * used to start the job originally. With precmd, useful for setting * xterm titles. * Cloned from cwd_cmd(). */ void job_cmd(Char *args) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); if (jobcmd_active) { /* an error must have been caught */ aliasrun(2, STRunalias, STRjobcmd); xprintf("%s", CGETS(22, 14, "Faulty alias 'jobcmd' removed.\n")); goto leave; } jobcmd_active = 1; if (!whyles && adrof1(STRjobcmd, &aliases)) { struct process *pp = pcurrjob; /* put things back after the hook */ aliasrun(2, STRjobcmd, args); pcurrjob = pp; } leave: jobcmd_active = 0; cleanup_until(&pintr_disabled); }
void rmstar(struct wordent *cp) { struct wordent *we, *args; struct wordent *tmp, *del; #ifdef RMDEBUG static Char STRrmdebug[] = {'r', 'm', 'd', 'e', 'b', 'u', 'g', '\0'}; Char *tag; #endif /* RMDEBUG */ Char *charac; char c; int ask, doit, star = 0, silent = 0, opintr_disabled; if (!adrof(STRrmstar)) return; #ifdef RMDEBUG tag = varval(STRrmdebug); #endif /* RMDEBUG */ we = cp->next; while (*we->word == ';' && we != cp) we = we->next; opintr_disabled = pintr_disabled; pintr_disabled = 0; while (we != cp) { #ifdef RMDEBUG if (*tag) xprintf(CGETS(22, 7, "parsing command line\n")); #endif /* RMDEBUG */ if (!Strcmp(we->word, STRrm)) { args = we->next; ask = (*args->word != '-'); while (*args->word == '-' && !silent) { /* check options */ for (charac = (args->word + 1); *charac && !silent; charac++) silent = (*charac == 'i' || *charac == 'f'); args = args->next; } ask = (ask || (!ask && !silent)); if (ask) { for (; !star && *args->word != ';' && args != cp; args = args->next) if (!Strcmp(args->word, STRstar)) star = 1; if (ask && star) { xprintf("%s", CGETS(22, 8, "Do you really want to delete all files? [n/y] ")); flush(); (void) force_read(SHIN, &c, 1); /* * Perhaps we should use the yesexpr from the * actual locale */ doit = (strchr(CGETS(22, 14, "Yy"), c) != NULL); while (c != '\n' && force_read(SHIN, &c, 1) == 1) continue; if (!doit) { /* remove the command instead */ #ifdef RMDEBUG if (*tag) xprintf(CGETS(22, 9, "skipping deletion of files!\n")); #endif /* RMDEBUG */ for (tmp = we; *tmp->word != '\n' && *tmp->word != ';' && tmp != cp;) { tmp->prev->next = tmp->next; tmp->next->prev = tmp->prev; xfree(tmp->word); del = tmp; tmp = tmp->next; xfree(del); } if (*tmp->word == ';') { tmp->prev->next = tmp->next; tmp->next->prev = tmp->prev; xfree(tmp->word); del = tmp; tmp = tmp->next; xfree(del); } we = tmp; continue; } } } } for (we = we->next; *we->word != ';' && we != cp; we = we->next) continue; if (*we->word == ';') we = we->next; } #ifdef RMDEBUG if (*tag) { xprintf(CGETS(22, 10, "command line now is:\n")); for (we = cp->next; we != cp; we = we->next) xprintf("%S ", we->word); } #endif /* RMDEBUG */ pintr_disabled = opintr_disabled; return; }
/*ARGSUSED*/ static void auto_lock(void) { #ifndef NO_CRYPT int i; char *srpp = NULL; struct passwd *pw; #undef XCRYPT #if defined(HAVE_AUTH_H) && defined(HAVE_GETAUTHUID) struct authorization *apw; extern char *crypt16 (const char *, const char *); # define XCRYPT(pw, a, b) crypt16(a, b) if ((pw = xgetpwuid(euid)) != NULL && /* effective user passwd */ (apw = getauthuid(euid)) != NULL) /* enhanced ultrix passwd */ srpp = apw->a_password; #elif defined(HAVE_SHADOW_H) struct spwd *spw; # define XCRYPT(pw, a, b) crypt(a, b) if ((pw = xgetpwuid(euid)) != NULL) { /* effective user passwd */ errno = 0; while ((spw = getspnam(pw->pw_name)) == NULL && errno == EINTR) { handle_pending_signals(); errno = 0; } if (spw != NULL) /* shadowed passwd */ srpp = spw->sp_pwdp; } #else #ifdef __CYGWIN__ # define XCRYPT(pw, a, b) cygwin_xcrypt(pw, a, b) #else # define XCRYPT(pw, a, b) crypt(a, b) #endif #if !defined(__MVS__) if ((pw = xgetpwuid(euid)) != NULL) /* effective user passwd */ srpp = pw->pw_passwd; #endif /* !MVS */ #endif if (srpp == NULL) { auto_logout(); /*NOTREACHED*/ return; } setalarm(0); /* Not for locking any more */ xputchar('\n'); for (i = 0; i < 5; i++) { const char *crpp; char *pp; #ifdef AFS char *afsname; Char *safs; if ((safs = varval(STRafsuser)) != STRNULL) afsname = short2str(safs); else if ((afsname = getenv("AFSUSER")) == NULL) afsname = pw->pw_name; #endif pp = xgetpass("Password:"******"\nIncorrect passwd for %s\n"), pw->pw_name); } #endif /* NO_CRYPT */ auto_logout(); }
/* Check if command is in continue list and do a "aliasing" if it exists as a job in background */ #undef CNDEBUG /* For now */ void continue_jobs(struct wordent *cp) { struct wordent *we; struct process *pp, *np; Char *cmd, *continue_list, *continue_args_list; #ifdef CNDEBUG Char *tag; static Char STRcndebug[] = {'c', 'n', 'd', 'e', 'b', 'u', 'g', '\0'}; #endif /* CNDEBUG */ int in_cont_list, in_cont_arg_list; #ifdef CNDEBUG tag = varval(STRcndebug); #endif /* CNDEBUG */ continue_list = varval(STRcontinue); continue_args_list = varval(STRcontinue_args); if (*continue_list == '\0' && *continue_args_list == '\0') return; we = cp->next; while (*we->word == ';' && we != cp) we = we->next; while (we != cp) { #ifdef CNDEBUG if (*tag) xprintf(CGETS(22, 11, "parsing command line\n")); #endif /* CNDEBUG */ cmd = we->word; in_cont_list = inlist(continue_list, cmd); in_cont_arg_list = inlist(continue_args_list, cmd); if (in_cont_list || in_cont_arg_list) { #ifdef CNDEBUG if (*tag) xprintf(CGETS(22, 12, "in one of the lists\n")); #endif /* CNDEBUG */ np = NULL; for (pp = proclist.p_next; pp; pp = pp->p_next) { if (prefix(cmd, pp->p_command)) { if (pp->p_index) { np = pp; break; } } } if (np) { insert(we, in_cont_arg_list); } } for (we = we->next; *we->word != ';' && we != cp; we = we->next) continue; if (*we->word == ';') we = we->next; } #ifdef CNDEBUG if (*tag) { xprintf(CGETS(22, 13, "command line now is:\n")); for (we = cp->next; we != cp; we = we->next) xprintf("%S ", we->word); } #endif /* CNDEBUG */ return; }
/*ARGSUSED*/ void TellTC(void) { xprintf(CGETS(7, 1, "\n\tYou're using a Windows console.\n")); }
/* * Init the elst depending on the locale */ void errinit(void) { #ifdef NLS_CATALOGS size_t i; for (i = 0; i < NO_ERRORS; i++) xfree((char *)(intptr_t)elst[i]); # if defined(__FreeBSD__) || defined(hpux) || defined(__MidnightBSD__) # define NLS_MAXSET 30 for (i = 1; i <= NLS_MAXSET; i++) CGETS(i, 1, "" ); # endif #endif elst[ERR_SYNTAX] = CSAVS(1, 1, "Syntax Error"); elst[ERR_NOTALLOWED] = CSAVS(1, 2, "%s is not allowed"); elst[ERR_WTOOLONG] = CSAVS(1, 3, "Word too long"); elst[ERR_LTOOLONG] = CSAVS(1, 4, "$< line too long"); elst[ERR_DOLZERO] = CSAVS(1, 5, "No file for $0"); elst[ERR_INCBR] = CSAVS(1, 6, "Incomplete [] modifier"); elst[ERR_EXPORD] = CSAVS(1, 7, "$ expansion must end before ]"); elst[ERR_BADMOD] = CSAVS(1, 8, "Bad : modifier in $ (%c)"); elst[ERR_SUBSCRIPT] = CSAVS(1, 9, "Subscript error"); elst[ERR_BADNUM] = CSAVS(1, 10, "Badly formed number"); elst[ERR_NOMORE] = CSAVS(1, 11, "No more words"); elst[ERR_FILENAME] = CSAVS(1, 12, "Missing file name"); elst[ERR_GLOB] = CSAVS(1, 13, "Internal glob error"); elst[ERR_COMMAND] = CSAVS(1, 14, "Command not found"); elst[ERR_TOOFEW] = CSAVS(1, 15, "Too few arguments"); elst[ERR_TOOMANY] = CSAVS(1, 16, "Too many arguments"); elst[ERR_DANGER] = CSAVS(1, 17, "Too dangerous to alias that"); elst[ERR_EMPTYIF] = CSAVS(1, 18, "Empty if"); elst[ERR_IMPRTHEN] = CSAVS(1, 19, "Improper then"); elst[ERR_NOPAREN] = CSAVS(1, 20, "Words not parenthesized"); elst[ERR_NOTFOUND] = CSAVS(1, 21, "%s not found"); elst[ERR_MASK] = CSAVS(1, 22, "Improper mask"); elst[ERR_LIMIT] = CSAVS(1, 23, "No such limit"); elst[ERR_TOOLARGE] = CSAVS(1, 24, "Argument too large"); elst[ERR_SCALEF] = CSAVS(1, 25, "Improper or unknown scale factor"); elst[ERR_UNDVAR] = CSAVS(1, 26, "Undefined variable"); elst[ERR_DEEP] = CSAVS(1, 27, "Directory stack not that deep"); elst[ERR_BADSIG] = CSAVS(1, 28, "Bad signal number"); elst[ERR_UNKSIG] = CSAVS(1, 29, "Unknown signal; kill -l lists signals"); elst[ERR_VARBEGIN] = CSAVS(1, 30, "Variable name must begin with a letter"); elst[ERR_VARTOOLONG] = CSAVS(1, 31, "Variable name too long"); elst[ERR_VARALNUM] = CSAVS(1, 32, "Variable name must contain alphanumeric characters"); elst[ERR_JOBCONTROL] = CSAVS(1, 33, "No job control in this shell"); elst[ERR_EXPRESSION] = CSAVS(1, 34, "Expression Syntax"); elst[ERR_NOHOMEDIR] = CSAVS(1, 35, "No home directory"); elst[ERR_CANTCHANGE] = CSAVS(1, 36, "Can't change to home directory"); elst[ERR_NULLCOM] = CSAVS(1, 37, "Invalid null command"); elst[ERR_ASSIGN] = CSAVS(1, 38, "Assignment missing expression"); elst[ERR_UNKNOWNOP] = CSAVS(1, 39, "Unknown operator"); elst[ERR_AMBIG] = CSAVS(1, 40, "Ambiguous"); elst[ERR_EXISTS] = CSAVS(1, 41, "%s: File exists"); elst[ERR_ARGC] = CSAVS(1, 42, "Argument for -c ends in backslash"); elst[ERR_INTR] = CSAVS(1, 43, "Interrupted"); elst[ERR_RANGE] = CSAVS(1, 44, "Subscript out of range"); elst[ERR_OVERFLOW] = CSAVS(1, 45, "Line overflow"); elst[ERR_NOSUCHJOB] = CSAVS(1, 46, "No such job"); elst[ERR_TERMINAL] = CSAVS(1, 47, "Can't from terminal"); elst[ERR_NOTWHILE] = CSAVS(1, 48, "Not in while/foreach"); elst[ERR_NOPROC] = CSAVS(1, 49, "No more processes"); elst[ERR_NOMATCH] = CSAVS(1, 50, "No match"); elst[ERR_MISSING] = CSAVS(1, 51, "Missing %c"); elst[ERR_UNMATCHED] = CSAVS(1, 52, "Unmatched %c"); elst[ERR_NOMEM] = CSAVS(1, 53, "Out of memory"); elst[ERR_PIPE] = CSAVS(1, 54, "Can't make pipe"); elst[ERR_SYSTEM] = CSAVS(1, 55, "%s: %s"); elst[ERR_STRING] = CSAVS(1, 56, "%s"); elst[ERR_JOBS] = CSAVS(1, 57, "Usage: jobs [ -l ]"); elst[ERR_JOBARGS] = CSAVS(1, 58, "Arguments should be jobs or process id's"); elst[ERR_JOBCUR] = CSAVS(1, 59, "No current job"); elst[ERR_JOBPREV] = CSAVS(1, 60, "No previous job"); elst[ERR_JOBPAT] = CSAVS(1, 61, "No job matches pattern"); elst[ERR_NESTING] = CSAVS(1, 62, "Fork nesting > %d; maybe `...` loop"); elst[ERR_JOBCTRLSUB] = CSAVS(1, 63, "No job control in subshells"); elst[ERR_SYNC] = CSAVS(1, 64, "Sync fault: Process %d not found"); elst[ERR_STOPPED] = #ifdef SUSPENDED CSAVS(1, 65, "%sThere are suspended jobs"); #else CSAVS(1, 66, "%sThere are stopped jobs"); #endif /* SUSPENDED */ elst[ERR_NODIR] = CSAVS(1, 67, "No other directory"); elst[ERR_EMPTY] = CSAVS(1, 68, "Directory stack empty"); elst[ERR_BADDIR] = CSAVS(1, 69, "Bad directory"); elst[ERR_DIRUS] = CSAVS(1, 70, "Usage: %s [-%s]%s"); elst[ERR_HFLAG] = CSAVS(1, 71, "No operand for -h flag"); elst[ERR_NOTLOGIN] = CSAVS(1, 72, "Not a login shell"); elst[ERR_DIV0] = CSAVS(1, 73, "Division by 0"); elst[ERR_MOD0] = CSAVS(1, 74, "Mod by 0"); elst[ERR_BADSCALE] = CSAVS(1, 75, "Bad scaling; did you mean \"%s\"?"); elst[ERR_SUSPLOG] = CSAVS(1, 76, "Can't suspend a login shell (yet)"); elst[ERR_UNKUSER] = CSAVS(1, 77, "Unknown user: %s"); elst[ERR_NOHOME] = CSAVS(1, 78, "No $home variable set"); elst[ERR_HISTUS] = CSAVS(1, 79, "Usage: history [-%s] [# number of events]"); elst[ERR_SPDOLLT] = CSAVS(1, 80, "$, ! or < not allowed with $# or $?"); elst[ERR_NEWLINE] = CSAVS(1, 81, "Newline in variable name"); elst[ERR_SPSTAR] = CSAVS(1, 82, "* not allowed with $# or $?"); elst[ERR_DIGIT] = CSAVS(1, 83, "$?<digit> or $#<digit> not allowed"); elst[ERR_VARILL] = CSAVS(1, 84, "Illegal variable name"); elst[ERR_NLINDEX] = CSAVS(1, 85, "Newline in variable index"); elst[ERR_EXPOVFL] = CSAVS(1, 86, "Expansion buffer overflow"); elst[ERR_VARSYN] = CSAVS(1, 87, "Variable syntax"); elst[ERR_BADBANG] = CSAVS(1, 88, "Bad ! form"); elst[ERR_NOSUBST] = CSAVS(1, 89, "No previous substitute"); elst[ERR_BADSUBST] = CSAVS(1, 90, "Bad substitute"); elst[ERR_LHS] = CSAVS(1, 91, "No previous left hand side"); elst[ERR_RHSLONG] = CSAVS(1, 92, "Right hand side too long"); elst[ERR_BADBANGMOD] = CSAVS(1, 93, "Bad ! modifier: %c"); elst[ERR_MODFAIL] = CSAVS(1, 94, "Modifier failed"); elst[ERR_SUBOVFL] = CSAVS(1, 95, "Substitution buffer overflow"); elst[ERR_BADBANGARG] = CSAVS(1, 96, "Bad ! arg selector"); elst[ERR_NOSEARCH] = CSAVS(1, 97, "No prev search"); elst[ERR_NOEVENT] = CSAVS(1, 98, "%s: Event not found"); elst[ERR_TOOMANYRP] = CSAVS(1, 99, "Too many )'s"); elst[ERR_TOOMANYLP] = CSAVS(1, 100, "Too many ('s"); elst[ERR_BADPLP] = CSAVS(1, 101, "Badly placed ("); elst[ERR_MISRED] = CSAVS(1, 102, "Missing name for redirect"); elst[ERR_OUTRED] = CSAVS(1, 103, "Ambiguous output redirect"); elst[ERR_REDPAR] = CSAVS(1, 104, "Can't << within ()'s"); elst[ERR_INRED] = CSAVS(1, 105, "Ambiguous input redirect"); elst[ERR_BADPLPS] = CSAVS(1, 106, "Badly placed ()'s"); elst[ERR_ALIASLOOP] = CSAVS(1, 107, "Alias loop"); elst[ERR_NOWATCH] = CSAVS(1, 108, "No $watch variable set"); elst[ERR_NOSCHED] = CSAVS(1, 109, "No scheduled events"); elst[ERR_SCHEDUSAGE] = CSAVS(1, 110, "Usage: sched -<item#>.\nUsage: sched [+]hh:mm <command>"); elst[ERR_SCHEDEV] = CSAVS(1, 111, "Not that many scheduled events"); elst[ERR_SCHEDCOM] = CSAVS(1, 112, "No command to run"); elst[ERR_SCHEDTIME] = CSAVS(1, 113, "Invalid time for event"); elst[ERR_SCHEDREL] = CSAVS(1, 114, "Relative time inconsistent with am/pm"); elst[ERR_TCNOSTR] = CSAVS(1, 115, "Out of termcap string space"); elst[ERR_SETTCUS] = CSAVS(1, 116, "Usage: settc %s [yes|no]"); elst[ERR_TCCAP] = CSAVS(1, 117, "Unknown capability `%s'"); elst[ERR_TCPARM] = CSAVS(1, 118, "Unknown termcap parameter `%%%c'"); elst[ERR_TCARGS] = CSAVS(1, 119, "Too many arguments for `%s' (%d)"); elst[ERR_TCNARGS] = CSAVS(1, 120, "`%s' requires %d arguments"); elst[ERR_TCUSAGE] = CSAVS(1, 121, "Usage: echotc [-v|-s] [<capability> [<args>]]"); elst[ERR_ARCH] = CSAVS(1, 122, "%s: %s. Binary file not executable"); elst[ERR_HISTLOOP] = CSAVS(1, 123, "!# History loop"); elst[ERR_FILEINQ] = CSAVS(1, 124, "Malformed file inquiry"); elst[ERR_SELOVFL] = CSAVS(1, 125, "Selector overflow"); #ifdef apollo elst[ERR_TCSHUSAGE] = CSAVS(1, 126, "Unknown option: `-%s'\nUsage: %s [ -bcdefilmnqstvVxX -Dname[=value] ] [ argument ... ]"); #else /* !apollo */ # ifdef convex elst[ERR_TCSHUSAGE] = CSAVS(1, 127, "Unknown option: `-%s'\nUsage: %s [ -bcdefFilmnqstvVxX ] [ argument ... ]"); # else /* rest */ elst[ERR_TCSHUSAGE] = CSAVS(1, 128, "Unknown option: `-%s'\nUsage: %s [ -bcdefilmnqstvVxX ] [ argument ... ]"); # endif /* convex */ #endif /* apollo */ elst[ERR_COMPCOM] = CSAVS(1, 129, "\nInvalid completion: \"%s\""); elst[ERR_COMPINV] = CSAVS(1, 130, "\nInvalid %s: '%c'"); elst[ERR_COMPMIS] = CSAVS(1, 131, "\nMissing separator '%c' after %s \"%s\""); elst[ERR_COMPINC] = CSAVS(1, 132, "\nIncomplete %s: \"%s\""); elst[ERR_MFLAG] = CSAVS(1, 133, "No operand for -m flag"); elst[ERR_ULIMUS] = CSAVS(1, 134, "Usage: unlimit [-fh] [limits]"); elst[ERR_READONLY] = CSAVS(1, 135, "$%S is read-only"); elst[ERR_BADJOB] = CSAVS(1, 136, "No such job (badjob)"); elst[ERR_BADCOLORVAR] = CSAVS(1, 137, "Unknown colorls variable `%c%c'"); elst[ERR_EOF] = CSAVS(1, 138, "Unexpected end of file"); }
/* tw_complete(): * Return the appropriate completion for the command * * valid completion strings are: * p/<range>/<completion>/[<suffix>/] positional * c/<pattern>/<completion>/[<suffix>/] current word ignore pattern * C/<pattern>/<completion>/[<suffix>/] current word with pattern * n/<pattern>/<completion>/[<suffix>/] next word * N/<pattern>/<completion>/[<suffix>/] next-next word */ int tw_complete(const Char *line, Char **word, Char **pat, int looking, eChar *suf) { Char *buf, **vec, **wl; static Char nomatch[2] = { (Char) ~0, 0x00 }; const Char *ptr; size_t wordno; int n; buf = Strsave(line); cleanup_push(buf, xfree); /* Single-character words, empty current word, terminating NULL */ wl = xmalloc(((Strlen(line) + 1) / 2 + 2) * sizeof (*wl)); cleanup_push(wl, xfree); /* find the command */ if ((wl[0] = tw_tok(buf)) == NULL || wl[0] == INVPTR) { cleanup_until(buf); return TW_ZERO; } /* * look for hardwired command completions using a globbing * search and for arguments using a normal search. */ if ((vec = tw_find(wl[0], &completions, (looking == TW_COMMAND))) == NULL) { cleanup_until(buf); return looking; } /* tokenize the line one more time :-( */ for (wordno = 1; (wl[wordno] = tw_tok(NULL)) != NULL && wl[wordno] != INVPTR; wordno++) continue; if (wl[wordno] == INVPTR) { /* Found a meta character */ cleanup_until(buf); return TW_ZERO; /* de-activate completions */ } #ifdef TDEBUG { size_t i; for (i = 0; i < wordno; i++) xprintf("'%s' ", short2str(wl[i])); xprintf("\n"); } #endif /* TDEBUG */ /* if the current word is empty move the last word to the next */ if (**word == '\0') { wl[wordno] = *word; wordno++; } wl[wordno] = NULL; #ifdef TDEBUG xprintf("\r\n"); xprintf(" w#: %lu\n", (unsigned long)wordno); xprintf("line: %s\n", short2str(line)); xprintf(" cmd: %s\n", short2str(wl[0])); xprintf("word: %s\n", short2str(*word)); xprintf("last: %s\n", wordno >= 2 ? short2str(wl[wordno-2]) : "n/a"); xprintf("this: %s\n", wordno >= 1 ? short2str(wl[wordno-1]) : "n/a"); #endif /* TDEBUG */ for (;vec != NULL && (ptr = vec[0]) != NULL; vec++) { Char *ran, /* The pattern or range X/<range>/XXXX/ */ *com, /* The completion X/XXXXX/<completion>/ */ *pos = NULL; /* scratch pointer */ int cmd, res; Char sep; /* the command and separator characters */ int exact; if (ptr[0] == '\0') continue; #ifdef TDEBUG xprintf("match %s\n", short2str(ptr)); #endif /* TDEBUG */ switch (cmd = ptr[0]) { case 'N': pos = (wordno < 3) ? nomatch : wl[wordno - 3]; break; case 'n': pos = (wordno < 2) ? nomatch : wl[wordno - 2]; break; case 'c': case 'C': pos = (wordno < 1) ? nomatch : wl[wordno - 1]; break; case 'p': break; default: stderror(ERR_COMPINV, CGETS(27, 1, "command"), cmd); return TW_ZERO; } sep = ptr[1]; if (!Ispunct(sep)) { /* Truncates data if WIDE_STRINGS */ stderror(ERR_COMPINV, CGETS(27, 2, "separator"), (int)sep); return TW_ZERO; } ptr = tw_dollar(&ptr[2], wl, wordno, &ran, sep, CGETS(27, 3, "pattern")); cleanup_push(ran, xfree); if (ran[0] == '\0') /* check for empty pattern (disallowed) */ { stderror(ERR_COMPINC, cmd == 'p' ? CGETS(27, 4, "range") : CGETS(27, 3, "pattern"), ""); return TW_ZERO; } ptr = tw_dollar(ptr, wl, wordno, &com, sep, CGETS(27, 5, "completion")); cleanup_push(com, xfree); if (*ptr != '\0') { if (*ptr == sep) *suf = CHAR_ERR; else *suf = *ptr; } else *suf = '\0'; #ifdef TDEBUG xprintf("command: %c\nseparator: %c\n", cmd, (int)sep); xprintf("pattern: %s\n", short2str(ran)); xprintf("completion: %s\n", short2str(com)); xprintf("suffix: "); switch (*suf) { case 0: xprintf("*auto suffix*\n"); break; case CHAR_ERR: xprintf("*no suffix*\n"); break; default: xprintf("%c\n", (int)*suf); break; } #endif /* TDEBUG */ exact = 0; switch (cmd) { case 'p': /* positional completion */ #ifdef TDEBUG xprintf("p: tw_pos(%s, %lu) = ", short2str(ran), (unsigned long)wordno - 1); xprintf("%d\n", tw_pos(ran, wordno - 1)); #endif /* TDEBUG */ if (!tw_pos(ran, wordno - 1)) { cleanup_until(ran); continue; } break; case 'N': /* match with the next-next word */ case 'n': /* match with the next word */ exact = 1; /*FALLTHROUGH*/ case 'c': /* match with the current word */ case 'C': #ifdef TDEBUG xprintf("%c: ", cmd); #endif /* TDEBUG */ if ((n = tw_match(pos, ran, exact)) < 0) { cleanup_until(ran); continue; } if (cmd == 'c') *word += n; break; default: abort(); /* Cannot happen */ } tsetenv(STRCOMMAND_LINE, line); res = tw_result(com, pat); Unsetenv(STRCOMMAND_LINE); cleanup_until(buf); return res; } cleanup_until(buf); *suf = '\0'; return TW_ZERO; } /* end tw_complete */
void update_dspmbyte_vars(void) { int lp, iskcode; Char *dstr1; struct varent *vp; /* if variable "nokanji" is set, multi-byte display is disabled */ if ((vp = adrof(CHECK_MBYTEVAR)) && !adrof(STRnokanji)) { _enable_mbdisp = 1; dstr1 = vp->vec[0]; if(eq (dstr1, STRsjis)) iskcode = 1; else if (eq(dstr1, STReuc)) iskcode = 2; else if (eq(dstr1, STRbig5)) iskcode = 3; else if (eq(dstr1, STRutf8)) iskcode = 4; else if ((dstr1[0] - '0') >= 0 && (dstr1[0] - '0') <= 3) { iskcode = 0; } else { xprintf(CGETS(18, 2, "Warning: unknown multibyte display; using default(euc(JP))\n")); iskcode = 2; } if (dstr1 && vp->vec[1] && eq(vp->vec[1], STRls)) dspmbyte_ls = 1; else dspmbyte_ls = 0; for (lp = 0; lp < 256 && iskcode > 0; lp++) { switch (iskcode) { case 1: /* Shift-JIS */ _cmap[lp] = _cmap_mbyte[lp]; _mbmap[lp] = _mbmap_sjis[lp]; break; case 2: /* 2 ... euc */ _cmap[lp] = _cmap_mbyte[lp]; _mbmap[lp] = _mbmap_euc[lp]; break; case 3: /* 3 ... big5 */ _cmap[lp] = _cmap_mbyte[lp]; _mbmap[lp] = _mbmap_big5[lp]; break; case 4: /* 4 ... utf8 */ _cmap[lp] = _cmap_mbyte[lp]; _mbmap[lp] = _mbmap_utf8[lp]; break; default: xprintf(CGETS(18, 3, "Warning: unknown multibyte code %d; multibyte disabled\n"), iskcode); _cmap[lp] = _cmap_c[lp]; _mbmap[lp] = 0; /* Default map all 0 */ _enable_mbdisp = 0; break; } } if (iskcode == 0) { /* check original table */ if (Strlen(dstr1) != 256) { xprintf(CGETS(18, 4, "Warning: Invalid multibyte table length (%d); multibyte disabled\n"), Strlen(dstr1)); _enable_mbdisp = 0; } for (lp = 0; lp < 256 && _enable_mbdisp == 1; lp++) { if (!((dstr1[lp] - '0') >= 0 && (dstr1[lp] - '0') <= 3)) { xprintf(CGETS(18, 4, "Warning: bad multibyte code at offset +%d; multibyte diabled\n"), lp); _enable_mbdisp = 0; break; } } /* set original table */ for (lp = 0; lp < 256; lp++) { if (_enable_mbdisp == 1) { _cmap[lp] = _cmap_mbyte[lp]; _mbmap[lp] = (unsigned short) ((dstr1[lp] - '0') & 0x0f); } else { _cmap[lp] = _cmap_c[lp]; _mbmap[lp] = 0; /* Default map all 0 */ } } } } else { for (lp = 0; lp < 256; lp++) { _cmap[lp] = _cmap_c[lp]; _mbmap[lp] = 0; /* Default map all 0 */ } _enable_mbdisp = 0; dspmbyte_ls = 0; } #ifdef MBYTEDEBUG /* Sorry, use for beta testing */ { Char mbmapstr[300]; for (lp = 0; lp < 256; lp++) mbmapstr[lp] = _mbmap[lp] + '0'; mbmapstr[lp] = 0; setcopy(STRmbytemap, mbmapstr, VAR_READWRITE); } #endif /* MBYTEMAP */ }
/* CCRETVAL */ int Inputl(void) { CCRETVAL retval; KEYCMD cmdnum = 0; unsigned char tch; /* the place where read() goes */ Char ch; int num; /* how many chars we have read at NL */ int expnum; struct varent *crct = inheredoc ? NULL : adrof(STRcorrect); struct varent *autol = adrof(STRautolist); struct varent *matchbeep = adrof(STRmatchbeep); struct varent *imode = adrof(STRinputmode); Char *SaveChar, *CorrChar; int matchval; /* from tenematch() */ int nr_history_exp; /* number of (attempted) history expansions */ COMMAND fn; int curlen = 0; int newlen; int idx; Char *autoexpand; if (!MapsAreInited) /* double extra just in case */ ed_InitMaps(); ClearDisp(); /* reset the display stuff */ ResetInLine(0); /* reset the input pointers */ if (GettingInput) MacroLvl = -1; /* editor was interrupted during input */ if (imode && imode->vec != NULL) { if (!Strcmp(*(imode->vec), STRinsert)) inputmode = MODE_INSERT; else if (!Strcmp(*(imode->vec), STRoverwrite)) inputmode = MODE_REPLACE; } #if defined(FIONREAD) && !defined(OREO) if (!Tty_raw_mode && MacroLvl < 0) { # ifdef SUNOS4 long chrs = 0; # else /* !SUNOS4 */ /* * *Everyone* else has an int, but SunOS wants long! * This breaks where int != long (alpha) */ int chrs = 0; # endif /* SUNOS4 */ (void) ioctl(SHIN, FIONREAD, (ioctl_t) & chrs); if (chrs == 0) { if (Rawmode() < 0) return 0; } } #endif /* FIONREAD && !OREO */ GettingInput = 1; NeedsRedraw = 0; tellwhat = 0; if (RestoreSaved) { copyn(InputBuf, SavedBuf.s, INBUFSIZE);/*FIXBUF*/ LastChar = InputBuf + LastSaved; Cursor = InputBuf + CursSaved; Hist_num = HistSaved; HistSaved = 0; RestoreSaved = 0; } if (HistSaved) { Hist_num = HistSaved; GetHistLine(); HistSaved = 0; } if (Expand) { (void) e_up_hist(0); Expand = 0; } Refresh(); /* print the prompt */ for (num = OKCMD; num == OKCMD;) { /* while still editing this line */ #ifdef DEBUG_EDIT if (Cursor > LastChar) xprintf("Cursor > LastChar\r\n"); if (Cursor < InputBuf) xprintf("Cursor < InputBuf\r\n"); if (Cursor > InputLim) xprintf("Cursor > InputLim\r\n"); if (LastChar > InputLim) xprintf("LastChar > InputLim\r\n"); if (InputLim != &InputBuf[INBUFSIZE - 2])/*FIXBUF*/ xprintf("InputLim != &InputBuf[INBUFSIZE-2]\r\n"); if ((!DoingArg) && (Argument != 1)) xprintf("(!DoingArg) && (Argument != 1)\r\n"); if (CcKeyMap[0] == 0) xprintf("CcKeyMap[0] == 0 (maybe not inited)\r\n"); #endif /* if EOF or error */ if ((num = GetNextCommand(&cmdnum, &ch)) != OKCMD) { break; } if (cmdnum >= NumFuns) {/* BUG CHECK command */ #ifdef DEBUG_EDIT xprintf(CGETS(6, 1, "ERROR: illegal command from key 0%o\r\n"), ch); #endif continue; /* try again */ } /* now do the real command */ retval = (*CcFuncTbl[cmdnum]) (ch); /* save the last command here */ LastCmd = cmdnum; /* make sure fn is initialized */ fn = (retval == CC_COMPLETE_ALL) ? LIST_ALL : LIST; /* use any return value */ switch (retval) { case CC_REFRESH: Refresh(); /*FALLTHROUGH*/ case CC_NORM: /* normal char */ Argument = 1; DoingArg = 0; /*FALLTHROUGH*/ case CC_ARGHACK: /* Suggested by Rich Salz */ /* <*****@*****.**> */ curchoice = -1; curlen = (int) (LastChar - InputBuf); break; /* keep going... */ case CC_EOF: /* end of file typed */ curchoice = -1; curlen = (int) (LastChar - InputBuf); num = 0; break; case CC_WHICH: /* tell what this command does */ tellwhat = 1; *LastChar++ = '\n'; /* for the benifit of CSH */ num = (int) (LastChar - InputBuf); /* number characters read */ break; case CC_NEWLINE: /* normal end of line */ curlen = 0; curchoice = -1; matchval = 1; if (crct && crct->vec != NULL && (!Strcmp(*(crct->vec), STRcmd) || !Strcmp(*(crct->vec), STRall))) { Char *Origin; PastBottom(); Origin = Strsave(InputBuf); cleanup_push(Origin, xfree); SaveChar = LastChar; if (SpellLine(!Strcmp(*(crct->vec), STRcmd)) == 1) { Char *Change; PastBottom(); Change = Strsave(InputBuf); cleanup_push(Change, xfree); *Strchr(Change, '\n') = '\0'; CorrChar = LastChar; /* Save the corrected end */ LastChar = InputBuf; /* Null the current line */ SoundBeep(); printprompt(2, short2str(Change)); cleanup_until(Change); Refresh(); if (xread(SHIN, &tch, 1) < 0) { #ifdef convex /* * need to print error message in case file * is migrated */ if (errno) stderror(ERR_SYSTEM, progname, strerror(errno)); #else cleanup_until(Origin); break; #endif } ch = tch; if (ch == 'y' || ch == ' ') { LastChar = CorrChar; /* Restore the corrected end */ xprintf("%s", CGETS(6, 2, "yes\n")); } else { Strcpy(InputBuf, Origin); LastChar = SaveChar; if (ch == 'e') { xprintf("%s", CGETS(6, 3, "edit\n")); *LastChar-- = '\0'; Cursor = LastChar; printprompt(3, NULL); ClearLines(); ClearDisp(); Refresh(); cleanup_until(Origin); break; } else if (ch == 'a') { xprintf("%s", CGETS(6, 4, "abort\n")); LastChar = InputBuf; /* Null the current line */ Cursor = LastChar; printprompt(0, NULL); Refresh(); cleanup_until(Origin); break; } xprintf("%s", CGETS(6, 5, "no\n")); } flush(); } cleanup_until(Origin); } else if (crct && crct->vec != NULL && !Strcmp(*(crct->vec), STRcomplete)) { if (LastChar > InputBuf && LastChar[-1] == '\n') { LastChar[-1] = '\0'; LastChar--; Cursor = LastChar; } match_unique_match = 1; /* match unique matches */ matchval = CompleteLine(); match_unique_match = 0; curlen = (int) (LastChar - InputBuf); if (matchval != 1) { PastBottom(); } if (matchval == 0) { xprintf("%s", CGETS(6, 6, "No matching command\n")); } else if (matchval == 2) { xprintf("%s", CGETS(6, 7, "Ambiguous command\n")); } if (NeedsRedraw) { ClearLines(); ClearDisp(); NeedsRedraw = 0; } Refresh(); Argument = 1; DoingArg = 0; if (matchval == 1) { PastBottom(); *LastChar++ = '\n'; *LastChar = '\0'; } curlen = (int) (LastChar - InputBuf); } else PastBottom(); if (matchval == 1) { tellwhat = 0; /* just in case */ Hist_num = 0; /* for the history commands */ /* return the number of chars read */ num = (int) (LastChar - InputBuf); /* * For continuation lines, we set the prompt to prompt 2 */ printprompt(1, NULL); } break; case CC_CORRECT: if (tenematch(InputBuf, Cursor - InputBuf, SPELL) < 0) SoundBeep(); /* Beep = No match/ambiguous */ curlen = Repair(); break; case CC_CORRECT_L: if (SpellLine(FALSE) < 0) SoundBeep(); /* Beep = No match/ambiguous */ curlen = Repair(); break; case CC_COMPLETE: case CC_COMPLETE_ALL: case CC_COMPLETE_FWD: case CC_COMPLETE_BACK: switch (retval) { case CC_COMPLETE: fn = RECOGNIZE; curlen = (int) (LastChar - InputBuf); curchoice = -1; rotate = 0; break; case CC_COMPLETE_ALL: fn = RECOGNIZE_ALL; curlen = (int) (LastChar - InputBuf); curchoice = -1; rotate = 0; break; case CC_COMPLETE_FWD: fn = RECOGNIZE_SCROLL; curchoice++; rotate = 1; break; case CC_COMPLETE_BACK: fn = RECOGNIZE_SCROLL; curchoice--; rotate = 1; break; default: abort(); } if (InputBuf[curlen] && rotate) { newlen = (int) (LastChar - InputBuf); for (idx = (int) (Cursor - InputBuf); idx <= newlen; idx++) InputBuf[idx - newlen + curlen] = InputBuf[idx]; LastChar = InputBuf + curlen; Cursor = Cursor - newlen + curlen; } curlen = (int) (LastChar - InputBuf); nr_history_exp = 0; autoexpand = varval(STRautoexpand); if (autoexpand != STRNULL) nr_history_exp += ExpandHistory(); /* try normal expansion only if no history references were found */ if (nr_history_exp == 0 || Strcmp(autoexpand, STRonlyhistory) != 0) { /* * Modified by Martin Boyer ([email protected]): * A separate variable now controls beeping after * completion, independently of autolisting. */ expnum = (int) (Cursor - InputBuf); switch (matchval = tenematch(InputBuf, Cursor-InputBuf, fn)){ case 1: if (non_unique_match && matchbeep && matchbeep->vec != NULL && (Strcmp(*(matchbeep->vec), STRnotunique) == 0)) SoundBeep(); break; case 0: if (matchbeep && matchbeep->vec != NULL) { if (Strcmp(*(matchbeep->vec), STRnomatch) == 0 || Strcmp(*(matchbeep->vec), STRambiguous) == 0 || Strcmp(*(matchbeep->vec), STRnotunique) == 0) SoundBeep(); } else SoundBeep(); break; default: if (matchval < 0) { /* Error from tenematch */ curchoice = -1; SoundBeep(); break; } if (matchbeep && matchbeep->vec != NULL) { if ((Strcmp(*(matchbeep->vec), STRambiguous) == 0 || Strcmp(*(matchbeep->vec), STRnotunique) == 0)) SoundBeep(); } else SoundBeep(); /* * Addition by David C Lawrence <*****@*****.**>: If an * attempted completion is ambiguous, list the choices. * (PWP: this is the best feature addition to tcsh I have * seen in many months.) */ if (autol && autol->vec != NULL && (Strcmp(*(autol->vec), STRambiguous) != 0 || expnum == Cursor - InputBuf)) { if (adrof(STRhighlight) && MarkIsSet) { /* clear highlighting before showing completions */ MarkIsSet = 0; ClearLines(); ClearDisp(); Refresh(); MarkIsSet = 1; } PastBottom(); fn = (retval == CC_COMPLETE_ALL) ? LIST_ALL : LIST; (void) tenematch(InputBuf, Cursor-InputBuf, fn); } break; } } if (NeedsRedraw) { PastBottom(); ClearLines(); ClearDisp(); NeedsRedraw = 0; } Refresh(); Argument = 1; DoingArg = 0; break; case CC_LIST_CHOICES: case CC_LIST_ALL: if (InputBuf[curlen] && rotate) { newlen = (int) (LastChar - InputBuf); for (idx = (int) (Cursor - InputBuf); idx <= newlen; idx++) InputBuf[idx - newlen + curlen] = InputBuf[idx]; LastChar = InputBuf + curlen; Cursor = Cursor - newlen + curlen; } curlen = (int) (LastChar - InputBuf); if (curchoice >= 0) curchoice--; fn = (retval == CC_LIST_ALL) ? LIST_ALL : LIST; /* should catch ^C here... */ if (tenematch(InputBuf, Cursor - InputBuf, fn) < 0) SoundBeep(); Refresh(); Argument = 1; DoingArg = 0; break; case CC_LIST_GLOB: if (tenematch(InputBuf, Cursor - InputBuf, GLOB) < 0) SoundBeep(); curlen = Repair(); break; case CC_EXPAND_GLOB: if (tenematch(InputBuf, Cursor - InputBuf, GLOB_EXPAND) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_NORMALIZE_PATH: if (tenematch(InputBuf, Cursor - InputBuf, PATH_NORMALIZE) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_EXPAND_VARS: if (tenematch(InputBuf, Cursor - InputBuf, VARS_EXPAND) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_NORMALIZE_COMMAND: if (tenematch(InputBuf, Cursor - InputBuf, COMMAND_NORMALIZE) <= 0) SoundBeep(); /* Beep = No match */ curlen = Repair(); break; case CC_HELPME: xputchar('\n'); /* should catch ^C here... */ (void) tenematch(InputBuf, LastChar - InputBuf, PRINT_HELP); Refresh(); Argument = 1; DoingArg = 0; curchoice = -1; curlen = (int) (LastChar - InputBuf); break; case CC_FATAL: /* fatal error, reset to known state */ #ifdef DEBUG_EDIT xprintf(CGETS(7, 8, "*** editor fatal ERROR ***\r\n\n")); #endif /* DEBUG_EDIT */ /* put (real) cursor in a known place */ ClearDisp(); /* reset the display stuff */ ResetInLine(1); /* reset the input pointers */ Refresh(); /* print the prompt again */ Argument = 1; DoingArg = 0; curchoice = -1; curlen = (int) (LastChar - InputBuf); break; case CC_ERROR: default: /* functions we don't know about */ if (adrof(STRhighlight)) { ClearLines(); ClearDisp(); Refresh(); } DoingArg = 0; Argument = 1; SoundBeep(); flush(); curchoice = -1; curlen = (int) (LastChar - InputBuf); break; } } (void) Cookedmode(); /* make sure the tty is set up correctly */ GettingInput = 0; flush(); /* flush any buffered output */ return num; }