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