/[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 812 by zherczeg, Mon Dec 19 14:05:44 2011 UTC revision 813 by ph10, Tue Dec 20 14:03:16 2011 UTC
# Line 4  Line 4 
4    
5  /* This program was hacked up as a tester for PCRE. I really should have  /* This program was hacked up as a tester for PCRE. I really should have
6  written it more tidily in the first place. Will I ever learn? It has grown and  written it more tidily in the first place. Will I ever learn? It has grown and
7  been extended and consequently is now rather, er, *very* untidy in places. The  been extended and consequently is now rather, er, *very* untidy in places. The
8  addition of 16-bit support has made it even worse. :-(  addition of 16-bit support has made it even worse. :-(
9    
10  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
# Line 181  SUPPORT_PCRE16 must be set. First define Line 181  SUPPORT_PCRE16 must be set. First define
181  use these in the definitions of generic macros. */  use these in the definitions of generic macros. */
182    
183  #ifdef SUPPORT_PCRE8  #ifdef SUPPORT_PCRE8
184    
185  #define PCHARS8(lv, p, len, f) \  #define PCHARS8(lv, p, len, f) \
186    lv = pchars((pcre_uint8 *)p, len, f)    lv = pchars((pcre_uint8 *)p, len, f)
187    
# Line 195  use these in the definitions of generic Line 196  use these in the definitions of generic
196    count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options, \    count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options, \
197      offsets, size_offsets)      offsets, size_offsets)
198    
 #define PCRE_STUDY8(extra, re, options, error) \  
   extra = pcre_study(re, options, error)  
   
199  #define PCRE_FREE_STUDY8(extra) \  #define PCRE_FREE_STUDY8(extra) \
200    pcre_free_study(extra)    pcre_free_study(extra)
201    
202  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER8(re, extra, tables) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER8(re, extra, tables) \
203    pcre_pattern_to_host_byte_order(re, extra, tables)    pcre_pattern_to_host_byte_order(re, extra, tables)
204    
205    #define PCRE_STUDY8(extra, re, options, error) \
206      extra = pcre_study(re, options, error)
207    
208  #endif /* SUPPORT_PCRE8 */  #endif /* SUPPORT_PCRE8 */
209    
210    
211  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
212    
213  #define PCHARS16(lv, p, len, f) \  #define PCHARS16(lv, p, len, f) \
214    lv = pchars16((PCRE_SPTR16)p, len, f)    lv = pchars16((PCRE_SPTR16)p, len, f)
215    
# Line 217  use these in the definitions of generic Line 219  use these in the definitions of generic
219  #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \  #define PCRE_COMPILE16(re, pat, options, error, erroffset, tables) \
220    re = pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, tables)    re = pcre16_compile((PCRE_SPTR16)pat, options, error, erroffset, tables)
221    
222    #define PCRE_FREE_STUDY16(extra) \
223      pcre16_free_study(extra)
224    
225  #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC16(count, re, extra, bptr, len, start_offset, options, \
226      offsets, size_offsets) \      offsets, size_offsets) \
227    count = pcre16_exec(re, extra, (PCRE_SPTR16)bptr, len, start_offset, \    count = pcre16_exec(re, extra, (PCRE_SPTR16)bptr, len, start_offset, \
228      options, offsets, size_offsets)      options, offsets, size_offsets)
229    
230  #define PCRE_FREE_STUDY16(extra) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables) \
231    pcre16_free_study(extra)    pcre16_pattern_to_host_byte_order(re, extra, tables)
232    
233  #define PCRE_STUDY16(extra, re, options, error) \  #define PCRE_STUDY16(extra, re, options, error) \
234    extra = pcre16_study(re, options, error)    extra = pcre16_study(re, options, error)
235    
 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables) \  
   pcre16_pattern_to_host_byte_order(re, extra, tables)  
   
