📄 ckufio.c
字号:
#ifdef NT x = isWin95() ? win95pclose(fp[filnum]) : pclose(fp[filnum]) ;#else /* NT */ x = pclose(fp[filnum]);#endif /* NT */ fp[filnum] = NULL; ispipe[filnum] = 0;#else if (filnum == ZWFILE) { int x; x = pclose(fp[filnum]); fp[filnum] = fp[ZSYSFN] = NULL;#endif /* OS2 */ return((x < 0) ? 0 : 1); }#endif /* NOPOPEN */ debug(F101,"zclosf fp[filnum]","", fp[filnum]); debug(F101,"zclosf fp[ZSYSFN]","", fp[ZSYSFN]);#ifdef OS2 fclose(fp[filnum]); fp[filnum] = NULL;#else if (pid != (PID_T) 0) { debug(F101,"zclosf killing pid","",pid);#ifdef Plan9 kill(pid, SIGKILL);#else kill(pid,9);#endif /* Plan9 */ while ((wstat = wait((WAIT_T *)0)) != pid && wstat != -1) ; pid = 0; } fclose(fp[filnum]); fp[filnum] = fp[ZSYSFN] = NULL;#endif /* OS2 */ return(1);}/* Z X P A N D -- Expand a wildcard string into an array of strings *//* Returns the number of files that match fn1, with data structures set up so that first file (if any) will be returned by the next znext() call. Depends on external variable wildxpand: 0 means we expand wildcards internally, nonzero means we call the shell to do it.*/#ifdef OS2/* Z X P A N D -- Expand a wildcard string into an array of strings *//* Returns the number of files that match fn1, with data structures set up so that first file (if any) will be returned by the next znext() call. Depends on external variable wildxpand: 0 means we expand wildcards internally, nonzero means we call the shell to do it.*/char findpath[MAXPATH];#ifdef NTWIN32_FIND_DATA finddata;HANDLE findhandle = INVALID_HANDLE_VALUE;#else /* NT */FILEFINDBUF3 finddata;HDIR findhandle = HDIR_CREATE;ULONG findcount;#endif /* NT */intzxpand(fn) char *fn; { int i, lasterror = 0; char localfn[MAXPATH]; if ( !fn || !(*fn) ) return(0); debug(F110,"zxpand fn",fn,0);#ifdef NT if (findhandle != INVALID_HANDLE_VALUE) { FindClose(findhandle); findhandle = INVALID_HANDLE_VALUE; }#else if (findhandle != HDIR_CREATE) { DosFindClose(findhandle); findhandle = HDIR_CREATE; }#endif /* NT */ fcount = 0; strcpy(findpath, fn); strcpy(localfn, fn); for (i = strlen(findpath); i >= 0; i--) { if (ISDIRSEP(findpath[i]) || findpath[i] == ':' ) { if (!findpath[i+1]) strcat(localfn, "*"); else findpath[i+1] = '\0'; break; } if (findpath[i] == ':') { if (!findpath[i+1]) { strcat(localfn, "*"); break; } } } if (i < 0) if (zchki(localfn) == -2) { if ( strlen(localfn) == 2 && localfn[1] == ':' ) { strcat(localfn, "./*"); } else { strcat(findpath, "/"); strcat(localfn, "/*"); } } else if (!ISDIRSEP(localfn[0]) && localfn[1] != ':') { findpath[0] = '\0'; strcpy(nambuf, "./"); strcat(nambuf, localfn); strcpy(localfn, nambuf); } debug(F100,"zxpand about to FindFirst","",0);#ifdef NT findhandle = FindFirstFile( localfn, &finddata ); if ( findhandle == INVALID_HANDLE_VALUE ) #else /* NT */ findcount = 1; DosFindFirst(localfn, &findhandle, (ULONG) FILE_NORMAL | FILE_ARCHIVED | FILE_DIRECTORY | FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY, (PVOID) &finddata, (ULONG) sizeof(finddata), &findcount, FIL_STANDARD ); if (findcount != 1)#endif /* NT */ return(fcount); fcount = 1; while ( #ifdef NT FindNextFile( findhandle, &finddata )#else /* NT */ !(lasterror = DosFindNext(findhandle, (PVOID) &finddata, (ULONG) sizeof(finddata), &findcount)) && findcount == 1#endif /* NT */ ) fcount++;#ifdef NT lasterror = GetLastError(); FindClose( findhandle ); findhandle = INVALID_HANDLE_VALUE;#else DosFindClose( findhandle ); findhandle = HDIR_CREATE;#endif /* NT */ if (lasterror != ERROR_NO_MORE_FILES) { fcount = 0; return (fcount); } debug(F111,"zxpand","fcount",fcount);#ifdef NT findhandle = FindFirstFile( localfn, &finddata );#else /* NT */ findcount = 1; DosFindFirst(localfn, &findhandle, (ULONG) FILE_NORMAL | FILE_ARCHIVED | FILE_DIRECTORY | FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY, (PVOID) &finddata, (ULONG) sizeof(finddata), &findcount, FIL_STANDARD );#endif /* NT */ return(fcount);}/* Z N E X T -- Get name of next file from list created by zxpand(). *//* Returns > 0 if there's another file, with its name copied into the argument string, or 0 if no more files in list.*/intznext(fn) char *fn; { int lasterror = 0; if (fcount-- > 0 #ifdef NT && findhandle != INVALID_HANDLE_VALUE#else && findhandle != HDIR_CREATE#endif /* NT */ ) { strcpy(fn,findpath);#ifdef NT strcat(fn,finddata.cFileName); if (!FindNextFile( findhandle, &finddata)) { FindClose( findhandle ); findhandle = INVALID_HANDLE_VALUE; fcount = 0; }#else /* NT */ strcat(fn,finddata.achName ); findcount = 1; lasterror = DosFindNext(findhandle, (PVOID) &finddata, (ULONG) sizeof(finddata), &findcount ); if (lasterror || findcount != 1) { DosFindClose(findhandle); findhandle = HDIR_CREATE; fcount = 0; }#endif /* NT */ } else { *fn = '\0'; fcount = -1; } debug(F111,"znext",fn,fcount+1); return(fcount+1);}#else /* Not OS2 */intzxpand(fn) char *fn; { char *p;#ifdef DTILDE /* Built with tilde-expansion? */ char *tnam;#endif /* DTILDE */ debug(F111,"zxpand entry",fn,wildxpand); if ( !fn || !(*fn) ) /* If no argument provided */ return(0); /* Return zero files found */#ifdef DTILDE /* Built with tilde-expansion? */ if (*fn == '~') { /* Starts with tilde? */ tnam = tilde_expand(fn); /* Try to expand it. */ if (tnam) fn = tnam; } debug(F110,"zxpand after tilde_x",fn,0);#endif /* DTILDE */#ifndef NOPUSH if (!nopush && wildxpand) /* Who is expanding wildcards? */ fcount = shxpand(fn,mtchs,MAXWLD); /* Shell */ else#endif /* NOPUSH */ fcount = (mtchs == NULL && /* Kermit */ (mtchs = (char **)malloc(MAXWLD * sizeof(*mtchs))) == NULL) ? 0 : fgen(fn,mtchs,MAXWLD); /* Look up the file. */ if (fcount > 0) { mtchptr = mtchs; /* Save pointer for next. */ debug(F111,"zxpand ok",mtchs[0],fcount); return(fcount); } debug(F111,"zxpand fgen1",fn,fcount); /* Didn't get one, or got too many */ p = malloc((int)strlen(fn) + 10); /* Make space */ if (!p) return(0); zrtol(fn,p); /* Try again, maybe lowercase */#ifndef NOPUSH if (!nopush && wildxpand) fcount = shxpand(p,mtchs,MAXWLD); /* Shell */ else#endif /* NOPUSH */ fcount = fgen(p,mtchs,MAXWLD); /* Kermit */ if (fcount > 0) { /* Got at least one? */ mtchptr = mtchs; /* Save pointer for next. */ debug(F111,"zxpand fgen2 ok",mtchs[0],fcount); } else debug(F111,"zxpand 2 not ok",p,fcount); free(p); return(fcount);}/* Z N E X T -- Get name of next file from list created by zxpand(). *//* Returns >0 if there's another file, with its name copied into the arg string, or 0 if no more files in list.*/intznext(fn) char *fn; { if (fcount-- > 0) strcpy(fn,*mtchptr++); else *fn = '\0'; debug(F111,"znext",fn,fcount+1); return(fcount+1);}#endif /* OS2 *//* Z C H K S P A -- Check if there is enough space to store the file *//* Call with file specification f, size n in bytes. Returns -1 on error, 0 if not enough space, 1 if enough space.*/int#ifdef CK_ANSICzchkspa(char *f, long n)#elsezchkspa(f,n) char *f; long n;#endif /* CK_ANSIC *//* zchkspa() */ {#ifdef OS2/* OS/2 gives us an easy way to do this. */ unsigned long x, filesize = 0L; debug(F111,"zchkspa",f,n); if (isalpha(f[0]) && f[1] == ':') { x = zdskspace(toupper(f[0]) - 'A' + 1); debug(F101,"zchkspa disk: size","",x); } else { x = zdskspace(0); debug(F101,"zchkspa no disk size","",x); } if (fncact == XYFX_U || fncact == XYFX_X) /* Update or Replace */ filesize = zchki(f); return((x+filesize >= n) ? 1 : 0);#else/* In UNIX there is no good (and portable) way. */ return(1); /* Always say OK. */#endif /* OS2 */}/* Z N E W N -- Make a new name for the given file *//* Given the name, fn, of a file that already exists, this function builds a new name of the form "<oldname>.~<n>~", where <oldname> is argument name (fn), and <n> is a version number, one higher than any existing version number for that file, up to 9999. This format is consistent with that used by GNU EMACS. If the constructed name is too long for the system's maximum, enough characters are truncated from the end of <fn> to allow the version number to fit. If no free version numbers exist between 1 and 9999, a version number of "xxxx" is used. Returns a pointer to the new name in argument s.*/VOIDznewn(fn,s) char *fn, **s; {#ifdef pdp11#define ZNEWNBL 63 /* Name buffer length */#define ZNEWNMD 3 /* Max digits for version number */#else#define ZNEWNBL 255#define ZNEWNMD 4#endif /* pdp11 */ static char buf[ZNEWNBL+1]; char *bp, *xp, *yp;#ifdef OS2 static char localfn[MAXPATH+1]; char *tp=NULL, *zp=NULL, ch, temp[14];#endif /* OS2 */ int len = 0, d = 0, n, t, i, j, k, power = 1; int max = MAXNAMLEN; /* Maximum name length */ if (max < 14) max = 14; /* Make it reasonable */ if (max > ZNEWNBL) max = ZNEWNBL; bp = buf; /* Buffer for building new name */ yp = fn; while (*yp) { /* Copy old name into buffer */ *bp++ = *yp++; if (len++ > ZNEWNBL) break; /* ...up to buffer length */ } *s = NULL; for (i = 1; i < ZNEWNMD + 1; i++) { /* Version numbers up to 10**i - 1 */ power *= 10; /* Next power of 10 */ j = max - len; /* Space left for version number */ k = 3 + i; /* Space needed for it */ if (j < k) { /* Make room if necessary */ len -= (k - j); /* Adjust length of filename */ bp = buf + len; /* Point to new end */ } *bp++ = '*'; /* Put a star on the end (UNIX) */ *bp-- = '\0'; /* Terminate with null */ debug(F110,"znewn: about to expand",buf,0); n = zxpand(buf); /* Expand the resulting wild name */ /* n is the number of matches */ debug(F101,"znewn matches","",n); while (n-- > 0) { /* Find any existing name.~n~ files */#ifdef OS2 znext(localfn); xp = localfn;#else /* OS2 */ xp = *mtchptr++; /* Point at matching name */#endif /* OS2 */ xp += len; /* Look for .~<n>~ at the end of it */ if (*xp == '.' && *(xp+1) == '~') { /* Has a version number */ t = atoi(xp+2); /* Get it */ if (t > d) d = t; /* Save d = highest version number */ } } if (d < power-1) { /* Less than maximum possible? */ debug(F110,"znewn number ok",buf,0); sprintf(bp,".~%d~",d+1); /* Yes, make "name.~<d+1>~" */ *s = buf; /* Point to new name */ ck_znewn = d+1; /* Also make it available globally */ break; /* Done, return it */ } } if (*s == NULL) { debug(F110,"znewn: too many names",buf,0); sprintf(bp,".~xxxx~"); /* Too many, use xxxx. */ ck_znewn = -1; /* Also make it available globally */ *s = buf; }#ifdef OS2 if (IsFileNameValid(buf)) { debug(F110,"znewn: os2 filename valid",buf,0); return; /* HPFS */ } /* otherwise make FAT 8.3 name */ debug(F110,"znewn: os2 filename invalid",buf,0); xp = bp = buf; yp = fn; while (*yp) { /* Copy name into buf */ ch = *bp++ = *yp++; if (ISDIRSEP(ch) || (ch == ':')) xp=bp; } *bp = '\0'; yp = xp; i = 1; while (*yp && (*yp != '.')) { yp++; if (++i<=6) zp=yp; } /* zp points to 6th character in name, or yp, whichever occurs first. */ strcpy(temp,yp); /* Copy extension, if any */ while (zp != xp+8) { if ( zp < xp+5 ) *zp++='0'; else *zp++='?'; /* Pad out with wild cards */ } strcpy(zp,temp); /* Get the extension back */ debug(F110,"znewn: about to expand",buf,0); n = zxpand(buf); /* Expand the resulting wild name */ debug(F101,"znewn: matches","",n); d = 0; /* Index number */ debug(F110,"znewn: temp",temp,0); while (znext(temp)) {#ifdef COMMENT i = atoi(temp+5); if (i > d) d = i;#else if ( tp = strrchr( temp, '/' ) ) tp++; else tp = temp; i = atoi(tp+5); debug(F111,"znewn: tp=atoi(tp+5)",tp,i); if (i > d) d = i; debug(F101,"znewn: d","",d);#endif /* COMMENT */ } sprintf(temp,"%03d",d+1); /* Get the number into a string */ ck_znewn = d+1; memcpy(xp+5, temp, 3); debug(F110,"znewn: os2 file name is FAT",buf,0);#endif /* OS2 */ return;}/* Z R E N A M E -- Rename a file *//* Call with old and new names. If new name is the name of a directory, the 'old' file is moved to that directory. Returns 0 on success, -1 on failure.*/intzrename(old,new) char *old, *new; { char *p = NULL, *s = new; int x; debug(F110,"zrename old",old,0); debug(F110,"zrename new",s,0); if (isdir(new)) { char *q = NULL; x = strlen(new); if (!(p = malloc(strlen(new) + strlen(old) + 2))) return(-1); strcpy(p,new); /* Directory part */ if (!ISDIRSEP(*(new+x-1))) /* Separator, if needed */ strcat(p,"/"); zstrip(old,&q); /* Strip path part from old name */ strcat(p,q); /* Concatenate to new directory */ s =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -