Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / cemcom.ansi / init.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 /* $Id: init.c,v 1.9 1994/06/27 08:00:14 ceriel Exp $ */
6 /* PREPROCESSOR: INITIALIZATION ROUTINES */
7
8 #include        "nopp.h"
9
10 #ifndef NOPP
11 #include        <system.h>
12 #include        <alloc.h>
13 #include        <time.h>
14 #include        "class.h"
15 #include        "macro.h"
16 #include        "idf.h"
17
18 extern char *sprint();
19
20 struct mkey     {
21         char *mk_reserved;
22         int mk_key;
23 } mkey[] =      {
24         {"define",      K_DEFINE},
25         {"elif",        K_ELIF},
26         {"else",        K_ELSE},
27         {"endif",       K_ENDIF},
28         {"error",       K_ERROR},
29         {"if",          K_IF},
30         {"ifdef",       K_IFDEF},
31         {"ifndef",      K_IFNDEF},
32         {"include",     K_INCLUDE},
33         {"line",        K_LINE},
34         {"pragma",      K_PRAGMA},
35         {"undef",       K_UNDEF},
36         {0,             K_UNKNOWN}
37 };
38
39 init_pp()
40 {
41         static char *months[12] = {
42                 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
43                 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
44         };
45         long clock, sys_time();
46         static char dbuf[30];
47         static char tbuf[30];
48         struct tm  *tp;
49
50         /*      Initialise the control line keywords (if, include, define, etc)
51                 Although the lexical analyzer treats them as identifiers, the
52                 control line handler can recognize them as keywords by the
53                 id_resmac field of the identifier.
54         */
55         {
56                 register struct mkey *mk = &mkey[0];
57
58                 while (mk->mk_reserved) {
59                         register struct idf *idf = str2idf(mk->mk_reserved, 0);
60                         
61                         if (idf->id_resmac)
62                                 fatal("maximum identifier length insufficient");
63                         idf->id_resmac = mk->mk_key;
64                         mk++;
65                 }
66         }
67
68         /*      Initialize __LINE__, __FILE__, __DATE__, __TIME__,
69                 and __STDC__ macro definitions.
70         */
71         clock = sys_time();
72         tp = localtime(&clock);
73
74         /* __DATE__ */
75         sprint(dbuf, "\"%s %02d %d\"", months[tp->tm_mon],
76                         tp->tm_mday, tp->tm_year+1900);
77         if (tp->tm_mday < 10) dbuf[5] = ' ';            /* hack */
78         macro_def(str2idf("__DATE__", 0), dbuf, -1, strlen(dbuf), NOUNDEF);
79
80         /* __TIME__ */
81         sprint(tbuf, "\"%02d:%02d:%02d\"", tp->tm_hour, tp->tm_min, tp->tm_sec);
82         macro_def(str2idf("__TIME__", 0), tbuf, -1, strlen(tbuf), NOUNDEF);
83
84         /* __LINE__     */
85         macro_def(str2idf("__LINE__", 0), "0", -1, 1, NOUNDEF | FUNC);
86
87         /* __FILE__     */
88         macro_def(str2idf("__FILE__", 0), "", -1, 1, NOUNDEF | FUNC);
89
90         /* __STDC__ */
91         macro_def(str2idf("__STDC__", 0), "1", -1, 1, NOUNDEF);
92
93         /* defined(??) */
94         macro_def(str2idf("defined", 0), "", 1, 1, NOUNDEF | FUNC);
95 }
96 #endif /* NOPP */