236  #endif /* SUPPORT_PCRE16 */  #endif /* SUPPORT_PCRE16 */
237    
238    
# Line 256  use these in the definitions of generic Line 258  use these in the definitions of generic
258    else \    else \
259      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)      PCRE_COMPILE8(re, pat, options, error, erroffset, tables)
260    
261    #define PCRE_FREE_STUDY(extra) \
262      if (use_pcre16) \
263        PCRE_FREE_STUDY16(extra); \
264      else \
265        PCRE_FREE_STUDY8(extra)
266    
267  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \  #define PCRE_EXEC(count, re, extra, bptr, len, start_offset, options, \
268      offsets, size_offsets) \      offsets, size_offsets) \
269    if (use_pcre16) \    if (use_pcre16) \
# Line 265  use these in the definitions of generic Line 273  use these in the definitions of generic
273      PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \      PCRE_EXEC8(count, re, extra, bptr, len, start_offset, options, \
274        offsets, size_offsets)        offsets, size_offsets)
275    
276  #define PCRE_FREE_STUDY(extra) \  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(re, extra, tables) \
277    if (use_pcre16) \    if (use_pcre16) \
278      PCRE_FREE_STUDY16(extra); \      PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables); \
279    else \    else \
280      PCRE_FREE_STUDY8(extra)      PCRE_PATTERN_TO_HOST_BYTE_ORDER8(re, extra, tables)
281    
282  #define PCRE_STUDY(extra, re, options, error) \  #define PCRE_STUDY(extra, re, options, error) \
283    if (use_pcre16) \    if (use_pcre16) \
# Line 277  use these in the definitions of generic Line 285  use these in the definitions of generic
285    else \    else \
286      PCRE_STUDY8(extra, re, options, error)      PCRE_STUDY8(extra, re, options, error)
287    
 #define PCRE_PATTERN_TO_HOST_BYTE_ORDER(re, extra, tables) \  
   if (use_pcre16) \  
     PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables); \  
   else \  
     PCRE_PATTERN_TO_HOST_BYTE_ORDER8(re, extra, tables)  
   
288  /* ----- Only 8-bit mode is supported ----- */  /* ----- Only 8-bit mode is supported ----- */
289    
290  #elif defined SUPPORT_PCRE8  #elif defined SUPPORT_PCRE8
# Line 291  use these in the definitions of generic Line 293  use these in the definitions of generic
293  #define PCRE_COMPILE     PCRE_COMPILE8  #define PCRE_COMPILE     PCRE_COMPILE8
294  #define PCRE_EXEC        PCRE_EXEC8  #define PCRE_EXEC        PCRE_EXEC8
295  #define PCRE_FREE_STUDY  PCRE_FREE_STUDY8  #define PCRE_FREE_STUDY  PCRE_FREE_STUDY8
 #define PCRE_STUDY       PCRE_STUDY8  
296  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER8  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER8
297    #define PCRE_STUDY       PCRE_STUDY8
298    
299  /* ----- Only 16-bit mode is supported ----- */  /* ----- Only 16-bit mode is supported ----- */
300    
# Line 302  use these in the definitions of generic Line 304  use these in the definitions of generic
304  #define PCRE_COMPILE     PCRE_COMPILE16  #define PCRE_COMPILE     PCRE_COMPILE16
305  #define PCRE_EXEC        PCRE_EXEC16  #define PCRE_EXEC        PCRE_EXEC16
306  #define PCRE_FREE_STUDY  PCRE_FREE_STUDY16  #define PCRE_FREE_STUDY  PCRE_FREE_STUDY16
 #define PCRE_STUDY       PCRE_STUDY16  
