704 |
int copystrings = 0; |
int copystrings = 0; |
705 |
int getstrings = 0; |
int getstrings = 0; |
706 |
int getlist = 0; |
int getlist = 0; |
707 |
|
int gmatched = 0; |
708 |
int start_offset = 0; |
int start_offset = 0; |
709 |
int offsets[45]; |
int offsets[45]; |
710 |
int size_offsets = sizeof(offsets)/sizeof(int); |
int size_offsets = sizeof(offsets)/sizeof(int); |
850 |
else |
else |
851 |
#endif /* !defined NOPOSIX */ |
#endif /* !defined NOPOSIX */ |
852 |
|
|
853 |
for (;;) |
for (;; gmatched++) /* Loop for /g or /G */ |
854 |
{ |
{ |
855 |
if (timeit) |
if (timeit) |
856 |
{ |
{ |
859 |
clock_t start_time = clock(); |
clock_t start_time = clock(); |
860 |
for (i = 0; i < LOOPREPEAT; i++) |
for (i = 0; i < LOOPREPEAT; i++) |
861 |
count = pcre_exec(re, extra, (char *)bptr, len, |
count = pcre_exec(re, extra, (char *)bptr, len, |
862 |
(do_g? start_offset : 0), options, offsets, size_offsets); |
start_offset, options, offsets, size_offsets); |
863 |
time_taken = clock() - start_time; |
time_taken = clock() - start_time; |
864 |
fprintf(outfile, "Execute time %.3f milliseconds\n", |
fprintf(outfile, "Execute time %.3f milliseconds\n", |
865 |
((double)time_taken * 1000.0)/ |
((double)time_taken * 1000.0)/ |
867 |
} |
} |
868 |
|
|
869 |
count = pcre_exec(re, extra, (char *)bptr, len, |
count = pcre_exec(re, extra, (char *)bptr, len, |
870 |
(do_g? start_offset : 0), options, offsets, size_offsets); |
start_offset, options, offsets, size_offsets); |
871 |
|
|
872 |
if (count == 0) |
if (count == 0) |
873 |
{ |
{ |
875 |
count = size_offsets/3; |
count = size_offsets/3; |
876 |
} |
} |
877 |
|
|
878 |
|
/* Matched */ |
879 |
|
|
880 |
if (count >= 0) |
if (count >= 0) |
881 |
{ |
{ |
882 |
int i; |
int i; |
891 |
fprintf(outfile, "\n"); |
fprintf(outfile, "\n"); |
892 |
if (i == 0) |
if (i == 0) |
893 |
{ |
{ |
|
start_offset = offsets[1]; |
|
894 |
if (do_showrest) |
if (do_showrest) |
895 |
{ |
{ |
896 |
fprintf(outfile, " 0+ "); |
fprintf(outfile, " 0+ "); |
948 |
free((void *)stringlist); |
free((void *)stringlist); |
949 |
} |
} |
950 |
} |
} |
|
|
|
951 |
} |
} |
952 |
|
|
953 |
|
/* Failed to match */ |
954 |
|
|
955 |
else |
else |
956 |
{ |
{ |
957 |
if (start_offset == 0) |
if (gmatched == 0) |
958 |
{ |
{ |
959 |
if (count == -1) fprintf(outfile, "No match\n"); |
if (count == -1) fprintf(outfile, "No match\n"); |
960 |
else fprintf(outfile, "Error %d\n", count); |
else fprintf(outfile, "Error %d\n", count); |
961 |
} |
} |
962 |
start_offset = -1; |
break; /* Out of the /g loop */ |
963 |
} |
} |
964 |
|
|
965 |
if ((!do_g && !do_G) || start_offset <= 0) break; |
/* If not /g or /G we are done */ |
966 |
if (do_G) |
|
967 |
|
if (!do_g && !do_G) break; |
968 |
|
|
969 |
|
/* If we have matched an empty string, set PCRE_NOTEMPTY for the next |
970 |
|
match. This mimics what Perl's /g option does. */ |
971 |
|
|
972 |
|
if (offsets[1] == offsets[0]) |
973 |
|
options |= PCRE_NOTEMPTY; |
974 |
|
else |
975 |
|
options &= ~PCRE_NOTEMPTY; |
976 |
|
|
977 |
|
/* For /g, update the start offset, leaving the rest alone */ |
978 |
|
|
979 |
|
if (do_g) start_offset = offsets[1]; |
980 |
|
|
981 |
|
/* For /G, update the pointer and length */ |
982 |
|
|
983 |
|
else |
984 |
{ |
{ |
985 |
bptr += start_offset; |
bptr += offsets[1]; |
986 |
len -= start_offset; |
len -= offsets[1]; |
987 |
} |
} |
988 |
} |
} /* End of loop for /g and /G */ |
989 |
} |
} /* End of loop for data lines */ |
990 |
|
|
991 |
CONTINUE: |
CONTINUE: |
992 |
|
|