Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / cemcom / 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 3.12 1994/06/24 12:04:06 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        "class.h"
14 #include        "macro.h"
15 #include        "idf.h"
16 #include        "interface.h"
17
18 PRIVATE struct mkey     {
19         char *mk_reserved;
20         int mk_key;
21 } mkey[] =      {
22         {"define",      K_DEFINE},
23         {"elif",        K_ELIF},
24         {"else",        K_ELSE},
25         {"endif",       K_ENDIF},
26         {"if",          K_IF},
27         {"ifdef",       K_IFDEF},
28         {"ifndef",      K_IFNDEF},
29         {"include",     K_INCLUDE},
30         {"line",        K_LINE},
31         {"undef",       K_UNDEF},
32         {"pragma",      K_PRAGMA},
33         {0,             K_UNKNOWN}
34 };
35
36 char *strcpy();
37
38 EXPORT
39 init_pp()
40 {
41         long clock, sys_time();
42         static char date[30];
43         char *ctime();
44
45         /*      Initialise the control line keywords (if, include, define, etc)
46                 Although the lexical analyzer treats them as identifiers, the
47                 control line handler can recognize them as keywords by the
48                 id_resmac field of the identifier.
49         */
50         {
51                 register struct mkey *mk = &mkey[0];
52
53                 while (mk->mk_reserved) {
54                         register struct idf *idf = str2idf(mk->mk_reserved);
55                         
56                         if (idf->id_resmac)
57                                 fatal("maximum identifier length insufficient");
58                         idf->id_resmac = mk->mk_key;
59                         mk++;
60                 }
61         }
62
63         /*      Initialize __DATE__, __FILE__ and __LINE__ macro
64                 definitions.
65         */
66         /* __DATE__     */
67         clock = sys_time();
68         strcpy(&date[1], ctime(&clock));
69         date[26] = '\0';                /* zap nl       */
70         date[0] = date[25] = '"';
71         macro_def(str2idf("__DATE__"), date, -1, 26, NOFLAG);
72
73         /* __LINE__     */
74         macro_def(str2idf("__LINE__"), "0", -1, 1, FUNC);
75
76         /* __FILE__     */
77         macro_def(str2idf("__FILE__"), "", -1, 1, FUNC);
78
79         /* defined(??) */
80         macro_def(str2idf("defined"), "", 1, 1, FUNC);
81 }
82 #endif /* NOPP */