307  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16  #define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16
308    #define PCRE_STUDY       PCRE_STUDY16
309  #endif  #endif
310    
311  /* ----- End of mode-specific function call macros ----- */  /* ----- End of mode-specific function call macros ----- */
# Line 347  static pcre_uint8 *buffer = NULL; Line 349  static pcre_uint8 *buffer = NULL;
349  static pcre_uint8 *dbuffer = NULL;  static pcre_uint8 *dbuffer = NULL;
350  static pcre_uint8 *pbuffer = NULL;  static pcre_uint8 *pbuffer = NULL;
351    
352    /* Another buffer is needed translation to 16-bit character strings. It will
353    obtained and extended as required. */
354    
355  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
356  static int buffer16_size = 0;  static int buffer16_size = 0;
357  static pcre_uint16 *buffer16 = NULL;  static pcre_uint16 *buffer16 = NULL;
358    
359    /* We need the table of operator lengths that is used for 16-bit compiling, in
360    order to swap bytes in a pattern for saving/reloading testing. Luckily, the
361    data is defined as a macro. However, we must ensure that LINK_SIZE is adjusted
362    appropriately for the 16-bit world. Just as a safety check, make sure that
363    COMPILE_PCRE16 is *not* set. */
364    
365    #ifdef COMPILE_PCRE16
366    #error COMPILE_PCRE16 must not be set when compiling pcretest.c
367    #endif
368    
369    #if LINK_SIZE == 2
370    #undef LINK_SIZE
371    #define LINK_SIZE 1
372    #elif LINK_SIZE == 3 || LINK_SIZE == 4
373    #undef LINK_SIZE
374    #define LINK_SIZE 2
375    #else
376    #error LINK_SIZE must be either 2, 3, or 4
377  #endif  #endif
378    
379    static const pcre_uint16 OP_lengths16[] = { OP_LENGTHS };
380    
381    #endif  /* SUPPORT_PCRE16 */
382    
383  /* If we have 8-bit support, default use_pcre16 to false; if there is also  /* If we have 8-bit support, default use_pcre16 to false; if there is also
384  16-bit support, it can be changed by an option. If there is no 8-bit support,  16-bit support, it can be changed by an option. If there is no 8-bit support,
385  there must be 16-bit support, so default it to 1. */  there must be 16-bit support, so default it to 1. */
# Line 862  return i + 1; Line 890  return i + 1;
890  8-bit size. For a UTF-8 string, the size needed for UTF-16 is no more than  8-bit size. For a UTF-8 string, the size needed for UTF-16 is no more than
891  double, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4  double, because up to 0xffff uses no more than 3 bytes in UTF-8 but possibly 4
892  in UTF-16. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-16. The  in UTF-16. Higher values use 4 bytes in UTF-8 and up to 4 bytes in UTF-16. The
893  result is always left in buffer16.  result is always left in buffer16.
894    
895  Arguments:  Arguments:
896    p          points to a byte string    p          points to a byte string
897    utf        true if UTF-8 (to be converted to UTF-16)    utf        true if UTF-8 (to be converted to UTF-16)
898    len        number of bytes in the string (excluding trailing zero)    len        number of bytes in the string (excluding trailing zero)
899    
900  Returns:     number of 16-bit data items used (excluding trailing zero)  Returns:     number of 16-bit data items used (excluding trailing zero)
901               OR -1 if a UTF-8 string is malformed               OR -1 if a UTF-8 string is malformed
902  */  */
903    
904  static int  static int
# Line 905  else Line 933  else
933      int chlen = utf82ord(p, &c);      int chlen = utf82ord(p, &c);
934      if (chlen <= 0) return -1;      if (chlen <= 0) return -1;
935      p += chlen;      p += chlen;
936      len -= chlen;      len -= chlen;
937      if (c < 0x10000) *pp++ = c; else      if (c < 0x10000) *pp++ = c; else
938        {        {
939        c -= 0x10000;        c -= 0x10000;
# Line 1067  if (PRINTOK(c)) Line 1095  if (PRINTOK(c))
1095    if (f != NULL) fprintf(f, "%c", c);    if (f != NULL) fprintf(f, "%c", c);
1096    return 1;    return 1;
1097    }    }
1098    
1099  if (c < 0x100)  if (c < 0x100)
1100    {    {
1101    if (use_utf)    if (use_utf)
1102      {      {
1103      if (f != NULL) fprintf(f, "\\x{%02x}", c);      if (f != NULL) fprintf(f, "\\x{%02x}", c);
1104      return 6;      return 6;
1105      }      }
1106    else    else
1107      {      {
1108      if (f != NULL) fprintf(f, "\\x%02x", c);      if (f != NULL) fprintf(f, "\\x%02x", c);
1109      return 4;      return 4;
1110      }      }
1111    }    }
1112    
1113  if (f != NULL) fprintf(f, "\\x{%02x}", c);  if (f != NULL) fprintf(f, "\\x{%02x}", c);
1114  return (c <= 0x000000ff)? 6 :  return (c <= 0x000000ff)? 6 :
1115         (c <= 0x00000fff)? 7 :         (c <= 0x00000fff)? 7 :
# Line 1115  while (length-- > 0) Line 1143  while (length-- > 0)
1143        length -= rc - 1;        length -= rc - 1;
1144        p += rc;        p += rc;
1145        yield += pchar(c, f);        yield += pchar(c, f);
1146        continue;        continue;
1147        }        }
1148      }      }
1149  #endif  #endif
# Line 1152  while (length-- > 0) Line 1180  while (length-- > 0)
1180        {        {
1181        c = ((c & 0x3ff) << 10) + (d & 0x3ff) + 0x10000;        c = ((c & 0x3ff) << 10) + (d & 0x3ff) + 0x10000;
1182        length--;        length--;
1183        p++;        p++;
1184        }        }
1185      }      }
1186  #endif  #endif
1187    yield += pchar(c, f);    yield += pchar(c, f);
1188    }    }
# Line 1343  if (rc < 0) fprintf(outfile, "Error %d f Line 1371  if (rc < 0) fprintf(outfile, "Error %d f
1371    
1372    
1373  /*************************************************  /*************************************************
1374  *         Byte flipping function                 *  *             Swap byte functions                *
1375  *************************************************/  *************************************************/
1376    
1377  static unsigned long int  /* The following functions swap the bytes of a pcre_uint16
1378  byteflip(unsigned long int value, int n)  and pcre_uint32 value.
1379    
1380    Arguments:
1381      value        any number
1382    
1383    Returns:       the byte swapped value
1384    */
1385    
1386    static pcre_uint32
1387    swap_uint32(pcre_uint32 value)
1388  {  {
 if (n == 2) return ((value & 0x00ff) << 8) | ((value & 0xff00) >> 8);  
1389  return ((value & 0x000000ff) << 24) |  return ((value & 0x000000ff) << 24) |
1390         ((value & 0x0000ff00) <<  8) |         ((value & 0x0000ff00) <<  8) |
1391         ((value & 0x00ff0000) >>  8) |         ((value & 0x00ff0000) >>  8) |
1392         ((value & 0xff000000) >> 24);         (value >> 24);
1393  }  }
1394    
1395    static pcre_uint16
1396    swap_uint16(pcre_uint16 value)
1397    {
1398    return (value >> 8) | (value << 8);
1399    }
1400    
1401    
1402    
1403    /*************************************************
1404    *        Flip bytes in a compiled pattern        *
1405    *************************************************/
1406    
1407    /* This function is called if the 'F' option was present on a pattern that is
1408    to be written to a file. We flip the bytes of all the integer fields in the
1409    regex data block and the study block. In 16-bit mode this also flips relevant
1410    bytes in the pattern itself. This is to make it possible to test PCRE's
1411    ability to reload byte-flipped patterns, e.g. those compiled on a different
1412    architecture. */
1413    
1414    static void
1415    regexflip(pcre *ere, pcre_extra *extra)
1416    {
1417    real_pcre *re = (real_pcre *)ere;
1418    int op;
1419    
1420    #ifdef SUPPORT_PCRE16
1421    pcre_uint16 *ptr = (pcre_uint16 *)re + re->name_table_offset;
1422    int length = re->name_count * re->name_entry_size;
1423    #ifdef SUPPORT_UTF
1424    BOOL utf = (re->options & PCRE_UTF16) != 0;
1425    BOOL utf16_char = FALSE;
1426    #endif /* SUPPORT_UTF */
1427    #endif /* SUPPORT_PCRE16 */
1428    
1429    /* Always flip the bytes in the main data block and study blocks. */
1430    
1431    re->magic_number = REVERSED_MAGIC_NUMBER;
1432    re->size = swap_uint32(re->size);
1433    re->options = swap_uint32(re->options);
1434    re->flags = swap_uint16(re->flags);
1435    re->top_bracket = swap_uint16(re->top_bracket);
1436    re->top_backref = swap_uint16(re->top_backref);
1437    re->first_char = swap_uint16(re->first_char);
1438    re->req_char = swap_uint16(re->req_char);
1439    re->name_table_offset = swap_uint16(re->name_table_offset);
1440    re->name_entry_size = swap_uint16(re->name_entry_size);
1441    re->name_count = swap_uint16(re->name_count);
1442    
1443    if (extra != NULL)
1444      {
1445      pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
1446      rsd->size = swap_uint32(rsd->size);
1447      rsd->flags = swap_uint32(rsd->flags);
1448      rsd->minlength = swap_uint32(rsd->minlength);
1449      }
1450    
1451    /* In 8-bit mode, that is all we need to do. In 16-bit mode we must swap bytes
1452    in the name table, if present, and then in the pattern itself. */
1453    
1454    #ifdef SUPPORT_PCRE16
1455    if (!use_pcre16) return;
1456    
1457    while(TRUE)
1458      {
1459      /* Swap previous characters. */
1460      while (length-- > 0)
1461        {
1462        *ptr = swap_uint16(*ptr);
1463        ptr++;
1464        }
1465    #ifdef SUPPORT_UTF
1466      if (utf16_char)
1467        {
1468        if ((ptr[-1] & 0xfc00) == 0xd800)
1469          {
1470          /* We know that there is only one extra character in UTF-16. */
1471          *ptr = swap_uint16(*ptr);
1472          ptr++;
1473          }
1474        }
1475      utf16_char = FALSE;
1476    #endif /* SUPPORT_UTF */
1477    
1478      /* Get next opcode. */
1479    
1480      length = 0;
1481      op = *ptr;
1482      *ptr++ = swap_uint16(op);
1483    
1484      switch (op)
1485        {
1486        case OP_END:
1487        return;
1488    
1489        case OP_CHAR:
1490        case OP_CHARI:
1491        case OP_NOT:
1492        case OP_NOTI:
1493        case OP_STAR:
1494        case OP_MINSTAR:
1495        case OP_PLUS:
1496        case OP_MINPLUS:
1497        case OP_QUERY:
1498        case OP_MINQUERY:
1499        case OP_UPTO:
1500        case OP_MINUPTO:
1501        case OP_EXACT:
1502        case OP_POSSTAR:
1503        case OP_POSPLUS:
1504        case OP_POSQUERY:
1505        case OP_POSUPTO:
1506        case OP_STARI:
1507        case OP_MINSTARI:
1508        case OP_PLUSI:
1509        case OP_MINPLUSI:
1510        case OP_QUERYI:
1511        case OP_MINQUERYI:
1512        case OP_UPTOI:
1513        case OP_MINUPTOI:
1514        case OP_EXACTI:
1515        case OP_POSSTARI:
1516        case OP_POSPLUSI:
1517        case OP_POSQUERYI:
1518        case OP_POSUPTOI:
1519        case OP_NOTSTAR:
1520        case OP_NOTMINSTAR:
1521        case OP_NOTPLUS:
1522        case OP_NOTMINPLUS:
1523        case OP_NOTQUERY:
1524        case OP_NOTMINQUERY:
1525        case OP_NOTUPTO:
1526        case OP_NOTMINUPTO:
1527        case OP_NOTEXACT:
1528        case OP_NOTPOSSTAR:
1529        case OP_NOTPOSPLUS:
1530        case OP_NOTPOSQUERY:
1531        case OP_NOTPOSUPTO:
1532        case OP_NOTSTARI:
1533        case OP_NOTMINSTARI:
1534        case OP_NOTPLUSI:
1535        case OP_NOTMINPLUSI:
1536        case OP_NOTQUERYI:
1537        case OP_NOTMINQUERYI:
1538        case OP_NOTUPTOI:
1539        case OP_NOTMINUPTOI:
1540        case OP_NOTEXACTI:
1541        case OP_NOTPOSSTARI:
1542        case OP_NOTPOSPLUSI:
1543        case OP_NOTPOSQUERYI:
1544        case OP_NOTPOSUPTOI:
1545    #ifdef SUPPORT_UTF
1546        if (utf) utf16_char = TRUE;
1547    #endif
1548        length = OP_lengths16[op] - 1;
1549        break;
1550    
1551        case OP_CLASS:
1552        case OP_NCLASS:
1553        /* Skip the character bit map. */
1554        ptr += 32/sizeof(pcre_uint16);
1555        length = 0;
1556        break;
1557    
1558        case OP_XCLASS:
1559        /* Reverse the size of the XCLASS instance. */
1560        ptr++;
1561        *ptr = swap_uint16(*ptr);
1562        if (LINK_SIZE > 1)
1563          {
1564          /* LINK_SIZE can be 1 or 2 in 16 bit mode. */
1565          ptr++;
1566          *ptr = swap_uint16(*ptr);
1567          }
1568        ptr++;
1569    
1570        if (LINK_SIZE > 1)
1571          length = ((ptr[-LINK_SIZE] << 16) | ptr[-LINK_SIZE + 1]) -
1572            (1 + LINK_SIZE + 1);
1573        else
1574          length = ptr[-LINK_SIZE] - (1 + LINK_SIZE + 1);
1575    
1576        op = *ptr;
1577        *ptr = swap_uint16(op);
1578        if ((op & XCL_MAP) != 0)
1579          {
1580          /* Skip the character bit map. */
1581          ptr += 32/sizeof(pcre_uint16);
1582          length -= 32/sizeof(pcre_uint16);
1583          }
1584        break;
1585    
1586        default:
1587        length = OP_lengths16[op] - 1;
1588        break;
1589        }
1590      }
1591    /* Control should never reach here in 16 bit mode. */
1592    #endif /* SUPPORT_PCRE16 */
1593    }
1594    
1595    
1596    
# Line 1662  are set, either both UTFs are supported Line 1897  are set, either both UTFs are supported
1897      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);      (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
1898      if (rc)      if (rc)
1899        printf("  UTF-8 and UTF-16 support\n");        printf("  UTF-8 and UTF-16 support\n");
1900      else      else
1901        printf("  No UTF-8 or UTF-16 support\n");        printf("  No UTF-8 or UTF-16 support\n");
1902  #elif defined SUPPORT_PCRE8  #elif defined SUPPORT_PCRE8
1903      printf("  8-bit support only\n");      printf("  8-bit support only\n");
# Line 1854  while (!done) Line 2089  while (!done)
2089      magic = ((real_pcre *)re)->magic_number;      magic = ((real_pcre *)re)->magic_number;
2090      if (magic != MAGIC_NUMBER)      if (magic != MAGIC_NUMBER)
2091        {        {
2092        if (byteflip(magic, sizeof(magic)) == MAGIC_NUMBER)        if (swap_uint32(magic) == MAGIC_NUMBER)
2093          {          {
2094          do_flip = 1;          do_flip = 1;
2095          }          }
# Line 1899  while (!done) Line 2134  while (!done)
2134      else fprintf(outfile, "No study data\n");      else fprintf(outfile, "No study data\n");
2135    
2136      /* Flip the necessary bytes. */      /* Flip the necessary bytes. */
2137      if (do_flip != 0)      if (do_flip)
2138        {        {
2139        PCRE_PATTERN_TO_HOST_BYTE_ORDER(re, extra, NULL);        PCRE_PATTERN_TO_HOST_BYTE_ORDER(re, extra, NULL);
2140        }        }
# Line 2139  while (!done) Line 2374  while (!done)
2374      /* In 16-bit mode, convert the input. */      /* In 16-bit mode, convert the input. */
2375    
2376  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
2377      if (use_pcre16)      if (use_pcre16)
2378        {        {
2379        if (to16(p, options & PCRE_UTF8, (int)strlen((char *)p)) < 0)        if (to16(p, options & PCRE_UTF8, (int)strlen((char *)p)) < 0)
2380          {          {
2381          fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "          fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
2382            "converted to UTF-16\n");            "converted to UTF-16\n");
2383          goto SKIP_DATA;          goto SKIP_DATA;
2384          }          }
2385        p = (pcre_uint8 *)buffer16;        p = (pcre_uint8 *)buffer16;
2386        }        }
2387  #endif  #endif
2388    
2389      /* Compile many times when timing */      /* Compile many times when timing */
# Line 2366  while (!done) Line 2601  while (!done)
2601        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");        if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
2602    
2603        all_options = ((real_pcre *)re)->options;        all_options = ((real_pcre *)re)->options;
2604        if (do_flip) all_options = byteflip(all_options, sizeof(all_options));        if (do_flip) all_options = swap_uint32(all_options);
2605    
2606        if (get_options == 0) fprintf(outfile, "No options\n");        if (get_options == 0) fprintf(outfile, "No options\n");
2607          else fprintf(outfile, "Options:%s%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",
# Line 2429  while (!done) Line 2664  while (!done)
2664          const char *caseless =          const char *caseless =
2665            ((((real_pcre *)re)->flags & PCRE_FCH_CASELESS) == 0)?            ((((real_pcre *)re)->flags & PCRE_FCH_CASELESS) == 0)?
2666            "" : " (caseless)";            "" : " (caseless)";
2667    
2668          if (PRINTOK(first_char))          if (PRINTOK(first_char))
2669            fprintf(outfile, "First char = \'%c\'%s\n", first_char, caseless);            fprintf(outfile, "First char = \'%c\'%s\n", first_char, caseless);
2670          else          else
2671            {            {
2672            fprintf(outfile, "First char = ");            fprintf(outfile, "First char = ");
2673            pchar(first_char, outfile);            pchar(first_char, outfile);
2674            fprintf(outfile, "%s\n", caseless);            fprintf(outfile, "%s\n", caseless);
2675            }            }
2676          }          }
2677    
2678        if (need_char < 0)        if (need_char < 0)
# Line 2533  while (!done) Line 2768  while (!done)
2768    
2769      if (to_file != NULL)      if (to_file != NULL)
2770        {        {
       /* If the 'F' option was present, we flip the bytes of all the integer  
       fields in the regex data block and the study block. This is to make it  
       possible to test PCRE's handling of byte-flipped patterns, e.g. those  
       compiled on a different architecture. */  
   
       if (do_flip)  
         {  
         real_pcre *rre = (real_pcre *)re;  
         rre->magic_number =  
           byteflip(rre->magic_number, sizeof(rre->magic_number));  
         rre->size = byteflip(rre->size, sizeof(rre->size));  
         rre->options = byteflip(rre->options, sizeof(rre->options));  
         rre->flags = (pcre_uint16)byteflip(rre->flags, sizeof(rre->flags));  
         rre->top_bracket =  
           (pcre_uint16)byteflip(rre->top_bracket, sizeof(rre->top_bracket));  
         rre->top_backref =  
           (pcre_uint16)byteflip(rre->top_backref, sizeof(rre->top_backref));  
         rre->first_char =  
           (pcre_uint16)byteflip(rre->first_char, sizeof(rre->first_char));  
         rre->req_char =  
           (pcre_uint16)byteflip(rre->req_char, sizeof(rre->req_char));  
         rre->name_table_offset = (pcre_uint16)byteflip(rre->name_table_offset,  
           sizeof(rre->name_table_offset));  
         rre->name_entry_size = (pcre_uint16)byteflip(rre->name_entry_size,  
           sizeof(rre->name_entry_size));  
         rre->name_count = (pcre_uint16)byteflip(rre->name_count,  
           sizeof(rre->name_count));  
   
         if (extra != NULL)  
           {  
           pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);  
           rsd->size = byteflip(rsd->size, sizeof(rsd->size));  
           rsd->flags = byteflip(rsd->flags, sizeof(rsd->flags));  
           rsd->minlength = byteflip(rsd->minlength, sizeof(rsd->minlength));  
           }  
         }  
   
2771        FILE *f = fopen((char *)to_file, "wb");        FILE *f = fopen((char *)to_file, "wb");
2772        if (f == NULL)        if (f == NULL)
2773          {          {
# Line 2578  while (!done) Line 2776  while (!done)
2776        else        else
2777          {          {
2778          pcre_uint8 sbuf[8];          pcre_uint8 sbuf[8];
2779    
2780            if (do_flip) regexflip(re, extra);
2781          sbuf[0] = (pcre_uint8)((true_size >> 24) & 255);          sbuf[0] = (pcre_uint8)((true_size >> 24) & 255);
2782          sbuf[1] = (pcre_uint8)((true_size >> 16) & 255);          sbuf[1] = (pcre_uint8)((true_size >> 16) & 255);
2783          sbuf[2] = (pcre_uint8)((true_size >>  8) & 255);          sbuf[2] = (pcre_uint8)((true_size >>  8) & 255);
2784          sbuf[3] = (pcre_uint8)((true_size) & 255);          sbuf[3] = (pcre_uint8)((true_size) & 255);
   
2785          sbuf[4] = (pcre_uint8)((true_study_size >> 24) & 255);          sbuf[4] = (pcre_uint8)((true_study_size >> 24) & 255);
2786          sbuf[5] = (pcre_uint8)((true_study_size >> 16) & 255);          sbuf[5] = (pcre_uint8)((true_study_size >> 16) & 255);
2787          sbuf[6] = (pcre_uint8)((true_study_size >>  8) & 255);          sbuf[6] = (pcre_uint8)((true_study_size >>  8) & 255);
# Line 2614  while (!done) Line 2813  while (!done)
2813          }          }
2814    
2815        new_free(re);        new_free(re);
2816        if (extra != NULL)        if (extra != NULL)
2817          {          {
2818          PCRE_FREE_STUDY(extra);          PCRE_FREE_STUDY(extra);
2819          }          }
# Line 3080  while (!done) Line 3279  while (!done)
3279      /* Handle matching via the native interface - repeats for /g and /G */      /* Handle matching via the native interface - repeats for /g and /G */
3280    
3281  #ifdef SUPPORT_PCRE16  #ifdef SUPPORT_PCRE16
3282      if (use_pcre16)      if (use_pcre16)
3283        {        {
3284        len = to16(bptr, (((real_pcre *)re)->options) & PCRE_UTF8, len);        len = to16(bptr, (((real_pcre *)re)->options) & PCRE_UTF8, len);
3285        if (len < 0)        if (len < 0)
3286          {          {
3287          fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "          fprintf(outfile, "**Failed: invalid UTF-8 string cannot be "
3288            "converted to UTF-16\n");            "converted to UTF-16\n");
3289          goto NEXT_DATA;          goto NEXT_DATA;
3290          }          }
3291        bptr = (pcre_uint8 *)buffer16;        bptr = (pcre_uint8 *)buffer16;
3292        }        }
3293  #endif  #endif
3294    
3295      for (;; gmatched++)    /* Loop for /g or /G */      for (;; gmatched++)    /* Loop for /g or /G */

Legend:
Removed from v.812  
changed lines
  Added in v.813

  ViewVC Help
Powered by ViewVC 1.1.5