Mxx_ru 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +26 -26
- data/NEWS +107 -107
- data/README +21 -21
- data/Rakefile +56 -56
- data/examples/exe_and_lib/prj.rb +11 -11
- data/examples/exe_and_lib/say.rb +7 -7
- data/examples/exe_dll_lib/inout.rb +18 -18
- data/examples/exe_dll_lib/prj.rb +11 -11
- data/examples/exe_dll_lib/say.rb +9 -9
- data/examples/exe_dll_lib_2/build.rb +10 -10
- data/examples/exe_dll_lib_2/inout/prj.rb +16 -16
- data/examples/exe_dll_lib_2/main/prj.rb +9 -9
- data/examples/exe_dll_lib_2/say/prj.rb +8 -8
- data/examples/simple_exe/prj.rb +7 -7
- data/lib/mxx_ru/abstract_target.rb +335 -335
- data/lib/mxx_ru/binary_library.rb +106 -106
- data/lib/mxx_ru/binary_target.rb +173 -173
- data/lib/mxx_ru/binary_unittest.rb +143 -143
- data/lib/mxx_ru/compat.rb +33 -33
- data/lib/mxx_ru/cpp.rb +38 -38
- data/lib/mxx_ru/cpp/analyzer.rb +237 -237
- data/lib/mxx_ru/cpp/composite.rb +118 -118
- data/lib/mxx_ru/cpp/detect_toolset.rb +122 -122
- data/lib/mxx_ru/cpp/mode.rb +90 -90
- data/lib/mxx_ru/cpp/obj_placement.rb +330 -330
- data/lib/mxx_ru/cpp/obj_placements/custom_subdir.rb +155 -155
- data/lib/mxx_ru/cpp/qt.rb +366 -366
- data/lib/mxx_ru/cpp/rucodegen.rb +157 -157
- data/lib/mxx_ru/cpp/source_file.rb +79 -79
- data/lib/mxx_ru/cpp/target.rb +1523 -1523
- data/lib/mxx_ru/cpp/toolset.rb +1087 -1087
- data/lib/mxx_ru/cpp/toolsets/bcc_win32_5.rb +53 -53
- data/lib/mxx_ru/cpp/toolsets/bcc_win32_family.rb +460 -460
- data/lib/mxx_ru/cpp/toolsets/c89_etk_nsk.rb +59 -59
- data/lib/mxx_ru/cpp/toolsets/c89_nsk.rb +59 -59
- data/lib/mxx_ru/cpp/toolsets/c89_nsk_family.rb +277 -277
- data/lib/mxx_ru/cpp/toolsets/gcc_cygwin.rb +58 -58
- data/lib/mxx_ru/cpp/toolsets/gcc_family.rb +420 -420
- data/lib/mxx_ru/cpp/toolsets/gcc_linux.rb +64 -64
- data/lib/mxx_ru/cpp/toolsets/gcc_mingw.rb +149 -150
- data/lib/mxx_ru/cpp/toolsets/gcc_sparc_solaris.rb +91 -91
- data/lib/mxx_ru/cpp/toolsets/gcc_unix_family.rb +103 -103
- data/lib/mxx_ru/cpp/toolsets/vc7.rb +62 -62
- data/lib/mxx_ru/cpp/toolsets/vc8.rb +455 -455
- data/lib/mxx_ru/cpp/toolsets/vc_family.rb +448 -448
- data/lib/mxx_ru/ex.rb +165 -165
- data/lib/mxx_ru/makestyle_generator.rb +146 -146
- data/lib/mxx_ru/textfile_unittest.rb +303 -303
- data/lib/mxx_ru/util.rb +340 -340
- data/tests/c/pcre/chartables.c +183 -183
- data/tests/c/pcre/config.h +99 -99
- data/tests/c/pcre/dftables.c +167 -167
- data/tests/c/pcre/get.c +349 -349
- data/tests/c/pcre/internal.h +677 -677
- data/tests/c/pcre/maketables.c +140 -140
- data/tests/c/pcre/pcre.c +8304 -8304
- data/tests/c/pcre/pcre.h +193 -193
- data/tests/c/pcre/pcre.rb +14 -14
- data/tests/c/pcre/pcredemo.c +316 -316
- data/tests/c/pcre/pcregrep.c +642 -642
- data/tests/c/pcre/pcreposix.c +305 -305
- data/tests/c/pcre/pcreposix.h +88 -88
- data/tests/c/pcre/pcretest.c +1483 -1483
- data/tests/c/pcre/perltest +211 -211
- data/tests/c/pcre/printint.c +360 -360
- data/tests/c/pcre/study.c +472 -472
- data/tests/cpp/cpp_sources_glob/build.rb +7 -7
- data/tests/cpp/cpp_sources_glob/some/module/prj.rb +10 -10
- data/tests/cpp/cpp_sources_glob/tc_cpp_sources_glob.rb +18 -18
- data/tests/cpp/mswin_res_dll/build.rb +14 -14
- data/tests/cpp/mswin_res_dll/dll.cpp +17 -17
- data/tests/cpp/mswin_res_dll/dll.rb +29 -29
- data/tests/cpp/mswin_res_dll/dll.rc +48 -48
- data/tests/cpp/mswin_res_dll/h/dll.hpp +8 -8
- data/tests/cpp/mswin_res_dll/h/res.h +3 -3
- data/tests/cpp/mswin_res_dll/main.cpp +13 -13
- data/tests/cpp/mswin_res_dll/main.rb +19 -19
- data/tests/cpp/mswin_res_dll/o/dll.o +0 -0
- data/tests/cpp/mswin_res_dll/tc_mswin_res_dll.rb +18 -18
- data/tests/cpp/mswin_res_exe/build.rb +23 -23
- data/tests/cpp/mswin_res_exe/h/res.h +3 -3
- data/tests/cpp/mswin_res_exe/main.cpp +17 -17
- data/tests/cpp/mswin_res_exe/main.rc +48 -48
- data/tests/cpp/mswin_res_exe/o/main.o +0 -0
- data/tests/cpp/mswin_res_exe/tc_mswin_res_exe.rb +18 -18
- data/tests/cpp/rucodegen.embedded/host_config.cpp +32 -32
- data/tests/cpp/rucodegen.embedded/impl/conn_params.cpp +7 -7
- data/tests/cpp/rucodegen.embedded/impl/conn_params.rb +14 -14
- data/tests/cpp/rucodegen.embedded/impl/h/conn_params.hpp +10 -10
- data/tests/cpp/rucodegen.embedded/prj.rb +16 -16
- data/tests/cpp/rucodegen.embedded/tc_rucodegen.rb +18 -18
- data/tests/cpp/rucodegen/host_config.cpp +20 -20
- data/tests/cpp/rucodegen/host_config.rb +14 -14
- data/tests/cpp/rucodegen/impl/conn_params.cpp +7 -7
- data/tests/cpp/rucodegen/impl/conn_params.rb +14 -14
- data/tests/cpp/rucodegen/impl/h/conn_params.hpp +10 -10
- data/tests/cpp/rucodegen/prj.rb +16 -16
- data/tests/cpp/rucodegen/tc_rucodegen.rb +18 -18
- data/tests/cpp/textfile_unittest/build.rb +8 -8
- data/tests/cpp/textfile_unittest/etalons/out_1.txt +1 -1
- data/tests/cpp/textfile_unittest/etalons/out_128.txt +128 -128
- data/tests/cpp/textfile_unittest/main.cpp +89 -89
- data/tests/cpp/textfile_unittest/prj.rb +8 -8
- data/tests/cpp/textfile_unittest/prj.ut.rb +18 -18
- data/tests/cpp/textfile_unittest/tc_textfile_unittest.rb +18 -18
- data/tests/cpp/toolset_name.rb +6 -6
- data/tests/cpp/vc_cleanup/prj_dll_no_implib.rb +10 -10
- data/tests/cpp/vc_cleanup/prj_dll_no_implib_simple_target_root.rb +11 -11
- data/tests/cpp/vc_cleanup/prj_dll_with_implib.rb +11 -11
- data/tests/cpp/vc_cleanup/prj_dll_with_implib_simple_target_root.rb +14 -14
- data/tests/cpp/vc_cleanup/prj_exe_no_implib.rb +10 -10
- data/tests/cpp/vc_cleanup/prj_exe_no_implib_simple_target_root.rb +11 -11
- data/tests/cpp/vc_cleanup/prj_lib.rb +10 -10
- data/tests/cpp/vc_cleanup/prj_lib_with_simple_target_root.rb +11 -11
- data/tests/cpp/vc_cleanup/tc_vc_cleanup.rb +23 -23
- data/tests/mxx_ru/binary_library/tc_binary_library.rb +57 -57
- data/tests/mxx_ru/binary_library/tc_binary_target_lib_methods.rb +114 -114
- data/tests/mxx_ru/change_default_value/ignoring_by_build_root/build.rb +8 -8
- data/tests/mxx_ru/change_default_value/ignoring_by_build_root/child_1.rb +5 -5
- data/tests/mxx_ru/change_default_value/ignoring_by_child_1/build.rb +7 -7
- data/tests/mxx_ru/change_default_value/ignoring_by_child_1/child_1.rb +5 -5
- data/tests/mxx_ru/change_default_value/ignoring_by_child_1/child_2.rb +5 -5
- data/tests/mxx_ru/change_default_value/ok/build.rb +8 -8
- data/tests/mxx_ru/change_default_value/ok/child_1.rb +8 -8
- data/tests/mxx_ru/lib_path/build.rb +8 -8
- data/tests/mxx_ru/lib_path/bye.rb +8 -8
- data/tests/mxx_ru/lib_path/hi.rb +8 -8
- data/tests/mxx_ru/lib_path/main.rb +12 -12
- data/tests/mxx_ru/lib_path/tc_lib_path.rb +18 -18
- data/tests/mxx_ru/obj_placements/tc_custom_subdir.rb +58 -58
- data/tests/mxx_ru/opt_lib_ext/build.rb +7 -7
- data/tests/mxx_ru/opt_lib_ext/hi.rb +7 -7
- data/tests/mxx_ru/opt_lib_ext/tc_opt_lib_ext.rb +18 -18
- data/tests/mxx_ru/opt_lib_ext/test-no-ext.rb +9 -9
- data/tests/mxx_ru/opt_lib_ext/test-with-ext.rb +13 -13
- data/tests/mxx_ru/plural_form_methods/tc.rb +72 -72
- data/tests/mxx_ru/qt_gen/tc_uic_result_subdir.rb +76 -76
- data/tests/mxx_ru/target_ext/prj_dll.rb +8 -8
- data/tests/mxx_ru/target_ext/prj_exe.rb +8 -8
- data/tests/mxx_ru/target_ext/prj_lib.rb +8 -8
- data/tests/mxx_ru/target_ext/tc_target_ext.rb +24 -24
- data/tests/mxx_ru/tc_makestyle_generator.rb +117 -117
- data/tests/mxx_ru/vc8/tc_actual_manifest.rb +230 -230
- data/tests/mxx_ru/vc8/tc_append_mt_commands.rb +104 -104
- data/tests/mxx_ru/vc8/tc_default_manifest.rb +17 -17
- data/tests/mxx_ru/vc8/tc_define_manifest.rb +173 -173
- data/tests/mxx_ru/vc8/tc_drop_default_manifest.rb +16 -16
- data/tests/mxx_ru/vc8/tc_invalid_params.rb +81 -81
- data/tests/mxx_ru/vc8/ts_vc8.rb +10 -10
- data/tests/qt/aclock/aclock.cpp +148 -148
- data/tests/qt/aclock/aclock.h +45 -45
- data/tests/qt/aclock/main.cpp +28 -28
- data/tests/qt/aclock/prj.rb +21 -21
- data/tests/qt/iconview/main.cpp +76 -76
- data/tests/qt/iconview/prj.rb +21 -21
- data/tests/qt/toplevel/main.cpp +9 -9
- data/tests/qt/toplevel/options.ui +587 -587
- data/tests/qt/toplevel/prj.rb +22 -22
- data/tests/test_with_compilation.rb +110 -110
- data/tests/unix/lib_linking_mode/a_shared.rb +7 -7
- data/tests/unix/lib_linking_mode/a_static.rb +7 -7
- data/tests/unix/lib_linking_mode/etalon/shared.txt +2 -2
- data/tests/unix/lib_linking_mode/etalon/static.txt +2 -2
- data/tests/unix/lib_linking_mode/main_conflict.rb +12 -12
- data/tests/unix/lib_linking_mode/main_conflict_2.rb +11 -11
- data/tests/unix/lib_linking_mode/main_shared.rb +9 -9
- data/tests/unix/lib_linking_mode/main_shared.ut.rb +11 -11
- data/tests/unix/lib_linking_mode/main_shared_2.rb +10 -10
- data/tests/unix/lib_linking_mode/main_shared_2.ut.rb +11 -11
- data/tests/unix/lib_linking_mode/main_static.rb +9 -9
- data/tests/unix/lib_linking_mode/main_static.ut.rb +11 -11
- data/tests/unix/lib_linking_mode/main_static_2.rb +10 -10
- data/tests/unix/lib_linking_mode/main_static_2.ut.rb +11 -11
- data/tests/unix/lib_linking_mode/tc_conflicted_build.rb +18 -18
- data/tests/unix/lib_linking_mode/tc_normal_build.rb +18 -18
- data/tests/unix/lib_order/tc_normal_build.rb +16 -16
- metadata +216 -205
data/tests/c/pcre/pcreposix.c
CHANGED
@@ -1,305 +1,305 @@
|
|
1
|
-
/*************************************************
|
2
|
-
* Perl-Compatible Regular Expressions *
|
3
|
-
*************************************************/
|
4
|
-
|
5
|
-
/*
|
6
|
-
This is a library of functions to support regular expressions whose syntax
|
7
|
-
and semantics are as close as possible to those of the Perl 5 language. See
|
8
|
-
the file Tech.Notes for some information on the internals.
|
9
|
-
|
10
|
-
This module is a wrapper that provides a POSIX API to the underlying PCRE
|
11
|
-
functions.
|
12
|
-
|
13
|
-
Written by: Philip Hazel <ph10@cam.ac.uk>
|
14
|
-
|
15
|
-
Copyright (c) 1997-2003 University of Cambridge
|
16
|
-
|
17
|
-
-----------------------------------------------------------------------------
|
18
|
-
Permission is granted to anyone to use this software for any purpose on any
|
19
|
-
computer system, and to redistribute it freely, subject to the following
|
20
|
-
restrictions:
|
21
|
-
|
22
|
-
1. This software is distributed in the hope that it will be useful,
|
23
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
24
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
25
|
-
|
26
|
-
2. The origin of this software must not be misrepresented, either by
|
27
|
-
explicit claim or by omission.
|
28
|
-
|
29
|
-
3. Altered versions must be plainly marked as such, and must not be
|
30
|
-
misrepresented as being the original software.
|
31
|
-
|
32
|
-
4. If PCRE is embedded in any software that is released under the GNU
|
33
|
-
General Purpose Licence (GPL), then the terms of that licence shall
|
34
|
-
supersede any condition above with which it is incompatible.
|
35
|
-
-----------------------------------------------------------------------------
|
36
|
-
*/
|
37
|
-
|
38
|
-
#include "internal.h"
|
39
|
-
#include "pcreposix.h"
|
40
|
-
#include "stdlib.h"
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
/* Corresponding tables of PCRE error messages and POSIX error codes. */
|
45
|
-
|
46
|
-
static const char *const estring[] = {
|
47
|
-
ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10,
|
48
|
-
ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20,
|
49
|
-
ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR29, ERR29, ERR30,
|
50
|
-
ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40,
|
51
|
-
ERR41, ERR42, ERR43, ERR44 };
|
52
|
-
|
53
|
-
static const int eint[] = {
|
54
|
-
REG_EESCAPE, /* "\\ at end of pattern" */
|
55
|
-
REG_EESCAPE, /* "\\c at end of pattern" */
|
56
|
-
REG_EESCAPE, /* "unrecognized character follows \\" */
|
57
|
-
REG_BADBR, /* "numbers out of order in {} quantifier" */
|
58
|
-
REG_BADBR, /* "number too big in {} quantifier" */
|
59
|
-
REG_EBRACK, /* "missing terminating ] for character class" */
|
60
|
-
REG_ECTYPE, /* "invalid escape sequence in character class" */
|
61
|
-
REG_ERANGE, /* "range out of order in character class" */
|
62
|
-
REG_BADRPT, /* "nothing to repeat" */
|
63
|
-
REG_BADRPT, /* "operand of unlimited repeat could match the empty string" */
|
64
|
-
REG_ASSERT, /* "internal error: unexpected repeat" */
|
65
|
-
REG_BADPAT, /* "unrecognized character after (?" */
|
66
|
-
REG_BADPAT, /* "POSIX named classes are supported only within a class" */
|
67
|
-
REG_EPAREN, /* "missing )" */
|
68
|
-
REG_ESUBREG, /* "reference to non-existent subpattern" */
|
69
|
-
REG_INVARG, /* "erroffset passed as NULL" */
|
70
|
-
REG_INVARG, /* "unknown option bit(s) set" */
|
71
|
-
REG_EPAREN, /* "missing ) after comment" */
|
72
|
-
REG_ESIZE, /* "parentheses nested too deeply" */
|
73
|
-
REG_ESIZE, /* "regular expression too large" */
|
74
|
-
REG_ESPACE, /* "failed to get memory" */
|
75
|
-
REG_EPAREN, /* "unmatched brackets" */
|
76
|
-
REG_ASSERT, /* "internal error: code overflow" */
|
77
|
-
REG_BADPAT, /* "unrecognized character after (?<" */
|
78
|
-
REG_BADPAT, /* "lookbehind assertion is not fixed length" */
|
79
|
-
REG_BADPAT, /* "malformed number after (?(" */
|
80
|
-
REG_BADPAT, /* "conditional group containe more than two branches" */
|
81
|
-
REG_BADPAT, /* "assertion expected after (?(" */
|
82
|
-
REG_BADPAT, /* "(?R or (?digits must be followed by )" */
|
83
|
-
REG_ECTYPE, /* "unknown POSIX class name" */
|
84
|
-
REG_BADPAT, /* "POSIX collating elements are not supported" */
|
85
|
-
REG_INVARG, /* "this version of PCRE is not compiled with PCRE_UTF8 support" */
|
86
|
-
REG_BADPAT, /* "spare error" */
|
87
|
-
REG_BADPAT, /* "character value in \x{...} sequence is too large" */
|
88
|
-
REG_BADPAT, /* "invalid condition (?(0)" */
|
89
|
-
REG_BADPAT, /* "\\C not allowed in lookbehind assertion" */
|
90
|
-
REG_EESCAPE, /* "PCRE does not support \\L, \\l, \\N, \\P, \\p, \\U, \\u, or \\X" */
|
91
|
-
REG_BADPAT, /* "number after (?C is > 255" */
|
92
|
-
REG_BADPAT, /* "closing ) for (?C expected" */
|
93
|
-
REG_BADPAT, /* "recursive call could loop indefinitely" */
|
94
|
-
REG_BADPAT, /* "unrecognized character after (?P" */
|
95
|
-
REG_BADPAT, /* "syntax error after (?P" */
|
96
|
-
REG_BADPAT, /* "two named groups have the same name" */
|
97
|
-
REG_BADPAT /* "invalid UTF-8 string" */
|
98
|
-
};
|
99
|
-
|
100
|
-
/* Table of texts corresponding to POSIX error codes */
|
101
|
-
|
102
|
-
static const char *const pstring[] = {
|
103
|
-
"", /* Dummy for value 0 */
|
104
|
-
"internal error", /* REG_ASSERT */
|
105
|
-
"invalid repeat counts in {}", /* BADBR */
|
106
|
-
"pattern error", /* BADPAT */
|
107
|
-
"? * + invalid", /* BADRPT */
|
108
|
-
"unbalanced {}", /* EBRACE */
|
109
|
-
"unbalanced []", /* EBRACK */
|
110
|
-
"collation error - not relevant", /* ECOLLATE */
|
111
|
-
"bad class", /* ECTYPE */
|
112
|
-
"bad escape sequence", /* EESCAPE */
|
113
|
-
"empty expression", /* EMPTY */
|
114
|
-
"unbalanced ()", /* EPAREN */
|
115
|
-
"bad range inside []", /* ERANGE */
|
116
|
-
"expression too big", /* ESIZE */
|
117
|
-
"failed to get memory", /* ESPACE */
|
118
|
-
"bad back reference", /* ESUBREG */
|
119
|
-
"bad argument", /* INVARG */
|
120
|
-
"match failed" /* NOMATCH */
|
121
|
-
};
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
/*************************************************
|
127
|
-
* Translate PCRE text code to int *
|
128
|
-
*************************************************/
|
129
|
-
|
130
|
-
/* PCRE compile-time errors are given as strings defined as macros. We can just
|
131
|
-
look them up in a table to turn them into POSIX-style error codes. */
|
132
|
-
|
133
|
-
static int
|
134
|
-
pcre_posix_error_code(const char *s)
|
135
|
-
{
|
136
|
-
size_t i;
|
137
|
-
for (i = 0; i < sizeof(estring)/sizeof(char *); i++)
|
138
|
-
if (strcmp(s, estring[i]) == 0) return eint[i];
|
139
|
-
return REG_ASSERT;
|
140
|
-
}
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
/*************************************************
|
145
|
-
* Translate error code to string *
|
146
|
-
*************************************************/
|
147
|
-
|
148
|
-
EXPORT size_t
|
149
|
-
regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
|
150
|
-
{
|
151
|
-
const char *message, *addmessage;
|
152
|
-
size_t length, addlength;
|
153
|
-
|
154
|
-
message = (errcode >= (int)(sizeof(pstring)/sizeof(char *)))?
|
155
|
-
"unknown error code" : pstring[errcode];
|
156
|
-
length = strlen(message) + 1;
|
157
|
-
|
158
|
-
addmessage = " at offset ";
|
159
|
-
addlength = (preg != NULL && (int)preg->re_erroffset != -1)?
|
160
|
-
strlen(addmessage) + 6 : 0;
|
161
|
-
|
162
|
-
if (errbuf_size > 0)
|
163
|
-
{
|
164
|
-
if (addlength > 0 && errbuf_size >= length + addlength)
|
165
|
-
sprintf(errbuf, "%s%s%-6d", message, addmessage, (int)preg->re_erroffset);
|
166
|
-
else
|
167
|
-
{
|
168
|
-
strncpy(errbuf, message, errbuf_size - 1);
|
169
|
-
errbuf[errbuf_size-1] = 0;
|
170
|
-
}
|
171
|
-
}
|
172
|
-
|
173
|
-
return length + addlength;
|
174
|
-
}
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
/*************************************************
|
180
|
-
* Free store held by a regex *
|
181
|
-
*************************************************/
|
182
|
-
|
183
|
-
EXPORT void
|
184
|
-
regfree(regex_t *preg)
|
185
|
-
{
|
186
|
-
(pcre_free)(preg->re_pcre);
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
/*************************************************
|
193
|
-
* Compile a regular expression *
|
194
|
-
*************************************************/
|
195
|
-
|
196
|
-
/*
|
197
|
-
Arguments:
|
198
|
-
preg points to a structure for recording the compiled expression
|
199
|
-
pattern the pattern to compile
|
200
|
-
cflags compilation flags
|
201
|
-
|
202
|
-
Returns: 0 on success
|
203
|
-
various non-zero codes on failure
|
204
|
-
*/
|
205
|
-
|
206
|
-
EXPORT int
|
207
|
-
regcomp(regex_t *preg, const char *pattern, int cflags)
|
208
|
-
{
|
209
|
-
const char *errorptr;
|
210
|
-
int erroffset;
|
211
|
-
int options = 0;
|
212
|
-
|
213
|
-
if ((cflags & REG_ICASE) != 0) options |= PCRE_CASELESS;
|
214
|
-
if ((cflags & REG_NEWLINE) != 0) options |= PCRE_MULTILINE;
|
215
|
-
|
216
|
-
preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset, NULL);
|
217
|
-
preg->re_erroffset = erroffset;
|
218
|
-
|
219
|
-
if (preg->re_pcre == NULL) return pcre_posix_error_code(errorptr);
|
220
|
-
|
221
|
-
preg->re_nsub = pcre_info((const pcre *)preg->re_pcre, NULL, NULL);
|
222
|
-
return 0;
|
223
|
-
}
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
/*************************************************
|
229
|
-
* Match a regular expression *
|
230
|
-
*************************************************/
|
231
|
-
|
232
|
-
/* Unfortunately, PCRE requires 3 ints of working space for each captured
|
233
|
-
substring, so we have to get and release working store instead of just using
|
234
|
-
the POSIX structures as was done in earlier releases when PCRE needed only 2
|
235
|
-
ints. However, if the number of possible capturing brackets is small, use a
|
236
|
-
block of store on the stack, to reduce the use of malloc/free. The threshold is
|
237
|
-
in a macro that can be changed at configure time. */
|
238
|
-
|
239
|
-
EXPORT int
|
240
|
-
regexec(const regex_t *preg, const char *string, size_t nmatch,
|
241
|
-
regmatch_t pmatch[], int eflags)
|
242
|
-
{
|
243
|
-
int rc;
|
244
|
-
int options = 0;
|
245
|
-
int *ovector = NULL;
|
246
|
-
int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
|
247
|
-
BOOL allocated_ovector = FALSE;
|
248
|
-
|
249
|
-
if ((eflags & REG_NOTBOL) != 0) options |= PCRE_NOTBOL;
|
250
|
-
if ((eflags & REG_NOTEOL) != 0) options |= PCRE_NOTEOL;
|
251
|
-
|
252
|
-
((regex_t *)preg)->re_erroffset = (size_t)(-1); /* Only has meaning after compile */
|
253
|
-
|
254
|
-
if (nmatch > 0)
|
255
|
-
{
|
256
|
-
if (nmatch <= POSIX_MALLOC_THRESHOLD)
|
257
|
-
{
|
258
|
-
ovector = &(small_ovector[0]);
|
259
|
-
}
|
260
|
-
else
|
261
|
-
{
|
262
|
-
ovector = (int *)malloc(sizeof(int) * nmatch * 3);
|
263
|
-
if (ovector == NULL) return REG_ESPACE;
|
264
|
-
allocated_ovector = TRUE;
|
265
|
-
}
|
266
|
-
}
|
267
|
-
|
268
|
-
rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string, (int)strlen(string),
|
269
|
-
0, options, ovector, nmatch * 3);
|
270
|
-
|
271
|
-
if (rc == 0) rc = nmatch; /* All captured slots were filled in */
|
272
|
-
|
273
|
-
if (rc >= 0)
|
274
|
-
{
|
275
|
-
size_t i;
|
276
|
-
for (i = 0; i < (size_t)rc; i++)
|
277
|
-
{
|
278
|
-
pmatch[i].rm_so = ovector[i*2];
|
279
|
-
pmatch[i].rm_eo = ovector[i*2+1];
|
280
|
-
}
|
281
|
-
if (allocated_ovector) free(ovector);
|
282
|
-
for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
|
283
|
-
return 0;
|
284
|
-
}
|
285
|
-
|
286
|
-
else
|
287
|
-
{
|
288
|
-
if (allocated_ovector) free(ovector);
|
289
|
-
switch(rc)
|
290
|
-
{
|
291
|
-
case PCRE_ERROR_NOMATCH: return REG_NOMATCH;
|
292
|
-
case PCRE_ERROR_NULL: return REG_INVARG;
|
293
|
-
case PCRE_ERROR_BADOPTION: return REG_INVARG;
|
294
|
-
case PCRE_ERROR_BADMAGIC: return REG_INVARG;
|
295
|
-
case PCRE_ERROR_UNKNOWN_NODE: return REG_ASSERT;
|
296
|
-
case PCRE_ERROR_NOMEMORY: return REG_ESPACE;
|
297
|
-
case PCRE_ERROR_MATCHLIMIT: return REG_ESPACE;
|
298
|
-
case PCRE_ERROR_BADUTF8: return REG_INVARG;
|
299
|
-
case PCRE_ERROR_BADUTF8_OFFSET: return REG_INVARG;
|
300
|
-
default: return REG_ASSERT;
|
301
|
-
}
|
302
|
-
}
|
303
|
-
}
|
304
|
-
|
305
|
-
/* End of pcreposix.c */
|
1
|
+
/*************************************************
|
2
|
+
* Perl-Compatible Regular Expressions *
|
3
|
+
*************************************************/
|
4
|
+
|
5
|
+
/*
|
6
|
+
This is a library of functions to support regular expressions whose syntax
|
7
|
+
and semantics are as close as possible to those of the Perl 5 language. See
|
8
|
+
the file Tech.Notes for some information on the internals.
|
9
|
+
|
10
|
+
This module is a wrapper that provides a POSIX API to the underlying PCRE
|
11
|
+
functions.
|
12
|
+
|
13
|
+
Written by: Philip Hazel <ph10@cam.ac.uk>
|
14
|
+
|
15
|
+
Copyright (c) 1997-2003 University of Cambridge
|
16
|
+
|
17
|
+
-----------------------------------------------------------------------------
|
18
|
+
Permission is granted to anyone to use this software for any purpose on any
|
19
|
+
computer system, and to redistribute it freely, subject to the following
|
20
|
+
restrictions:
|
21
|
+
|
22
|
+
1. This software is distributed in the hope that it will be useful,
|
23
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
24
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
25
|
+
|
26
|
+
2. The origin of this software must not be misrepresented, either by
|
27
|
+
explicit claim or by omission.
|
28
|
+
|
29
|
+
3. Altered versions must be plainly marked as such, and must not be
|
30
|
+
misrepresented as being the original software.
|
31
|
+
|
32
|
+
4. If PCRE is embedded in any software that is released under the GNU
|
33
|
+
General Purpose Licence (GPL), then the terms of that licence shall
|
34
|
+
supersede any condition above with which it is incompatible.
|
35
|
+
-----------------------------------------------------------------------------
|
36
|
+
*/
|
37
|
+
|
38
|
+
#include "internal.h"
|
39
|
+
#include "pcreposix.h"
|
40
|
+
#include "stdlib.h"
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
/* Corresponding tables of PCRE error messages and POSIX error codes. */
|
45
|
+
|
46
|
+
static const char *const estring[] = {
|
47
|
+
ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10,
|
48
|
+
ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20,
|
49
|
+
ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR29, ERR29, ERR30,
|
50
|
+
ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40,
|
51
|
+
ERR41, ERR42, ERR43, ERR44 };
|
52
|
+
|
53
|
+
static const int eint[] = {
|
54
|
+
REG_EESCAPE, /* "\\ at end of pattern" */
|
55
|
+
REG_EESCAPE, /* "\\c at end of pattern" */
|
56
|
+
REG_EESCAPE, /* "unrecognized character follows \\" */
|
57
|
+
REG_BADBR, /* "numbers out of order in {} quantifier" */
|
58
|
+
REG_BADBR, /* "number too big in {} quantifier" */
|
59
|
+
REG_EBRACK, /* "missing terminating ] for character class" */
|
60
|
+
REG_ECTYPE, /* "invalid escape sequence in character class" */
|
61
|
+
REG_ERANGE, /* "range out of order in character class" */
|
62
|
+
REG_BADRPT, /* "nothing to repeat" */
|
63
|
+
REG_BADRPT, /* "operand of unlimited repeat could match the empty string" */
|
64
|
+
REG_ASSERT, /* "internal error: unexpected repeat" */
|
65
|
+
REG_BADPAT, /* "unrecognized character after (?" */
|
66
|
+
REG_BADPAT, /* "POSIX named classes are supported only within a class" */
|
67
|
+
REG_EPAREN, /* "missing )" */
|
68
|
+
REG_ESUBREG, /* "reference to non-existent subpattern" */
|
69
|
+
REG_INVARG, /* "erroffset passed as NULL" */
|
70
|
+
REG_INVARG, /* "unknown option bit(s) set" */
|
71
|
+
REG_EPAREN, /* "missing ) after comment" */
|
72
|
+
REG_ESIZE, /* "parentheses nested too deeply" */
|
73
|
+
REG_ESIZE, /* "regular expression too large" */
|
74
|
+
REG_ESPACE, /* "failed to get memory" */
|
75
|
+
REG_EPAREN, /* "unmatched brackets" */
|
76
|
+
REG_ASSERT, /* "internal error: code overflow" */
|
77
|
+
REG_BADPAT, /* "unrecognized character after (?<" */
|
78
|
+
REG_BADPAT, /* "lookbehind assertion is not fixed length" */
|
79
|
+
REG_BADPAT, /* "malformed number after (?(" */
|
80
|
+
REG_BADPAT, /* "conditional group containe more than two branches" */
|
81
|
+
REG_BADPAT, /* "assertion expected after (?(" */
|
82
|
+
REG_BADPAT, /* "(?R or (?digits must be followed by )" */
|
83
|
+
REG_ECTYPE, /* "unknown POSIX class name" */
|
84
|
+
REG_BADPAT, /* "POSIX collating elements are not supported" */
|
85
|
+
REG_INVARG, /* "this version of PCRE is not compiled with PCRE_UTF8 support" */
|
86
|
+
REG_BADPAT, /* "spare error" */
|
87
|
+
REG_BADPAT, /* "character value in \x{...} sequence is too large" */
|
88
|
+
REG_BADPAT, /* "invalid condition (?(0)" */
|
89
|
+
REG_BADPAT, /* "\\C not allowed in lookbehind assertion" */
|
90
|
+
REG_EESCAPE, /* "PCRE does not support \\L, \\l, \\N, \\P, \\p, \\U, \\u, or \\X" */
|
91
|
+
REG_BADPAT, /* "number after (?C is > 255" */
|
92
|
+
REG_BADPAT, /* "closing ) for (?C expected" */
|
93
|
+
REG_BADPAT, /* "recursive call could loop indefinitely" */
|
94
|
+
REG_BADPAT, /* "unrecognized character after (?P" */
|
95
|
+
REG_BADPAT, /* "syntax error after (?P" */
|
96
|
+
REG_BADPAT, /* "two named groups have the same name" */
|
97
|
+
REG_BADPAT /* "invalid UTF-8 string" */
|
98
|
+
};
|
99
|
+
|
100
|
+
/* Table of texts corresponding to POSIX error codes */
|
101
|
+
|
102
|
+
static const char *const pstring[] = {
|
103
|
+
"", /* Dummy for value 0 */
|
104
|
+
"internal error", /* REG_ASSERT */
|
105
|
+
"invalid repeat counts in {}", /* BADBR */
|
106
|
+
"pattern error", /* BADPAT */
|
107
|
+
"? * + invalid", /* BADRPT */
|
108
|
+
"unbalanced {}", /* EBRACE */
|
109
|
+
"unbalanced []", /* EBRACK */
|
110
|
+
"collation error - not relevant", /* ECOLLATE */
|
111
|
+
"bad class", /* ECTYPE */
|
112
|
+
"bad escape sequence", /* EESCAPE */
|
113
|
+
"empty expression", /* EMPTY */
|
114
|
+
"unbalanced ()", /* EPAREN */
|
115
|
+
"bad range inside []", /* ERANGE */
|
116
|
+
"expression too big", /* ESIZE */
|
117
|
+
"failed to get memory", /* ESPACE */
|
118
|
+
"bad back reference", /* ESUBREG */
|
119
|
+
"bad argument", /* INVARG */
|
120
|
+
"match failed" /* NOMATCH */
|
121
|
+
};
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
/*************************************************
|
127
|
+
* Translate PCRE text code to int *
|
128
|
+
*************************************************/
|
129
|
+
|
130
|
+
/* PCRE compile-time errors are given as strings defined as macros. We can just
|
131
|
+
look them up in a table to turn them into POSIX-style error codes. */
|
132
|
+
|
133
|
+
static int
|
134
|
+
pcre_posix_error_code(const char *s)
|
135
|
+
{
|
136
|
+
size_t i;
|
137
|
+
for (i = 0; i < sizeof(estring)/sizeof(char *); i++)
|
138
|
+
if (strcmp(s, estring[i]) == 0) return eint[i];
|
139
|
+
return REG_ASSERT;
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
/*************************************************
|
145
|
+
* Translate error code to string *
|
146
|
+
*************************************************/
|
147
|
+
|
148
|
+
EXPORT size_t
|
149
|
+
regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
|
150
|
+
{
|
151
|
+
const char *message, *addmessage;
|
152
|
+
size_t length, addlength;
|
153
|
+
|
154
|
+
message = (errcode >= (int)(sizeof(pstring)/sizeof(char *)))?
|
155
|
+
"unknown error code" : pstring[errcode];
|
156
|
+
length = strlen(message) + 1;
|
157
|
+
|
158
|
+
addmessage = " at offset ";
|
159
|
+
addlength = (preg != NULL && (int)preg->re_erroffset != -1)?
|
160
|
+
strlen(addmessage) + 6 : 0;
|
161
|
+
|
162
|
+
if (errbuf_size > 0)
|
163
|
+
{
|
164
|
+
if (addlength > 0 && errbuf_size >= length + addlength)
|
165
|
+
sprintf(errbuf, "%s%s%-6d", message, addmessage, (int)preg->re_erroffset);
|
166
|
+
else
|
167
|
+
{
|
168
|
+
strncpy(errbuf, message, errbuf_size - 1);
|
169
|
+
errbuf[errbuf_size-1] = 0;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
return length + addlength;
|
174
|
+
}
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
/*************************************************
|
180
|
+
* Free store held by a regex *
|
181
|
+
*************************************************/
|
182
|
+
|
183
|
+
EXPORT void
|
184
|
+
regfree(regex_t *preg)
|
185
|
+
{
|
186
|
+
(pcre_free)(preg->re_pcre);
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
/*************************************************
|
193
|
+
* Compile a regular expression *
|
194
|
+
*************************************************/
|
195
|
+
|
196
|
+
/*
|
197
|
+
Arguments:
|
198
|
+
preg points to a structure for recording the compiled expression
|
199
|
+
pattern the pattern to compile
|
200
|
+
cflags compilation flags
|
201
|
+
|
202
|
+
Returns: 0 on success
|
203
|
+
various non-zero codes on failure
|
204
|
+
*/
|
205
|
+
|
206
|
+
EXPORT int
|
207
|
+
regcomp(regex_t *preg, const char *pattern, int cflags)
|
208
|
+
{
|
209
|
+
const char *errorptr;
|
210
|
+
int erroffset;
|
211
|
+
int options = 0;
|
212
|
+
|
213
|
+
if ((cflags & REG_ICASE) != 0) options |= PCRE_CASELESS;
|
214
|
+
if ((cflags & REG_NEWLINE) != 0) options |= PCRE_MULTILINE;
|
215
|
+
|
216
|
+
preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset, NULL);
|
217
|
+
preg->re_erroffset = erroffset;
|
218
|
+
|
219
|
+
if (preg->re_pcre == NULL) return pcre_posix_error_code(errorptr);
|
220
|
+
|
221
|
+
preg->re_nsub = pcre_info((const pcre *)preg->re_pcre, NULL, NULL);
|
222
|
+
return 0;
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
/*************************************************
|
229
|
+
* Match a regular expression *
|
230
|
+
*************************************************/
|
231
|
+
|
232
|
+
/* Unfortunately, PCRE requires 3 ints of working space for each captured
|
233
|
+
substring, so we have to get and release working store instead of just using
|
234
|
+
the POSIX structures as was done in earlier releases when PCRE needed only 2
|
235
|
+
ints. However, if the number of possible capturing brackets is small, use a
|
236
|
+
block of store on the stack, to reduce the use of malloc/free. The threshold is
|
237
|
+
in a macro that can be changed at configure time. */
|
238
|
+
|
239
|
+
EXPORT int
|
240
|
+
regexec(const regex_t *preg, const char *string, size_t nmatch,
|
241
|
+
regmatch_t pmatch[], int eflags)
|
242
|
+
{
|
243
|
+
int rc;
|
244
|
+
int options = 0;
|
245
|
+
int *ovector = NULL;
|
246
|
+
int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
|
247
|
+
BOOL allocated_ovector = FALSE;
|
248
|
+
|
249
|
+
if ((eflags & REG_NOTBOL) != 0) options |= PCRE_NOTBOL;
|
250
|
+
if ((eflags & REG_NOTEOL) != 0) options |= PCRE_NOTEOL;
|
251
|
+
|
252
|
+
((regex_t *)preg)->re_erroffset = (size_t)(-1); /* Only has meaning after compile */
|
253
|
+
|
254
|
+
if (nmatch > 0)
|
255
|
+
{
|
256
|
+
if (nmatch <= POSIX_MALLOC_THRESHOLD)
|
257
|
+
{
|
258
|
+
ovector = &(small_ovector[0]);
|
259
|
+
}
|
260
|
+
else
|
261
|
+
{
|
262
|
+
ovector = (int *)malloc(sizeof(int) * nmatch * 3);
|
263
|
+
if (ovector == NULL) return REG_ESPACE;
|
264
|
+
allocated_ovector = TRUE;
|
265
|
+
}
|
266
|
+
}
|
267
|
+
|
268
|
+
rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string, (int)strlen(string),
|
269
|
+
0, options, ovector, nmatch * 3);
|
270
|
+
|
271
|
+
if (rc == 0) rc = nmatch; /* All captured slots were filled in */
|
272
|
+
|
273
|
+
if (rc >= 0)
|
274
|
+
{
|
275
|
+
size_t i;
|
276
|
+
for (i = 0; i < (size_t)rc; i++)
|
277
|
+
{
|
278
|
+
pmatch[i].rm_so = ovector[i*2];
|
279
|
+
pmatch[i].rm_eo = ovector[i*2+1];
|
280
|
+
}
|
281
|
+
if (allocated_ovector) free(ovector);
|
282
|
+
for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
|
283
|
+
return 0;
|
284
|
+
}
|
285
|
+
|
286
|
+
else
|
287
|
+
{
|
288
|
+
if (allocated_ovector) free(ovector);
|
289
|
+
switch(rc)
|
290
|
+
{
|
291
|
+
case PCRE_ERROR_NOMATCH: return REG_NOMATCH;
|
292
|
+
case PCRE_ERROR_NULL: return REG_INVARG;
|
293
|
+
case PCRE_ERROR_BADOPTION: return REG_INVARG;
|
294
|
+
case PCRE_ERROR_BADMAGIC: return REG_INVARG;
|
295
|
+
case PCRE_ERROR_UNKNOWN_NODE: return REG_ASSERT;
|
296
|
+
case PCRE_ERROR_NOMEMORY: return REG_ESPACE;
|
297
|
+
case PCRE_ERROR_MATCHLIMIT: return REG_ESPACE;
|
298
|
+
case PCRE_ERROR_BADUTF8: return REG_INVARG;
|
299
|
+
case PCRE_ERROR_BADUTF8_OFFSET: return REG_INVARG;
|
300
|
+
default: return REG_ASSERT;
|
301
|
+
}
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
/* End of pcreposix.c */
|