Annotation of 43BSD/contrib/mh/zotnet/tws/dtimep.lex, revision 1.1

1.1     ! root        1: %e 2000
        !             2: %p 5000
        !             3: %n 1000
        !             4: %a 4000
        !             5: %START Z
        !             6: sun    (sun(day)?)
        !             7: mon    (mon(day)?)
        !             8: tue    (tue(sday)?)
        !             9: wed    (wed(nesday)?)
        !            10: thu    (thu(rsday)?)
        !            11: fri    (fri(day)?)
        !            12: sat    (sat(urday)?)
        !            13: 
        !            14: DAY    ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
        !            15: 
        !            16: jan    (jan(uary)?)
        !            17: feb    (feb(ruary)?)
        !            18: mar    (mar(ch)?)
        !            19: apr    (apr(il)?)
        !            20: may    (may)
        !            21: jun    (jun(e)?)
        !            22: jul    (jul(y)?)
        !            23: aug    (aug(est)?)
        !            24: sep    (sep(tember)?)
        !            25: oct    (oct(ober)?)
        !            26: nov    (nov(ember)?)
        !            27: dec    (dec(ember)?)
        !            28: 
        !            29: MONTH  ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
        !            30: 
        !            31: w      ([ \t]*)
        !            32: W      ([ \t]+)
        !            33: D      ([0-9]?[0-9])
        !            34: d      [0-9]
        !            35: %{
        !            36: #include "tws.h"
        !            37: #include <ctype.h>
        !            38: 
        !            39: /*
        !            40:  * Table to convert month names to numeric month.  We use the
        !            41:  * fact that the low order 5 bits of the sum of the 2nd & 3rd
        !            42:  * characters of the name is a hash with no collisions for the 12
        !            43:  * valid month names.  (The mask to 5 bits maps any combination of
        !            44:  * upper and lower case into the same hash value).
        !            45:  */
        !            46: static int month_map[] = {
        !            47:        0,
        !            48:        6,      /* 1 - Jul */
        !            49:        3,      /* 2 - Apr */
        !            50:        5,      /* 3 - Jun */
        !            51:        0,
        !            52:        10,     /* 5 - Nov */
        !            53:        0,
        !            54:        1,      /* 7 - Feb */
        !            55:        11,     /* 8 - Dec */
        !            56:        0,
        !            57:        0,
        !            58:        0,
        !            59:        0,
        !            60:        0,
        !            61:        0,
        !            62:        0,      /*15 - Jan */
        !            63:        0,
        !            64:        0,
        !            65:        0,
        !            66:        2,      /*19 - Mar */
        !            67:        0,
        !            68:        8,      /*21 - Sep */
        !            69:        0,
        !            70:        9,      /*23 - Oct */
        !            71:        0,
        !            72:        0,
        !            73:        4,      /*26 - May */
        !            74:        0,
        !            75:        7       /*28 - Aug */
        !            76: };
        !            77: /*
        !            78:  * Same trick for day-of-week using the hash function
        !            79:  *  (c1 & 7) + (c2 & 4)
        !            80:  */
        !            81: static int day_map[] = {
        !            82:        0,
        !            83:        0,
        !            84:        0,
        !            85:        6,      /* 3 - Sat */
        !            86:        4,      /* 4 - Thu */
        !            87:        0,
        !            88:        5,      /* 6 - Fri */
        !            89:        0,      /* 7 - Sun */
        !            90:        2,      /* 8 - Tue */
        !            91:        1       /* 9 - Mon */,
        !            92:        0,
        !            93:        3       /*11 - Wed */
        !            94: };
        !            95: #define SETDAY tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)];\
        !            96:                tw.tw_flags |= TW_SEXP;\
        !            97:                cp += 2;
        !            98: #define SETMONTH tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; gotdate++;\
        !            99:                 cp += 2;\
        !           100:                 SKIPD;
        !           101: #define CVT2   (i=(*cp++ - '0'),isdigit(*cp)? i*10 + (*cp++ - '0') : i)
        !           102: #define SKIPD  while ( !isdigit(*cp++) ) ;  --cp;
        !           103: #define ZONE(x)        tw.tw_zone=(x);
        !           104: #define ZONED(x)  tw.tw_zone=(x); tw.tw_flags |= TW_DST;
        !           105: #define LC(c)  (isupper(c) ? tolower(c) : (c))
        !           106: %}
        !           107: %%
        !           108: %{
        !           109: struct tws *dparsetime (str)
        !           110:        char *str;
        !           111: {
        !           112:        register int i;
        !           113:        static struct tws tw;
        !           114:        register char *cp;
        !           115:        register int gotdate = 0;
        !           116: 
        !           117:        start_cond = 0;
        !           118:        bzero( (char *) &tw, sizeof tw);
        !           119:        while (isspace(*str))
        !           120:                str++;
        !           121:        while ( 1 )
        !           122:                switch (cp = str, *cp? lex_string( &str, start_cond) : 0) {
        !           123: 
        !           124:                case -1:
        !           125:                        if (!gotdate || tw.tw_year == 0)
        !           126:                                return 0;
        !           127:                        /* fall through */
        !           128:                case 0:
        !           129:                        return &tw;
        !           130: 
        !           131: %}
        !           132: {DAY}","?{w}                           SETDAY;
        !           133: "("{DAY}")"(","?)                      cp++, SETDAY;
        !           134: 
        !           135: {D}"/"{D}"/"19[0-9][0-9]{w}            {
        !           136:                                        tw.tw_mday = CVT2; cp++;
        !           137:                                        tw.tw_mon  = CVT2 - 1; cp += 3;
        !           138:                                        tw.tw_year = CVT2;
        !           139:                                        gotdate++;
        !           140:                                        }
        !           141: {D}"/"{D}"/"[0-9][0-9]{w}              {
        !           142:                                        tw.tw_mday = CVT2; cp++;
        !           143:                                        tw.tw_mon  = CVT2 - 1; cp++;
        !           144:                                        tw.tw_year = CVT2;
        !           145:                                        gotdate++;
        !           146:                                        }
        !           147: {D}[- ]?{MONTH}[- ]?(19)?{D}{w}(at{W})?        {
        !           148:                                        tw.tw_mday = CVT2;
        !           149:                                        while ( !isalpha(*cp++) )
        !           150:                                                ;
        !           151:                                        SETMONTH;
        !           152:                                        for (i = 0; isdigit(*cp); )
        !           153:                                                i = i*10 + (*cp++ - '0');
        !           154:                                        tw.tw_year = i % 100;
        !           155:                                        }
        !           156: {MONTH}{W}{D}","{W}(19)?{D}{w}         {
        !           157:                                        cp++;
        !           158:                                        SETMONTH;
        !           159:                                        tw.tw_mday = CVT2;
        !           160:                                        SKIPD;
        !           161:                                        for (i = 0; isdigit(*cp); )
        !           162:                                                i = i*10 + (*cp++ - '0');
        !           163:                                        tw.tw_year = i % 100;
        !           164:                                        }
        !           165: 
        !           166: {MONTH}{W}{D}{w}                       {
        !           167:                                        cp++;
        !           168:                                        SETMONTH;
        !           169:                                        tw.tw_mday = CVT2;
        !           170:                                        }
        !           171: 
        !           172: {D}:{D}:{D}{w}                         {
        !           173:                                        tw.tw_hour = CVT2; cp++;
        !           174:                                        tw.tw_min  = CVT2; cp++;
        !           175:                                        tw.tw_sec  = CVT2;
        !           176:                                        BEGIN Z;
        !           177:                                        }
        !           178: {D}:{D}{w}                             |
        !           179: {D}:{D}{w}am{w}                                {
        !           180:                                        tw.tw_hour = CVT2; cp++;
        !           181:                                        tw.tw_min  = CVT2;
        !           182:                                        BEGIN Z;
        !           183:                                        }
        !           184: {D}:{D}{w}pm{w}                                {
        !           185:                                        tw.tw_hour = CVT2 + 12; cp++;
        !           186:                                        tw.tw_min  = CVT2;
        !           187:                                        BEGIN Z;
        !           188:                                        }
        !           189: [0-2]{d}{d}{d}{d}{d}{w}                        {
        !           190:                                        tw.tw_hour = CVT2;
        !           191:                                        tw.tw_min  = CVT2;
        !           192:                                        tw.tw_sec  = CVT2;
        !           193:                                        BEGIN Z;
        !           194:                                        }
        !           195: [0-2]{d}{d}{d}{w}                      {
        !           196:                                        tw.tw_hour = CVT2;
        !           197:                                        tw.tw_min  = CVT2;
        !           198:                                        BEGIN Z;
        !           199:                                        }
        !           200: <Z>"-"?ut                              ZONE(0 * 60);
        !           201: <Z>"-"?gmt                             ZONE(0 * 60);
        !           202: <Z>"-"?jst                             ZONE(2 * 60);
        !           203: <Z>"-"?jdt                             ZONED(2 * 60);
        !           204: <Z>"-"?est                             ZONE(-5 * 60);
        !           205: <Z>"-"?edt                             ZONED(-5 * 60);
        !           206: <Z>"-"?cst                             ZONE(-6 * 60);
        !           207: <Z>"-"?cdt                             ZONED(-6 * 60);
        !           208: <Z>"-"?mst                             ZONE(-7 * 60);
        !           209: <Z>"-"?mdt                             ZONED(-7 * 60);
        !           210: <Z>"-"?pst                             ZONE(-8 * 60);
        !           211: <Z>"-"?pdt                             ZONED(-8 * 60);
        !           212: <Z>"-"?nst                             ZONE(-(3 * 60 + 30));
        !           213: <Z>"-"?ast                             ZONE(-4 * 60);
        !           214: <Z>"-"?adt                             ZONED(-4 * 60);
        !           215: <Z>"-"?yst                             ZONE(-9 * 60);
        !           216: <Z>"-"?ydt                             ZONED(-9 * 60);
        !           217: <Z>"-"?hst                             ZONE(-10 * 60);
        !           218: <Z>"-"?hdt                             ZONED(-10 * 60);
        !           219: <Z>"-"?bst                             ZONED(-1 * 60);
        !           220: <Z>[a-i]                               tw.tw_zone = 60 * (('a'-1) - LC(*cp));
        !           221: <Z>[k-m]                               tw.tw_zone = 60 * ('a' - LC(*cp));
        !           222: <Z>[n-y]                               tw.tw_zone = 60 * (LC(*cp) - 'm');
        !           223: <Z>"+"[0-1]{d}{d}{d}                   {
        !           224:                                        cp++;
        !           225:                                        tw.tw_zone = ((cp[0] * 10 + cp[1])
        !           226:                                                     -('0' * 10   + '0'))*60
        !           227:                                                    +((cp[2] * 10 + cp[3])
        !           228:                                                     -('0' * 10   + '0'));
        !           229:                                        cp += 4;
        !           230:                                        }
        !           231: <Z>"-"[0-1]{d}{d}{d}                   {
        !           232:                                        cp++;
        !           233:                                        tw.tw_zone = (('0' * 10   + '0')
        !           234:                                                     -(cp[0] * 10 + cp[1]))*60
        !           235:                                                    +(('0' * 10   + '0')
        !           236:                                                     -(cp[2] * 10 + cp[3]));
        !           237:                                        cp += 4;
        !           238:                                        }
        !           239: <Z>{W}19[6-9]{d}                       {
        !           240:                                        while( !isdigit(*cp++) )
        !           241:                                                ;
        !           242:                                        cp++;
        !           243:                                        tw.tw_year = CVT2;
        !           244:                                        }
        !           245: 
        !           246: \n     |
        !           247: {W}    ;
        !           248: %%

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.