📄 ckucmd.c
字号:
debug(F111,"cmifi sv wild",sv,*wild); if (y == 0) { if (path && !isabsolute(sv)) { char * ptr = path; char c; while (1) { c = *ptr; if (c == PATHSEP || c == NUL) { if (!*path) { path = NULL; break; } *ptr = NUL; strcpy(atmbuf,path); strcat(atmbuf,sv); debug(F110,"cmifip add path",atmbuf,0); if (c == PATHSEP) ptr++; path = ptr; break; } ptr++; } x = 1; inword = 0; cc = 0; xc = (int) strlen(atmbuf); *xp = ""; goto i_path; } if (d) { if (sv) free(sv); return(-2); } else { printf("?No files match - %s\n",sv); if (sv) free(sv); return(-9); } } else if (y < 0) { printf("?Too many files match - %s\n",sv); if (sv) free(sv); return(-9); } else if (y > 1) { if (sv) free(sv); return(x); } /* If not wild, see if it exists and is readable. */ debug(F111,"cmifi sv not wild",sv,*wild); znext(*xp); /* Get first (only?) matching file */ y = zchki(*xp); /* Check its accessibility */ zxpand(sv); /* Rewind so next znext() gets 1st */ free(sv); /* done with this */ sv = NULL; if (y == -3) { printf("?Read permission denied - %s\n",*xp); return(-9); } else if (y == -2) { if (d) return(0); printf("?File not readable - %s\n",*xp); return(-9); } else if (y < 0) { printf("?File not found - %s\n",*xp); return(-9); } return(x);#ifndef MAC case 2: /* ESC */ debug(F101,"cmifi esc, xc","",xc); if (xc == 0) { if (*xdef != '\0') { printf("%s ",xdef); /* If at beginning of field, */#ifdef GEMDOS fflush(stdout);#endif /* GEMDOS */ inword = cmflgs = 0; addbuf(xdef); /* Supply default. */ if (setatm(xdef,0) < 0) { printf("Default input filename too long\n"); return(-9); } } else { /* No default */ bleep(BP_WARN); } break; }#ifndef NOSPL if (f) { /* If a conversion function is given */ char *s = *xp; /* See if there are any variables in */ while (*s) { /* the string and if so, expand it. */ if (chkvar(s)) { zq = atxbuf; atxn = CMDBL; if ((x = (*f)(*xp,&zq,&atxn)) < 0) return(-2); /* reduce cc by number of \\ consumed by conversion */ /* function (needed for OS/2, where \ is path separator) */ if ((int) strlen(atxbuf) > 0) { cc -= (strlen(*xp) - strlen(atxbuf)); *xp = atxbuf; break; } } s++; } }#endif /* NOSPL */#ifdef DTILDE dirp = tilde_expand(*xp); /* Expand tilde, if any, */ if (*dirp != '\0') { /* in the atom buffer. */ if (setatm(dirp,0) < 0) { printf("Expanded input filename too long\n"); return(-9); } } *xp = atmbuf;#endif /* DTILDE */ sp = *xp + cc;#ifdef datageneral *sp++ = '+'; /* Data General AOS wildcard */#else *sp++ = '*'; /* Others */#endif /* datageneral */ *sp-- = '\0';#ifdef GEMDOS if (! strchr(*xp, '.')) /* abde.e -> abcde.e* */ strcat(*xp, ".*"); /* abc -> abc*.* */#endif /* GEMDOS */ y = zxpand(*xp); /* Add wildcard and expand list. */ if (y > 0) {#ifdef OS2 znext(filbuf); zxpand(*xp); /* Must "rewind" */#else strcpy(filbuf,mtchs[0]);#endif /* OS2 */ } else *filbuf = '\0'; *sp = '\0'; /* Remove wildcard. */ *wild = (y > 1); if (y == 0) { printf("?No files match - %s\n",atmbuf); return(-9); } else if (y < 0) { printf("?Too many files match - %s\n",atmbuf); return(-9); } else if (y > 1) { /* Not unique. */#ifndef NOPARTIAL/* Partial filename completion */ int i, j, k; char c; k = 0; debug(F111,"cmifi partial",filbuf,cc);#ifdef OS2 { int cur = 0, len = 0, len2 = 0, min = strlen(filbuf); char localfn[257]; len = min; for (j = 1; j < y; j++) { znext(localfn); len2 = strlen(localfn); for (cur = cc; cur < len && cur < len2 && cur <= min; cur++ ) { if (tolower(filbuf[cur]) != tolower(localfn[cur]) ) break; } if (cur < min) min = cur; } filbuf[min] = NUL; if (min > cc) k++; }#else /* OS2 */ for (i = cc; (c = filbuf[i]); i++) { for (j = 1; j < y; j++) if (mtchs[j][i] != c) break; if (j == y) k++; else filbuf[i] = filbuf[i+1] = NUL; }#endif /* OS2 */ debug(F111,"cmifi partial k",filbuf,k); if (k > 0) { /* Got more characters */ sp = filbuf + cc; /* Point to new ones */#ifdef VMS for (i = 0; i < cc; i++) { cmdchardel(); /* Back up over old partial spec */ bp--; } sp = filbuf; /* Point to new word start */ debug(F100,"cmifi vms erase ok","",0);#endif /* VMS */ cc = k; /* How many new ones we just got */ printf("%s",sp); /* Print them */ while (*bp++ = *sp++) ; /* Copy to command buffer */ bp--; /* Back up over NUL */ debug(F110,"cmifi partial cmdbuf",cmdbuf,0); if (setatm(filbuf,0) < 0) { printf("?Partial filename too long\n"); return(-9); } debug(F111,"cmifi partial atmbuf",atmbuf,cc); *xp = atmbuf; }#endif /* NOPARTIAL */ bleep(BP_WARN); } else { /* Unique, complete it. */#ifndef VMS#ifdef CK_TMPDIR /* isdir() function required for this! */ if (isdir(filbuf)) {#ifdef UNIX strcat(filbuf,"/");#endif#ifdef OS2 strcat(filbuf,"/");#endif#ifdef AMIGA strcat(filbuf,"/");#endif#ifdef OSK strcat(filbuf,"/");#endif#ifdef datageneral strcat(filbuf,":");#endif#ifdef MAC strcat(filbuf,":");#endif#ifdef STRATUS strcat(filbuf,">");#endif#ifdef GEMDOS strcat(filbuf,"\\");#endif sp = filbuf + cc; bleep(BP_WARN); printf("%s",sp); cc++; while (*bp++ = *sp++) ; bp--; if (setatm(filbuf,0) < 0) { printf("?Directory name too long\n"); return(-9); } debug(F111,"cmifi directory atmbuf",atmbuf,cc); *xp = atmbuf; } else { /* Not a directory... */#endif /* CK_TMPDIR */#endif /* VMS */ sp = filbuf + cc; /* Point past what user typed. */#ifdef VMS for (i = 0; i < cc; i++) { cmdchardel(); /* Back up over old partial spec */ bp--; } sp = filbuf; /* Point to new word start */#endif /* VMS */ printf("%s ",sp); /* Complete the name. */#ifdef GEMDOS fflush(stdout);#endif /* GEMDOS */ addbuf(sp); /* Add the characters to cmdbuf. */ if (setatm(filbuf,0) < 0) { /* And to atmbuf. */ printf("?Completed filename too long\n"); return(-9); } inword = cmflgs = 0; *xp = atmbuf; /* Return pointer to atmbuf. */ return(0);#ifndef VMS#ifdef CK_TMPDIR }#endif /* CK_TMPDIR */#endif /* VMS */ } break; case 3: /* Question mark - file menu wanted */ if (*xhlp == NUL) printf(" Input file specification"); else printf(" %s",xhlp);#ifdef GEMDOS fflush(stdout);#endif /* GEMDOS */#ifdef OLDHELP if (xc > 0) {#endif /* OLDHELP */#ifndef NOSPL if (f) { /* If a conversion function is given */ char *s = *xp; /* See if there are any variables in */ while (*s) { /* the string and if so, expand them */ if (chkvar(s)) { zq = atxbuf; atxn = CMDBL; if ((x = (*f)(*xp,&zq,&atxn)) < 0) return(-2); if ((int) strlen(atxbuf) > 0) { *xp = atxbuf; break; } } s++; } }#endif /* NOSPL */#ifdef DTILDE dirp = tilde_expand(*xp); /* Expand tilde, if any */ if (*dirp != '\0') { if (setatm(dirp,0) < 0) { printf("?Expanded filename too long\n"); return(-9); } } *xp = atmbuf;#endif /* DTILDE */ debug(F111,"cmifi ? *xp, cc",*xp,cc); sp = *xp + cc; /* Insert "*" at end */#ifdef datageneral *sp++ = '+'; /* Insert +, the DG wild card */#else *sp++ = '*';#endif /* datageneral */ *sp-- = '\0';#ifdef GEMDOS if (! strchr(*xp, '.')) /* abde.e -> abcde.e* */ strcat(*xp, ".*"); /* abc -> abc*.* */#endif /* GEMDOS */ debug(F110,"cmifi ? wild",*xp,0); y = zxpand(*xp); *sp = '\0'; if (y == 0) { printf("?No files match - %s\n",atmbuf); return(-9); } else if (y < 0) { printf("?Too many files match - %s\n",atmbuf); return(-9); } else { printf(", one of the following:\n");#ifdef OLDHELP clrhlp(); for (i = 0; i < y; i++) { znext(filbuf);#ifdef VMS printf(" %s\n",filbuf); /* VMS names can be long */#else addhlp(filbuf);#endif /* VMS */ } dmphlp();#else /* New way... */ if (filhelp(y,"","",1) < 0) return(-9);#endif /* OLDHELP */ }#ifdef OLDHELP } else printf("\n");#endif /* OLDHELP */ printf("%s%s",cmprom,cmdbuf); fflush(stdout); break;#endif /* MAC */ }#ifdef BS_DIRSEP cmdirflg = 1; x = gtword(); /* No, get a word */ cmdirflg = 0;#else x = gtword(); /* No, get a word */#endif /* BS_DIRSEP */ *xp = atmbuf; }#else /* Not NEWCMIFI ... */ int i, x, xc; long y; char *sp, *zq; char *sv = NULL;#ifdef DTILDE char *tilde_expand(), *dirp;#endif /* DTILDE */#ifdef OS2 int tries;#endif /* OS2 */#ifndef NOPARTIAL#ifndef OS2#ifdef OSK extern char **mtchs; /* This large array is dynamic for OS-9 */#else extern char *mtchs[];#endif /* OSK */#endif /* OS2 */#endif /* NOPARTIAL */ inword = 0; /* Initialize counts & pointers */ cc = 0; xc = 0; *xp = ""; if ((x = cmflgs) != 1) { /* Already confirmed? */#ifdef BS_DIRSEP cmdirflg = 1; x = gtword(); /* No, get a word */ cmdirflg = 0;#else x = gtword(); /* No, get a word */#endif /* BS_DIRSEP */ } else { /* If so, use default, if any. */ if (setatm(xdef,0) < 0) { printf("?Default input filename too long\n"); return(-9); } } i_path: *xp = atmbuf; /* Point to result. */ while (1) { xc += cc; /* Count the characters. */ debug(F111,"cmifi gtword",atmbuf,xc); debug(F101,"cmifi switch x","",x); switch (x) { case -9: printf("Command or field too long\n"); 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. */ if (**xp == NUL) return(-3); /* If field empty, return -3. */ if (**xp == '{') { /* Strip enclosing braces first */ char *s = *xp; int n; n = strlen(s); if (s[n-1] == '}') { s[n-1] = NUL; s++; *xp = s;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -