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