MCPcopy Create free account
hub / github.com/IBM/Project_CodeNet / get

Function get

tools/tokenizer/token_common.c:134–184  ·  view source on GitHub ↗

Detects escaped newlines (line continuations) and signals them with the special '\r' character (that otherwise is not used). Keeps track of physical coordinates and absolute location for each character. */

Source from the content-addressed store, hash-verified

132 Keeps track of physical coordinates and absolute location for each character.
133*/
134int get(void)
135{
136 int cc;
137
138 // Get the next character:
139 if (buffered) { // chars available in lookahead buffer
140 cc = buffer[--buffered]; // never EOF
141 // cc maybe '\r'; act like '\n':
142 if (cc == '\n' || cc == '\r') {
143 linenr++;
144 saved_col = column;
145 column = 0;
146 return cc;
147 }
148 column++;
149 return cc;
150 }
151
152 // Read a fresh char:
153 cc = normalize_newline(); // cc != '\r'
154 if (cc == EOF) return EOF;
155 char_count++;
156 if (utf8_start(cc)) utf8_count++;
157
158 if (cc == '\n') { // a normalized (physical) end-of-line
159 linenr++;
160 saved_col = column;
161 column = 0;
162 return cc;
163 }
164
165 // Deal with explicit \ line continuations!
166 if (cc == '\\') {
167 // Must look ahead (never maintained across get calls!):
168 int nc = normalize_newline(); // cc != '\r'
169 if (nc == '\n') {
170 char_count++; // counts the newline
171 utf8_count++;
172 linenr++; // on next physical line
173 saved_col = column+1; // +1 for backslash
174 column = 0;
175 // Signal that this was an escaped newline:
176 return '\r';
177 }
178 // Mind nc not \n.
179 if (nc != EOF) ungetc(nc, stdin);
180 // cc == '\\' a regular backslash
181 }
182 column++;
183 return cc;
184}
185
186void unget(int cc)
187{

Callers

nothing calls this directly

Calls 1

normalize_newlineFunction · 0.70

Tested by

no test coverage detected