📄 ckucmd.c
字号:
#else *sp++ = '*';#endif *sp-- = '\0'; y = zxpand(atmbuf); *sp = '\0'; if (y == 0) { printf("\n?No files match - %s\n",atmbuf); return(-2); } else if (y < 0) { printf("\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"); printf("%s%s",cmprom,cmdbuf); break; } x = gtword(); }} /* C H K W L D -- Check for wildcard characters '*' or '?' */ chkwld(s) char *s; { for ( ; *s != '\0'; s++) {#ifdef datageneral /* Valid DG wild cards are '-', '+', '#', or '*' */ if ( (*s <= '-') && (*s >= '#') && ((*s == '-') || (*s == '+') || (*s == '#') || (*s == '*')) )#else if ((*s == '*') || (*s == '?'))#endif 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 = gtword(); /* 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: gtword",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) { printf("%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 printf(" %s",xhlp); printf("\n%s%s",cmprom,cmdbuf); break; } x = gtword(); }} /* 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 = gtword(); /* Get first word. */ *xp = pp; /* Save pointer to it. */ } while (1) { xc += cc; /* Char count for all words. */ debug(F111,"cmtxt: gtword",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) { printf("%s ",xdef); cc = addbuf(xdef); } else { putchar(BEL); } break; case 3: /* Question Mark */ if (*xhlp == NUL) printf(" Text string"); else printf(" %s",xhlp); printf("\n%s%s",cmprom,cmdbuf); break; default: printf("\n?Unexpected return code from gtword() - %d\n",x); return(-2); } x = gtword(); }} /* 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 = gtword(); debug(F101,"cmkey: table length","",n);debug(F101," cmflgs","",cmflgs);debug(F101," zz","",zz);while (1) { xc += cc; debug(F111,"cmkey: gtword",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: printf("\n?Ambiguous - %s\n",atmbuf); return(cmflgs = -2); case -1: printf("\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 */ printf("%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) { printf("\n?Invalid - %s\n",atmbuf); return(cmflgs = -2); } xp = table[z].kwd + cc; printf("%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) { printf(" %s\n%s%s",table[z].kwd,cmprom,cmdbuf); break; } else if (y == -1) { printf("\n?Invalid\n"); return(cmflgs = -2); } if (*xhlp == NUL) printf(" One of the following:\n"); else printf(" %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(); printf("%s%s", cmprom, cmdbuf); break; default: printf("\n%d - Unexpected return code from gtword\n",zz); return(cmflgs = -2); } zz = gtword(); }} /* 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 = gtword(); xc += cc; debug(F111,"cmcfm: gtword",atmbuf,xc); switch (x) { case -4: /* EOF */ case -2: case -1: return(x); case 0: /* Space */ continue; case 1: /* End of line */ if (xc > 0) { printf("?Not confirmed - %s\n",atmbuf); return(-2); } else return(0); case 2: putchar(BEL); continue; case 3: if (xc > 0) { printf("\n?Not confirmed - %s\n",atmbuf); return(-2); } printf("\n Type a carriage return to confirm the command\n"); printf("%s%s",cmprom,cmdbuf); continue; } }} /* Keyword help routines */ /* C L R H L P -- Initialize/Clear the help line buffer */ clrhlp() { /* Clear the help buffer */ hlpbuf[0] = NUL; hh = hx = 0;} /* A D D H L P -- Add a string to the help line buffer */ addhlp(s) char *s; { /* Add a word to the help buffer */ int j; hh++; /* Count this column */ for (j = 0; (j < hc) && (*s != NUL); j++) { /* Fill the column */ hlpbuf[hx++] = *s++; } if (*s != NUL) /* Still some chars left in string? */ hlpbuf[hx-1] = '+'; /* Mark as too long for column. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -