Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / cpp.ansi / skip.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: skip.c,v 1.6 1994/10/28 15:23:55 ceriel Exp $ */
6 /* PREPROCESSOR: INPUT SKIP FUNCTIONS */
7
8 #include        "arith.h"
9 #include        "LLlex.h"
10 #include        "class.h"
11 #include        "input.h"
12
13 extern int InputLevel;
14
15 int
16 skipspaces(ch, skipnl)
17         register int ch;
18 {
19         /*      skipspaces() skips any white space and returns the first
20                 non-space character.
21         */
22         register int nlseen = 0;
23
24         for (;;) {
25                 while (class(ch) == STSKIP)
26                         ch = GetChar();
27                 if (skipnl && class(ch) == STNL) {
28                         ch = GetChar();
29                         LineNumber++;
30                         nlseen++;
31                         continue;
32                 }
33                 if (ch == TOKSEP && InputLevel) {
34                         ch = GetChar();
35                         continue;
36                 }
37
38                 /* \\\n are handled by trigraph */
39
40                 if (ch == '/') {
41                         ch = GetChar();
42                         if (ch == '*' && !InputLevel) {
43                                 skipcomment();
44                                 ch = GetChar();
45                         }
46                         else    {
47                                 UnGetChar();
48                                 return '/';
49                         }
50                 }
51                 else if (nlseen && ch == '#') {
52                         domacro();
53                         ch = GetChar();
54                 } else
55                         return ch;
56         }
57 }
58
59 SkipToNewLine()
60 {
61         register int ch;
62         register int garbage = 0;
63         register int delim = 0;
64
65         while ((ch = GetChar()) != '\n') {
66                 if (delim) {
67                         if (ch == '\\') {
68                                 if (GetChar() == '\n') break;
69                         } else if (ch == delim) {
70                                 delim = 0;
71                         }
72                         continue;
73                 } else if (ch == '\'' || ch == '\"') {
74                         delim = ch;
75                         garbage = 1;
76                 } else if (ch == '/') {
77                         if (GetChar() == '*' && !InputLevel) {
78                                 skipcomment();
79                                 continue;
80                         }
81                         else UnGetChar();
82                 }
83                 else if (ch == TOKSEP && InputLevel) {
84                         continue;
85                 }
86                 if (!is_wsp(ch))
87                         garbage = 1;
88         }
89         if (delim) strict("unclosed opening %c", delim);
90         ++LineNumber;
91         return garbage;
92 }