1989-10-23 10:35:56 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1989-10-23 10:35:56 +00:00
|
|
|
/* PREPROCESSOR: INITIALIZATION ROUTINES */
|
|
|
|
|
2006-07-30 23:40:35 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-11-09 20:52:04 +00:00
|
|
|
#include <time.h>
|
2006-07-30 23:40:35 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "alloc.h"
|
|
|
|
#include "time.h"
|
1989-10-23 10:35:56 +00:00
|
|
|
#include "class.h"
|
|
|
|
#include "macro.h"
|
|
|
|
#include "idf.h"
|
|
|
|
|
|
|
|
struct mkey {
|
|
|
|
char *mk_reserved;
|
|
|
|
int mk_key;
|
|
|
|
} mkey[] = {
|
|
|
|
{"define", K_DEFINE},
|
|
|
|
{"elif", K_ELIF},
|
|
|
|
{"else", K_ELSE},
|
|
|
|
{"endif", K_ENDIF},
|
|
|
|
{"error", K_ERROR},
|
|
|
|
{"if", K_IF},
|
|
|
|
{"ifdef", K_IFDEF},
|
|
|
|
{"ifndef", K_IFNDEF},
|
|
|
|
{"include", K_INCLUDE},
|
|
|
|
{"line", K_LINE},
|
|
|
|
{"pragma", K_PRAGMA},
|
|
|
|
{"undef", K_UNDEF},
|
|
|
|
{0, K_UNKNOWN}
|
|
|
|
};
|
|
|
|
|
1993-03-18 13:24:20 +00:00
|
|
|
char *sprint();
|
1989-10-23 10:35:56 +00:00
|
|
|
|
|
|
|
init_pp()
|
|
|
|
{
|
|
|
|
static char *months[12] = {
|
|
|
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
|
|
|
};
|
2016-11-09 20:52:04 +00:00
|
|
|
time_t clock;
|
1989-10-23 10:35:56 +00:00
|
|
|
static char dbuf[30];
|
|
|
|
static char tbuf[30];
|
|
|
|
struct tm *tp;
|
|
|
|
|
|
|
|
/* Initialise the control line keywords (if, include, define, etc)
|
|
|
|
Although the lexical analyzer treats them as identifiers, the
|
|
|
|
control line handler can recognize them as keywords by the
|
|
|
|
id_resmac field of the identifier.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
register struct mkey *mk = &mkey[0];
|
|
|
|
|
|
|
|
while (mk->mk_reserved) {
|
1989-11-03 10:36:56 +00:00
|
|
|
register struct idf *idf = str2idf(mk->mk_reserved, 0);
|
1989-10-23 10:35:56 +00:00
|
|
|
|
|
|
|
if (idf->id_resmac)
|
|
|
|
fatal("maximum identifier length insufficient");
|
|
|
|
idf->id_resmac = mk->mk_key;
|
|
|
|
mk++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize __LINE__, __FILE__, __DATE__, __TIME__,
|
|
|
|
and __STDC__ macro definitions.
|
|
|
|
*/
|
2016-11-09 20:52:04 +00:00
|
|
|
clock = time(NULL);
|
1989-10-23 10:35:56 +00:00
|
|
|
tp = localtime(&clock);
|
|
|
|
|
|
|
|
/* __DATE__ */
|
1989-11-09 21:33:29 +00:00
|
|
|
sprint(dbuf, "\"%s %2d %d\"", months[tp->tm_mon],
|
1989-10-23 10:35:56 +00:00
|
|
|
tp->tm_mday, tp->tm_year+1900);
|
1989-11-09 21:33:29 +00:00
|
|
|
/* if (tp->tm_mday < 10) dbuf[5] = ' '; /* hack */
|
1989-10-23 10:35:56 +00:00
|
|
|
macro_def(str2idf("__DATE__", 0), dbuf, -1, strlen(dbuf), NOUNDEF);
|
|
|
|
|
|
|
|
/* __TIME__ */
|
1989-11-09 21:33:29 +00:00
|
|
|
sprint(tbuf, "\"%02d:%02d:%02d\"", tp->tm_hour, tp->tm_min, tp->tm_sec);
|
1989-10-23 10:35:56 +00:00
|
|
|
macro_def(str2idf("__TIME__", 0), tbuf, -1, strlen(tbuf), NOUNDEF);
|
|
|
|
|
|
|
|
/* __LINE__ */
|
|
|
|
macro_def(str2idf("__LINE__", 0), "0", -1, 1, NOUNDEF | FUNC);
|
|
|
|
|
|
|
|
/* __FILE__ */
|
|
|
|
macro_def(str2idf("__FILE__", 0), "", -1, 1, NOUNDEF | FUNC);
|
|
|
|
|
|
|
|
/* __STDC__ */
|
|
|
|
macro_def(str2idf("__STDC__", 0), "1", -1, 1, NOUNDEF);
|
|
|
|
|
|
|
|
/* defined(??) */
|
|
|
|
macro_def(str2idf("defined", 0), "", 1, 1, NOUNDEF | FUNC);
|
|
|
|
}
|