📄 ckucmd.c
字号:
strcpy(p,*xp); i = ckindex(".",p,-1,1,1); d = ckindex(".dir",p,0,0,0); j = ckindex("]",p,-1,1,1); if (j == 0) { j = ckindex(">",p,-1,1,1); rb[0] = '>'; } k = ckindex(":",p,-1,1,1); if (i < j || i < k) i = 0; if (d < j || d < k) d = 0; /* Change [FOO]BAR or [FOO]BAR.DIR */ /* to [FOO.BAR] */ if (j > 0 && j < n) { p[j-1] = '.'; if (d > 0) p[d-1] = NUL; strcat(p,rb); debug(F110,"cmdir xxx",p,0); } itsadir = isdir(p); debug(F111,"cmdir p",p,itsadir); if (itsadir) { setatm(p,0); *xp = atmbuf; debug(F110,"cmdir new *xp",*xp,0); } free(p); } } }#endif /* VMS */ y = (!itsadir) ? 0 : 1; debug(F111,"cmifi y itsadir",*xp,y); } } else { /* Parsing a filename. */ debug(F110,"cmifi *xp pre-zxpand",*xp,0);#ifndef COMMENT nzxopts = (d == 0) ? ZX_FILONLY : 0; /* So always expand. */ if (matchdot) nzxopts |= ZX_MATCHDOT; if (recursive) nzxopts |= ZX_RECURSE; y = nzxpand(*xp,nzxopts);#else/* Here we're trying to fix a problem in which a directory name is accepted *//* as a filename, but this breaks too many other things. */ nzxopts = 0; if (!d) { if (itsadir & !iswild(*xp)) { debug(F100,"cmifi dir when filonly","",0); printf("?Not a regular file: \"%s\"\n",*xp); if (sv) free(sv); if (np) free(np); return(-9); } else { nzxopts = ZX_FILONLY; if (matchdot) nzxopts |= ZX_MATCHDOT; if (recursive) nzxopts |= ZX_RECURSE; y = nzxpand(*xp,nzxopts); } }#endif /* COMMENT */ nfiles = y; debug(F111,"cmifi y nzxpand",*xp,y); debug(F111,"cmifi y atmbuf",atmbuf,itsadir); expanded = 1; } /* domydir() calls zxrewind() so we MUST call nzxpand() here */ if (!expanded && diractive) { debug(F110,"cmifi diractive catch-all zxpand",*xp,0); nzxopts = (d == 0) ? ZX_FILONLY : (dirflg ? ZX_DIRONLY : 0); if (matchdot) nzxopts |= ZX_MATCHDOT; if (recursive) nzxopts |= ZX_RECURSE; y = nzxpand(*xp,nzxopts); nfiles = y; expanded = 1; } *wild = (iswild(sv) || (y > 1)) && (itsadir == 0);#ifdef RECURSIVE if (!*wild) *wild = recursive;#endif /* RECURSIVE */ debug(F111,"cmifi sv wild",sv,*wild); if (dirflg && *wild && !diractive) { printf("?Wildcard matches more than one directory\n"); if (sv) free(sv); if (np) free(np); return(-9); } if (itsadir && d && !dirflg) { /* It's a directory and not wild */ if (sv) free(sv); /* and it's ok to parse directories */ if (np) free(np); return(x); } 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;#ifdef UNIX/* By definition of CDPATH, an empty member denotes the current directory */ if (!*path) strcpy(atmbuf,"."); else#endif /* UNIX */ strncpy(atmbuf,path,ATMBL);#ifdef VMS atmbuf[ATMBL] = NUL;/* If we have a logical name, evaluate it recursively */ if (*(ptr-1) == ':') { /* Logical name ends in : */ char *p; int n; while (((n = strlen(atmbuf)) > 0) && atmbuf[n-1] == ':') { atmbuf[n-1] = NUL; for (p = atmbuf; *p; p++) if (islower(*p)) *p = toupper(*p); debug(F111,"cmdir CDPATH LN 1",atmbuf,n); p = getenv(atmbuf); debug(F110,"cmdir CDPATH LN 2",p,0); if (!p) break; strncpy(atmbuf,p,ATMBL); atmbuf[ATMBL] = NUL; } }#else#ifdef OS2 if (*(ptr-1) != '\\' && *(ptr-1) != '/') strcat(atmbuf,"\\");#else#ifdef UNIX if (*(ptr-1) != '/') strcat(atmbuf,"/");#else#ifdef datageneral if (*(ptr-1) != ':') strcat(atmbuf,":");#endif /* datageneral */#endif /* UNIX */#endif /* OS2 */#endif /* VMS */ 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); if (np) free(np); return(-2); } else { if (!nomsg) printf("?No %s match - %s\n", dirflg ? "directories" : "files", sv); if (sv) free(sv); if (np) free(np); return(-9); } } else if (y < 0) { printf("?Too many %s match - %s\n", dirflg ? "directories" : "files", sv); if (sv) free(sv); if (np) free(np); return(-9); } else if (*wild || y > 1) { if (sv) free(sv); if (np) free(np); return(x); } /* If not wild, see if it exists and is readable. */ debug(F111,"cmifi sv not wild",sv,*wild); if (expanded) znext(*xp); /* Get first (only?) matching file */ if (dirflg) /* Maybe wild and expanded */ itsadir = isdir(*xp); /* so do this again. */ y = dirflg ? itsadir : zchki(*xp); /* Now check accessibility */ if (expanded) {#ifdef ZXREWIND nfiles = zxrewind(); /* Rewind so next znext() gets 1st */#else nzxopts = dirflg ? ZX_DIRONLY : 0; if (matchdot) nzxopts |= ZX_MATCHDOT; if (recursive) nzxopts |= ZX_RECURSE; nfiles = nzxpand(*xp,nzxopts);#endif /* ZXREWIND */ } debug(F111,"cmifi nfiles",*xp,nfiles); free(sv); /* done with this */ sv = NULL; if (dirflg && y == 0) { printf("?Not a directory - %s\n",*xp);#ifdef CKCHANNELIO z_error = FX_ACC;#endif /* CKCHANNELIO */ return(-9); } else if (y == -3) { if (!xcmfdb) { if (diractive) /* Don't show filename if we're not allowed to see it */ printf("?Read permission denied\n"); else printf("?Read permission denied - %s\n",*xp); } if (np) free(np);#ifdef CKCHANNELIO z_error = FX_ACC;#endif /* CKCHANNELIO */ return(xcmfdb ? -6 : -9); } else if (y == -2) { if (!recursive) { if (np) free(np); if (d) return(0); if (!xcmfdb) printf("?File not readable - %s\n",*xp);#ifdef CKCHANNELIO z_error = FX_ACC;#endif /* CKCHANNELIO */ return(xcmfdb ? -6 : -9); } } else if (y < 0) { if (np) free(np); if (!nomsg && !xcmfdb) printf("?File not found - %s\n",*xp);#ifdef CKCHANNELIO z_error = FX_FNF;#endif /* CKCHANNELIO */ return(xcmfdb ? -6 : -9); } if (np) free(np); return(x);#ifndef MAC case 2: /* ESC */ debug(F101,"cmifi esc, xc","",xc); if (xc == 0) { if (*xdef) { 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 name too long\n"); if (np) free(np); return(-9); } } else { /* No default */ bleep(BP_WARN); } break; }#ifndef NOSPL if (f) { /* If a conversion function is given */#ifdef DOCHKVAR char *s = *xp; /* See if there are any variables in */ while (*s) { /* the string and if so, expand it. */ if (chkvar(s)) {#endif /* DOCHKVAR */ zq = atxbuf; atxn = CMDBL; if ((x = (*f)(*xp,&zq,&atxn)) < 0) { if (np) free(np); return(-2); }#ifdef DOCHKVAR /* reduce cc by number of \\ consumed by conversion */ /* function (needed for OS/2, where \ is path separator) */ cc -= (strlen(*xp) - strlen(atxbuf));#endif /* DOCHKVAR */ *xp = atxbuf; if (!atxbuf[0]) { /* Result empty, use default */ *xp = xdef; cc = strlen(xdef); }#ifdef DOCHKVAR break; } s++; }#endif /* DOCHKVAR */ }#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 name too long\n"); if (np) free(np); return(-9); } } *xp = atmbuf;#endif /* DTILDE */ sp = *xp + cc;#ifdef UNIXOROSK if (!strcmp(atmbuf,"..")) { printf(" "); strcat(cmdbuf," "); cc++; bp++; *wild = 0; *xp = atmbuf; break; } else if (!strcmp(atmbuf,".")) { bleep(BP_WARN); if (np) free(np); return(-1); } else { /* This patches a glitch when user types "./foo<ESC>" */ /* in which the next two chars are omitted from the */ /* expansion. There should be a better fix, however, */ /* since there is no problem with "../foo<ESC>". */ char *p = *xp; if (*p == '.' && *(p+1) == '/') cc -= 2; }#endif /* UNIXOROSK */#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 */ /* Add wildcard and expand list. */#ifdef COMMENT /* This kills partial completion when ESC given in path segment */ nzxopts = dirflg ? ZX_DIRONLY : (d ? 0 : ZX_FILONLY);#else nzxopts = 0;#endif /* COMMENT */ if (matchdot) nzxopts |= ZX_MATCHDOT; if (recursive) nzxopts |= ZX_RECURSE; y = nzxpand(*xp,nzxopts); nfiles = y; debug(F111,"cmifi nzxpand",*xp,y); if (y > 0) {#ifdef OS2 znext(filbuf); /* Get first */#ifdef ZXREWIND zxrewind(); /* Must "rewind" */#else nzxpand(*xp,nxzopts);#endif /* ZXREWIND */#else /* Not OS2 */ ckstrncpy(filbuf,mtchs[0],CKMAXPATH);#endif /* OS2 */ } else *filbuf = '\0'; filbuf[CKMAXPATH] = NUL; debug(F111,"cmifi filbuf",filbuf,y); *sp = '\0'; /* Remove wildcard. */ *wild = (y > 1); if (y == 0) { if (!nomsg) { printf("?No %s match - %s\n", dirflg ? "directories" : "files", atmbuf); if (np) free(np); return(-9); } else { bleep(BP_WARN); if (np) free(np); return(-1); } } else if (y < 0) { printf("?Too many %s match - %s\n", dirflg ? "directories" : "files", atmbuf); if (np) free(np); return(-9); } else if (y > 1) { /* Not unique. */#ifndef NOPARTIAL/* Partial filename completion */ int 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[CKMAXPATH+1]; len = min; for (j = 1; j <= y; j++) { znext(localfn); if (dirflg && !isdir(localfn)) continue; len2 = strlen(localfn); for (cur = cc; cur < len && cur < len2 && cur <= min; cur++ ) { /* OS/2 or Windows, case doesn't matter */ 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 name too long\n"); if (np) free(np); return(-9); } debug(F111,"cmifi partial atmbuf",atmbuf,cc); *xp = atmbuf; }#endif /* NOPARTIAL */ bleep(BP_WARN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -