/[pcre]/code/branches/pcre16/pcretest.c
ViewVC logotype

Diff of /code/branches/pcre16/pcretest.c

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

revision 545 by ph10, Wed Jun 16 10:51:15 2010 UTC revision 604 by ph10, Thu Jun 2 19:04:54 2011 UTC
# Line 79  input mode under Windows. */ Line 79  input mode under Windows. */
79  #define fileno _fileno  #define fileno _fileno
80  #endif  #endif
81    
82    /* A user sent this fix for Borland Builder 5 under Windows. */
83    
84    #ifdef __BORLANDC__
85    #define _setmode(handle, mode) setmode(handle, mode)
86    #endif
87    
88    /* Not Windows */
89    
90  #else  #else
91  #include <sys/time.h>          /* These two includes are needed */  #include <sys/time.h>          /* These two includes are needed */
92  #include <sys/resource.h>      /* for setrlimit(). */  #include <sys/resource.h>      /* for setrlimit(). */
# Line 189  static uschar *buffer = NULL; Line 197  static uschar *buffer = NULL;
197  static uschar *dbuffer = NULL;  static uschar *dbuffer = NULL;
198  static uschar *pbuffer = NULL;  static uschar *pbuffer = NULL;
199    
200    /* Textual explanations for runtime error codes */
201    
202    static const char *errtexts[] = {
203      NULL,  /* 0 is no error */
204      NULL,  /* NOMATCH is handled specially */
205      "NULL argument passed",
206      "bad option value",
207      "magic number missing",
208      "unknown opcode - pattern overwritten?",
209      "no more memory",
210      NULL,  /* never returned by pcre_exec() or pcre_dfa_exec() */
211      "match limit exceeded",
212      "callout error code",
213      NULL,  /* BADUTF8 is handled specially */
214      "bad UTF-8 offset",
215      NULL,  /* PARTIAL is handled specially */
216      "not used - internal error",
217      "internal error - pattern overwritten?",
218      "bad count value",
219      "item unsupported for DFA matching",
220      "backreference condition or recursion test not supported for DFA matching",
221      "match limit not supported for DFA matching",
222      "workspace size exceeded in DFA matching",
223      "too much recursion for DFA matching",
224      "recursion limit exceeded",
225      "not used - internal error",
226      "invalid combination of newline options",
227      "bad offset value",
228      NULL  /* SHORTUTF8 is handled specially */
229    };
230    
231    
232  /*************************************************  /*************************************************
233  *         Alternate character tables             *  *         Alternate character tables             *
# Line 516  static const unsigned char tables1[] = { Line 555  static const unsigned char tables1[] = {
555    
556    
557    
558    
559    #ifndef HAVE_STRERROR
560    /*************************************************
561    *     Provide strerror() for non-ANSI libraries  *
562    *************************************************/
563    
564    /* Some old-fashioned systems still around (e.g. SunOS4) don't have strerror()
565    in their libraries, but can provide the same facility by this simple
566    alternative function. */
567    
568    extern int   sys_nerr;
569    extern char *sys_errlist[];
570    
571    char *
572    strerror(int n)
573    {
574    if (n < 0 || n >= sys_nerr) return "unknown error number";
575    return sys_errlist[n];
576    }
577    #endif /* HAVE_STRERROR */
578    
579    
580    
581    
582  /*************************************************  /*************************************************
583  *        Read or extend an input line            *  *        Read or extend an input line            *
584  *************************************************/  *************************************************/
# Line 1564  while (!done) Line 1627  while (!done)
1627        case 'U': options |= PCRE_UNGREEDY; break;        case 'U': options |= PCRE_UNGREEDY; break;
1628        case 'W': options |= PCRE_UCP; break;        case 'W': options |= PCRE_UCP; break;
1629        case 'X': options |= PCRE_EXTRA; break;        case 'X': options |= PCRE_EXTRA; break;
1630          case 'Y': options |= PCRE_NO_START_OPTIMISE; break;
1631        case 'Z': debug_lengths = 0; break;        case 'Z': debug_lengths = 0; break;
1632        case '8': options |= PCRE_UTF8; use_utf8 = 1; break;        case '8': options |= PCRE_UTF8; use_utf8 = 1; break;
1633        case '?': options |= PCRE_NO_UTF8_CHECK; break;        case '?': options |= PCRE_NO_UTF8_CHECK; break;
# Line 1900  while (!done) Line 1964  while (!done)
1964        if (do_flip) all_options = byteflip(all_options, sizeof(all_options));        if (do_flip) all_options = byteflip(all_options, sizeof(all_options));
1965    
1966        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
1967          else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",          else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1968            ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",            ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",
1969            ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",            ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",
1970            ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",            ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",
# Line 1916  while (!done) Line 1980  while (!done)
1980            ((get_options & PCRE_UTF8) != 0)? " utf8" : "",            ((get_options & PCRE_UTF8) != 0)? " utf8" : "",
1981            ((get_options & PCRE_UCP) != 0)? " ucp" : "",            ((get_options & PCRE_UCP) != 0)? " ucp" : "",
1982            ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "",            ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "",
1983              ((get_options & PCRE_NO_START_OPTIMIZE) != 0)? " no_start_optimize" : "",
1984            ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");            ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");
1985    
1986        if (jchanged) fprintf(outfile, "Duplicate name status changes\n");        if (jchanged) fprintf(outfile, "Duplicate name status changes\n");
# Line 2108  while (!done) Line 2173  while (!done)
2173      int getlist = 0;      int getlist = 0;
2174      int gmatched = 0;      int gmatched = 0;
2175      int start_offset = 0;      int start_offset = 0;
2176        int start_offset_sign = 1;
2177      int g_notempty = 0;      int g_notempty = 0;
2178      int use_dfa = 0;      int use_dfa = 0;
2179    
# Line 2240  while (!done) Line 2306  while (!done)
2306          continue;          continue;
2307    
2308          case '>':          case '>':
2309            if (*p == '-')
2310              {
2311              start_offset_sign = -1;
2312              p++;
2313              }
2314          while(isdigit(*p)) start_offset = start_offset * 10 + *p++ - '0';          while(isdigit(*p)) start_offset = start_offset * 10 + *p++ - '0';
2315            start_offset *= start_offset_sign;
2316          continue;          continue;
2317    
2318          case 'A':  /* Option setting */          case 'A':  /* Option setting */
# Line 2313  while (!done) Line 2385  while (!done)
2385  #endif  #endif
2386            use_dfa = 1;            use_dfa = 1;
2387          continue;          continue;
2388    #endif
2389    
2390    #if !defined NODFA
2391          case 'F':          case 'F':
2392          options |= PCRE_DFA_SHORTEST;          options |= PCRE_DFA_SHORTEST;
2393          continue;          continue;
# Line 2765  while (!done) Line 2839  while (!done)
2839        to advance the start offset, and continue. We won't be at the end of the        to advance the start offset, and continue. We won't be at the end of the
2840        string - that was checked before setting g_notempty.        string - that was checked before setting g_notempty.
2841    
2842        Complication arises in the case when the newline option is "any" or        Complication arises in the case when the newline convention is "any",
2843        "anycrlf". If the previous match was at the end of a line terminated by        "crlf", or "anycrlf". If the previous match was at the end of a line
2844        CRLF, an advance of one character just passes the \r, whereas we should        terminated by CRLF, an advance of one character just passes the \r,
2845        prefer the longer newline sequence, as does the code in pcre_exec().        whereas we should prefer the longer newline sequence, as does the code in
2846        Fudge the offset value to achieve this.        pcre_exec(). Fudge the offset value to achieve this. We check for a
2847          newline setting in the pattern; if none was set, use pcre_config() to
2848          find the default.
2849    
2850        Otherwise, in the case of UTF-8 matching, the advance must be one        Otherwise, in the case of UTF-8 matching, the advance must be one
2851        character, not one byte. */        character, not one byte. */
# Line 2794  while (!done) Line 2870  while (!done)
2870                      (d == -1)? PCRE_NEWLINE_ANY : 0;                      (d == -1)? PCRE_NEWLINE_ANY : 0;
2871              }              }
2872            if (((obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANY ||            if (((obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANY ||
2873                   (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_CRLF ||
2874                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)                 (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF)
2875                &&                &&
2876                start_offset < len - 1 &&                start_offset < len - 1 &&
# Line 2804  while (!done) Line 2881  while (!done)
2881              {              {
2882              while (start_offset + onechar < len)              while (start_offset + onechar < len)
2883                {                {
2884                int tb = bptr[start_offset+onechar];                if ((bptr[start_offset+onechar] & 0xc0) != 0x80) break;
2885                if (tb <= 127) break;                onechar++;
               tb &= 0xc0;  
               if (tb != 0 && tb != 0xc0) onechar++;  
2886                }                }
2887              }              }
2888            use_offsets[1] = start_offset + onechar;            use_offsets[1] = start_offset + onechar;
2889            }            }
2890          else          else
2891            {            {
2892            if (count == PCRE_ERROR_NOMATCH)            switch(count)
2893              {              {
2894                case PCRE_ERROR_NOMATCH:
2895              if (gmatched == 0)              if (gmatched == 0)
2896                {                {
2897                if (markptr == NULL) fprintf(outfile, "No match\n");                if (markptr == NULL) fprintf(outfile, "No match\n");
2898                  else fprintf(outfile, "No match, mark = %s\n", markptr);                  else fprintf(outfile, "No match, mark = %s\n", markptr);
2899                }                }
2900                break;
2901    
2902                case PCRE_ERROR_BADUTF8:
2903                case PCRE_ERROR_SHORTUTF8:
2904                fprintf(outfile, "Error %d (%s UTF-8 string)", count,
2905                  (count == PCRE_ERROR_BADUTF8)? "bad" : "short");
2906                if (use_size_offsets >= 2)
2907                  fprintf(outfile, " offset=%d reason=%d", use_offsets[0],
2908                    use_offsets[1]);
2909                fprintf(outfile, "\n");
2910                break;
2911    
2912                default:
2913                if (count < 0 && (-count) < sizeof(errtexts)/sizeof(const char *))
2914                  fprintf(outfile, "Error %d (%s)\n", count, errtexts[-count]);
2915                else
2916                  fprintf(outfile, "Error %d (Unexpected value)\n", count);
2917                break;
2918              }              }
2919            else fprintf(outfile, "Error %d\n", count);  
2920            break;  /* Out of the /g loop */            break;  /* Out of the /g loop */
2921            }            }
2922          }          }

Legend:
Removed from v.545  
changed lines
  Added in v.604

  ViewVC Help
Powered by ViewVC 1.1.5