ack/lang/cem/cemcom.ansi/domacro.c

103 lines
2 KiB
C
Raw Permalink Normal View History

1989-02-07 11:04:05 +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-27 08:03:14 +00:00
/* $Id$ */
1989-02-07 11:04:05 +00:00
/* PREPROCESSOR: CONTROLLINE INTERPRETER */
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "domacro.h"
#include "parameters.h"
#include "idf.h"
#include "interface.h"
#include "arith.h"
#include "LLlex.h"
#include "Lpars.h"
#include "input.h"
#include "pragma.h"
#include "skip.h"
#include "error.h"
1989-02-07 11:04:05 +00:00
#ifdef DBSYMTAB
#include <stb.h>
#include <em.h>
int IncludeLevel = 0;
#endif
1989-02-07 11:04:05 +00:00
extern char options[];
static void do_line(unsigned int);
struct idf* GetIdentifier(int skiponerr) /* skip the rest of the line on error */
1989-10-16 12:38:25 +00:00
{
/* returns a pointer to the descriptor of the identifier that is
read from the input stream. When the input does not contain
an identifier, the rest of the line is skipped when
skiponerr is on, and a null-pointer is returned.
The substitution of macros is disabled.
1989-10-16 12:38:25 +00:00
*/
int tok;
struct token tk;
tok = GetToken(&tk);
if (tok != IDENTIFIER)
{
if (skiponerr && tok != EOI)
SkipToNewLine();
return (struct idf*)0;
1989-10-16 12:38:25 +00:00
}
return tk.tk_idf;
}
void domacro(void)
1989-02-07 11:04:05 +00:00
{
int tok;
struct token tk;
EoiForNewline = 1;
if ((tok = GetToken(&tk)) == IDENTIFIER)
{
if (!strcmp(tk.tk_idf->id_text, "pragma"))
{
do_pragma();
EoiForNewline = 0;
return;
}
}
else if (tok == INTEGER)
{
do_line((unsigned int)tk.tk_ival);
1989-10-24 15:02:02 +00:00
EoiForNewline = 0;
return;
1989-02-07 11:04:05 +00:00
}
lexerror("illegal # line");
1989-02-07 11:04:05 +00:00
EoiForNewline = 0;
SkipToNewLine();
1989-02-07 11:04:05 +00:00
}
static void do_line(unsigned int l)
1989-02-07 11:04:05 +00:00
{
struct token tk;
int t = GetToken(&tk);
1989-02-07 11:04:05 +00:00
if (t != EOI)
SkipToNewLine();
LineNumber = l; /* the number of the next input line */
if (t == STRING)
{ /* is there a filespecifier? */
/*
* Do not attempt to free the old string, since it might
* be used in a def structure.
*/
#ifdef DBSYMTAB
if (options['g'] && strcmp(FileName, tk.tk_bts) != 0)
{
C_ms_std(tk.tk_bts, N_SOL, 0);
}
#endif /* DBSYMTAB */
FileName = tk.tk_bts;
}
1989-02-07 11:04:05 +00:00
}