Pristine Ack-5.5
[Ack-5.5.git] / util / cpp / init.c
1 /* $Id: init.c,v 1.5 1994/06/24 10:18:27 ceriel Exp $ */
2 /*
3  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4  * See the copyright notice in the ACK home directory, in the file "Copyright".
5  */
6 /* PREPROCESSOR: INITIALIZATION ROUTINES */
7
8 #include        <system.h>
9 #include        <alloc.h>
10 #include        "class.h"
11 #include        "macro.h"
12 #include        "idf.h"
13 #include        "interface.h"
14
15 PRIVATE struct mkey     {
16         char *mk_reserved;
17         int mk_key;
18 } mkey[] =      {
19         {"define",      K_DEFINE},
20         {"elif",        K_ELIF},
21         {"else",        K_ELSE},
22         {"endif",       K_ENDIF},
23         {"if",          K_IF},
24         {"ifdef",       K_IFDEF},
25         {"ifndef",      K_IFNDEF},
26         {"include",     K_INCLUDE},
27         {"line",        K_LINE},
28         {"undef",       K_UNDEF},
29         {"pragma",      K_PRAGMA},
30         {0,             K_UNKNOWN}
31 };
32
33 char *strcpy();
34
35 EXPORT
36 init_pp()
37 {
38         long clock, sys_time();
39         static char date[30];
40         char *ctime();
41
42         /*      Initialise the control line keywords (if, include, define, etc)
43                 Although the lexical analyzer treats them as identifiers, the
44                 control line handler can recognize them as keywords by the
45                 id_resmac field of the identifier.
46         */
47         {
48                 register struct mkey *mk = &mkey[0];
49
50                 while (mk->mk_reserved) {
51                         struct idf *idf = str2idf(mk->mk_reserved, 0);
52                         
53                         if (idf->id_resmac)
54                                 fatal("maximum identifier length insufficient");
55                         idf->id_resmac = mk->mk_key;
56                         mk++;
57                 }
58         }
59
60         /*      Initialize __DATE__, __FILE__ and __LINE__ macro
61                 definitions.
62         */
63         /* __DATE__     */
64         clock = sys_time();
65         strcpy(&date[1], ctime(&clock));
66         date[26] = '\0';                /* zap nl       */
67         date[0] = date[25] = '"';
68         macro_def(str2idf("__DATE__", 0), date, -1, 26, NOFLAG);
69
70         /* __LINE__     */
71         macro_def(str2idf("__LINE__", 0), "0", -1, 1, FUNC);
72
73         /* __FILE__     */
74         macro_def(str2idf("__FILE__", 0), "", -1, 1, FUNC);
75
76         /* defined(??) */
77         macro_def(str2idf("defined", 0), "", 1, 1, FUNC);
78 }