Deal with DOS (\r \n) and classic Mac OS (\r) line endings. Keeps track of physical coordinates and absolute location for each character. */
| 237 | Keeps track of physical coordinates and absolute location for each character. |
| 238 | */ |
| 239 | int normalize_newline(void) |
| 240 | { |
| 241 | int cc = getchar(); |
| 242 | |
| 243 | if (cc == '\r') { |
| 244 | // Maybe \r \n (CR NL) combination? |
| 245 | int nc = getchar(); |
| 246 | if (nc == '\n') { |
| 247 | char_count++; // counts the carriage return |
| 248 | utf8_count++; |
| 249 | // No use incrementing column. |
| 250 | return nc; // return \n; effectively skipping the \r |
| 251 | } |
| 252 | // Mind nc not \n. ungetc(EOF) is Okay. |
| 253 | ungetc(nc, stdin); |
| 254 | // cc == '\r'; consider a newline as well, so turn into \n: |
| 255 | cc = '\n'; |
| 256 | } |
| 257 | return cc; |
| 258 | } |
| 259 | |
| 260 | /* Phase 1. |
| 261 | Forms logical lines by resolving escaped newlines (line continuations). |