⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckufio.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
    }    debug(F111,"zstime date check 1",yy->date.val,yy->date.len);    for(i = 0; i < 8; i++) {	if (!isdigit(yy->date.val[i])) {	    debug(F111,"Bad creation date ",yy->date.val,yy->date.len);	    return(-1);	}    }    debug(F111,"zstime date check 2",yy->date.val,yy->date.len);    i++;    for (; i < 16; i += 3) {	if ((!isdigit(yy->date.val[i])) || (!isdigit(yy->date.val[i + 1]))) {	    debug(F111,"Bad creation date ",yy->date.val,yy->date.len);	    return(-1);	}    }    debug(F111,"zstime date check 3",yy->date.val,yy->date.len);#ifdef ANYBSD    debug(F100,"ztime BSD calling ftime","",0);    ftime(&tbp);    debug(F100,"ztime BSD back from ftime","",0);    timezone = tbp.timezone * 60L;    debug(F101,"ztime BSD timezone","",timezone);#endif#ifdef OS2#ifdef __EMX__    ftime(&tbp);    timezone = tbp.timezone * 60L;#endif /* __EMX__ */#endif /* OS2 */#ifdef ATTSV    tzset();				/* Set `timezone'. */#endif /* ATTSV */#ifdef V7    if ((tz = getenv("TZ")) == NULL)      timezone = 0;		/* UTC/GMT */    else      timezone = atoi(&tz[3]);	/* Set 'timezone'. */    timezone *= 60L;#endif    debug(F100,"zstime so far so good","",0);    s[4] = '\0';    for (i = 0; i < 4; i++)	/* Fix the year */      s[i] = yy->date.val[i];    debug(F110,"zstime year",s,0);    n = atoi(s);    debug(F111,"zstime year",s,n);/* Previous year's leap days. This won't work after year 2100. */    isleapyear = (( n % 4 == 0 && n % 100 !=0) || n % 400 == 0);    days = (long) (n - 1970) * 365;    days += (n - 1968 - 1) / 4 - (n - 1900 - 1) / 100 + (n - 1600 - 1) / 400;    s[2] = '\0';    for (i = 4 ; i < 16; i += 2) {	s[0] = yy->date.val[i];	s[1] = yy->date.val[i + 1];	n = atoi(s);	switch (i) {	  case 4:			/* MM: month */	    if ((n < 1 ) || ( n > 12)) {		debug(F111,"zstime 4 bad date ",yy->date.val,yy->date.len);		return(-1);	    }	    days += monthdays [n];	    if (isleapyear && n > 2)	      ++days;	    continue;	  case 6:			/* DD: day */	    if ((n < 1 ) || ( n > 31)) {		debug(F111,"zstime 6 bad date ",yy->date.val,yy->date.len);		return(-1);	    }	    tm = (days + n - 1) * 24L * 60L * 60L;	    i++;			/* Skip the space */	    continue;	  case 9:			/* hh: hour */	    if ((n < 0 ) || ( n > 23)) {		debug(F111,"zstime 9 bad date ",yy->date.val,yy->date.len);		return(-1);	    }	    tm += n * 60L * 60L;	    i++;			/* Skip the colon */	    continue;	  case 12:			/* mm: minute */	    if ((n < 0 ) || ( n > 59)) {		debug(F111,"zstime 12 bad date ",yy->date.val,yy->date.len);		return(-1);	    }#ifdef ANYBSD				/* Correct for time zone */	    tm += timezone;#else#ifndef BSD44				/* For now... */#ifdef ultrix	    tm += (long) timezone;#else	    tm += timezone;#endif /* ultrix */#endif /* BSD44 */#endif /* ANYBSD */	    tm += n * 60L;	    i++;			/* Skip the colon */	    continue;	  case 15:			/* ss: second */	    if ((n < 0 ) || ( n > 59)) {		debug(F111,"zstime 15 bad date ",yy->date.val,yy->date.len);		return(-1);	    }	    tm += n;	}	if (localtime(&tm)->tm_isdst)	  tm -= 60L * 60L;		/* Adjust for daylight savings time */    }    debug(F111,"A-pkt date ok ",yy->date.val,yy->date.len);    if (stat(f,&sb)) {			/* Get the time for the file */	debug(F110,"Can't stat file:",f,0);	return(-1);    }#ifdef OS2    tp.modtime = tm;			/* Set modif. time to creation date */    tp.actime = sb.st_atime;		/* Don't change the access time */#else#ifdef SYSUTIMEH    tp.modtime = tm;			/* Set modif. time to creation date */    tp.actime = sb.st_atime;		/* Don't change the access time */#else#ifdef V7    tp.timep[0] = tm;			/* Set modif. time to creation date */    tp.timep[1] = sb.st_atime;		/* Don't change the access time */#else#ifdef BSD44    tp[0].tv_sec = sb.st_atime;		/* Access time first */    tp[1].tv_sec = tm;			/* Update time second */#else    tp.mtime = tm;			/* Set modif. time to creation date */    tp.atime = sb.st_atime;		/* Don't change the access time */#endif /* BSD44 */#endif /* V7 */#endif /* SYSUTIMEH */#endif /* OS2 */    switch (x) {			/* Execute desired function */      case 0:				/* Set the creation date of the file */	if (#ifdef BSD44	    utimes(f,tp)#else	    utime(f,&tp)#endif /* BSD44 */	    ) {		/* Fix modification time */	    debug(F110,"Can't set modification time for file: ",f,0);	    r = -1;	} else  {	    debug(F110,"Modification time is set for file: ",f,0);	    r = 0;	}	break;      case 1:				/* Compare the dates */	debug(F111,"zstime compare",f,sb.st_atime);	debug(F111,"zstime compare","packet",tm);	r = (sb.st_atime < tm) ? 0 : 1;	break;      default:				/* Error */	r = -1;    }#endif /* TIMESTAMP */    return(r);}/* Find initialization file. */#ifdef NOTUSEDintzkermini() {/*  nothing here for Unix.  This function added for benefit of VMS Kermit.  */    return(0);}#endif /* NOTUSED */#ifndef NOFRILLSintzmail(p,f) char *p; char *f; {		/* Send file f as mail to address p *//*  Returns 0 on success   2 if mail delivered but temp file can't be deleted  -2 if mail can't be delivered  The UNIX version always returns 0 because it can't get a good return  code from zsyscmd.*/#ifdef BSD4/* The idea is to use /usr/ucb/mail, rather than regular mail, so that   *//* a subject line can be included with -s.  Since we can't depend on the *//* user's path, we use the convention that /usr/ucb/Mail = /usr/ucb/mail *//* and even if Mail has been moved to somewhere else, this should still  *//* find it...  The search could be made more reliable by actually using  *//* access() to see if /usr/ucb/Mail exists. *//* Should also make some check on zmbuf overflow... */#ifdef OXOS    sprintf(zmbuf,"mailx -s %c%s%c %s < %s", '"', f, '"', p, f);#else#ifdef DGUX540    sprintf(zmbuf,"mailx -s %c%s%c %s < %s", '"', f, '"', p, f);#else    sprintf(zmbuf,"Mail -s %c%s%c %s < %s", '"', f, '"', p, f);#endif /* DGUX540 */#endif /* OXOS */    zsyscmd(zmbuf);#else#ifdef SVORPOSIX    sprintf(zmbuf,"mail %s < %s", p, f);    zsyscmd(zmbuf);#else    *zmbuf = '\0';#endif#endif    return(0);}#endif /* NOFRILLS */#ifndef NOFRILLSintzprint(p,f) char *p; char *f; {		/* Print file f with options p */#ifdef OS2    sprintf(zmbuf,"print %s %s", p, f); /* Construct print command */    zsyscmd(zmbuf);#else#ifdef UNIX#ifdef ANYBSD				/* BSD uses lpr to spool */#ifdef OXOS				/* Except Olivetti... */#define SPOOLER "lp"#else#ifdef DGUX540				/* And DG/UX */#define SPOOLER "lp"#else#define SPOOLER "lpr"#endif /* DGUX540 */#endif /* OXOS */#else					/* Sys V uses lp */#ifdef TRS16				/* except for Tandy-16/6000... */#define SPOOLER "lpr"#else#define SPOOLER "lp"#endif#endif/*  Note use of standard input redirection.  In some systems, lp[r] runs  setuid to lp (or ...?), so if user has sent a file into a directory  that lp does not have read access to, it can't be printed unless it is  feed to lp[r] as standard input.*/    sprintf(zmbuf,"%s %s < %s", SPOOLER, p, f); /* Construct print command */    zsyscmd(zmbuf);#else /* Not UNIX */    *zmbuf = '\0';#endif /* UNIX */#endif /* OS2 */    return(0);}#endif /* NOFRILLS *//*  Wildcard expansion functions.  C-Kermit used to insist on doing this itself  New code (version 5A, 1990-91) gives user option to ask UNIX to do it.  This lets users use the wildcard expansion features of their favorite shell.  Operation is slower because of the forking & piping, but flexibility is  greater and program is smaller.  For OS/2, C-Kermit still does this itself.*/static char scratch[MAXPATH+4];		/* Used by both methods */#ifndef OS2static int oldmtchs = 0;		/* Let shell (ls) expand them. */#ifdef COMMENTstatic char *lscmd = "/bin/ls -d"; 	/* Command to use. */#elsestatic char *lscmd = "echo";		/* Command to use. */#endif /* COMMENT */intshxpand(pat,namlst,len) char *pat, *namlst[]; int len; {    char *fgbuf = NULL;			/* Buffer for forming ls command */    char *p, *q;			/* Workers */    int i, x, retcode; char c;		/* ... */    x = (int)strlen(pat) + (int)strlen(lscmd) + 3; /* Length of ls command */    for (i = 0; i < oldmtchs; i++)	/* Free previous file list */      free(namlst[i]);    fgbuf = malloc(x);			/* Get buffer for command */    if (!fgbuf) return(-1);		/* Fail if cannot */    sprintf(fgbuf,"%s %s",lscmd,pat);	/* Form the command */    zxcmd(ZIFILE,fgbuf);		/* Start the command */    i = 0;				/* File counter */    p = scratch;			/* Point to scratch area */    retcode = -1;			/* Assume failure */    while ((x = zminchar()) != -1) {	/* Read characters from command */	c = (char) x;	if (c == ' ' || c == '\n') {	/* Got newline or space? */	    *p = '\0';			/* Yes, terminate string */	    p = scratch;		/* Point back to beginning */	    if (zchki(p) == -1)		/* Does file exist? */	      continue;			/* No, continue */	    x = (int)strlen(p);		/* Yes, get length of name */	    q = malloc(x+1);		/* Allocate space for it */	    if (!q) goto shxfin;	/* Fail if space can't be obtained */	    strcpy(q,scratch);		/* Copy name to space */	    namlst[i++] = q;		/* Copy pointer to name into array */	    if (i > len) goto shxfin;	/* Fail if too many */	} else {			/* Regular character */	    *p++ = c;			/* Copy it into scratch area */	}    }    retcode = i;			/* Return number of matching files */shxfin:					/* Common exit point */    free(fgbuf);			/* Free command buffer */    zclosf(ZIFILE);			/* Delete the command fork. */    oldmtchs = i;			/* Remember how many files */    return(retcode);}#endif /* OS2 *//* Directory Functions for Unix, written by Jeff Damens, CUCCA, 1984. *//* Define the size of the string space for filename expansion. */#ifndef DYNAMIC#ifdef PROVX1#define SSPACE 500#else#ifdef BSD29#define SSPACE 500#else#ifdef pdp11#define SSPACE 500#else#ifdef aegis#define SSPACE 10000			/* size of string-generating buffer */static char bslash;			/* backslash character if active */#else					/* Default static buffer size */#define SSPACE 2000			/* size of string-generating buffer */#endif /* aegis */#endif /* pdp11 */#endif /* BSD29 */#endif /* PROVX1 */static char sspace[SSPACE];             /* buffer for generating filenames */#else /* DYNAMIC */#define SSPACE 10000static char *sspace = (char *)0;#endif /* DYNAMIC */static int ssplen = SSPACE;		/* length of string space buffer */static char *freeptr,**resptr;         	/* copies of caller's arguments */static int remlen;                      /* remaining length in caller's array*/static int numfnd;                      /* number of matches found *//* * splitpath: *  takes a string and splits the slash-separated portions into *  a list of path structures.  Returns the head of the list.  The *  structures are allocated by malloc, so they must be freed. *  Splitpath is used internally by the filename generator. * * Input: A string. * Returns: A linked list of the slash-separated segments of the input. */struct path *splitpath(p) char *p; {    struct path *head,*cur,*prv;    int i;    debug(F110,"splitpath",p,0);    head = prv = NULL;    if (ISDIRSEP(*p)) p++;			/* skip leading slash */    while (*p != '\0') {	cur = (struct path *) malloc(sizeof (struct path));	debug(F101,"splitpath malloc","",cur);	if (cur == NULL) {	    debug(F100,"splitpath malloc failure","",0);	    return((struct path *)NULL);	}	cur -> fwd = NULL;	if (head == NULL)	  head = cur;	else	  prv -> fwd = cur;		/* link into chain */	prv = cur;#ifdef aegis	/* treat backslash as "../" */	if (bslash && *p == bslash) {	    strcpy(cur->npart, "..");	    ++p;	} else {	    for (i=0; i < MAXNAMLEN && *p && *p != '/' && *p != bslash; i++)	      cur -> npart[i] = *p++;	    cur -> npart[i] = '\0';	/* end this segment */	    if (i >= MAXNAMLEN)	      while (*p && *p != '/' && *p != bslash)		p++;	}	if (*p == '/') p++;#else#ifdef OS2	for (i = 0;	     i < MAXNAMLEN && !ISDIRSEP(*p) && *p != ':' && *p != '\0';	     i++ )	    cur -> npart[i] = *p++;        if ( *p == ':' ) {            cur -> npart[i++] = *p++;            if ( !ISDIRSEP(*p) )                cur -> npart[i++] = '.';        }#else	for (i=0; i < MAXNAMLEN && !ISDIRSEP(*p) && *p != '\0'; i++) {	    cur -> npart[i] = *p++;	}#endif /* OS2 */	cur -> npart[i] = '\0';		/* end this segment */	if (i >= MAXNAMLEN)	  while (!ISDIRSEP(*p) && *p != '\0') p++;	if (ISDIRSEP(*p))	  p++;#endif /* aegis */    }    return(head);}/* * fgen: *  This is the actual name generator.  It is passed a string, *  possibly containing wildcards, and an array of character pointers. *  It finds all the matching filenames and stores them into the array. *  The returned strings are allocated from a static buffer local to *  this module (so the caller doesn't have to worry about deallocating *  them); this means that successive calls to fgen will wipe out *  the results of previous calls.  This isn't a problem here *  because we process one wildcard string at a time. * * Input: a wildcard string, an array to write names to, the *        length of the array. * Returns: the number of matches.  The array is filled with filenames *          that matched the pattern.  If there wasn't enough room in the *	    array, -1 is returned. * Originally by: Jeff Damens, CUCCA, 1984.  Many changes since then. */static intfgen(pat,resarry,len) char *pat,*resarry[]; int len; {    struct path *head;    char *sptr;#ifdef aegis    char *namechars;    int tilde = 0, bquote = 0;    if ((namechars = getenv("NAMECHARS")) != NULL) {	if (xindex(namechars, '~' ) != NULL) tilde  = '

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -