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

Contents of /code/branches/pcre16/pcre_byte_order.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 774 - (hide annotations) (download)
Thu Dec 1 06:08:45 2011 UTC (2 years, 8 months ago) by zherczeg
Original Path: code/branches/pcre16/pcre_try_flipped.c
File MIME type: text/plain
File size: 5559 byte(s)
better digit parsing, first_byte, req_byte are renamed to first_char req_char respectively
1 nigel 77 /*************************************************
2     * Perl-Compatible Regular Expressions *
3     *************************************************/
4    
5     /* PCRE is a library of functions to support regular expressions whose syntax
6     and semantics are as close as possible to those of the Perl 5 language.
7    
8     Written by Philip Hazel
9 ph10 455 Copyright (c) 1997-2009 University of Cambridge
10 nigel 77
11     -----------------------------------------------------------------------------
12     Redistribution and use in source and binary forms, with or without
13     modification, 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    
26     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36     POSSIBILITY OF SUCH DAMAGE.
37     -----------------------------------------------------------------------------
38     */
39    
40    
41     /* This module contains an internal function that tests a compiled pattern to
42     see if it was compiled with the opposite endianness. If so, it uses an
43     auxiliary local function to flip the appropriate bytes. */
44    
45    
46 ph10 200 #ifdef HAVE_CONFIG_H
47 ph10 236 #include "config.h"
48 ph10 200 #endif
49 ph10 199
50 nigel 77 #include "pcre_internal.h"
51    
52    
53     /*************************************************
54     * Flip bytes in an integer *
55     *************************************************/
56    
57     /* This function is called when the magic number in a regex doesn't match, in
58     order to flip its bytes to see if we are dealing with a pattern that was
59     compiled on a host of different endianness. If so, this function is used to
60     flip other byte values.
61    
62     Arguments:
63     value the number to flip
64     n the number of bytes to flip (assumed to be 2 or 4)
65    
66     Returns: the flipped value
67     */
68    
69 nigel 91 static unsigned long int
70     byteflip(unsigned long int value, int n)
71 nigel 77 {
72     if (n == 2) return ((value & 0x00ff) << 8) | ((value & 0xff00) >> 8);
73     return ((value & 0x000000ff) << 24) |
74     ((value & 0x0000ff00) << 8) |
75     ((value & 0x00ff0000) >> 8) |
76     ((value & 0xff000000) >> 24);
77     }
78    
79    
80    
81     /*************************************************
82     * Test for a byte-flipped compiled regex *
83     *************************************************/
84    
85     /* This function is called from pcre_exec(), pcre_dfa_exec(), and also from
86     pcre_fullinfo(). Its job is to test whether the regex is byte-flipped - that
87     is, it was compiled on a system of opposite endianness. The function is called
88     only when the native MAGIC_NUMBER test fails. If the regex is indeed flipped,
89     we flip all the relevant values into a different data block, and return it.
90    
91     Arguments:
92     re points to the regex
93     study points to study data, or NULL
94     internal_re points to a new regex block
95     internal_study points to a new study block
96    
97     Returns: the new block if is is indeed a byte-flipped regex
98     NULL if it is not
99     */
100    
101 nigel 87 real_pcre *
102 zherczeg 764 PRIV(try_flipped)(const real_pcre *re, real_pcre *internal_re,
103 nigel 77 const pcre_study_data *study, pcre_study_data *internal_study)
104     {
105     if (byteflip(re->magic_number, sizeof(re->magic_number)) != MAGIC_NUMBER)
106     return NULL;
107    
108     *internal_re = *re; /* To copy other fields */
109     internal_re->size = byteflip(re->size, sizeof(re->size));
110     internal_re->options = byteflip(re->options, sizeof(re->options));
111 ph10 230 internal_re->flags = (pcre_uint16)byteflip(re->flags, sizeof(re->flags));
112 nigel 77 internal_re->top_bracket =
113     (pcre_uint16)byteflip(re->top_bracket, sizeof(re->top_bracket));
114     internal_re->top_backref =
115     (pcre_uint16)byteflip(re->top_backref, sizeof(re->top_backref));
116 zherczeg 774 internal_re->first_char =
117     (pcre_uint16)byteflip(re->first_char, sizeof(re->first_char));
118     internal_re->req_char =
119     (pcre_uint16)byteflip(re->req_char, sizeof(re->req_char));
120 nigel 77 internal_re->name_table_offset =
121     (pcre_uint16)byteflip(re->name_table_offset, sizeof(re->name_table_offset));
122     internal_re->name_entry_size =
123     (pcre_uint16)byteflip(re->name_entry_size, sizeof(re->name_entry_size));
124     internal_re->name_count =
125     (pcre_uint16)byteflip(re->name_count, sizeof(re->name_count));
126    
127     if (study != NULL)
128     {
129     *internal_study = *study; /* To copy other fields */
130     internal_study->size = byteflip(study->size, sizeof(study->size));
131 ph10 455 internal_study->flags = byteflip(study->flags, sizeof(study->flags));
132 ph10 461 internal_study->minlength = byteflip(study->minlength,
133 ph10 455 sizeof(study->minlength));
134 nigel 77 }
135    
136     return internal_re;
137     }
138    
139     /* End of pcre_tryflipped.c */

Properties

Name Value
svn:eol-style native
svn:keywords "Author Date Id Revision Url"

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12