MCPcopy Index your code
hub / github.com/IBM/Project_CodeNet / get

Function get

tools/tokenizer/libtoken.c:322–380  ·  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

320 Keeps track of physical coordinates and absolute location for each character.
321*/
322int get(void)
323{
324 int cc;
325
326 restart:
327 // Get the next character:
328 if (buffered) { // chars available in lookahead buffer
329 cc = buffer[--buffered]; // never EOF
330 char_count++;
331 // cc maybe '\r' (line continuation); act like '\n':
332 if (cc == '\n' || cc == '\r') {
333 linenr++;
334 saved_col = column;
335 column = 0;
336 return cc;
337 }
338 column++;
339 return cc;
340 }
341
342 // Read a fresh char:
343 cc = normalize_newline(); // cc != '\r'
344 if (cc == EOF) return EOF;
345 char_count++;
346 if (utf8_start(cc)) utf8_count++;
347
348 if (cc == '\n') { // a normalized end-of-line (\r|\r?\n)
349 linenr++;
350 saved_col = column;
351 column = 0;
352 return cc; // \n here signals a logical end-of-line
353 }
354
355 // Deal with explicit \ line continuations!
356 if (cc == '\\') {
357 // Must look ahead (never maintained across get calls!):
358 int nc = normalize_newline(); // cc != '\r'
359 if (nc == '\n') {
360 char_count++; // counts the newline
361 utf8_count++;
362 linenr++; // on next physical line
363 saved_col = column+1; // +1 for backslash
364 column = 0;
365
366 if (logical_lines)
367 // Still need to get a character.
368 // Could again start a line continuation!
369 goto restart;
370
371 // Signal that this was an escaped newline (= line continuation):
372 return '\r';
373 }
374 // Mind nc not \n. ungetc(EOF) is Okay.
375 ungetc(nc, stdin);
376 // cc == '\\' a regular backslash
377 }
378 column++;
379 return cc;

Callers 5

tokenizeFunction · 0.70
C_tokenize_intFunction · 0.70
process_wsFunction · 0.70
utf8_codepointFunction · 0.70
tokenizeFunction · 0.70

Calls 1

normalize_newlineFunction · 0.70

Tested by

no test coverage detected