Pristine Ack-5.5
[Ack-5.5.git] / util / cpp / 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/06/24 10:19:03 ceriel Exp $ */
6 /* PREPROCESSOR: INPUT SKIP FUNCTIONS */
7
8 #include        "LLlex.h"
9 #include        "class.h"
10 #include        "input.h"
11
12 int
13 skipspaces(ch, skipnl)
14         register int ch;
15 {
16         /*      skipspaces() skips any white space and returns the first
17                 non-space character.
18         */
19         register int nlseen = 0;
20
21         for (;;) {
22                 while (class(ch) == STSKIP) {
23                         nlseen = 0;
24                         LoadChar(ch);
25                 }
26                 if (skipnl && class(ch) == STNL) {
27                         LoadChar(ch);
28                         ++LineNumber;
29                         nlseen++;
30                         continue;
31                 }
32                 /* How about "\\\n"?????????    */
33                 if (ch == '/') {
34                         LoadChar(ch);
35                         if (ch == '*') {
36                                 skipcomment();
37                                 LoadChar(ch);
38                         }
39                         else    {
40                                 PushBack();
41                                 return '/';
42                         }
43                 }
44                 else if (nlseen && ch == '#') {
45                         domacro();
46                         LoadChar(ch);
47                         /* ch is the first character of a line. This means
48                          * that nlseen will still be true.
49                          */
50                 } else
51                         return ch;
52         }
53 }
54
55 skipline()
56 {
57         /*      skipline() skips all characters until a newline character
58                 is seen, not escaped by a '\\'.
59                 Any comment is skipped.
60         */
61         register int c;
62
63         LoadChar(c);
64         while (class(c) != STNL && c != EOI) {
65                 if (class(c) == STSTR || class(c) == STCHAR) {
66                         register int stopc = c;
67                         int escaped;
68                         do {
69                                 escaped = 0;
70                                 LoadChar(c);
71                                 if (class(c) == STNL || c == EOI) {
72                                         break;
73                                 }
74                                 if (c == '\\') {
75                                         LoadChar(c);
76                                         if (c == '\n') {
77                                                 ++LineNumber;
78                                         }
79                                         else escaped = 1;
80                                 }
81                         } while (escaped || c != stopc);
82                         if (class(c) != STNL && c != EOI) {
83                                 LoadChar(c);
84                         }
85                         continue;
86                 }
87                 if (c == '\\') {
88                         LoadChar(c);
89                         if (class(c) == STNL)
90                                 ++LineNumber;
91                 }
92                 if (c == '/') {
93                         LoadChar(c);
94                         if (c == '*')
95                                 skipcomment();
96                         else
97                                 continue;
98                 }
99                 LoadChar(c);
100         }
101         ++LineNumber;
102         if (c == EOI) {         /* garbage input...             */
103                 error("unexpected EOF while skipping text");
104                 PushBack();
105         }
106 }