ack/lang/cem/cpp.ansi/skip.c

128 lines
1.9 KiB
C
Raw Permalink Normal View History

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