| 94 |
|
|
| 95 |
#ifdef JFRIEDL_DEBUG |
#ifdef JFRIEDL_DEBUG |
| 96 |
static int S_arg = -1; |
static int S_arg = -1; |
| 97 |
|
static unsigned int jfriedl_XR = 0; /* repeat regex attempt this many times */ |
| 98 |
|
static unsigned int jfriedl_XT = 0; /* replicate text this many times */ |
| 99 |
|
static const char *jfriedl_prefix = ""; |
| 100 |
|
static const char *jfriedl_postfix = ""; |
| 101 |
#endif |
#endif |
| 102 |
|
|
| 103 |
static char *colour_string = (char *)"1;31"; |
static char *colour_string = (char *)"1;31"; |
| 569 |
while (t < endptr && *t++ != '\n') linelength++; |
while (t < endptr && *t++ != '\n') linelength++; |
| 570 |
length = multiline? endptr - ptr : linelength; |
length = multiline? endptr - ptr : linelength; |
| 571 |
|
|
| 572 |
|
|
| 573 |
|
/* Extra processing for Jeffrey Friedl's debugging. */ |
| 574 |
|
|
| 575 |
|
#ifdef JFRIEDL_DEBUG |
| 576 |
|
if (jfriedl_XT || jfriedl_XR) |
| 577 |
|
{ |
| 578 |
|
#include <sys/time.h> |
| 579 |
|
#include <time.h> |
| 580 |
|
struct timeval start_time, end_time; |
| 581 |
|
struct timezone dummy; |
| 582 |
|
|
| 583 |
|
if (jfriedl_XT) |
| 584 |
|
{ |
| 585 |
|
unsigned long newlen = length * jfriedl_XT + strlen(jfriedl_prefix) + strlen(jfriedl_postfix); |
| 586 |
|
const char *orig = ptr; |
| 587 |
|
ptr = malloc(newlen + 1); |
| 588 |
|
if (!ptr) { |
| 589 |
|
printf("out of memory"); |
| 590 |
|
exit(2); |
| 591 |
|
} |
| 592 |
|
endptr = ptr; |
| 593 |
|
strcpy(endptr, jfriedl_prefix); endptr += strlen(jfriedl_prefix); |
| 594 |
|
for (i = 0; i < jfriedl_XT; i++) { |
| 595 |
|
strncpy(endptr, orig, length); |
| 596 |
|
endptr += length; |
| 597 |
|
} |
| 598 |
|
strcpy(endptr, jfriedl_postfix); endptr += strlen(jfriedl_postfix); |
| 599 |
|
length = newlen; |
| 600 |
|
} |
| 601 |
|
|
| 602 |
|
if (gettimeofday(&start_time, &dummy) != 0) |
| 603 |
|
perror("bad gettimeofday"); |
| 604 |
|
|
| 605 |
|
|
| 606 |
|
for (i = 0; i < jfriedl_XR; i++) |
| 607 |
|
match = (pcre_exec(pattern_list[0], hints_list[0], ptr, length, 0, 0, offsets, 99) >= 0); |
| 608 |
|
|
| 609 |
|
if (gettimeofday(&end_time, &dummy) != 0) |
| 610 |
|
perror("bad gettimeofday"); |
| 611 |
|
|
| 612 |
|
double delta = ((end_time.tv_sec + (end_time.tv_usec / 1000000.0)) |
| 613 |
|
- |
| 614 |
|
(start_time.tv_sec + (start_time.tv_usec / 1000000.0))); |
| 615 |
|
|
| 616 |
|
printf("%s TIMER[%.4f]\n", match ? "MATCH" : "FAIL", delta); |
| 617 |
|
return 0; |
| 618 |
|
} |
| 619 |
|
#endif |
| 620 |
|
|
| 621 |
|
|
| 622 |
/* Run through all the patterns until one matches. Note that we don't include |
/* Run through all the patterns until one matches. Note that we don't include |
| 623 |
the final newline in the subject string. */ |
the final newline in the subject string. */ |
| 624 |
|
|
| 1348 |
} |
} |
| 1349 |
} |
} |
| 1350 |
|
|
| 1351 |
|
|
| 1352 |
|
/* Jeffrey Friedl's debugging harness uses these additional options which |
| 1353 |
|
are not in the right form for putting in the option table because they use |
| 1354 |
|
only one hyphen, yet are more than one character long. By putting them |
| 1355 |
|
separately here, they will not get displayed as part of the help() output, |
| 1356 |
|
but I don't think Jeffrey will care about that. */ |
| 1357 |
|
|
| 1358 |
|
#ifdef JFRIEDL_DEBUG |
| 1359 |
|
else if (strcmp(argv[i], "-pre") == 0) { |
| 1360 |
|
jfriedl_prefix = argv[++i]; |
| 1361 |
|
continue; |
| 1362 |
|
} else if (strcmp(argv[i], "-post") == 0) { |
| 1363 |
|
jfriedl_postfix = argv[++i]; |
| 1364 |
|
continue; |
| 1365 |
|
} else if (strcmp(argv[i], "-XT") == 0) { |
| 1366 |
|
sscanf(argv[++i], "%d", &jfriedl_XT); |
| 1367 |
|
continue; |
| 1368 |
|
} else if (strcmp(argv[i], "-XR") == 0) { |
| 1369 |
|
sscanf(argv[++i], "%d", &jfriedl_XR); |
| 1370 |
|
continue; |
| 1371 |
|
} |
| 1372 |
|
#endif |
| 1373 |
|
|
| 1374 |
|
|
| 1375 |
/* One-char options; many that have no data may be in a single argument; we |
/* One-char options; many that have no data may be in a single argument; we |
| 1376 |
continue till we hit the last one or one that needs data. */ |
continue till we hit the last one or one that needs data. */ |
| 1377 |
|
|
| 1411 |
/* If the option type is OP_OP_STRING or OP_OP_NUMBER, it's an option that |
/* If the option type is OP_OP_STRING or OP_OP_NUMBER, it's an option that |
| 1412 |
either has a value or defaults to something. It cannot have data in a |
either has a value or defaults to something. It cannot have data in a |
| 1413 |
separate item. At the moment, the only such options are "colo(u)r" and |
separate item. At the moment, the only such options are "colo(u)r" and |
| 1414 |
Jeffrey Friedl's special debugging option. */ |
Jeffrey Friedl's special -S debugging option. */ |
| 1415 |
|
|
| 1416 |
if (*option_data == 0 && |
if (*option_data == 0 && |
| 1417 |
(op->type == OP_OP_STRING || op->type == OP_OP_NUMBER)) |
(op->type == OP_OP_STRING || op->type == OP_OP_NUMBER)) |
| 1568 |
} |
} |
| 1569 |
} |
} |
| 1570 |
|
|
| 1571 |
/* Check the value for Jeff Friedl's debugging option. */ |
/* Check the values for Jeffrey Friedl's debugging options. */ |
| 1572 |
|
|
| 1573 |
#ifdef JFRIEDL_DEBUG |
#ifdef JFRIEDL_DEBUG |
| 1574 |
if (S_arg > 9) |
if (S_arg > 9) |
| 1576 |
fprintf(stderr, "pcregrep: bad value for -S option\n"); |
fprintf(stderr, "pcregrep: bad value for -S option\n"); |
| 1577 |
return 2; |
return 2; |
| 1578 |
} |
} |
| 1579 |
|
if (jfriedl_XT != 0 || jfriedl_XR != 0) |
| 1580 |
|
{ |
| 1581 |
|
if (jfriedl_XT == 0) jfriedl_XT = 1; |
| 1582 |
|
if (jfriedl_XR == 0) jfriedl_XR = 1; |
| 1583 |
|
} |
| 1584 |
#endif |
#endif |
| 1585 |
|
|
| 1586 |
/* Get memory to store the pattern and hints lists. */ |
/* Get memory to store the pattern and hints lists. */ |