📄 ckucmd.c
字号:
return(-2); } else if (y > 1) { /* Not unique, just beep. */ putchar(BEL); } else { /* Unique, complete it. */ znext(filbuf); /* Get whole name of file. */ sp = filbuf + cc; /* Point past what user typed. */ printf2("%s ",sp); /* Complete the name. */ addbuf(sp); /* Add the characters to cmdbuf. */ setatm(pp); /* And to atmbuf. */ *xp = atmbuf; /* Return pointer to atmbuf. */ return(cmflgs = 0); } break;/* cont'd... *//* ...cmifi(), cont'd */ case 3: /* Question mark */ if (*xhlp == NUL) printf(" Input file specification"); else printf2(" %s",xhlp); if (xc > 0) { sp = atmbuf + cc; /* Insert * at end */ *sp++ = '*'; *sp-- = '\0'; y = zxpand(atmbuf); *sp = '\0'; if (y == 0) { printf2("\n?No files match - %s\n",atmbuf); return(-2); } else if (y < 0) { printf2("\n?Too many file match - %s\n",atmbuf); return(-2); } else { printf(", one of the following:\n"); clrhlp(); for (i = 0; i < y; i++) { znext(filbuf); addhlp(filbuf); } dmphlp(); } } else printf("\n"); printf3("%s%s",cmprom,cmdbuf); break; } x = getwd(); }}/* C H K W L D -- Check for wildcard characters '*' or '?' */chkwld(s) char *s; { for ( ; *s != '\0'; s++) { if ((*s == '*') || (*s == '?')) return(1); } return(0);}/* C M F L D -- Parse an arbitrary field *//* Returns -3 if no input present when required, -2 if field too big for buffer, -1 if reparse needed, 0 otherwise, xp pointing to string result.*/cmfld(xhlp,xdef,xp) char *xhlp, *xdef, **xp; { int x, xc; cc = xc = 0; /* Initialize counts & pointers */ *xp = ""; if ((x = cmflgs) != 1) { /* Already confirmed? */ x = getwd(); /* No, get a word */ } else { cc = setatm(xdef); /* If so, use default, if any. */ } *xp = atmbuf; /* Point to result. */ while (1) { xc += cc; /* Count the characters. */ debug(F111,"cmfld: getwd",atmbuf,xc); debug(F101," x","",x); switch (x) { case -4: /* EOF */ case -2: /* Out of space. */ case -1: /* Reparse needed */ return(x); case 0: /* SP or NL */ case 1: if (xc == 0) *xp = xdef; /* If no input, return default. */ else *xp = atmbuf; if (**xp == NUL) x = -3; /* If field empty, return -3. */ return(x); case 2: /* ESC */ if (xc == 0) { printf2("%s ",xdef); /* If at beginning of field, */ addbuf(xdef); /* supply default. */ cc = setatm(xdef); /* Return as if whole field */ return(0); /* typed, followed by space. */ } else { putchar(BEL); /* Beep if already into field. */ } break; case 3: /* Question mark */ if (*xhlp == NUL) printf(" Please complete this field"); else printf2(" %s",xhlp); printf3("\n%s%s",cmprom,cmdbuf); break; } x = getwd(); }}/* C M T X T -- Get a text string, including confirmation *//* Print help message 'xhlp' if ? typed, supply default 'xdef' if null string typed. Returns -1 if reparse needed or buffer overflows. 1 otherwise. with cmflgs set to return code, and xp pointing to result string.*/cmtxt(xhlp,xdef,xp) char *xhlp; char *xdef; char **xp; { int x; static int xc; debug(F101,"cmtxt, cmflgs","",cmflgs); cc = 0; /* Start atmbuf counter off at 0 */ if (cmflgs == -1) { /* If reparsing, */ xc = strlen(*xp); /* get back the total text length, */ } else { /* otherwise, */ *xp = ""; /* start fresh. */ xc = 0; } *atmbuf = NUL; /* And empty atom buffer. */ if ((x = cmflgs) != 1) { x = getwd(); /* Get first word. */ *xp = pp; /* Save pointer to it. */ } while (1) { xc += cc; /* Char count for all words. */ debug(F111,"cmtxt: getwd",atmbuf,xc); debug(F101," x","",x); switch (x) { case -4: /* EOF */ case -2: /* Overflow */ case -1: /* Deletion */ return(x); case 0: /* Space */ xc++; /* Just count it */ break; case 1: /* CR or LF */ if (xc == 0) *xp = xdef; return(x); case 2: /* ESC */ if (xc == 0) { printf2("%s ",xdef); cc = addbuf(xdef); } else { putchar(BEL); } break; case 3: /* Question Mark */ if (*xhlp == NUL) printf(" Text string"); else printf2(" %s",xhlp); printf3("\n%s%s",cmprom,cmdbuf); break; default: printf2("\n?Unexpected return code from getwd() - %d\n",x); return(-2); } x = getwd(); }}/* C M K E Y -- Parse a keyword *//* Call with: table -- keyword table, in 'struct keytab' format; n -- number of entries in table; xhlp -- pointer to help string; xdef -- pointer to default keyword; Returns: -3 -- no input supplied and no default available -2 -- input doesn't uniquely match a keyword in the table -1 -- user deleted too much, command reparse required n >= 0 -- value associated with keyword*/cmkey(table,n,xhlp,xdef) struct keytab table[]; int n; char *xhlp, *xdef; { int i, y, z, zz, xc; char *xp; xc = cc = 0; /* Clear character counters. */ if ((zz = cmflgs) == 1) /* Command already entered? */ setatm(xdef); else zz = getwd();debug(F101,"cmkey: table length","",n);debug(F101," cmflgs","",cmflgs);debug(F101," zz","",zz);while (1) { xc += cc; debug(F111,"cmkey: getwd",atmbuf,xc); switch(zz) { case -4: /* EOF */ case -2: /* Buffer overflow */ case -1: /* Or user did some deleting. */ return(zz); case 0: /* User terminated word with space */ case 1: /* or newline */ if (cc == 0) setatm(xdef); y = lookup(table,atmbuf,n,&z); switch (y) { case -2: printf2("\n?Ambiguous - %s\n",atmbuf); return(cmflgs = -2); case -1: printf2("\n?Invalid - %s\n",atmbuf); return(cmflgs = -2); default: break; } return(y);/* cont'd... *//* ...cmkey(), cont'd */ case 2: /* User terminated word with ESC */ if (cc == 0) { if (*xdef != NUL) { /* Nothing in atmbuf */ printf2("%s ",xdef); /* Supply default if any */ addbuf(xdef); cc = setatm(xdef); debug(F111,"cmkey: default",atmbuf,cc); } else { putchar(BEL); /* No default, just beep */ break; } } y = lookup(table,atmbuf,n,&z); /* Something in atmbuf */ debug(F111,"cmkey: esc",atmbuf,y); if (y == -2) { putchar(BEL); break; } if (y == -1) { printf2("\n?Invalid - %s\n",atmbuf); return(cmflgs = -2); } xp = table[z].kwd + cc; printf2("%s ",xp); addbuf(xp); debug(F110,"cmkey: addbuf",cmdbuf,0); return(y);/* cont'd... *//* ...cmkey(), cont'd */ case 3: /* User terminated word with "?" */ y = lookup(table,atmbuf,n,&z); if (y > -1) { printf2(" %s\n",table[z].kwd); printf3("%s%s",cmprom,cmdbuf); break; } else if (y == -1) { printf("\n?Invalid\n"); return(cmflgs = -2); } if (*xhlp == NUL) printf(" One of the following:\n"); else printf2(" %s, one of the following:\n",xhlp); clrhlp(); for (i = 0; i < n; i++) { if (!strncmp(table[i].kwd,atmbuf,cc) && !test(table[i].flgs,CM_INV)) addhlp(table[i].kwd); } dmphlp(); printf3("%s%s", cmprom, cmdbuf); break; default: printf2("\n%d - Unexpected return code from getwd\n",zz); return(cmflgs = -2); } zz = getwd(); }}/* C M C F M -- Parse command confirmation (end of line) *//* Returns -2: User typed anything but whitespace or newline -1: Reparse needed 0: Confirmation was received*/cmcfm() { int x, xc; debug(F101,"cmcfm: cmflgs","",cmflgs); xc = cc = 0; if (cmflgs == 1) return(0); while (1) { x = getwd(); xc += cc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -