source: XMLIO_V2/external/src/POCO/Foundation/pcre_try_flipped.not_used @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

File size: 5.3 KB
Line 
1/*************************************************
2*      Perl-Compatible Regular Expressions       *
3*************************************************/
4
5/* PCRE is a library of functions to support regular expressions whose syntax
6and semantics are as close as possible to those of the Perl 5 language.
7
8                       Written by Philip Hazel
9           Copyright (c) 1997-2008 University of Cambridge
10
11-----------------------------------------------------------------------------
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14
15    * Redistributions of source code must retain the above copyright notice,
16      this list of conditions and the following disclaimer.
17
18    * Redistributions in binary form must reproduce the above copyright
19      notice, this list of conditions and the following disclaimer in the
20      documentation and/or other materials provided with the distribution.
21
22    * Neither the name of the University of Cambridge nor the names of its
23      contributors may be used to endorse or promote products derived from
24      this software without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36POSSIBILITY OF SUCH DAMAGE.
37-----------------------------------------------------------------------------
38*/
39
40
41/* This module contains an internal function that tests a compiled pattern to
42see if it was compiled with the opposite endianness. If so, it uses an
43auxiliary local function to flip the appropriate bytes. */
44
45
46#include "pcre_config.h"
47#include "pcre_internal.h"
48
49
50/*************************************************
51*         Flip bytes in an integer               *
52*************************************************/
53
54/* This function is called when the magic number in a regex doesn't match, in
55order to flip its bytes to see if we are dealing with a pattern that was
56compiled on a host of different endianness. If so, this function is used to
57flip other byte values.
58
59Arguments:
60  value        the number to flip
61  n            the number of bytes to flip (assumed to be 2 or 4)
62
63Returns:       the flipped value
64*/
65
66static unsigned long int
67byteflip(unsigned long int value, int n)
68{
69if (n == 2) return ((value & 0x00ff) << 8) | ((value & 0xff00) >> 8);
70return ((value & 0x000000ff) << 24) |
71       ((value & 0x0000ff00) <<  8) |
72       ((value & 0x00ff0000) >>  8) |
73       ((value & 0xff000000) >> 24);
74}
75
76
77
78/*************************************************
79*       Test for a byte-flipped compiled regex   *
80*************************************************/
81
82/* This function is called from pcre_exec(), pcre_dfa_exec(), and also from
83pcre_fullinfo(). Its job is to test whether the regex is byte-flipped - that
84is, it was compiled on a system of opposite endianness. The function is called
85only when the native MAGIC_NUMBER test fails. If the regex is indeed flipped,
86we flip all the relevant values into a different data block, and return it.
87
88Arguments:
89  re               points to the regex
90  study            points to study data, or NULL
91  internal_re      points to a new regex block
92  internal_study   points to a new study block
93
94Returns:           the new block if is is indeed a byte-flipped regex
95                   NULL if it is not
96*/
97
98real_pcre *
99_pcre_try_flipped(const real_pcre *re, real_pcre *internal_re,
100  const pcre_study_data *study, pcre_study_data *internal_study)
101{
102if (byteflip(re->magic_number, sizeof(re->magic_number)) != MAGIC_NUMBER)
103  return NULL;
104
105*internal_re = *re;           /* To copy other fields */
106internal_re->size = byteflip(re->size, sizeof(re->size));
107internal_re->options = byteflip(re->options, sizeof(re->options));
108internal_re->flags = (pcre_uint16)byteflip(re->flags, sizeof(re->flags));
109internal_re->top_bracket =
110  (pcre_uint16)byteflip(re->top_bracket, sizeof(re->top_bracket));
111internal_re->top_backref =
112  (pcre_uint16)byteflip(re->top_backref, sizeof(re->top_backref));
113internal_re->first_byte =
114  (pcre_uint16)byteflip(re->first_byte, sizeof(re->first_byte));
115internal_re->req_byte =
116  (pcre_uint16)byteflip(re->req_byte, sizeof(re->req_byte));
117internal_re->name_table_offset =
118  (pcre_uint16)byteflip(re->name_table_offset, sizeof(re->name_table_offset));
119internal_re->name_entry_size =
120  (pcre_uint16)byteflip(re->name_entry_size, sizeof(re->name_entry_size));
121internal_re->name_count =
122  (pcre_uint16)byteflip(re->name_count, sizeof(re->name_count));
123
124if (study != NULL)
125  {
126  *internal_study = *study;   /* To copy other fields */
127  internal_study->size = byteflip(study->size, sizeof(study->size));
128  internal_study->options = byteflip(study->options, sizeof(study->options));
129  }
130
131return internal_re;
132}
133
134/* End of pcre_tryflipped.c */
Note: See TracBrowser for help on using the repository browser.