1 /*
2 buildnum.c
3
4 build number function
5
6 Copyright (C) 1996-1997 Id Software, Inc.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) 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.
16
17 See the GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to:
21
22 Free Software Foundation, Inc.
23 59 Temple Place - Suite 330
24 Boston, MA 02111-1307, USA
25
26 */
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_STRING_H
32 # include <string.h>
33 #endif
34 #ifdef HAVE_STRINGS_H
35 # include <strings.h>
36 #endif
37
38 #include <stdlib.h>
39
40 #include "buildnum.h"
41
42 static const char *date = __DATE__; // Was "Dec 21 1999"
43 static const char *mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
44 "Aug", "Sep", "Oct", "Nov", "Dec" };
45 static const char mond[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
46
47
48 /* returns days since Dec 21 1999 */
49 VISIBLE int
build_number(void)50 build_number (void)
51 {
52 int m = 0;
53 int d = 0;
54 int y = 0;
55 static int b = 0;
56
57 if (b != 0)
58 return b;
59
60 for (m = 0; m < 11; m++) {
61 if (strncasecmp (&date[0], mon[m], 3) == 0)
62 break;
63 d += mond[m];
64 }
65
66 d += atoi (&date[4]) - 1;
67
68 y = atoi (&date[7]) - 1900;
69
70 b = d + (int) ((y - 1) * 365.25);
71
72 if (((y % 4) == 0) && m > 1) {
73 b += 1;
74 }
75
76 b -= 36148; // Dec 21 1999
77
78 return b;
79 }
80