import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / net / khttpd / make_times_h.c
1 /*
2
3 This program generates the "times.h" file with the zulu-times of the first of
4 every month of a decade.
5
6 */
7 /****************************************************************
8  *      This program is free software; you can redistribute it and/or modify
9  *      it under the terms of the GNU General Public License as published by
10  *      the Free Software Foundation; either version 2, or (at your option)
11  *      any later version.
12  *
13  *      This program is distributed in the hope that it will be useful,
14  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *      GNU General Public License for more details.
17  *
18  *      You should have received a copy of the GNU General Public License
19  *      along with this program; if not, write to the Free Software
20  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  ****************************************************************/
23
24 #include <time.h>
25 #include <stdio.h>
26
27 static time_t GetDay(int D,int M,int Y)
28 {
29         struct tm TM;
30         
31         TM.tm_sec       = 0;
32         TM.tm_min       = 0;
33         TM.tm_hour      = 0;
34         TM.tm_mday      = D;
35         TM.tm_mon       = M;
36         TM.tm_wday      = 0;
37         TM.tm_yday      = 0;
38         TM.tm_year      = Y-1900;
39         TM.tm_isdst     = 0;
40         
41         return mktime(&TM);
42         
43 }
44 static int WeekGetDay(int D,int M,int Y)
45 {
46         struct tm TM;
47         
48         TM.tm_sec       = 0;
49         TM.tm_min       = 0;
50         TM.tm_hour      = 0;
51         TM.tm_mday      = D;
52         TM.tm_mon       = M;
53         TM.tm_year      = Y-1900;
54         TM.tm_isdst     = 0;
55         TM.tm_wday      = 0;
56         TM.tm_yday      = 0;
57         
58         (void)mktime(&TM);
59         
60         return TM.tm_wday;
61         
62 }
63
64 int main(void)
65 {
66         int M,Y;
67         FILE *file;
68         
69         file=fopen("times.h","w");
70         
71         if (file==NULL) 
72                 return 0; 
73         
74         fprintf(file,"static time_t TimeDays[10][13] = { \n");
75         
76         Y=1997;
77         while (Y<2007)
78         {
79                 M=0;
80                 fprintf(file," { ");
81                 while (M<12)
82                 {
83                         fprintf(file,"%i",(int)GetDay(1,M,Y));
84                         fprintf(file,",\t");
85                 
86                         M++;
87                 }
88                 
89                 fprintf(file,"%i } ",(int)GetDay(1,0,Y+1));
90                 if (Y!=2006) fprintf(file,",");
91                 fprintf(file,"\n");
92                 Y++;
93         }
94         fprintf(file,"};\n");
95
96         fprintf(file,"static int WeekDays[10][13] = { \n");
97         
98         Y=1997;
99         while (Y<2007)
100         {
101                 M=0;
102                 fprintf(file," { ");
103                 while (M<12)
104                 {
105                         fprintf(file,"%i",(int)WeekGetDay(1,M,Y));
106                         fprintf(file,",\t");
107                 
108                         M++;
109                 }
110                 
111                 fprintf(file,"%i } ",(int)WeekGetDay(1,0,Y+1));
112                 if (Y!=2006) fprintf(file,",");
113                 fprintf(file,"\n");
114                 Y++;
115         }
116         fprintf(file,"};\n");
117         fprintf(file,"#define KHTTPD_YEAROFFSET   1997\n");
118         fprintf(file,"#define KHTTPD_NUMYEARS     10\n");
119         (void)fclose(file);
120         
121         return 0;
122 }