| 2425 | } |
| 2426 | |
| 2427 | static void |
| 2428 | print_error (const char *raw, size_t error_location) |
| 2429 | { |
| 2430 | fprintf(stderr, "\n*** %s ***\n\n", |
| 2431 | http_errno_description(HTTP_PARSER_ERRNO(parser))); |
| 2432 | |
| 2433 | int this_line = 0, char_len = 0; |
| 2434 | size_t i, j, len = strlen(raw), error_location_line = 0; |
| 2435 | for (i = 0; i < len; i++) { |
| 2436 | if (i == error_location) this_line = 1; |
| 2437 | switch (raw[i]) { |
| 2438 | case '\r': |
| 2439 | char_len = 2; |
| 2440 | fprintf(stderr, "\\r"); |
| 2441 | break; |
| 2442 | |
| 2443 | case '\n': |
| 2444 | fprintf(stderr, "\\n\n"); |
| 2445 | |
| 2446 | if (this_line) goto print; |
| 2447 | |
| 2448 | error_location_line = 0; |
| 2449 | continue; |
| 2450 | |
| 2451 | default: |
| 2452 | char_len = 1; |
| 2453 | fputc(raw[i], stderr); |
| 2454 | break; |
| 2455 | } |
| 2456 | if (!this_line) error_location_line += char_len; |
| 2457 | } |
| 2458 | |
| 2459 | fprintf(stderr, "[eof]\n"); |
| 2460 | |
| 2461 | print: |
| 2462 | for (j = 0; j < error_location_line; j++) { |
| 2463 | fputc(' ', stderr); |
| 2464 | } |
| 2465 | fprintf(stderr, "^\n\nerror location: %u\n", (unsigned int)error_location); |
| 2466 | } |
| 2467 | |
| 2468 | void |
| 2469 | test_preserve_data (void) |
no test coverage detected