diff options
| author | Mattias EngdegÄrd | 2019-06-28 10:35:41 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2019-06-28 13:35:17 +0200 |
| commit | 24a329608ddcdc8921d709bad65ddeed451d9a8e (patch) | |
| tree | afb554e3aeaa4a2cbd199753ede79f1c5db60c43 /src | |
| parent | 821725580720f9974b87189fe950435818a17e39 (diff) | |
| download | emacs-24a329608ddcdc8921d709bad65ddeed451d9a8e.tar.gz emacs-24a329608ddcdc8921d709bad65ddeed451d9a8e.zip | |
More readable regexp debug output
* src/regex-emacs.c (debug_putchar): New.
(print_fastmap, print_partial_compiled_pattern, print_double_string)
(regex_compile): Use debug_putchar.
(re_match_2_internal): Add newline.
Diffstat (limited to 'src')
| -rw-r--r-- | src/regex-emacs.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/regex-emacs.c b/src/regex-emacs.c index 47ee6647482..c353a78fb4f 100644 --- a/src/regex-emacs.c +++ b/src/regex-emacs.c | |||
| @@ -449,6 +449,14 @@ static int regex_emacs_debug = -100000; | |||
| 449 | # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ | 449 | # define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ |
| 450 | if (regex_emacs_debug > 0) print_double_string (w, s1, sz1, s2, sz2) | 450 | if (regex_emacs_debug > 0) print_double_string (w, s1, sz1, s2, sz2) |
| 451 | 451 | ||
| 452 | static void | ||
| 453 | debug_putchar (int c) | ||
| 454 | { | ||
| 455 | if (c >= 32 && c <= 126) | ||
| 456 | fputc (c, stderr); | ||
| 457 | else | ||
| 458 | fprintf (stderr, "{%02x}", c); | ||
| 459 | } | ||
| 452 | 460 | ||
| 453 | /* Print the fastmap in human-readable form. */ | 461 | /* Print the fastmap in human-readable form. */ |
| 454 | 462 | ||
| @@ -463,7 +471,7 @@ print_fastmap (char *fastmap) | |||
| 463 | if (fastmap[i++]) | 471 | if (fastmap[i++]) |
| 464 | { | 472 | { |
| 465 | was_a_range = false; | 473 | was_a_range = false; |
| 466 | fputc (i - 1, stderr); | 474 | debug_putchar (i - 1); |
| 467 | while (i < (1 << BYTEWIDTH) && fastmap[i]) | 475 | while (i < (1 << BYTEWIDTH) && fastmap[i]) |
| 468 | { | 476 | { |
| 469 | was_a_range = true; | 477 | was_a_range = true; |
| @@ -472,7 +480,7 @@ print_fastmap (char *fastmap) | |||
| 472 | if (was_a_range) | 480 | if (was_a_range) |
| 473 | { | 481 | { |
| 474 | fprintf (stderr, "-"); | 482 | fprintf (stderr, "-"); |
| 475 | fputc (i - 1, stderr); | 483 | debug_putchar (i - 1); |
| 476 | } | 484 | } |
| 477 | } | 485 | } |
| 478 | } | 486 | } |
| @@ -516,7 +524,8 @@ print_partial_compiled_pattern (re_char *start, re_char *end) | |||
| 516 | fprintf (stderr, "/exactn/%d", mcnt); | 524 | fprintf (stderr, "/exactn/%d", mcnt); |
| 517 | do | 525 | do |
| 518 | { | 526 | { |
| 519 | fprintf (stderr, "/%c", *p++); | 527 | fprintf (stderr, "/"); |
| 528 | debug_putchar (*p++); | ||
| 520 | } | 529 | } |
| 521 | while (--mcnt); | 530 | while (--mcnt); |
| 522 | break; | 531 | break; |
| @@ -564,18 +573,18 @@ print_partial_compiled_pattern (re_char *start, re_char *end) | |||
| 564 | /* Have we broken a range? */ | 573 | /* Have we broken a range? */ |
| 565 | else if (last + 1 != c && in_range) | 574 | else if (last + 1 != c && in_range) |
| 566 | { | 575 | { |
| 567 | fprintf (stderr, "%c", last); | 576 | debug_putchar (last); |
| 568 | in_range = false; | 577 | in_range = false; |
| 569 | } | 578 | } |
| 570 | 579 | ||
| 571 | if (! in_range) | 580 | if (! in_range) |
| 572 | fprintf (stderr, "%c", c); | 581 | debug_putchar (c); |
| 573 | 582 | ||
| 574 | last = c; | 583 | last = c; |
| 575 | } | 584 | } |
| 576 | 585 | ||
| 577 | if (in_range) | 586 | if (in_range) |
| 578 | fprintf (stderr, "%c", last); | 587 | debug_putchar (last); |
| 579 | 588 | ||
| 580 | fprintf (stderr, "]"); | 589 | fprintf (stderr, "]"); |
| 581 | 590 | ||
| @@ -759,13 +768,16 @@ print_double_string (re_char *where, re_char *string1, ptrdiff_t size1, | |||
| 759 | fprintf (stderr, "(null)"); | 768 | fprintf (stderr, "(null)"); |
| 760 | else | 769 | else |
| 761 | { | 770 | { |
| 771 | int i; | ||
| 762 | if (FIRST_STRING_P (where)) | 772 | if (FIRST_STRING_P (where)) |
| 763 | { | 773 | { |
| 764 | fwrite_unlocked (where, 1, string1 + size1 - where, stderr); | 774 | for (i = 0; i < string1 + size1 - where; i++) |
| 775 | debug_putchar (where[i]); | ||
| 765 | where = string2; | 776 | where = string2; |
| 766 | } | 777 | } |
| 767 | 778 | ||
| 768 | fwrite_unlocked (where, 1, string2 + size2 - where, stderr); | 779 | for (i = 0; i < string2 + size2 - where; i++) |
| 780 | debug_putchar (where[i]); | ||
| 769 | } | 781 | } |
| 770 | } | 782 | } |
| 771 | 783 | ||
| @@ -1735,7 +1747,7 @@ regex_compile (re_char *pattern, ptrdiff_t size, | |||
| 1735 | if (regex_emacs_debug > 0) | 1747 | if (regex_emacs_debug > 0) |
| 1736 | { | 1748 | { |
| 1737 | for (ptrdiff_t debug_count = 0; debug_count < size; debug_count++) | 1749 | for (ptrdiff_t debug_count = 0; debug_count < size; debug_count++) |
| 1738 | fputc (pattern[debug_count], stderr); | 1750 | debug_putchar (pattern[debug_count]); |
| 1739 | fputc ('\n', stderr); | 1751 | fputc ('\n', stderr); |
| 1740 | } | 1752 | } |
| 1741 | #endif | 1753 | #endif |
| @@ -3997,7 +4009,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, | |||
| 3997 | dend = end_match_1; | 4009 | dend = end_match_1; |
| 3998 | } | 4010 | } |
| 3999 | 4011 | ||
| 4000 | DEBUG_PRINT ("The compiled pattern is: "); | 4012 | DEBUG_PRINT ("The compiled pattern is:\n"); |
| 4001 | DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); | 4013 | DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); |
| 4002 | DEBUG_PRINT ("The string to match is: \""); | 4014 | DEBUG_PRINT ("The string to match is: \""); |
| 4003 | DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); | 4015 | DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); |