/[pcre]/code/trunk/pcretest.c
ViewVC logotype

Diff of /code/trunk/pcretest.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 37 by nigel, Sat Feb 24 21:39:09 2007 UTC revision 39 by nigel, Sat Feb 24 21:39:13 2007 UTC
# Line 704  while (!done) Line 704  while (!done)
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);
# Line 849  while (!done) Line 850  while (!done)
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          {          {
# Line 858  while (!done) Line 859  while (!done)
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)/
# Line 866  while (!done) Line 867  while (!done)
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          {          {
# Line 874  while (!done) Line 875  while (!done)
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;
# Line 888  while (!done) Line 891  while (!done)
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+ ");
# Line 946  while (!done) Line 948  while (!done)
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    

Legend:
Removed from v.37  
changed lines
  Added in v.39

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12