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: INPUT SKIP FUNCTIONS */
|
|
|
|
|
2018-09-02 09:49:40 +00:00
|
|
|
#include "arith.h"
|
|
|
|
#include "LLlex.h"
|
|
|
|
#include "class.h"
|
|
|
|
#include "input.h"
|
2019-03-01 17:36:11 +00:00
|
|
|
#include "domacro.h"
|
|
|
|
#include "error.h"
|
1989-10-23 10:35:56 +00:00
|
|
|
|
|
|
|
extern int InputLevel;
|
|
|
|
|
2019-03-01 17:36:11 +00:00
|
|
|
int skipspaces(register int ch, int skipnl)
|
1989-10-23 10:35:56 +00:00
|
|
|
{
|
|
|
|
register int nlseen = 0;
|
|
|
|
|
2018-09-02 09:49:40 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
1989-10-23 10:35:56 +00:00
|
|
|
while (class(ch) == STSKIP)
|
|
|
|
ch = GetChar();
|
2018-09-02 09:49:40 +00:00
|
|
|
if (skipnl && class(ch) == STNL)
|
|
|
|
{
|
1989-10-23 10:35:56 +00:00
|
|
|
ch = GetChar();
|
|
|
|
LineNumber++;
|
|
|
|
nlseen++;
|
|
|
|
continue;
|
|
|
|
}
|
2018-09-02 09:49:40 +00:00
|
|
|
if (ch == TOKSEP && InputLevel)
|
|
|
|
{
|
1989-10-23 10:35:56 +00:00
|
|
|
ch = GetChar();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* \\\n are handled by trigraph */
|
|
|
|
|
2018-09-02 09:49:40 +00:00
|
|
|
if (ch == '/')
|
|
|
|
{
|
1989-10-23 10:35:56 +00:00
|
|
|
ch = GetChar();
|
2018-09-02 09:49:40 +00:00
|
|
|
if (ch == '*' && !InputLevel)
|
|
|
|
{
|
1989-10-23 10:35:56 +00:00
|
|
|
skipcomment();
|
|
|
|
ch = GetChar();
|
|
|
|
}
|
2018-09-02 10:14:59 +00:00
|
|
|
else if (ch == '/' && !InputLevel)
|
|
|
|
{
|
|
|
|
skiplinecomment();
|
|
|
|
ch = GetChar();
|
|
|
|
}
|
2018-09-02 09:49:40 +00:00
|
|
|
else
|
|
|
|
{
|
1989-10-23 10:35:56 +00:00
|
|
|
UnGetChar();
|
|
|
|
return '/';
|
|
|
|
}
|
|
|
|
}
|
2018-09-02 09:49:40 +00:00
|
|
|
else if (nlseen && ch == '#')
|
|
|
|
{
|
1989-10-23 10:35:56 +00:00
|
|
|
domacro();
|
|
|
|
ch = GetChar();
|
2018-09-02 09:49:40 +00:00
|
|
|
}
|
|
|
|
else
|
1989-10-23 10:35:56 +00:00
|
|
|
return ch;
|
|
|
|
}
|
2019-03-01 17:36:11 +00:00
|
|
|
/* garbage */
|
|
|
|
return 0;
|
1989-10-23 10:35:56 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 17:36:11 +00:00
|
|
|
int SkipToNewLine(void)
|
1989-10-23 10:35:56 +00:00
|
|
|
{
|
|
|
|
register int ch;
|
1989-11-22 12:59:15 +00:00
|
|
|
register int garbage = 0;
|
1989-12-12 12:41:39 +00:00
|
|
|
register int delim = 0;
|
1989-10-23 10:35:56 +00:00
|
|
|
|
2018-09-02 09:49:40 +00:00
|
|
|
while ((ch = GetChar()) != '\n')
|
|
|
|
{
|
|
|
|
if (delim)
|
|
|
|
{
|
|
|
|
if (ch == '\\')
|
|
|
|
{
|
|
|
|
if (GetChar() == '\n')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (ch == delim)
|
|
|
|
{
|
1989-12-12 12:41:39 +00:00
|
|
|
delim = 0;
|
|
|
|
}
|
|
|
|
continue;
|
2018-09-02 09:49:40 +00:00
|
|
|
}
|
|
|
|
else if (ch == '\'' || ch == '\"')
|
|
|
|
{
|
1989-12-12 12:41:39 +00:00
|
|
|
delim = ch;
|
|
|
|
garbage = 1;
|
2018-09-02 09:49:40 +00:00
|
|
|
}
|
|
|
|
else if (ch == '/')
|
|
|
|
{
|
2018-09-02 10:14:59 +00:00
|
|
|
if (!InputLevel)
|
2018-09-02 09:49:40 +00:00
|
|
|
{
|
2018-09-02 10:14:59 +00:00
|
|
|
int nch = GetChar();
|
|
|
|
if (nch == '*')
|
|
|
|
{
|
|
|
|
skipcomment();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (nch == '/')
|
|
|
|
{
|
|
|
|
skiplinecomment();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
UnGetChar();
|
1989-10-23 10:35:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-02 09:49:40 +00:00
|
|
|
else if (ch == TOKSEP && InputLevel)
|
|
|
|
{
|
1991-01-15 11:51:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
1989-11-22 12:59:15 +00:00
|
|
|
if (!is_wsp(ch))
|
|
|
|
garbage = 1;
|
1989-10-23 10:35:56 +00:00
|
|
|
}
|
2018-09-02 09:49:40 +00:00
|
|
|
if (delim)
|
|
|
|
strict("unclosed opening %c", delim);
|
1989-10-23 10:35:56 +00:00
|
|
|
++LineNumber;
|
1989-11-22 12:59:15 +00:00
|
|
|
return garbage;
|
1989-10-23 10:35:56 +00:00
|
|
|
}
|