📄 ckufio.c
字号:
return(1);#endif /* OS2 */}/* Z C L O S F - wait for the child fork to terminate and close the pipe. */intzclosf(filnum) int filnum; { int wstat; debug(F101,"zclosf filnum","",filnum);#ifndef NOPOPEN#ifdef OS2 if (ispipe[filnum]) { int x; x = pclose(fp[filnum]); 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); kill(pid,9); 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.*/intzxpand(fn) char *fn; { char *p;#ifdef DTILDE /* Built with tilde-expansion? */ char *tnam;#endif /* DTILDE */ debug(F111,"zxpand entry",fn,wildxpand);#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 OS2 if (wildxpand) /* Who is expanding wildcards? */ fcount = shxpand(fn,mtchs,MAXWLD); /* Shell */ else#endif /* OS2 */ fcount = fgen(fn,mtchs,MAXWLD); /* Kermit */ if (fcount > 0) { mtchptr = mtchs; /* Save pointer for next. */ } if (fcount > 0) { 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 OS2 if (wildxpand) fcount = shxpand(p,mtchs,MAXWLD); /* Shell */ else#endif /* OS2 */ fcount = fgen(p,mtchs,MAXWLD); /* Kermit */ if (fcount > 0) { /* Got 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);}/* 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. */ if (isalpha(f[0]) && f[1] == ':') return(zdskspace(toupper(f[0]) - 'A' + 1) >= n); else return(zdskspace(0) >= n);#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 char *zp, 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 */ n = zxpand(buf); /* Expand the resulting wild name */ /* n is the number of matches */ while (n-- > 0) { /* Find any existing name.~n~ files */ xp = *mtchptr++; /* Point at matching name */ 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? */ sprintf(bp,".~%d~",d+1); /* Yes, make "name.~<d+1>~" */ *s = buf; /* Point to new name */ break; /* Done, return it */ } } if (*s == NULL) { sprintf(bp,".~xxxx~"); /* Too many, use xxxx. */ *s = buf; }#ifdef OS2 if (IsFileNameValid(buf)) return; /* HPFS */ /* otherwise make FAT 8.3 name */ 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 */ n = zxpand(buf); /* Expand the resulting wild name */ d = 0; /* Index number */ while (znext(temp)) { i = atoi(temp+5); if (i > d) d = i; } sprintf(temp,"%03d",d+1); /* get the number into a string */ memcpy(xp+5, temp, 3);#endif /* OS2 */ return;}/* Z R E N A M E -- Rename a file *//* Note, link() and unlink() are used because rename() is not available *//* in some versions of UNIX. *//* Call with old and new names *//* Returns 0 on success, -1 on failure. */intzrename(old,new) char *old, *new; {#ifdef OS2 return rename(old, new);#else if (link(old,new) < 0) { /* Make a link with the new name. */ debug(F111,"zrename link fails, errno",old,errno); return(-1); } if (unlink(old) < 0) { /* Unlink the old name. */ debug(F111,"zrename unlink fails, errno",old,errno); return(-1); } return(0);#endif /* OS2 */}/* Z S A T T R *//* Fills in a Kermit file attribute structure for the file which is to be sent. Returns 0 on success with the structure filled in, or -1 on failure. If any string member is null, then it should be ignored. If any numeric member is -1, then it should be ignored.*/intzsattr(xx) struct zattr *xx; { long k; k = iflen % 1024L; /* File length in K */ if (k != 0L) k = 1L; xx->lengthk = (iflen / 1024L) + k; xx->type.len = 0; /* File type can't be filled in here */ xx->type.val = ""; if (*nambuf) { xx->date.val = zfcdat(nambuf); /* File creation date */ xx->date.len = (int)strlen(xx->date.val); } else { xx->date.len = 0; xx->date.val = ""; } xx->creator.len = 0; /* File creator */ xx->creator.val = ""; xx->account.len = 0; /* File account */ xx->account.val = ""; xx->area.len = 0; /* File area */ xx->area.val = ""; xx->passwd.len = 0; /* Area password */ xx->passwd.val = ""; xx->blksize = -1L; /* File blocksize */ xx->access.len = 0; /* File access */ xx->access.val = ""; xx->encoding.len = 0; /* Transfer syntax */ xx->encoding.val = 0; xx->disp.len = 0; /* Disposition upon arrival */ xx->disp.val = ""; xx->lprotect.len = 0; /* Local protection */ xx->lprotect.val = ""; xx->gprotect.len = 0; /* Generic protection */ xx->gprotect.val = ""; xx->systemid.len = 2; /* System ID */ xx->systemid.val = "U1"; xx->recfm.len = 0; /* Record format */ xx->recfm.val = ""; xx->sysparam.len = 0; /* System-dependent parameters */ xx->sysparam.val = ""; xx->length = iflen; /* Length */ return(0);}/* Z F C D A T -- Get file creation date *//* Call with pointer to filename. On success, returns pointer to creation date in yyyymmdd hh:mm:ss format. On failure, returns pointer to null string.*/static char datbuf[40];/* static */ /* (===OS2 change===) */char *zfcdat(name) char *name; {#ifdef TIMESTAMP struct stat buffer; struct tm *time_stamp, *localtime(); int yy, ss; datbuf[0] = '\0'; if(stat(name,&buffer) != 0) { debug(F110,"zfcdat stat failed",name,0); return(""); } time_stamp = localtime(&(buffer.st_mtime)); yy = time_stamp->tm_year; if (yy < 100) /* In case it returns 2-digit year? */ yy += 1900; if (yy < 0 || yy > 9999) { /* Make sure year is ok */ debug(F110,"zfcdat date failed",name,0); return(""); } if (time_stamp->tm_mon < 0 || time_stamp->tm_mon > 11) return(""); if (time_stamp->tm_mday < 0 || time_stamp->tm_mday > 31) return(""); if (time_stamp->tm_hour < 0 || time_stamp->tm_hour > 23) return(""); if (time_stamp->tm_min < 0 || time_stamp->tm_min > 59) return(""); ss = time_stamp->tm_sec; /* Seconds */ if (ss < 0 || ss > 59) /* Some systems give a BIG number */ ss = 0; sprintf(datbuf,#ifdef pdp11/* For some reason, 2.1x BSD sprintf gets the last field wrong. */ "%04d%02d%02d %02d:%02d:00",#else "%04d%02d%02d %02d:%02d:%02d",#endif /* pdp11 */ yy, time_stamp->tm_mon + 1, time_stamp->tm_mday, time_stamp->tm_hour, time_stamp->tm_min#ifndef pdp11 , ss#endif /* pdp11 */ ); yy = (int)strlen(datbuf); debug(F111,"zfcdat",datbuf,yy); if (yy > 17) datbuf[17] = '\0'; return(datbuf);#else return("");#endif /* TIMESTAMP */}/* Z S T I M E -- Set creation date for incoming file *//* Call with: f = pointer to name of existing file. yy = pointer to a Kermit file attribute structure in which yy->date.val is a date of the form yyyymmdd hh:mm:ss, e.g. 19900208 13:00:00. x = is a function code: 0 means to set the file's creation date as given. 1 means compare the given date with the file creation date. Returns: -1 on any kind of error. 0 if x is 0 and the file date was set successfully. 0 if x is 1 and date from attribute structure <= file creation date. 1 if x is 1 and date from attribute structure > file creation date.*/intzstime(f,yy,x) char *f; struct zattr *yy; int x; { int r = -1; /* return code *//* It is ifdef'd TIMESTAMP because it might not work on V7. bk@kullmar.se.*/#ifdef TIMESTAMP/* To do: adapt code from OS-9 Kermit's ck9fio.c zstime function, which is more flexible, allowing [yy]yymmdd[ hh:mm[:ss]].*/#ifndef OS2 extern int ftime(), stat();#ifdef BSD44 extern int utimes();#else extern int utime();#endif /* BSD44 */ /* at least, the declarations for int functions are not needed anyway */ extern struct tm *localtime(); /* and this should have been declared always through a header file */#endif /* OS2 */ long tm, days; int i, n, isleapyear; /* J F M A M J J A S O N D */ /* 31 28 31 30 31 30 31 31 30 31 30 31 */ static int monthdays [13] = { 0,0,31,59,90,120,151,181,212,243,273,304,334 }; char s[5]; struct stat sb;#ifdef BSD44 struct timeval tp[2];#else#ifdef OS2 struct utimbuf tp;#ifdef __EMX__ long timezone; struct timeb tbp;#endif /* __EMX__ */#else#ifdef V7 struct utimbuf { time_t timep[2]; /* New access and modificaton time */ } tp; char *tz; long timezone; /* In case timezone not defined in .h file */#else#ifdef SYSUTIMEH struct utimbuf tp;#else struct utimbuf { time_t atime; /* New access time */ time_t mtime; /* New modification time */ } tp;#endif /* SYSUTIMEH */#endif /* V7 */#endif /* OS2 */#endif /* BSD44 */#ifdef ANYBSD long timezone; static struct timeb tbp;#endif /* ANYBSD */ debug(F110,"zstime",f,0); if ((yy->date.len == 0) || (yy->date.len != 17) || (yy->date.val[8] != ' ') || (yy->date.val[11] != ':') || (yy->date.val[14] != ':') ) { debug(F111,"Bad creation date ",yy->date.val,yy->date.len); return(-1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -