| 338 | #define PS_ESC 4 |
| 339 | |
| 340 | inline void process_stream_char(const char c, uint8_t &sis, char (&buff)[MAX_CMD_SIZE], int &ind) { |
| 341 | |
| 342 | if (sis == PS_EOL) return; // EOL comment or overflow |
| 343 | |
| 344 | #if ENABLED(PAREN_COMMENTS) |
| 345 | else if (sis == PS_PAREN) { // Inline comment |
| 346 | if (c == ')') sis = PS_NORMAL; |
| 347 | return; |
| 348 | } |
| 349 | #endif |
| 350 | |
| 351 | else if (sis >= PS_ESC) // End escaped char |
| 352 | sis -= PS_ESC; |
| 353 | |
| 354 | else if (c == '\\') { // Start escaped char |
| 355 | sis += PS_ESC; |
| 356 | if (sis == PS_ESC) return; // Keep if quoting |
| 357 | } |
| 358 | |
| 359 | #if ENABLED(GCODE_QUOTED_STRINGS) |
| 360 | |
| 361 | else if (sis == PS_QUOTED) { |
| 362 | if (c == '"') sis = PS_NORMAL; // End quoted string |
| 363 | } |
| 364 | else if (c == '"') // Start quoted string |
| 365 | sis = PS_QUOTED; |
| 366 | |
| 367 | #endif |
| 368 | |
| 369 | else if (c == ';') { // Start end-of-line comment |
| 370 | sis = PS_EOL; |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | #if ENABLED(PAREN_COMMENTS) |
| 375 | else if (c == '(') { // Start inline comment |
| 376 | sis = PS_PAREN; |
| 377 | return; |
| 378 | } |
| 379 | #endif |
| 380 | |
| 381 | // Backspace erases previous characters |
| 382 | if (c == 0x08) { |
| 383 | if (ind) buff[--ind] = '\0'; |
| 384 | } |
| 385 | else { |
| 386 | buff[ind++] = c; |
| 387 | if (ind >= MAX_CMD_SIZE - 1) |
| 388 | sis = PS_EOL; // Skip the rest on overflow |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Handle a line being completed. For an empty line |
no outgoing calls
no test coverage detected