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