Mxx_ru 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/COPYING +26 -0
  2. data/NEWS +52 -0
  3. data/README +21 -0
  4. data/Rakefile +32 -0
  5. data/examples/exe_and_lib/main.cpp +15 -0
  6. data/examples/exe_and_lib/prj.rb +11 -0
  7. data/examples/exe_and_lib/say.cpp +13 -0
  8. data/examples/exe_and_lib/say.hpp +11 -0
  9. data/examples/exe_and_lib/say.rb +7 -0
  10. data/examples/exe_dll_lib/inout.cpp +15 -0
  11. data/examples/exe_dll_lib/inout.hpp +26 -0
  12. data/examples/exe_dll_lib/inout.rb +18 -0
  13. data/examples/exe_dll_lib/main.cpp +23 -0
  14. data/examples/exe_dll_lib/prj.rb +11 -0
  15. data/examples/exe_dll_lib/say.cpp +13 -0
  16. data/examples/exe_dll_lib/say.hpp +12 -0
  17. data/examples/exe_dll_lib/say.rb +9 -0
  18. data/examples/exe_dll_lib_2/build.rb +7 -0
  19. data/examples/exe_dll_lib_2/inout/inout.cpp +15 -0
  20. data/examples/exe_dll_lib_2/inout/inout.hpp +26 -0
  21. data/examples/exe_dll_lib_2/inout/prj.rb +16 -0
  22. data/examples/exe_dll_lib_2/main/main.cpp +23 -0
  23. data/examples/exe_dll_lib_2/main/prj.rb +9 -0
  24. data/examples/exe_dll_lib_2/say/prj.rb +8 -0
  25. data/examples/exe_dll_lib_2/say/say.cpp +13 -0
  26. data/examples/exe_dll_lib_2/say/say.hpp +12 -0
  27. data/examples/simple_exe/main.cpp +26 -0
  28. data/examples/simple_exe/prj.rb +7 -0
  29. data/lib/mxx_ru/abstract_target.rb +283 -0
  30. data/lib/mxx_ru/binary_target.rb +89 -0
  31. data/lib/mxx_ru/binary_unittest.rb +130 -0
  32. data/lib/mxx_ru/cpp/analyzer.rb +230 -0
  33. data/lib/mxx_ru/cpp/composite.rb +106 -0
  34. data/lib/mxx_ru/cpp/detect_toolset.rb +122 -0
  35. data/lib/mxx_ru/cpp/mode.rb +85 -0
  36. data/lib/mxx_ru/cpp/obj_placement.rb +321 -0
  37. data/lib/mxx_ru/cpp/qt.rb +333 -0
  38. data/lib/mxx_ru/cpp/rucodegen.rb +114 -0
  39. data/lib/mxx_ru/cpp/source_file.rb +71 -0
  40. data/lib/mxx_ru/cpp/target.rb +1371 -0
  41. data/lib/mxx_ru/cpp/toolset.rb +1029 -0
  42. data/lib/mxx_ru/cpp/toolsets/bcc_win32_5.rb +52 -0
  43. data/lib/mxx_ru/cpp/toolsets/bcc_win32_family.rb +451 -0
  44. data/lib/mxx_ru/cpp/toolsets/c89_etk_nsk.rb +56 -0
  45. data/lib/mxx_ru/cpp/toolsets/c89_nsk.rb +56 -0
  46. data/lib/mxx_ru/cpp/toolsets/c89_nsk_family.rb +273 -0
  47. data/lib/mxx_ru/cpp/toolsets/gcc_cygwin.rb +54 -0
  48. data/lib/mxx_ru/cpp/toolsets/gcc_family.rb +382 -0
  49. data/lib/mxx_ru/cpp/toolsets/gcc_linux.rb +60 -0
  50. data/lib/mxx_ru/cpp/toolsets/gcc_mingw.rb +144 -0
  51. data/lib/mxx_ru/cpp/toolsets/gcc_sparc_solaris.rb +87 -0
  52. data/lib/mxx_ru/cpp/toolsets/vc7.rb +62 -0
  53. data/lib/mxx_ru/cpp/toolsets/vc8.rb +452 -0
  54. data/lib/mxx_ru/cpp/toolsets/vc_family.rb +428 -0
  55. data/lib/mxx_ru/cpp.rb +36 -0
  56. data/lib/mxx_ru/ex.rb +134 -0
  57. data/lib/mxx_ru/makestyle_generator.rb +138 -0
  58. data/lib/mxx_ru/textfile_unittest.rb +284 -0
  59. data/lib/mxx_ru/util.rb +258 -0
  60. data/tests/c/pcre/chartables.c +183 -0
  61. data/tests/c/pcre/config.h +99 -0
  62. data/tests/c/pcre/dftables.c +167 -0
  63. data/tests/c/pcre/get.c +349 -0
  64. data/tests/c/pcre/internal.h +677 -0
  65. data/tests/c/pcre/maketables.c +140 -0
  66. data/tests/c/pcre/pcre.c +8304 -0
  67. data/tests/c/pcre/pcre.h +193 -0
  68. data/tests/c/pcre/pcre.rb +14 -0
  69. data/tests/c/pcre/pcredemo.c +316 -0
  70. data/tests/c/pcre/pcregrep.c +642 -0
  71. data/tests/c/pcre/pcreposix.c +305 -0
  72. data/tests/c/pcre/pcreposix.h +88 -0
  73. data/tests/c/pcre/pcretest.c +1483 -0
  74. data/tests/c/pcre/perltest +211 -0
  75. data/tests/c/pcre/printint.c +360 -0
  76. data/tests/c/pcre/study.c +472 -0
  77. data/tests/cpp/mswin_res_dll/build.rb +14 -0
  78. data/tests/cpp/mswin_res_dll/dll.cpp +17 -0
  79. data/tests/cpp/mswin_res_dll/dll.rb +30 -0
  80. data/tests/cpp/mswin_res_dll/dll.rc +48 -0
  81. data/tests/cpp/mswin_res_dll/h/dll.hpp +8 -0
  82. data/tests/cpp/mswin_res_dll/h/res.h +3 -0
  83. data/tests/cpp/mswin_res_dll/main.cpp +13 -0
  84. data/tests/cpp/mswin_res_dll/main.rb +20 -0
  85. data/tests/cpp/mswin_res_dll/res/tree_fol.bmp +0 -0
  86. data/tests/cpp/mswin_res_dll/res/tree_state_1.bmp +0 -0
  87. data/tests/cpp/mswin_res_dll/res/tree_state_2.bmp +0 -0
  88. data/tests/cpp/mswin_res_exe/build.rb +23 -0
  89. data/tests/cpp/mswin_res_exe/h/res.h +3 -0
  90. data/tests/cpp/mswin_res_exe/main.cpp +17 -0
  91. data/tests/cpp/mswin_res_exe/main.rc +48 -0
  92. data/tests/cpp/mswin_res_exe/res/tree_fol.bmp +0 -0
  93. data/tests/cpp/mswin_res_exe/res/tree_state_1.bmp +0 -0
  94. data/tests/cpp/mswin_res_exe/res/tree_state_2.bmp +0 -0
  95. data/tests/cpp/rucodegen/host_config.cpp +20 -0
  96. data/tests/cpp/rucodegen/host_config.rb +14 -0
  97. data/tests/cpp/rucodegen/impl/conn_params.cpp +7 -0
  98. data/tests/cpp/rucodegen/impl/conn_params.rb +14 -0
  99. data/tests/cpp/rucodegen/impl/h/conn_params.hpp +10 -0
  100. data/tests/cpp/rucodegen/prj.rb +17 -0
  101. data/tests/cpp/textfile_unittest/build.rb +8 -0
  102. data/tests/cpp/textfile_unittest/etalons/out_0.txt +0 -0
  103. data/tests/cpp/textfile_unittest/etalons/out_1.txt +1 -0
  104. data/tests/cpp/textfile_unittest/etalons/out_128.txt +128 -0
  105. data/tests/cpp/textfile_unittest/main.cpp +89 -0
  106. data/tests/cpp/textfile_unittest/prj.rb +8 -0
  107. data/tests/cpp/textfile_unittest/prj.ut.rb +18 -0
  108. data/tests/cpp/toolset_name.rb +6 -0
  109. data/tests/cpp/vc_cleanup/cout.log +72 -0
  110. data/tests/cpp/vc_cleanup/dll_hi.cpp +5 -0
  111. data/tests/cpp/vc_cleanup/exe_hi.cpp +10 -0
  112. data/tests/cpp/vc_cleanup/lib_hi.cpp +5 -0
  113. data/tests/cpp/vc_cleanup/prj_dll_no_implib.rb +10 -0
  114. data/tests/cpp/vc_cleanup/prj_dll_no_implib_simple_target_root.rb +11 -0
  115. data/tests/cpp/vc_cleanup/prj_dll_with_implib.rb +11 -0
  116. data/tests/cpp/vc_cleanup/prj_dll_with_implib_simple_target_root.rb +14 -0
  117. data/tests/cpp/vc_cleanup/prj_exe_no_implib.rb +10 -0
  118. data/tests/cpp/vc_cleanup/prj_exe_no_implib_simple_target_root.rb +11 -0
  119. data/tests/cpp/vc_cleanup/prj_lib.rb +10 -0
  120. data/tests/cpp/vc_cleanup/prj_lib_with_simple_target_root.rb +11 -0
  121. data/tests/cpp/vc_cleanup/tc_vc_cleanup.rb +60 -0
  122. data/tests/mxx_ru/change_default_value/ignoring_by_build_root/build.rb +8 -0
  123. data/tests/mxx_ru/change_default_value/ignoring_by_build_root/child_1.rb +5 -0
  124. data/tests/mxx_ru/change_default_value/ignoring_by_child_1/build.rb +7 -0
  125. data/tests/mxx_ru/change_default_value/ignoring_by_child_1/child_1.rb +5 -0
  126. data/tests/mxx_ru/change_default_value/ignoring_by_child_1/child_2.rb +5 -0
  127. data/tests/mxx_ru/change_default_value/ok/build.rb +8 -0
  128. data/tests/mxx_ru/change_default_value/ok/child_1.rb +8 -0
  129. data/tests/mxx_ru/tc_makestyle_generator.rb +117 -0
  130. data/tests/mxx_ru/vc8/tc_actual_manifest.rb +230 -0
  131. data/tests/mxx_ru/vc8/tc_append_mt_commands.rb +104 -0
  132. data/tests/mxx_ru/vc8/tc_default_manifest.rb +17 -0
  133. data/tests/mxx_ru/vc8/tc_define_manifest.rb +173 -0
  134. data/tests/mxx_ru/vc8/tc_drop_default_manifest.rb +16 -0
  135. data/tests/mxx_ru/vc8/tc_invalid_params.rb +81 -0
  136. data/tests/mxx_ru/vc8/ts_vc8.rb +10 -0
  137. data/tests/qt/aclock/aclock.cpp +148 -0
  138. data/tests/qt/aclock/aclock.h +45 -0
  139. data/tests/qt/aclock/main.cpp +28 -0
  140. data/tests/qt/aclock/prj.rb +21 -0
  141. data/tests/qt/iconview/main.cpp +76 -0
  142. data/tests/qt/iconview/prj.rb +21 -0
  143. data/tests/qt/toplevel/main.cpp +9 -0
  144. data/tests/qt/toplevel/options.ui +587 -0
  145. data/tests/qt/toplevel/options.ui.h +98 -0
  146. data/tests/qt/toplevel/prj.rb +21 -0
  147. metadata +241 -0
@@ -0,0 +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 */
@@ -0,0 +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
+ )
@@ -0,0 +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 */