1 #include "yyyymm.h"
2
date2yyyymm(const char * s)3 unsigned int date2yyyymm(const char *s)
4 /* expects a qmail date string s and returns yyyymm */
5 /* if there are problems, it returns 0. If there is no terminating char */
6 /* we may segfault if the syntax is bad. Assure that the ';' is there */
7 /* or add '\0' */
8 {
9 unsigned int mo;
10 unsigned int year; /* must hold yyyymm - ok to year 65K */
11 char ch,ch1,ch2;
12
13 /* jan feb mar apr may jun jul aug sep oct nov dec */
14 /* - strictly qmail datefmt dependent*/
15 for (;;s++) {
16 ch = *s;
17 if (ch != ' ' && (ch < '0' || ch > '9')) break;
18 }
19 mo = 0;
20 if (!(ch = *(s++))) return 0;
21 if (ch >= 'a') ch -= ('a' - 'A'); /* toupper */
22 if (!(ch1 = *(s++))) return 0; /* rfc822 hrds are case-insens */
23 if (ch1 >= 'a') ch1 -= ('a' - 'A');
24 if (!(ch2 = *(s++))) return 0;
25 if (ch2 >= 'a') ch2 -= ('a' - 'A');
26
27 switch (ch) {
28 case 'J':
29 if (ch1 == 'A' && ch2 == 'N') { mo = 1; break; }
30 if (ch1 == 'U') {
31 if (ch2 == 'N') mo = 6;
32 else if (ch2 == 'L') mo = 7;
33 }
34 break;
35 case 'F': if (ch1 == 'E' && ch2 == 'B') mo = 2; break;
36 case 'A':
37 if (ch1 == 'P' && ch2 == 'R') mo = 4;
38 else if (ch1 == 'U' && ch2 == 'G') mo = 8;
39 break;
40 case 'M':
41 if (ch1 != 'A') break;
42 if (ch2 == 'R') mo = 3;
43 else if (ch2 == 'Y') mo = 5;
44 break;
45 case 'S': if (ch1 == 'E' && ch2 == 'P') mo = 9; break;
46 case 'O': if (ch1 == 'C' && ch2 == 'T') mo = 10; break;
47 case 'N': if (ch1 == 'O' && ch2 == 'V') mo = 11; break;
48 case 'D': if (ch1 == 'E' && ch2 == 'C') mo = 12; break;
49 default:
50 break;
51 }
52 if (!mo || *(s++) != ' ')
53 return 0L; /* mo true means s[0-2] valid */
54 year = 0L;
55 for (;;) {
56 unsigned char chy;
57 chy = (unsigned char) *(s++);
58 if (chy < '0' || chy > '9') {
59 if (year) break;
60 else return 0;
61 }
62 year = year * 10 + (chy - '0');
63 }
64 return year * 100 + mo;
65 }
66
67
68