20 #include <sys/types.h> 50 #define CNTRL_D '\004' 115 if (wlist->wl_next) {
125 s = strrchr(xbuf, DIR_TERM);
126 i = strlen(s ? s + 1 : xbuf);
127 if ((*xbuf ==
'~') && !strchr(xbuf, DIR_TERM))
133 if (cc && (cc->
cc_kwords[arg] & (1 << j))) {
135 a =
ccmatch(xbuf, &keywords[j]);
146 pmatches =
ccmatch(xbuf, &commands);
155 if (pmatches ==
NULL) {
156 (void) putchar(
'\07');
167 for (j = 0;; j++, i++) {
168 wbuf[j] = pmatches->
wl_word[i];
170 if (a->
wl_word[i] != wbuf[j]) {
179 for (i = 0; wbuf[i]; i++)
180 (
void) ioctl(fileno(
cp_in), TIOCSTI, &wbuf[i]);
202 while (ntries-- > 0) {
212 fprintf(
cp_err,
"\nError: alias loop.\n");
215 return (
clookup(first, &commands,
false,
false));
234 lcomp = strrchr(
buf, DIR_TERM);
240 while (pw = getpwent()) {
271 while (de = readdir(wdir))
272 if ((
prefix(lcomp, de->d_name)) && (*lcomp ||
273 (*de->d_name !=
'.'))) {
283 (void) closedir(wdir);
303 cc =
clookup(word, dbase,
true,
false);
326 int maxl = 0, num, i, j, k, width, ncols, nlines;
341 maxl += 8 - (maxl % 8);
342 ncols = width / maxl;
343 if (width == maxl * ncols) shrink = 1;
346 nlines = num / ncols + (num % ncols ? 1 : 0);
347 for (k = 0; k < nlines; k++) {
348 for (i = 0; i < ncols; i++) {
385 if (!cc->cc_invalid) {
393 wl =
cctowl(cc->cc_child,
true);
403 wl =
cctowl(cc->cc_sibling,
true);
429 #ifdef HAVE_TERMIOS_H 431 #define TERM_GET TCGETS 432 #define TERM_SET TCSETS 433 static struct termios sbuf;
434 static struct termios OS_Buf;
440 #define TERM_GET TCGETA 441 #define TERM_SET TCSETA 442 static struct termio sbuf;
443 static struct termio OS_Buf;
447 static bool ison =
false;
459 (void) ioctl(fileno(
cp_in), TIOCGETC, (
char *) &tbuf);
464 (void) ioctl(fileno(
cp_in), TIOCSETC, (
char *) &tbuf);
466 (void) ioctl(fileno(
cp_in), TIOCGETP, (
char *) &sbuf);
467 sbuf.sg_flags &= ~(RAW|CBREAK);
468 (void) ioctl(fileno(
cp_in), TIOCSETP, (
char *) &sbuf);
474 static bool ison =
false;
481 (void) ioctl(fileno(
cp_in), TERM_GET, (
char *) &OS_Buf);
486 (void) ioctl(fileno(
cp_in), TERM_SET, (
char *) &sbuf);
489 (void) ioctl(fileno(
cp_in), TERM_SET, (
char *) &OS_Buf);
510 if (word && *word &&
clookup(word, &commands,
false,
false))
523 long bits0, bits1, bits2, bits3;
530 cc =
clookup(word, &commands,
false,
true);
549 cc =
clookup(word, &commands,
false,
false);
569 if ((
class < 1) || (
class >=
NCLASSES)) {
570 fprintf(
cp_err,
"cp_addkword: Internal Error: bad class %d\n",
574 cc =
clookup(word, &keywords[
class],
false,
true);
589 if ((
class < 1) || (
class >=
NCLASSES)) {
590 fprintf(
cp_err,
"cp_addkword: Internal Error: bad class %d\n",
594 cc =
clookup(word, &keywords[
class],
false,
false);
614 if ((
class < 1) || (
class >=
NCLASSES)) {
615 fprintf(
cp_err,
"cp_addkword: Internal Error: bad class %d\n",
619 old = (
char *) keywords[
class];
620 keywords[
class] = (
struct ccom *) tree;
631 struct ccom *dbase = (
struct ccom*)pntr;
633 if (dbase == commands) commands =
NULL;
635 if (dbase == keywords[i])
668 if (dbase ==
NULL)
return;
671 if (dbase->cc_sibling)
673 tfree(dbase->cc_name);
693 struct ccom *place = *dd, *tmpc;
697 if (!word || !*word)
return place;
718 if (place->
cc_name[ind] < word[ind]) {
729 for (i = 0; i < ind + 1; i++)
731 place->
cc_name[ind + 1] =
'\0';
734 else if (place->
cc_name[ind] > word[ind]) {
745 if (tmpc->cc_ysibling)
747 else if (tmpc->cc_parent)
752 for (i = 0; i < ind + 1; i++)
754 place->
cc_name[ind + 1] =
'\0';
770 tmpc->cc_parent = place;
774 for (i = 0; i < ind + 2; i++)
776 place->
cc_name[ind + 2] =
'\0';
static char buf[MAXPROMPT]
void cp_remkword(class, char *word)
struct alias * cp_aliases
bool cp_comlook(char *word)
static struct ccom * getccom()
void cp_ccom(wordlist *wlist, char *buf, bool esc)
static struct ccom * clookup()
struct wordlist * wl_prev
void cp_remcomm(char *word)
void cp_ccrestart(bool kwords)
static wordlist * cctowl()
void cp_addkword(int class, char *word)
static wordlist * ccmatch()
static struct ccom * commands
static wordlist * ccfilec()
struct wordlist * wl_next
wordlist * cp_cctowl(char *stuff)
static struct ccom * keywords[NCLASSES]
void cp_ccfreetrie(char *pntr)
struct ccom * cc_ysibling
void cp_addcomm(char *word, long bits0, long bits1, long bits2, long bits3)
char * cp_kwswitch(int class, char *tree)