📄 ckucmd.c
字号:
x = cvtdir(*xp,p,ATMBL); /* Convert to [FOO.BAR] */ if (x > 0) { setatm(p,0); *xp = atmbuf; debug(F110,"cmdir cvtdir",*xp,0); } free(p); } }#endif /* VMS */ debug(F101,"cmifi dirflg","",dirflg); if (dirflg) { /* Parsing a directory name? */ /* Yes, does it contain wildcards? */ if (iswild(*xp) || (diractive && (!strcmp(*xp,".") || !strcmp(*xp,".."))) ) { nzxopts |= ZX_DIRONLY; /* Match only directory names */ if (matchdot) nzxopts |= ZX_MATCHDOT; if (recursive) nzxopts |= ZX_RECURSE; debug(F111,"cmifi nzxopts 2",*xp,nzxopts); y = nzxpand(*xp,nzxopts); debug(F111,"cmifi nzxpand 2",*xp,y); nfiles = y; expanded = 1; } else {#ifdef VMS/* This is to allow (e.g.) "cd foo", where FOO.DIR;1 is in the current directory.*/ debug(F111,"cmdir itsadir",*xp,itsadir); if (!itsadir) { char *s; int n; s = *xp; n = strlen(s); if (n > 0 &&#ifdef COMMENT *s != '[' && s[n-1] != ']' && *s != '<' && s[n-1] != '>' &&#else ckindex("[",s,0,0,1) == 0 && ckindex("<",s,0,0,1) == 0 &&#endif /* COMMENT */ s[n-1] != ':') { char * dirbuf = NULL; dirbuf = (char *)malloc(n+4); if (dirbuf) { if (*s == '.') ckmakmsg(dirbuf,n+4,"[",s,"]",NULL); else ckmakmsg(dirbuf,n+4,"[.",s,"]",NULL); itsadir = isdir(dirbuf); debug(F111,"cmdir dirbuf",dirbuf,itsadir); if (itsadir) { setatm(dirbuf,0); *xp = atmbuf; debug(F110,"cmdir new *xp",*xp,0); } free(dirbuf); }/* This is to allow CDPATH to work in VMS... */ } else if (n > 0) { char * p; int i, j, k, d; char rb[2] = "]"; if (p = malloc(x + 8)) { ckstrncpy(p,*xp,x+8); 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; ckstrncat(p,rb,x+8); 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); debug(F111,"cmifi diractive nzxpand",*xp,y); 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); debug(F101,"cmifi y","",y); if (dirflg && *wild && cdactive) { if (y > 1) { printf("?Wildcard matches more than one directory\n"); if (sv) free(sv); if (np) free(np); return(-9); } else { znext(*xp); } } 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) { /* File was not found */ int dosearch = 0; dosearch = (path != NULL); /* A search path was given */ if (dosearch) { dosearch = hasnopath(sv); /* Filename includes no path */ debug(F111,"cmifip hasnopath",sv,dosearch); } if (dosearch) { /* Search the path... */ 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) ckstrncpy(atmbuf,".",ATMBL); else#endif /* UNIX */ ckstrncpy(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) != '/') ckstrncat(atmbuf,"\\",ATMBL);#else#ifdef UNIX if (*(ptr-1) != '/') ckstrncat(atmbuf,"/",ATMBL);#else#ifdef datageneral if (*(ptr-1) != ':') ckstrncat(atmbuf,":",ATMBL);#endif /* datageneral */#endif /* UNIX */#endif /* OS2 */#endif /* VMS */ ckstrncat(atmbuf,sv,ATMBL); 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) {#ifdef CKROOT if (ckrooterr) printf("?Off Limits: %s\n",sv); else#endif /* CKROOT */ printf("?No %s match - %s\n", dirflg ? "directories" : "files", sv); } if (sv) free(sv); if (np) free(np); return(-9); } } else if (y < 0) {#ifdef CKROOT if (ckrooterr) printf("?Off Limits: %s\n",sv); else#endif /* CKROOT */ 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; } if (**xp == '{') { /* Did user type opening brace... */ *xp = *xp + 1; xc--; cc--; qflag = '}'; } else if (dblquo && **xp == '"') { /* or doublequote? */ *xp = *xp + 1; /* If so ignore it and space past it */ xc--; cc--; qflag = '"'; }#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 if (dirflg && *(*xp) == '~') { debug(F111,"cmifi tilde_expand A",*xp,cc); dirp = tilde_expand(*xp); /* Expand tilde, if any... */ if (!dirp) dirp = ""; if (*dirp) { int i, xx; char * sp; xc = cc; /* Length of ~thing */ xx = setatm(dirp,0); /* Copy expansion to atom buffer */ debug(F111,"cmifi tilde_expand B",atmbuf,cc); if (xx < 0) { printf("Expanded name too long\n"); if (np) free(np); return(-9); } debug(F111,"cmifi tilde_expand xc","",xc); for (i = 0; i < xc; i++) { cmdchardel(); /* Back up over ~thing */ bp--; } xc = cc; /* How many new ones we just got */ sp = atmbuf; printf("%s",sp); /* Print them */ while ((*bp++ = *sp++)) ; /* Copy to command buffer */ bp--; /* Back up over NUL */ } *xp = atmbuf; }#endif /* DTILDE */ sp = *xp + cc;#ifdef UNIXOROSK if (!strcmp(atmbuf,"..")) { printf(" "); ckstrncat(cmdbuf," ",CMDBL); 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 /
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -