dtimep.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 1,336 行 · 第 1/2 页
C
1,336 行
# include "stdio.h"static int start_cond = 0;#define BEGIN start_cond =struct yysvf { struct yywork *yystoff; struct yysvf *yyother; int *yystops;};# define Z 2#ifndef lintstatic char ident[] = "@(#)$Id: dtimep.lex,v 1.2 90/11/25 19:07:42 sharpe Exp $";#endif#include "tws.h"#include "../h/strings.h"#include <ctype.h>#include <sys/types.h>#ifndef SYS5#include <sys/timeb.h>#endif not SYS5#ifdef SYS5extern int daylight;extern long timezone;extern char *tzname[];#endif SYS5/* * Patchable flag that says how to interpret NN/NN/NN dates. When * true, we do it European style: DD/MM/YY. When false, we do it * American style: MM/DD/YY. Of course, these are all non-RFC822 * compliant. */int europeandate = 0;/* * Table to convert month names to numeric month. We use the * fact that the low order 5 bits of the sum of the 2nd & 3rd * characters of the name is a hash with no collisions for the 12 * valid month names. (The mask to 5 bits maps any combination of * upper and lower case into the same hash value). */static int month_map[] = { 0, 6, /* 1 - Jul */ 3, /* 2 - Apr */ 5, /* 3 - Jun */ 0, 10, /* 5 - Nov */ 0, 1, /* 7 - Feb */ 11, /* 8 - Dec */ 0, 0, 0, 0, 0, 0, 0, /*15 - Jan */ 0, 0, 0, 2, /*19 - Mar */ 0, 8, /*21 - Sep */ 0, 9, /*23 - Oct */ 0, 0, 4, /*26 - May */ 0, 7 /*28 - Aug */};/* * Same trick for day-of-week using the hash function * (c1 & 7) + (c2 & 4) */static int day_map[] = { 0, 0, 0, 6, /* 3 - Sat */ 4, /* 4 - Thu */ 0, 5, /* 6 - Fri */ 0, /* 7 - Sun */ 2, /* 8 - Tue */ 1 /* 9 - Mon */, 0, 3 /*11 - Wed */};#define SETDAY { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)];\ tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP;\ cp += 2; }#define SETMONTH { tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; gotdate++;\ cp += 2;\ SKIPD;}#define CVT2 (i=(*cp++ - '0'),isdigit(*cp)? i*10 + (*cp++ - '0') : i)#define SKIPD { while ( !isdigit(*cp++) ) ; --cp; }#define EXPZONE { tw.tw_flags &= ~TW_SZONE; tw.tw_flags |= TW_SZEXP; }#define ZONE(x) { tw.tw_zone=(x); EXPZONE; }#define ZONED(x) { ZONE(x); tw.tw_flags |= TW_DST; }#define LC(c) (isupper (c) ? tolower (c) : (c))#ifdef DSTXXX#ifndef BSD42#include <time.h>#else BSD42#include <sys/time.h>#endif BSD42static zonehack (tw)register struct tws *tw;{ register struct tm *tm; if (twclock (tw) == -1L) return; tm = localtime (&tw -> tw_clock); if (tm -> tm_isdst) { tw -> tw_flags |= TW_DST; tw -> tw_zone -= 60; }}#endif DSTXXXstruct tws *dparsetime (str) char *str;{ register int i; static struct tws tw; register char *cp; register int gotdate = 0;#ifndef SYS5 struct timeb tb;#endif not SYS5 start_cond = 0; /* Zero out the struct. */ bzero( (char *) &tw, sizeof tw); /* Set default time zone. */#ifndef SYS5 ftime( &tb ); tw.tw_zone = -tb.timezone;#else SYS5 tzset( ); tw.tw_zone = -(timezone / 60);#endif SYS5 while (isspace(*str)) str++; while ( 1 ) switch (cp = str, *cp ? lex_string( &str, start_cond) : 0) { case -1: if (!gotdate || tw.tw_year == 0) return 0; /* fall through */ case 0: return &tw;case 1: SETDAY;break;case 2: { cp++; SETDAY; }break;case 3: { if (europeandate) { /* European: DD/MM/YY */ tw.tw_mday = CVT2; cp++; tw.tw_mon = CVT2 - 1; } else { /* American: MM/DD/YY */ tw.tw_mon = CVT2 - 1; cp++; tw.tw_mday = CVT2; } cp++; for (i = 0; isdigit(*cp); ) i = i*10 + (*cp++ - '0'); tw.tw_year = i % 100; }break;case 4:{ tw.tw_mday = CVT2; while ( !isalpha(*cp++) ) ; SETMONTH; for (i = 0; isdigit(*cp); ) i = i*10 + (*cp++ - '0'); tw.tw_year = i % 100; }break;case 5: { cp++; SETMONTH; tw.tw_mday = CVT2; SKIPD; for (i = 0; isdigit(*cp); ) i = i*10 + (*cp++ - '0'); tw.tw_year = i % 100; }break;case 6: { cp++; SETMONTH; tw.tw_mday = CVT2; }break;case 7: { /* hack: ctime w/o TZ */ tw.tw_hour = CVT2; cp++; tw.tw_min = CVT2; cp++; tw.tw_sec = CVT2; while( !isdigit(*cp++) ) ; cp++; tw.tw_year = CVT2; }break;case 8: { tw.tw_hour = CVT2; cp++; tw.tw_min = CVT2; cp++; tw.tw_sec = CVT2; BEGIN Z; }break;case 9: { tw.tw_hour = CVT2; cp++; tw.tw_min = CVT2; BEGIN Z; }break;case 10: { tw.tw_hour = CVT2; cp++; if (tw.tw_hour == 12) tw.tw_hour = 0; tw.tw_min = CVT2; BEGIN Z; }break;case 11: { tw.tw_hour = CVT2; cp++; if (tw.tw_hour != 12) tw.tw_hour += 12; tw.tw_min = CVT2; BEGIN Z; }break;case 12: { tw.tw_hour = CVT2; tw.tw_min = CVT2; tw.tw_sec = CVT2; BEGIN Z; }break;case 13: { /* * Luckly, 4 digit times in the range * 1960-1999 aren't legal as hour * and minutes. */ cp += 2; tw.tw_year = CVT2; }break;case 14: { if (tw.tw_hour) { cp += 2; tw.tw_year = CVT2; tw.tw_zone = 0; } else { tw.tw_hour = CVT2; tw.tw_min = CVT2; BEGIN Z; } }break;case 15: ZONE(0 * 60);break;case 16: ZONE(0 * 60);break;case 17: ZONE(2 * 60);break;case 18: ZONED(2 * 60);break;case 19: ZONE(-5 * 60);break;case 20: ZONED(-5 * 60);break;case 21: ZONE(-6 * 60);break;case 22: ZONED(-6 * 60);break;case 23: ZONE(-7 * 60);break;case 24: ZONED(-7 * 60);break;case 25: ZONE(-8 * 60);break;case 26: ZONED(-8 * 60);break;case 27: ZONE(-(3 * 60 + 30));break;case 28: ZONE(-4 * 60);break;case 29: ZONED(-4 * 60);break;case 30: ZONE(-9 * 60);break;case 31: ZONED(-9 * 60);break;case 32: ZONE(-10 * 60);break;case 33: ZONED(-10 * 60);break;case 34: ZONED(0 * 60);break;case 35: { tw.tw_zone = 60 * (('a'-1) - LC(*cp)); EXPZONE; }break;case 36: { tw.tw_zone = 60 * ('a' - LC(*cp)); EXPZONE; }break;case 37: { tw.tw_zone = 60 * (LC(*cp) - 'm'); EXPZONE; }break;case 38: { cp++; tw.tw_zone = ((cp[0] * 10 + cp[1]) -('0' * 10 + '0'))*60 +((cp[2] * 10 + cp[3]) -('0' * 10 + '0')); EXPZONE;#ifdef DSTXXX zonehack (&tw);#endif DSTXXX cp += 4; }break;case 39: { cp++; tw.tw_zone = (('0' * 10 + '0') -(cp[0] * 10 + cp[1]))*60 +(('0' * 10 + '0') -(cp[2] * 10 + cp[3])); EXPZONE;#ifdef DSTXXX zonehack (&tw);#endif DSTXXX cp += 4; }break;case 40: { while( !isdigit(*cp++) ) ; cp++; tw.tw_year = CVT2; }break;case 41:case 42:;break;default: return(0);} }/* end of yylex */int yyvstop[] ={0,42,0,41,0,42,0,35,0,35,0,35,0,35,0,35,0,35,0,35,0,35,0,35,0,36,0,36,0,37,0,37,0,37,0,37,0,37,0,37,0,37,0,37,0,37,0,15,0,9,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,29,0,28,0,34,0,22,0,21,0,20,0,19,0,16,0,33,0,32,0,18,0,17,0,24,0,23,0,27,0,26,0,25,0,31,0,30,0,14,0,9,0,9,0,13,14,0,1,0,2,0,14,0,8,0,10,0,11,0,4,0,4,0,13,14,0,6,0,40,0,38,0,39,0,2,0,3,0,3,0,12,0,8,0,8,0,4,0,4,0,4,0,6,0,6,0,1,0,4,0,5,0,5,0,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?