Mxx_ru 1.3.0 → 1.3.1
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 -59
- 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 -424
- data/lib/mxx_ru/cpp/toolsets/gcc_linux.rb +64 -64
- data/lib/mxx_ru/cpp/toolsets/gcc_mingw.rb +150 -150
- data/lib/mxx_ru/cpp/toolsets/gcc_sparc_solaris.rb +91 -91
- data/lib/mxx_ru/cpp/toolsets/gcc_unix_family.rb +103 -84
- 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/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/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/a.cpp +4 -0
- data/tests/unix/lib_order/a.hpp +1 -0
- data/tests/unix/lib_order/a.rb +8 -0
- data/tests/unix/lib_order/b.cpp +10 -0
- data/tests/unix/lib_order/b.hpp +1 -0
- data/tests/unix/lib_order/b.rb +8 -0
- data/tests/unix/lib_order/build.rb +9 -0
- data/tests/unix/lib_order/c.cpp +12 -0
- data/tests/unix/lib_order/c.hpp +2 -0
- data/tests/unix/lib_order/c.rb +8 -0
- data/tests/unix/lib_order/d.cpp +7 -0
- data/tests/unix/lib_order/d.hpp +1 -0
- data/tests/unix/lib_order/d.rb +8 -0
- data/tests/unix/lib_order/main.cpp +7 -0
- data/tests/unix/lib_order/main.rb +14 -0
- data/tests/unix/lib_order/tc_normal_build.rb +16 -0
- metadata +342 -319
data/tests/c/pcre/pcre.h
CHANGED
@@ -1,193 +1,193 @@
|
|
1
|
-
/*************************************************
|
2
|
-
* Perl-Compatible Regular Expressions *
|
3
|
-
*************************************************/
|
4
|
-
|
5
|
-
/* Copyright (c) 1997-2003 University of Cambridge */
|
6
|
-
|
7
|
-
#ifndef _PCRE_H
|
8
|
-
#define _PCRE_H
|
9
|
-
|
10
|
-
/* The file pcre.h is build by "configure". Do not edit it; instead
|
11
|
-
make changes to pcre.in. */
|
12
|
-
|
13
|
-
#define PCRE_MAJOR @PCRE_MAJOR@
|
14
|
-
#define PCRE_MINOR @PCRE_MINOR@
|
15
|
-
#define PCRE_DATE @PCRE_DATE@
|
16
|
-
|
17
|
-
/* Win32 uses DLL by default */
|
18
|
-
|
19
|
-
#ifdef _WIN32
|
20
|
-
# ifdef PCRE_DEFINITION
|
21
|
-
# ifdef DLL_EXPORT
|
22
|
-
# define PCRE_DATA_SCOPE __declspec(dllexport)
|
23
|
-
# endif
|
24
|
-
# else
|
25
|
-
# ifndef PCRE_STATIC
|
26
|
-
# define PCRE_DATA_SCOPE extern __declspec(dllimport)
|
27
|
-
# endif
|
28
|
-
# endif
|
29
|
-
#endif
|
30
|
-
#ifndef PCRE_DATA_SCOPE
|
31
|
-
# define PCRE_DATA_SCOPE extern
|
32
|
-
#endif
|
33
|
-
|
34
|
-
/* Have to include stdlib.h in order to ensure that size_t is defined;
|
35
|
-
it is needed here for malloc. */
|
36
|
-
|
37
|
-
#include <stdlib.h>
|
38
|
-
|
39
|
-
/* Allow for C++ users */
|
40
|
-
|
41
|
-
#ifdef __cplusplus
|
42
|
-
extern "C" {
|
43
|
-
#endif
|
44
|
-
|
45
|
-
/* Options */
|
46
|
-
|
47
|
-
#define PCRE_CASELESS 0x0001
|
48
|
-
#define PCRE_MULTILINE 0x0002
|
49
|
-
#define PCRE_DOTALL 0x0004
|
50
|
-
#define PCRE_EXTENDED 0x0008
|
51
|
-
#define PCRE_ANCHORED 0x0010
|
52
|
-
#define PCRE_DOLLAR_ENDONLY 0x0020
|
53
|
-
#define PCRE_EXTRA 0x0040
|
54
|
-
#define PCRE_NOTBOL 0x0080
|
55
|
-
#define PCRE_NOTEOL 0x0100
|
56
|
-
#define PCRE_UNGREEDY 0x0200
|
57
|
-
#define PCRE_NOTEMPTY 0x0400
|
58
|
-
#define PCRE_UTF8 0x0800
|
59
|
-
#define PCRE_NO_AUTO_CAPTURE 0x1000
|
60
|
-
#define PCRE_NO_UTF8_CHECK 0x2000
|
61
|
-
|
62
|
-
/* Exec-time and get/set-time error codes */
|
63
|
-
|
64
|
-
#define PCRE_ERROR_NOMATCH (-1)
|
65
|
-
#define PCRE_ERROR_NULL (-2)
|
66
|
-
#define PCRE_ERROR_BADOPTION (-3)
|
67
|
-
#define PCRE_ERROR_BADMAGIC (-4)
|
68
|
-
#define PCRE_ERROR_UNKNOWN_NODE (-5)
|
69
|
-
#define PCRE_ERROR_NOMEMORY (-6)
|
70
|
-
#define PCRE_ERROR_NOSUBSTRING (-7)
|
71
|
-
#define PCRE_ERROR_MATCHLIMIT (-8)
|
72
|
-
#define PCRE_ERROR_CALLOUT (-9) /* Never used by PCRE itself */
|
73
|
-
#define PCRE_ERROR_BADUTF8 (-10)
|
74
|
-
#define PCRE_ERROR_BADUTF8_OFFSET (-11)
|
75
|
-
|
76
|
-
/* Request types for pcre_fullinfo() */
|
77
|
-
|
78
|
-
#define PCRE_INFO_OPTIONS 0
|
79
|
-
#define PCRE_INFO_SIZE 1
|
80
|
-
#define PCRE_INFO_CAPTURECOUNT 2
|
81
|
-
#define PCRE_INFO_BACKREFMAX 3
|
82
|
-
#define PCRE_INFO_FIRSTBYTE 4
|
83
|
-
#define PCRE_INFO_FIRSTCHAR 4 /* For backwards compatibility */
|
84
|
-
#define PCRE_INFO_FIRSTTABLE 5
|
85
|
-
#define PCRE_INFO_LASTLITERAL 6
|
86
|
-
#define PCRE_INFO_NAMEENTRYSIZE 7
|
87
|
-
#define PCRE_INFO_NAMECOUNT 8
|
88
|
-
#define PCRE_INFO_NAMETABLE 9
|
89
|
-
#define PCRE_INFO_STUDYSIZE 10
|
90
|
-
|
91
|
-
/* Request types for pcre_config() */
|
92
|
-
|
93
|
-
#define PCRE_CONFIG_UTF8 0
|
94
|
-
#define PCRE_CONFIG_NEWLINE 1
|
95
|
-
#define PCRE_CONFIG_LINK_SIZE 2
|
96
|
-
#define PCRE_CONFIG_POSIX_MALLOC_THRESHOLD 3
|
97
|
-
#define PCRE_CONFIG_MATCH_LIMIT 4
|
98
|
-
#define PCRE_CONFIG_STACKRECURSE 5
|
99
|
-
|
100
|
-
/* Bit flags for the pcre_extra structure */
|
101
|
-
|
102
|
-
#define PCRE_EXTRA_STUDY_DATA 0x0001
|
103
|
-
#define PCRE_EXTRA_MATCH_LIMIT 0x0002
|
104
|
-
#define PCRE_EXTRA_CALLOUT_DATA 0x0004
|
105
|
-
|
106
|
-
/* Types */
|
107
|
-
|
108
|
-
struct real_pcre; /* declaration; the definition is private */
|
109
|
-
typedef struct real_pcre pcre;
|
110
|
-
|
111
|
-
/* The structure for passing additional data to pcre_exec(). This is defined in
|
112
|
-
such as way as to be extensible. */
|
113
|
-
|
114
|
-
typedef struct pcre_extra {
|
115
|
-
unsigned long int flags; /* Bits for which fields are set */
|
116
|
-
void *study_data; /* Opaque data from pcre_study() */
|
117
|
-
unsigned long int match_limit; /* Maximum number of calls to match() */
|
118
|
-
void *callout_data; /* Data passed back in callouts */
|
119
|
-
} pcre_extra;
|
120
|
-
|
121
|
-
/* The structure for passing out data via the pcre_callout_function. We use a
|
122
|
-
structure so that new fields can be added on the end in future versions,
|
123
|
-
without changing the API of the function, thereby allowing old clients to work
|
124
|
-
without modification. */
|
125
|
-
|
126
|
-
typedef struct pcre_callout_block {
|
127
|
-
int version; /* Identifies version of block */
|
128
|
-
/* ------------------------ Version 0 ------------------------------- */
|
129
|
-
int callout_number; /* Number compiled into pattern */
|
130
|
-
int *offset_vector; /* The offset vector */
|
131
|
-
const char *subject; /* The subject being matched */
|
132
|
-
int subject_length; /* The length of the subject */
|
133
|
-
int start_match; /* Offset to start of this match attempt */
|
134
|
-
int current_position; /* Where we currently are */
|
135
|
-
int capture_top; /* Max current capture */
|
136
|
-
int capture_last; /* Most recently closed capture */
|
137
|
-
void *callout_data; /* Data passed in with the call */
|
138
|
-
/* ------------------------------------------------------------------ */
|
139
|
-
} pcre_callout_block;
|
140
|
-
|
141
|
-
/* Indirection for store get and free functions. These can be set to
|
142
|
-
alternative malloc/free functions if required. Special ones are used in the
|
143
|
-
non-recursive case for "frames". There is also an optional callout function
|
144
|
-
that is triggered by the (?) regex item. Some magic is required for Win32 DLL;
|
145
|
-
it is null on other OS. For Virtual Pascal, these have to be different again.
|
146
|
-
*/
|
147
|
-
|
148
|
-
#ifndef VPCOMPAT
|
149
|
-
PCRE_DATA_SCOPE void *(*pcre_malloc)(size_t);
|
150
|
-
PCRE_DATA_SCOPE void (*pcre_free)(void *);
|
151
|
-
PCRE_DATA_SCOPE void *(*pcre_stack_malloc)(size_t);
|
152
|
-
PCRE_DATA_SCOPE void (*pcre_stack_free)(void *);
|
153
|
-
PCRE_DATA_SCOPE int (*pcre_callout)(pcre_callout_block *);
|
154
|
-
#else /* VPCOMPAT */
|
155
|
-
extern void *pcre_malloc(size_t);
|
156
|
-
extern void pcre_free(void *);
|
157
|
-
extern void *pcre_stack_malloc(size_t);
|
158
|
-
extern void pcre_stack_free(void *);
|
159
|
-
extern int pcre_callout(pcre_callout_block *);
|
160
|
-
#endif /* VPCOMPAT */
|
161
|
-
|
162
|
-
/* Exported PCRE functions */
|
163
|
-
|
164
|
-
extern pcre *pcre_compile(const char *, int, const char **,
|
165
|
-
int *, const unsigned char *);
|
166
|
-
extern int pcre_config(int, void *);
|
167
|
-
extern int pcre_copy_named_substring(const pcre *, const char *,
|
168
|
-
int *, int, const char *, char *, int);
|
169
|
-
extern int pcre_copy_substring(const char *, int *, int, int,
|
170
|
-
char *, int);
|
171
|
-
extern int pcre_exec(const pcre *, const pcre_extra *,
|
172
|
-
const char *, int, int, int, int *, int);
|
173
|
-
extern void pcre_free_substring(const char *);
|
174
|
-
extern void pcre_free_substring_list(const char **);
|
175
|
-
extern int pcre_fullinfo(const pcre *, const pcre_extra *, int,
|
176
|
-
void *);
|
177
|
-
extern int pcre_get_named_substring(const pcre *, const char *,
|
178
|
-
int *, int, const char *, const char **);
|
179
|
-
extern int pcre_get_stringnumber(const pcre *, const char *);
|
180
|
-
extern int pcre_get_substring(const char *, int *, int, int,
|
181
|
-
const char **);
|
182
|
-
extern int pcre_get_substring_list(const char *, int *, int,
|
183
|
-
const char ***);
|
184
|
-
extern int pcre_info(const pcre *, int *, int *);
|
185
|
-
extern const unsigned char *pcre_maketables(void);
|
186
|
-
extern pcre_extra *pcre_study(const pcre *, int, const char **);
|
187
|
-
extern const char *pcre_version(void);
|
188
|
-
|
189
|
-
#ifdef __cplusplus
|
190
|
-
} /* extern "C" */
|
191
|
-
#endif
|
192
|
-
|
193
|
-
#endif /* End of pcre.h */
|
1
|
+
/*************************************************
|
2
|
+
* Perl-Compatible Regular Expressions *
|
3
|
+
*************************************************/
|
4
|
+
|
5
|
+
/* Copyright (c) 1997-2003 University of Cambridge */
|
6
|
+
|
7
|
+
#ifndef _PCRE_H
|
8
|
+
#define _PCRE_H
|
9
|
+
|
10
|
+
/* The file pcre.h is build by "configure". Do not edit it; instead
|
11
|
+
make changes to pcre.in. */
|
12
|
+
|
13
|
+
#define PCRE_MAJOR @PCRE_MAJOR@
|
14
|
+
#define PCRE_MINOR @PCRE_MINOR@
|
15
|
+
#define PCRE_DATE @PCRE_DATE@
|
16
|
+
|
17
|
+
/* Win32 uses DLL by default */
|
18
|
+
|
19
|
+
#ifdef _WIN32
|
20
|
+
# ifdef PCRE_DEFINITION
|
21
|
+
# ifdef DLL_EXPORT
|
22
|
+
# define PCRE_DATA_SCOPE __declspec(dllexport)
|
23
|
+
# endif
|
24
|
+
# else
|
25
|
+
# ifndef PCRE_STATIC
|
26
|
+
# define PCRE_DATA_SCOPE extern __declspec(dllimport)
|
27
|
+
# endif
|
28
|
+
# endif
|
29
|
+
#endif
|
30
|
+
#ifndef PCRE_DATA_SCOPE
|
31
|
+
# define PCRE_DATA_SCOPE extern
|
32
|
+
#endif
|
33
|
+
|
34
|
+
/* Have to include stdlib.h in order to ensure that size_t is defined;
|
35
|
+
it is needed here for malloc. */
|
36
|
+
|
37
|
+
#include <stdlib.h>
|
38
|
+
|
39
|
+
/* Allow for C++ users */
|
40
|
+
|
41
|
+
#ifdef __cplusplus
|
42
|
+
extern "C" {
|
43
|
+
#endif
|
44
|
+
|
45
|
+
/* Options */
|
46
|
+
|
47
|
+
#define PCRE_CASELESS 0x0001
|
48
|
+
#define PCRE_MULTILINE 0x0002
|
49
|
+
#define PCRE_DOTALL 0x0004
|
50
|
+
#define PCRE_EXTENDED 0x0008
|
51
|
+
#define PCRE_ANCHORED 0x0010
|
52
|
+
#define PCRE_DOLLAR_ENDONLY 0x0020
|
53
|
+
#define PCRE_EXTRA 0x0040
|
54
|
+
#define PCRE_NOTBOL 0x0080
|
55
|
+
#define PCRE_NOTEOL 0x0100
|
56
|
+
#define PCRE_UNGREEDY 0x0200
|
57
|
+
#define PCRE_NOTEMPTY 0x0400
|
58
|
+
#define PCRE_UTF8 0x0800
|
59
|
+
#define PCRE_NO_AUTO_CAPTURE 0x1000
|
60
|
+
#define PCRE_NO_UTF8_CHECK 0x2000
|
61
|
+
|
62
|
+
/* Exec-time and get/set-time error codes */
|
63
|
+
|
64
|
+
#define PCRE_ERROR_NOMATCH (-1)
|
65
|
+
#define PCRE_ERROR_NULL (-2)
|
66
|
+
#define PCRE_ERROR_BADOPTION (-3)
|
67
|
+
#define PCRE_ERROR_BADMAGIC (-4)
|
68
|
+
#define PCRE_ERROR_UNKNOWN_NODE (-5)
|
69
|
+
#define PCRE_ERROR_NOMEMORY (-6)
|
70
|
+
#define PCRE_ERROR_NOSUBSTRING (-7)
|
71
|
+
#define PCRE_ERROR_MATCHLIMIT (-8)
|
72
|
+
#define PCRE_ERROR_CALLOUT (-9) /* Never used by PCRE itself */
|
73
|
+
#define PCRE_ERROR_BADUTF8 (-10)
|
74
|
+
#define PCRE_ERROR_BADUTF8_OFFSET (-11)
|
75
|
+
|
76
|
+
/* Request types for pcre_fullinfo() */
|
77
|
+
|
78
|
+
#define PCRE_INFO_OPTIONS 0
|
79
|
+
#define PCRE_INFO_SIZE 1
|
80
|
+
#define PCRE_INFO_CAPTURECOUNT 2
|
81
|
+
#define PCRE_INFO_BACKREFMAX 3
|
82
|
+
#define PCRE_INFO_FIRSTBYTE 4
|
83
|
+
#define PCRE_INFO_FIRSTCHAR 4 /* For backwards compatibility */
|
84
|
+
#define PCRE_INFO_FIRSTTABLE 5
|
85
|
+
#define PCRE_INFO_LASTLITERAL 6
|
86
|
+
#define PCRE_INFO_NAMEENTRYSIZE 7
|
87
|
+
#define PCRE_INFO_NAMECOUNT 8
|
88
|
+
#define PCRE_INFO_NAMETABLE 9
|
89
|
+
#define PCRE_INFO_STUDYSIZE 10
|
90
|
+
|
91
|
+
/* Request types for pcre_config() */
|
92
|
+
|
93
|
+
#define PCRE_CONFIG_UTF8 0
|
94
|
+
#define PCRE_CONFIG_NEWLINE 1
|
95
|
+
#define PCRE_CONFIG_LINK_SIZE 2
|
96
|
+
#define PCRE_CONFIG_POSIX_MALLOC_THRESHOLD 3
|
97
|
+
#define PCRE_CONFIG_MATCH_LIMIT 4
|
98
|
+
#define PCRE_CONFIG_STACKRECURSE 5
|
99
|
+
|
100
|
+
/* Bit flags for the pcre_extra structure */
|
101
|
+
|
102
|
+
#define PCRE_EXTRA_STUDY_DATA 0x0001
|
103
|
+
#define PCRE_EXTRA_MATCH_LIMIT 0x0002
|
104
|
+
#define PCRE_EXTRA_CALLOUT_DATA 0x0004
|
105
|
+
|
106
|
+
/* Types */
|
107
|
+
|
108
|
+
struct real_pcre; /* declaration; the definition is private */
|
109
|
+
typedef struct real_pcre pcre;
|
110
|
+
|
111
|
+
/* The structure for passing additional data to pcre_exec(). This is defined in
|
112
|
+
such as way as to be extensible. */
|
113
|
+
|
114
|
+
typedef struct pcre_extra {
|
115
|
+
unsigned long int flags; /* Bits for which fields are set */
|
116
|
+
void *study_data; /* Opaque data from pcre_study() */
|
117
|
+
unsigned long int match_limit; /* Maximum number of calls to match() */
|
118
|
+
void *callout_data; /* Data passed back in callouts */
|
119
|
+
} pcre_extra;
|
120
|
+
|
121
|
+
/* The structure for passing out data via the pcre_callout_function. We use a
|
122
|
+
structure so that new fields can be added on the end in future versions,
|
123
|
+
without changing the API of the function, thereby allowing old clients to work
|
124
|
+
without modification. */
|
125
|
+
|
126
|
+
typedef struct pcre_callout_block {
|
127
|
+
int version; /* Identifies version of block */
|
128
|
+
/* ------------------------ Version 0 ------------------------------- */
|
129
|
+
int callout_number; /* Number compiled into pattern */
|
130
|
+
int *offset_vector; /* The offset vector */
|
131
|
+
const char *subject; /* The subject being matched */
|
132
|
+
int subject_length; /* The length of the subject */
|
133
|
+
int start_match; /* Offset to start of this match attempt */
|
134
|
+
int current_position; /* Where we currently are */
|
135
|
+
int capture_top; /* Max current capture */
|
136
|
+
int capture_last; /* Most recently closed capture */
|
137
|
+
void *callout_data; /* Data passed in with the call */
|
138
|
+
/* ------------------------------------------------------------------ */
|
139
|
+
} pcre_callout_block;
|
140
|
+
|
141
|
+
/* Indirection for store get and free functions. These can be set to
|
142
|
+
alternative malloc/free functions if required. Special ones are used in the
|
143
|
+
non-recursive case for "frames". There is also an optional callout function
|
144
|
+
that is triggered by the (?) regex item. Some magic is required for Win32 DLL;
|
145
|
+
it is null on other OS. For Virtual Pascal, these have to be different again.
|
146
|
+
*/
|
147
|
+
|
148
|
+
#ifndef VPCOMPAT
|
149
|
+
PCRE_DATA_SCOPE void *(*pcre_malloc)(size_t);
|
150
|
+
PCRE_DATA_SCOPE void (*pcre_free)(void *);
|
151
|
+
PCRE_DATA_SCOPE void *(*pcre_stack_malloc)(size_t);
|
152
|
+
PCRE_DATA_SCOPE void (*pcre_stack_free)(void *);
|
153
|
+
PCRE_DATA_SCOPE int (*pcre_callout)(pcre_callout_block *);
|
154
|
+
#else /* VPCOMPAT */
|
155
|
+
extern void *pcre_malloc(size_t);
|
156
|
+
extern void pcre_free(void *);
|
157
|
+
extern void *pcre_stack_malloc(size_t);
|
158
|
+
extern void pcre_stack_free(void *);
|
159
|
+
extern int pcre_callout(pcre_callout_block *);
|
160
|
+
#endif /* VPCOMPAT */
|
161
|
+
|
162
|
+
/* Exported PCRE functions */
|
163
|
+
|
164
|
+
extern pcre *pcre_compile(const char *, int, const char **,
|
165
|
+
int *, const unsigned char *);
|
166
|
+
extern int pcre_config(int, void *);
|
167
|
+
extern int pcre_copy_named_substring(const pcre *, const char *,
|
168
|
+
int *, int, const char *, char *, int);
|
169
|
+
extern int pcre_copy_substring(const char *, int *, int, int,
|
170
|
+
char *, int);
|
171
|
+
extern int pcre_exec(const pcre *, const pcre_extra *,
|
172
|
+
const char *, int, int, int, int *, int);
|
173
|
+
extern void pcre_free_substring(const char *);
|
174
|
+
extern void pcre_free_substring_list(const char **);
|
175
|
+
extern int pcre_fullinfo(const pcre *, const pcre_extra *, int,
|
176
|
+
void *);
|
177
|
+
extern int pcre_get_named_substring(const pcre *, const char *,
|
178
|
+
int *, int, const char *, const char **);
|
179
|
+
extern int pcre_get_stringnumber(const pcre *, const char *);
|
180
|
+
extern int pcre_get_substring(const char *, int *, int, int,
|
181
|
+
const char **);
|
182
|
+
extern int pcre_get_substring_list(const char *, int *, int,
|
183
|
+
const char ***);
|
184
|
+
extern int pcre_info(const pcre *, int *, int *);
|
185
|
+
extern const unsigned char *pcre_maketables(void);
|
186
|
+
extern pcre_extra *pcre_study(const pcre *, int, const char **);
|
187
|
+
extern const char *pcre_version(void);
|
188
|
+
|
189
|
+
#ifdef __cplusplus
|
190
|
+
} /* extern "C" */
|
191
|
+
#endif
|
192
|
+
|
193
|
+
#endif /* End of pcre.h */
|
data/tests/c/pcre/pcre.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'mxx_ru/cpp'
|
2
|
-
|
3
|
-
Mxx_ru::setup_target(
|
4
|
-
Mxx_ru::Cpp::Lib_target.new( "pcre.rb" ) {
|
5
|
-
target( "lib/pcre.4.5" )
|
6
|
-
|
7
|
-
define( "PCRE_STATIC", Mxx_ru::Cpp::Target::OPT_UPSPREAD )
|
8
|
-
|
9
|
-
c_source( "get.c" )
|
10
|
-
c_source( "maketables.c" )
|
11
|
-
c_source( "pcre.c" )
|
12
|
-
c_source( "study.c" )
|
13
|
-
}
|
14
|
-
)
|
1
|
+
require 'mxx_ru/cpp'
|
2
|
+
|
3
|
+
Mxx_ru::setup_target(
|
4
|
+
Mxx_ru::Cpp::Lib_target.new( "pcre.rb" ) {
|
5
|
+
target( "lib/pcre.4.5" )
|
6
|
+
|
7
|
+
define( "PCRE_STATIC", Mxx_ru::Cpp::Target::OPT_UPSPREAD )
|
8
|
+
|
9
|
+
c_source( "get.c" )
|
10
|
+
c_source( "maketables.c" )
|
11
|
+
c_source( "pcre.c" )
|
12
|
+
c_source( "study.c" )
|
13
|
+
}
|
14
|
+
)
|
data/tests/c/pcre/pcredemo.c
CHANGED
@@ -1,316 +1,316 @@
|
|
1
|
-
/*************************************************
|
2
|
-
* PCRE DEMONSTRATION PROGRAM *
|
3
|
-
*************************************************/
|
4
|
-
|
5
|
-
/* This is a demonstration program to illustrate the most straightforward ways
|
6
|
-
of calling the PCRE regular expression library from a C program. See the
|
7
|
-
pcresample documentation for a short discussion.
|
8
|
-
|
9
|
-
Compile thuswise:
|
10
|
-
gcc -Wall pcredemo.c -I/opt/local/include -L/opt/local/lib \
|
11
|
-
-R/opt/local/lib -lpcre
|
12
|
-
|
13
|
-
Replace "/opt/local/include" and "/opt/local/lib" with wherever the include and
|
14
|
-
library files for PCRE are installed on your system. Only some operating
|
15
|
-
systems (e.g. Solaris) use the -R option.
|
16
|
-
*/
|
17
|
-
|
18
|
-
|
19
|
-
#include <stdio.h>
|
20
|
-
#include <string.h>
|
21
|
-
#include <pcre.h>
|
22
|
-
|
23
|
-
#define OVECCOUNT 30 /* should be a multiple of 3 */
|
24
|
-
|
25
|
-
|
26
|
-
int main(int argc, char **argv)
|
27
|
-
{
|
28
|
-
pcre *re;
|
29
|
-
const char *error;
|
30
|
-
char *pattern;
|
31
|
-
char *subject;
|
32
|
-
unsigned char *name_table;
|
33
|
-
int erroffset;
|
34
|
-
int find_all;
|
35
|
-
int namecount;
|
36
|
-
int name_entry_size;
|
37
|
-
int ovector[OVECCOUNT];
|
38
|
-
int subject_length;
|
39
|
-
int rc, i;
|
40
|
-
|
41
|
-
|
42
|
-
/*************************************************************************
|
43
|
-
* First, sort out the command line. There is only one possible option at *
|
44
|
-
* the moment, "-g" to request repeated matching to find all occurrences, *
|
45
|
-
* like Perl's /g option. We set the variable find_all non-zero if it is *
|
46
|
-
* present. Apart from that, there must be exactly two arguments. *
|
47
|
-
*************************************************************************/
|
48
|
-
|
49
|
-
find_all = 0;
|
50
|
-
for (i = 1; i < argc; i++)
|
51
|
-
{
|
52
|
-
if (strcmp(argv[i], "-g") == 0) find_all = 1;
|
53
|
-
else break;
|
54
|
-
}
|
55
|
-
|
56
|
-
/* After the options, we require exactly two arguments, which are the pattern,
|
57
|
-
and the subject string. */
|
58
|
-
|
59
|
-
if (argc - i != 2)
|
60
|
-
{
|
61
|
-
printf("Two arguments required: a regex and a subject string\n");
|
62
|
-
return 1;
|
63
|
-
}
|
64
|
-
|
65
|
-
pattern = argv[i];
|
66
|
-
subject = argv[i+1];
|
67
|
-
subject_length = (int)strlen(subject);
|
68
|
-
|
69
|
-
|
70
|
-
/*************************************************************************
|
71
|
-
* Now we are going to compile the regular expression pattern, and handle *
|
72
|
-
* and errors that are detected. *
|
73
|
-
*************************************************************************/
|
74
|
-
|
75
|
-
re = pcre_compile(
|
76
|
-
pattern, /* the pattern */
|
77
|
-
0, /* default options */
|
78
|
-
&error, /* for error message */
|
79
|
-
&erroffset, /* for error offset */
|
80
|
-
NULL); /* use default character tables */
|
81
|
-
|
82
|
-
/* Compilation failed: print the error message and exit */
|
83
|
-
|
84
|
-
if (re == NULL)
|
85
|
-
{
|
86
|
-
printf("PCRE compilation failed at offset %d: %s\n", erroffset, error);
|
87
|
-
return 1;
|
88
|
-
}
|
89
|
-
|
90
|
-
|
91
|
-
/*************************************************************************
|
92
|
-
* If the compilation succeeded, we call PCRE again, in order to do a *
|
93
|
-
* pattern match against the subject string. This just does ONE match. If *
|
94
|
-
* further matching is needed, it will be done below. *
|
95
|
-
*************************************************************************/
|
96
|
-
|
97
|
-
rc = pcre_exec(
|
98
|
-
re, /* the compiled pattern */
|
99
|
-
NULL, /* no extra data - we didn't study the pattern */
|
100
|
-
subject, /* the subject string */
|
101
|
-
subject_length, /* the length of the subject */
|
102
|
-
0, /* start at offset 0 in the subject */
|
103
|
-
0, /* default options */
|
104
|
-
ovector, /* output vector for substring information */
|
105
|
-
OVECCOUNT); /* number of elements in the output vector */
|
106
|
-
|
107
|
-
/* Matching failed: handle error cases */
|
108
|
-
|
109
|
-
if (rc < 0)
|
110
|
-
{
|
111
|
-
switch(rc)
|
112
|
-
{
|
113
|
-
case PCRE_ERROR_NOMATCH: printf("No match\n"); break;
|
114
|
-
/*
|
115
|
-
Handle other special cases if you like
|
116
|
-
*/
|
117
|
-
default: printf("Matching error %d\n", rc); break;
|
118
|
-
}
|
119
|
-
return 1;
|
120
|
-
}
|
121
|
-
|
122
|
-
/* Match succeded */
|
123
|
-
|
124
|
-
printf("\nMatch succeeded at offset %d\n", ovector[0]);
|
125
|
-
|
126
|
-
|
127
|
-
/*************************************************************************
|
128
|
-
* We have found the first match within the subject string. If the output *
|
129
|
-
* vector wasn't big enough, set its size to the maximum. Then output any *
|
130
|
-
* substrings that were captured. *
|
131
|
-
*************************************************************************/
|
132
|
-
|
133
|
-
/* The output vector wasn't big enough */
|
134
|
-
|
135
|
-
if (rc == 0)
|
136
|
-
{
|
137
|
-
rc = OVECCOUNT/3;
|
138
|
-
printf("ovector only has room for %d captured substrings\n", rc - 1);
|
139
|
-
}
|
140
|
-
|
141
|
-
/* Show substrings stored in the output vector by number. Obviously, in a real
|
142
|
-
application you might want to do things other than print them. */
|
143
|
-
|
144
|
-
for (i = 0; i < rc; i++)
|
145
|
-
{
|
146
|
-
char *substring_start = subject + ovector[2*i];
|
147
|
-
int substring_length = ovector[2*i+1] - ovector[2*i];
|
148
|
-
printf("%2d: %.*s\n", i, substring_length, substring_start);
|
149
|
-
}
|
150
|
-
|
151
|
-
|
152
|
-
/*************************************************************************
|
153
|
-
* That concludes the basic part of this demonstration program. We have *
|
154
|
-
* compiled a pattern, and performed a single match. The code that follows*
|
155
|
-
* first shows how to access named substrings, and then how to code for *
|
156
|
-
* repeated matches on the same subject. *
|
157
|
-
*************************************************************************/
|
158
|
-
|
159
|
-
/* See if there are any named substrings, and if so, show them by name. First
|
160
|
-
we have to extract the count of named parentheses from the pattern. */
|
161
|
-
|
162
|
-
(void)pcre_fullinfo(
|
163
|
-
re, /* the compiled pattern */
|
164
|
-
NULL, /* no extra data - we didn't study the pattern */
|
165
|
-
PCRE_INFO_NAMECOUNT, /* number of named substrings */
|
166
|
-
&namecount); /* where to put the answer */
|
167
|
-
|
168
|
-
if (namecount <= 0) printf("No named substrings\n"); else
|
169
|
-
{
|
170
|
-
unsigned char *tabptr;
|
171
|
-
printf("Named substrings\n");
|
172
|
-
|
173
|
-
/* Before we can access the substrings, we must extract the table for
|
174
|
-
translating names to numbers, and the size of each entry in the table. */
|
175
|
-
|
176
|
-
(void)pcre_fullinfo(
|
177
|
-
re, /* the compiled pattern */
|
178
|
-
NULL, /* no extra data - we didn't study the pattern */
|
179
|
-
PCRE_INFO_NAMETABLE, /* address of the table */
|
180
|
-
&name_table); /* where to put the answer */
|
181
|
-
|
182
|
-
(void)pcre_fullinfo(
|
183
|
-
re, /* the compiled pattern */
|
184
|
-
NULL, /* no extra data - we didn't study the pattern */
|
185
|
-
PCRE_INFO_NAMEENTRYSIZE, /* size of each entry in the table */
|
186
|
-
&name_entry_size); /* where to put the answer */
|
187
|
-
|
188
|
-
/* Now we can scan the table and, for each entry, print the number, the name,
|
189
|
-
and the substring itself. */
|
190
|
-
|
191
|
-
tabptr = name_table;
|
192
|
-
for (i = 0; i < namecount; i++)
|
193
|
-
{
|
194
|
-
int n = (tabptr[0] << 8) | tabptr[1];
|
195
|
-
printf("(%d) %*s: %.*s\n", n, name_entry_size - 3, tabptr + 2,
|
196
|
-
ovector[2*n+1] - ovector[2*n], subject + ovector[2*n]);
|
197
|
-
tabptr += name_entry_size;
|
198
|
-
}
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
/*************************************************************************
|
203
|
-
* If the "-g" option was given on the command line, we want to continue *
|
204
|
-
* to search for additional matches in the subject string, in a similar *
|
205
|
-
* way to the /g option in Perl. This turns out to be trickier than you *
|
206
|
-
* might think because of the possibility of matching an empty string. *
|
207
|
-
* What happens is as follows: *
|
208
|
-
* *
|
209
|
-
* If the previous match was NOT for an empty string, we can just start *
|
210
|
-
* the next match at the end of the previous one. *
|
211
|
-
* *
|
212
|
-
* If the previous match WAS for an empty string, we can't do that, as it *
|
213
|
-
* would lead to an infinite loop. Instead, a special call of pcre_exec() *
|
214
|
-
* is made with the PCRE_NOTEMPTY and PCRE_ANCHORED flags set. The first *
|
215
|
-
* of these tells PCRE that an empty string is not a valid match; other *
|
216
|
-
* possibilities must be tried. The second flag restricts PCRE to one *
|
217
|
-
* match attempt at the initial string position. If this match succeeds, *
|
218
|
-
* an alternative to the empty string match has been found, and we can *
|
219
|
-
* proceed round the loop. *
|
220
|
-
*************************************************************************/
|
221
|
-
|
222
|
-
if (!find_all) return 0; /* Finish unless -g was given */
|
223
|
-
|
224
|
-
/* Loop for second and subsequent matches */
|
225
|
-
|
226
|
-
for (;;)
|
227
|
-
{
|
228
|
-
int options = 0; /* Normally no options */
|
229
|
-
int start_offset = ovector[1]; /* Start at end of previous match */
|
230
|
-
|
231
|
-
/* If the previous match was for an empty string, we are finished if we are
|
232
|
-
at the end of the subject. Otherwise, arrange to run another match at the
|
233
|
-
same point to see if a non-empty match can be found. */
|
234
|
-
|
235
|
-
if (ovector[0] == ovector[1])
|
236
|
-
{
|
237
|
-
if (ovector[0] == subject_length) break;
|
238
|
-
options = PCRE_NOTEMPTY | PCRE_ANCHORED;
|
239
|
-
}
|
240
|
-
|
241
|
-
/* Run the next matching operation */
|
242
|
-
|
243
|
-
rc = pcre_exec(
|
244
|
-
re, /* the compiled pattern */
|
245
|
-
NULL, /* no extra data - we didn't study the pattern */
|
246
|
-
subject, /* the subject string */
|
247
|
-
subject_length, /* the length of the subject */
|
248
|
-
start_offset, /* starting offset in the subject */
|
249
|
-
options, /* options */
|
250
|
-
ovector, /* output vector for substring information */
|
251
|
-
OVECCOUNT); /* number of elements in the output vector */
|
252
|
-
|
253
|
-
/* This time, a result of NOMATCH isn't an error. If the value in "options"
|
254
|
-
is zero, it just means we have found all possible matches, so the loop ends.
|
255
|
-
Otherwise, it means we have failed to find a non-empty-string match at a
|
256
|
-
point where there was a previous empty-string match. In this case, we do what
|
257
|
-
Perl does: advance the matching position by one, and continue. We do this by
|
258
|
-
setting the "end of previous match" offset, because that is picked up at the
|
259
|
-
top of the loop as the point at which to start again. */
|
260
|
-
|
261
|
-
if (rc == PCRE_ERROR_NOMATCH)
|
262
|
-
{
|
263
|
-
if (options == 0) break;
|
264
|
-
ovector[1] = start_offset + 1;
|
265
|
-
continue; /* Go round the loop again */
|
266
|
-
}
|
267
|
-
|
268
|
-
/* Other matching errors are not recoverable. */
|
269
|
-
|
270
|
-
if (rc < 0)
|
271
|
-
{
|
272
|
-
printf("Matching error %d\n", rc);
|
273
|
-
return 1;
|
274
|
-
}
|
275
|
-
|
276
|
-
/* Match succeded */
|
277
|
-
|
278
|
-
printf("\nMatch succeeded again at offset %d\n", ovector[0]);
|
279
|
-
|
280
|
-
/* The match succeeded, but the output vector wasn't big enough. */
|
281
|
-
|
282
|
-
if (rc == 0)
|
283
|
-
{
|
284
|
-
rc = OVECCOUNT/3;
|
285
|
-
printf("ovector only has room for %d captured substrings\n", rc - 1);
|
286
|
-
}
|
287
|
-
|
288
|
-
/* As before, show substrings stored in the output vector by number, and then
|
289
|
-
also any named substrings. */
|
290
|
-
|
291
|
-
for (i = 0; i < rc; i++)
|
292
|
-
{
|
293
|
-
char *substring_start = subject + ovector[2*i];
|
294
|
-
int substring_length = ovector[2*i+1] - ovector[2*i];
|
295
|
-
printf("%2d: %.*s\n", i, substring_length, substring_start);
|
296
|
-
}
|
297
|
-
|
298
|
-
if (namecount <= 0) printf("No named substrings\n"); else
|
299
|
-
{
|
300
|
-
unsigned char *tabptr = name_table;
|
301
|
-
printf("Named substrings\n");
|
302
|
-
for (i = 0; i < namecount; i++)
|
303
|
-
{
|
304
|
-
int n = (tabptr[0] << 8) | tabptr[1];
|
305
|
-
printf("(%d) %*s: %.*s\n", n, name_entry_size - 3, tabptr + 2,
|
306
|
-
ovector[2*n+1] - ovector[2*n], subject + ovector[2*n]);
|
307
|
-
tabptr += name_entry_size;
|
308
|
-
}
|
309
|
-
}
|
310
|
-
} /* End of loop to find second and subsequent matches */
|
311
|
-
|
312
|
-
printf("\n");
|
313
|
-
return 0;
|
314
|
-
}
|
315
|
-
|
316
|
-
/* End of pcredemo.c */
|
1
|
+
/*************************************************
|
2
|
+
* PCRE DEMONSTRATION PROGRAM *
|
3
|
+
*************************************************/
|
4
|
+
|
5
|
+
/* This is a demonstration program to illustrate the most straightforward ways
|
6
|
+
of calling the PCRE regular expression library from a C program. See the
|
7
|
+
pcresample documentation for a short discussion.
|
8
|
+
|
9
|
+
Compile thuswise:
|
10
|
+
gcc -Wall pcredemo.c -I/opt/local/include -L/opt/local/lib \
|
11
|
+
-R/opt/local/lib -lpcre
|
12
|
+
|
13
|
+
Replace "/opt/local/include" and "/opt/local/lib" with wherever the include and
|
14
|
+
library files for PCRE are installed on your system. Only some operating
|
15
|
+
systems (e.g. Solaris) use the -R option.
|
16
|
+
*/
|
17
|
+
|
18
|
+
|
19
|
+
#include <stdio.h>
|
20
|
+
#include <string.h>
|
21
|
+
#include <pcre.h>
|
22
|
+
|
23
|
+
#define OVECCOUNT 30 /* should be a multiple of 3 */
|
24
|
+
|
25
|
+
|
26
|
+
int main(int argc, char **argv)
|
27
|
+
{
|
28
|
+
pcre *re;
|
29
|
+
const char *error;
|
30
|
+
char *pattern;
|
31
|
+
char *subject;
|
32
|
+
unsigned char *name_table;
|
33
|
+
int erroffset;
|
34
|
+
int find_all;
|
35
|
+
int namecount;
|
36
|
+
int name_entry_size;
|
37
|
+
int ovector[OVECCOUNT];
|
38
|
+
int subject_length;
|
39
|
+
int rc, i;
|
40
|
+
|
41
|
+
|
42
|
+
/*************************************************************************
|
43
|
+
* First, sort out the command line. There is only one possible option at *
|
44
|
+
* the moment, "-g" to request repeated matching to find all occurrences, *
|
45
|
+
* like Perl's /g option. We set the variable find_all non-zero if it is *
|
46
|
+
* present. Apart from that, there must be exactly two arguments. *
|
47
|
+
*************************************************************************/
|
48
|
+
|
49
|
+
find_all = 0;
|
50
|
+
for (i = 1; i < argc; i++)
|
51
|
+
{
|
52
|
+
if (strcmp(argv[i], "-g") == 0) find_all = 1;
|
53
|
+
else break;
|
54
|
+
}
|
55
|
+
|
56
|
+
/* After the options, we require exactly two arguments, which are the pattern,
|
57
|
+
and the subject string. */
|
58
|
+
|
59
|
+
if (argc - i != 2)
|
60
|
+
{
|
61
|
+
printf("Two arguments required: a regex and a subject string\n");
|
62
|
+
return 1;
|
63
|
+
}
|
64
|
+
|
65
|
+
pattern = argv[i];
|
66
|
+
subject = argv[i+1];
|
67
|
+
subject_length = (int)strlen(subject);
|
68
|
+
|
69
|
+
|
70
|
+
/*************************************************************************
|
71
|
+
* Now we are going to compile the regular expression pattern, and handle *
|
72
|
+
* and errors that are detected. *
|
73
|
+
*************************************************************************/
|
74
|
+
|
75
|
+
re = pcre_compile(
|
76
|
+
pattern, /* the pattern */
|
77
|
+
0, /* default options */
|
78
|
+
&error, /* for error message */
|
79
|
+
&erroffset, /* for error offset */
|
80
|
+
NULL); /* use default character tables */
|
81
|
+
|
82
|
+
/* Compilation failed: print the error message and exit */
|
83
|
+
|
84
|
+
if (re == NULL)
|
85
|
+
{
|
86
|
+
printf("PCRE compilation failed at offset %d: %s\n", erroffset, error);
|
87
|
+
return 1;
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
/*************************************************************************
|
92
|
+
* If the compilation succeeded, we call PCRE again, in order to do a *
|
93
|
+
* pattern match against the subject string. This just does ONE match. If *
|
94
|
+
* further matching is needed, it will be done below. *
|
95
|
+
*************************************************************************/
|
96
|
+
|
97
|
+
rc = pcre_exec(
|
98
|
+
re, /* the compiled pattern */
|
99
|
+
NULL, /* no extra data - we didn't study the pattern */
|
100
|
+
subject, /* the subject string */
|
101
|
+
subject_length, /* the length of the subject */
|
102
|
+
0, /* start at offset 0 in the subject */
|
103
|
+
0, /* default options */
|
104
|
+
ovector, /* output vector for substring information */
|
105
|
+
OVECCOUNT); /* number of elements in the output vector */
|
106
|
+
|
107
|
+
/* Matching failed: handle error cases */
|
108
|
+
|
109
|
+
if (rc < 0)
|
110
|
+
{
|
111
|
+
switch(rc)
|
112
|
+
{
|
113
|
+
case PCRE_ERROR_NOMATCH: printf("No match\n"); break;
|
114
|
+
/*
|
115
|
+
Handle other special cases if you like
|
116
|
+
*/
|
117
|
+
default: printf("Matching error %d\n", rc); break;
|
118
|
+
}
|
119
|
+
return 1;
|
120
|
+
}
|
121
|
+
|
122
|
+
/* Match succeded */
|
123
|
+
|
124
|
+
printf("\nMatch succeeded at offset %d\n", ovector[0]);
|
125
|
+
|
126
|
+
|
127
|
+
/*************************************************************************
|
128
|
+
* We have found the first match within the subject string. If the output *
|
129
|
+
* vector wasn't big enough, set its size to the maximum. Then output any *
|
130
|
+
* substrings that were captured. *
|
131
|
+
*************************************************************************/
|
132
|
+
|
133
|
+
/* The output vector wasn't big enough */
|
134
|
+
|
135
|
+
if (rc == 0)
|
136
|
+
{
|
137
|
+
rc = OVECCOUNT/3;
|
138
|
+
printf("ovector only has room for %d captured substrings\n", rc - 1);
|
139
|
+
}
|
140
|
+
|
141
|
+
/* Show substrings stored in the output vector by number. Obviously, in a real
|
142
|
+
application you might want to do things other than print them. */
|
143
|
+
|
144
|
+
for (i = 0; i < rc; i++)
|
145
|
+
{
|
146
|
+
char *substring_start = subject + ovector[2*i];
|
147
|
+
int substring_length = ovector[2*i+1] - ovector[2*i];
|
148
|
+
printf("%2d: %.*s\n", i, substring_length, substring_start);
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
/*************************************************************************
|
153
|
+
* That concludes the basic part of this demonstration program. We have *
|
154
|
+
* compiled a pattern, and performed a single match. The code that follows*
|
155
|
+
* first shows how to access named substrings, and then how to code for *
|
156
|
+
* repeated matches on the same subject. *
|
157
|
+
*************************************************************************/
|
158
|
+
|
159
|
+
/* See if there are any named substrings, and if so, show them by name. First
|
160
|
+
we have to extract the count of named parentheses from the pattern. */
|
161
|
+
|
162
|
+
(void)pcre_fullinfo(
|
163
|
+
re, /* the compiled pattern */
|
164
|
+
NULL, /* no extra data - we didn't study the pattern */
|
165
|
+
PCRE_INFO_NAMECOUNT, /* number of named substrings */
|
166
|
+
&namecount); /* where to put the answer */
|
167
|
+
|
168
|
+
if (namecount <= 0) printf("No named substrings\n"); else
|
169
|
+
{
|
170
|
+
unsigned char *tabptr;
|
171
|
+
printf("Named substrings\n");
|
172
|
+
|
173
|
+
/* Before we can access the substrings, we must extract the table for
|
174
|
+
translating names to numbers, and the size of each entry in the table. */
|
175
|
+
|
176
|
+
(void)pcre_fullinfo(
|
177
|
+
re, /* the compiled pattern */
|
178
|
+
NULL, /* no extra data - we didn't study the pattern */
|
179
|
+
PCRE_INFO_NAMETABLE, /* address of the table */
|
180
|
+
&name_table); /* where to put the answer */
|
181
|
+
|
182
|
+
(void)pcre_fullinfo(
|
183
|
+
re, /* the compiled pattern */
|
184
|
+
NULL, /* no extra data - we didn't study the pattern */
|
185
|
+
PCRE_INFO_NAMEENTRYSIZE, /* size of each entry in the table */
|
186
|
+
&name_entry_size); /* where to put the answer */
|
187
|
+
|
188
|
+
/* Now we can scan the table and, for each entry, print the number, the name,
|
189
|
+
and the substring itself. */
|
190
|
+
|
191
|
+
tabptr = name_table;
|
192
|
+
for (i = 0; i < namecount; i++)
|
193
|
+
{
|
194
|
+
int n = (tabptr[0] << 8) | tabptr[1];
|
195
|
+
printf("(%d) %*s: %.*s\n", n, name_entry_size - 3, tabptr + 2,
|
196
|
+
ovector[2*n+1] - ovector[2*n], subject + ovector[2*n]);
|
197
|
+
tabptr += name_entry_size;
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
/*************************************************************************
|
203
|
+
* If the "-g" option was given on the command line, we want to continue *
|
204
|
+
* to search for additional matches in the subject string, in a similar *
|
205
|
+
* way to the /g option in Perl. This turns out to be trickier than you *
|
206
|
+
* might think because of the possibility of matching an empty string. *
|
207
|
+
* What happens is as follows: *
|
208
|
+
* *
|
209
|
+
* If the previous match was NOT for an empty string, we can just start *
|
210
|
+
* the next match at the end of the previous one. *
|
211
|
+
* *
|
212
|
+
* If the previous match WAS for an empty string, we can't do that, as it *
|
213
|
+
* would lead to an infinite loop. Instead, a special call of pcre_exec() *
|
214
|
+
* is made with the PCRE_NOTEMPTY and PCRE_ANCHORED flags set. The first *
|
215
|
+
* of these tells PCRE that an empty string is not a valid match; other *
|
216
|
+
* possibilities must be tried. The second flag restricts PCRE to one *
|
217
|
+
* match attempt at the initial string position. If this match succeeds, *
|
218
|
+
* an alternative to the empty string match has been found, and we can *
|
219
|
+
* proceed round the loop. *
|
220
|
+
*************************************************************************/
|
221
|
+
|
222
|
+
if (!find_all) return 0; /* Finish unless -g was given */
|
223
|
+
|
224
|
+
/* Loop for second and subsequent matches */
|
225
|
+
|
226
|
+
for (;;)
|
227
|
+
{
|
228
|
+
int options = 0; /* Normally no options */
|
229
|
+
int start_offset = ovector[1]; /* Start at end of previous match */
|
230
|
+
|
231
|
+
/* If the previous match was for an empty string, we are finished if we are
|
232
|
+
at the end of the subject. Otherwise, arrange to run another match at the
|
233
|
+
same point to see if a non-empty match can be found. */
|
234
|
+
|
235
|
+
if (ovector[0] == ovector[1])
|
236
|
+
{
|
237
|
+
if (ovector[0] == subject_length) break;
|
238
|
+
options = PCRE_NOTEMPTY | PCRE_ANCHORED;
|
239
|
+
}
|
240
|
+
|
241
|
+
/* Run the next matching operation */
|
242
|
+
|
243
|
+
rc = pcre_exec(
|
244
|
+
re, /* the compiled pattern */
|
245
|
+
NULL, /* no extra data - we didn't study the pattern */
|
246
|
+
subject, /* the subject string */
|
247
|
+
subject_length, /* the length of the subject */
|
248
|
+
start_offset, /* starting offset in the subject */
|
249
|
+
options, /* options */
|
250
|
+
ovector, /* output vector for substring information */
|
251
|
+
OVECCOUNT); /* number of elements in the output vector */
|
252
|
+
|
253
|
+
/* This time, a result of NOMATCH isn't an error. If the value in "options"
|
254
|
+
is zero, it just means we have found all possible matches, so the loop ends.
|
255
|
+
Otherwise, it means we have failed to find a non-empty-string match at a
|
256
|
+
point where there was a previous empty-string match. In this case, we do what
|
257
|
+
Perl does: advance the matching position by one, and continue. We do this by
|
258
|
+
setting the "end of previous match" offset, because that is picked up at the
|
259
|
+
top of the loop as the point at which to start again. */
|
260
|
+
|
261
|
+
if (rc == PCRE_ERROR_NOMATCH)
|
262
|
+
{
|
263
|
+
if (options == 0) break;
|
264
|
+
ovector[1] = start_offset + 1;
|
265
|
+
continue; /* Go round the loop again */
|
266
|
+
}
|
267
|
+
|
268
|
+
/* Other matching errors are not recoverable. */
|
269
|
+
|
270
|
+
if (rc < 0)
|
271
|
+
{
|
272
|
+
printf("Matching error %d\n", rc);
|
273
|
+
return 1;
|
274
|
+
}
|
275
|
+
|
276
|
+
/* Match succeded */
|
277
|
+
|
278
|
+
printf("\nMatch succeeded again at offset %d\n", ovector[0]);
|
279
|
+
|
280
|
+
/* The match succeeded, but the output vector wasn't big enough. */
|
281
|
+
|
282
|
+
if (rc == 0)
|
283
|
+
{
|
284
|
+
rc = OVECCOUNT/3;
|
285
|
+
printf("ovector only has room for %d captured substrings\n", rc - 1);
|
286
|
+
}
|
287
|
+
|
288
|
+
/* As before, show substrings stored in the output vector by number, and then
|
289
|
+
also any named substrings. */
|
290
|
+
|
291
|
+
for (i = 0; i < rc; i++)
|
292
|
+
{
|
293
|
+
char *substring_start = subject + ovector[2*i];
|
294
|
+
int substring_length = ovector[2*i+1] - ovector[2*i];
|
295
|
+
printf("%2d: %.*s\n", i, substring_length, substring_start);
|
296
|
+
}
|
297
|
+
|
298
|
+
if (namecount <= 0) printf("No named substrings\n"); else
|
299
|
+
{
|
300
|
+
unsigned char *tabptr = name_table;
|
301
|
+
printf("Named substrings\n");
|
302
|
+
for (i = 0; i < namecount; i++)
|
303
|
+
{
|
304
|
+
int n = (tabptr[0] << 8) | tabptr[1];
|
305
|
+
printf("(%d) %*s: %.*s\n", n, name_entry_size - 3, tabptr + 2,
|
306
|
+
ovector[2*n+1] - ovector[2*n], subject + ovector[2*n]);
|
307
|
+
tabptr += name_entry_size;
|
308
|
+
}
|
309
|
+
}
|
310
|
+
} /* End of loop to find second and subsequent matches */
|
311
|
+
|
312
|
+
printf("\n");
|
313
|
+
return 0;
|
314
|
+
}
|
315
|
+
|
316
|
+
/* End of pcredemo.c */
|