2 /*$Id: date2yyyymm.c,v 1.1 1999/10/09 16:45:43 lindberg Exp $*/
3 /*$Name: ezmlm-idx-040 $*/
6 unsigned int date2yyyymm(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 */
14 unsigned int year
; /* must hold yyyymm - ok to year 65K */
17 /* jan feb mar apr may jun jul aug sep oct nov dec */
18 /* - strictly qmail datefmt dependent*/
21 if (ch
!= ' ' && (ch
< '0' || ch
> '9')) break;
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');
33 if (ch1
== 'A' && ch2
== 'N') { mo
= 1; break; }
35 if (ch2
== 'N') mo
= 6;
36 else if (ch2
== 'L') mo
= 7;
39 case 'F': if (ch1
== 'E' && ch2
== 'B') mo
= 2; break;
41 if (ch1
== 'P' && ch2
== 'R') mo
= 4;
42 else if (ch1
== 'U' && ch2
== 'G') mo
= 8;
45 if (ch1
!= 'A') break;
46 if (ch2
== 'R') mo
= 3;
47 else if (ch2
== 'Y') mo
= 5;
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;
56 if (!mo
|| *(s
++) != ' ')
57 return 0L; /* mo true means s[0-2] valid */
60 register unsigned char chy
;
61 chy
= (unsigned char) *(s
++);
62 if (chy
< '0' || chy
> '9') {
66 year
= year
* 10 + (chy
- '0');
68 return year
* 100 + mo
;