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.
Files changed (177) hide show
  1. data/COPYING +26 -26
  2. data/NEWS +107 -107
  3. data/README +21 -21
  4. data/Rakefile +56 -56
  5. data/examples/exe_and_lib/prj.rb +11 -11
  6. data/examples/exe_and_lib/say.rb +7 -7
  7. data/examples/exe_dll_lib/inout.rb +18 -18
  8. data/examples/exe_dll_lib/prj.rb +11 -11
  9. data/examples/exe_dll_lib/say.rb +9 -9
  10. data/examples/exe_dll_lib_2/build.rb +10 -10
  11. data/examples/exe_dll_lib_2/inout/prj.rb +16 -16
  12. data/examples/exe_dll_lib_2/main/prj.rb +9 -9
  13. data/examples/exe_dll_lib_2/say/prj.rb +8 -8
  14. data/examples/simple_exe/prj.rb +7 -7
  15. data/lib/mxx_ru/abstract_target.rb +335 -335
  16. data/lib/mxx_ru/binary_library.rb +106 -106
  17. data/lib/mxx_ru/binary_target.rb +173 -173
  18. data/lib/mxx_ru/binary_unittest.rb +143 -143
  19. data/lib/mxx_ru/compat.rb +33 -33
  20. data/lib/mxx_ru/cpp.rb +38 -38
  21. data/lib/mxx_ru/cpp/analyzer.rb +237 -237
  22. data/lib/mxx_ru/cpp/composite.rb +118 -118
  23. data/lib/mxx_ru/cpp/detect_toolset.rb +122 -122
  24. data/lib/mxx_ru/cpp/mode.rb +90 -90
  25. data/lib/mxx_ru/cpp/obj_placement.rb +330 -330
  26. data/lib/mxx_ru/cpp/obj_placements/custom_subdir.rb +155 -155
  27. data/lib/mxx_ru/cpp/qt.rb +366 -366
  28. data/lib/mxx_ru/cpp/rucodegen.rb +157 -157
  29. data/lib/mxx_ru/cpp/source_file.rb +79 -79
  30. data/lib/mxx_ru/cpp/target.rb +1523 -1523
  31. data/lib/mxx_ru/cpp/toolset.rb +1087 -1087
  32. data/lib/mxx_ru/cpp/toolsets/bcc_win32_5.rb +53 -53
  33. data/lib/mxx_ru/cpp/toolsets/bcc_win32_family.rb +460 -460
  34. data/lib/mxx_ru/cpp/toolsets/c89_etk_nsk.rb +59 -59
  35. data/lib/mxx_ru/cpp/toolsets/c89_nsk.rb +59 -59
  36. data/lib/mxx_ru/cpp/toolsets/c89_nsk_family.rb +277 -277
  37. data/lib/mxx_ru/cpp/toolsets/gcc_cygwin.rb +58 -58
  38. data/lib/mxx_ru/cpp/toolsets/gcc_family.rb +420 -420
  39. data/lib/mxx_ru/cpp/toolsets/gcc_linux.rb +64 -64
  40. data/lib/mxx_ru/cpp/toolsets/gcc_mingw.rb +149 -150
  41. data/lib/mxx_ru/cpp/toolsets/gcc_sparc_solaris.rb +91 -91
  42. data/lib/mxx_ru/cpp/toolsets/gcc_unix_family.rb +103 -103
  43. data/lib/mxx_ru/cpp/toolsets/vc7.rb +62 -62
  44. data/lib/mxx_ru/cpp/toolsets/vc8.rb +455 -455
  45. data/lib/mxx_ru/cpp/toolsets/vc_family.rb +448 -448
  46. data/lib/mxx_ru/ex.rb +165 -165
  47. data/lib/mxx_ru/makestyle_generator.rb +146 -146
  48. data/lib/mxx_ru/textfile_unittest.rb +303 -303
  49. data/lib/mxx_ru/util.rb +340 -340
  50. data/tests/c/pcre/chartables.c +183 -183
  51. data/tests/c/pcre/config.h +99 -99
  52. data/tests/c/pcre/dftables.c +167 -167
  53. data/tests/c/pcre/get.c +349 -349
  54. data/tests/c/pcre/internal.h +677 -677
  55. data/tests/c/pcre/maketables.c +140 -140
  56. data/tests/c/pcre/pcre.c +8304 -8304
  57. data/tests/c/pcre/pcre.h +193 -193
  58. data/tests/c/pcre/pcre.rb +14 -14
  59. data/tests/c/pcre/pcredemo.c +316 -316
  60. data/tests/c/pcre/pcregrep.c +642 -642
  61. data/tests/c/pcre/pcreposix.c +305 -305
  62. data/tests/c/pcre/pcreposix.h +88 -88
  63. data/tests/c/pcre/pcretest.c +1483 -1483
  64. data/tests/c/pcre/perltest +211 -211
  65. data/tests/c/pcre/printint.c +360 -360
  66. data/tests/c/pcre/study.c +472 -472
  67. data/tests/cpp/cpp_sources_glob/build.rb +7 -7
  68. data/tests/cpp/cpp_sources_glob/some/module/prj.rb +10 -10
  69. data/tests/cpp/cpp_sources_glob/tc_cpp_sources_glob.rb +18 -18
  70. data/tests/cpp/mswin_res_dll/build.rb +14 -14
  71. data/tests/cpp/mswin_res_dll/dll.cpp +17 -17
  72. data/tests/cpp/mswin_res_dll/dll.rb +29 -29
  73. data/tests/cpp/mswin_res_dll/dll.rc +48 -48
  74. data/tests/cpp/mswin_res_dll/h/dll.hpp +8 -8
  75. data/tests/cpp/mswin_res_dll/h/res.h +3 -3
  76. data/tests/cpp/mswin_res_dll/main.cpp +13 -13
  77. data/tests/cpp/mswin_res_dll/main.rb +19 -19
  78. data/tests/cpp/mswin_res_dll/o/dll.o +0 -0
  79. data/tests/cpp/mswin_res_dll/tc_mswin_res_dll.rb +18 -18
  80. data/tests/cpp/mswin_res_exe/build.rb +23 -23
  81. data/tests/cpp/mswin_res_exe/h/res.h +3 -3
  82. data/tests/cpp/mswin_res_exe/main.cpp +17 -17
  83. data/tests/cpp/mswin_res_exe/main.rc +48 -48
  84. data/tests/cpp/mswin_res_exe/o/main.o +0 -0
  85. data/tests/cpp/mswin_res_exe/tc_mswin_res_exe.rb +18 -18
  86. data/tests/cpp/rucodegen.embedded/host_config.cpp +32 -32
  87. data/tests/cpp/rucodegen.embedded/impl/conn_params.cpp +7 -7
  88. data/tests/cpp/rucodegen.embedded/impl/conn_params.rb +14 -14
  89. data/tests/cpp/rucodegen.embedded/impl/h/conn_params.hpp +10 -10
  90. data/tests/cpp/rucodegen.embedded/prj.rb +16 -16
  91. data/tests/cpp/rucodegen.embedded/tc_rucodegen.rb +18 -18
  92. data/tests/cpp/rucodegen/host_config.cpp +20 -20
  93. data/tests/cpp/rucodegen/host_config.rb +14 -14
  94. data/tests/cpp/rucodegen/impl/conn_params.cpp +7 -7
  95. data/tests/cpp/rucodegen/impl/conn_params.rb +14 -14
  96. data/tests/cpp/rucodegen/impl/h/conn_params.hpp +10 -10
  97. data/tests/cpp/rucodegen/prj.rb +16 -16
  98. data/tests/cpp/rucodegen/tc_rucodegen.rb +18 -18
  99. data/tests/cpp/textfile_unittest/build.rb +8 -8
  100. data/tests/cpp/textfile_unittest/etalons/out_1.txt +1 -1
  101. data/tests/cpp/textfile_unittest/etalons/out_128.txt +128 -128
  102. data/tests/cpp/textfile_unittest/main.cpp +89 -89
  103. data/tests/cpp/textfile_unittest/prj.rb +8 -8
  104. data/tests/cpp/textfile_unittest/prj.ut.rb +18 -18
  105. data/tests/cpp/textfile_unittest/tc_textfile_unittest.rb +18 -18
  106. data/tests/cpp/toolset_name.rb +6 -6
  107. data/tests/cpp/vc_cleanup/prj_dll_no_implib.rb +10 -10
  108. data/tests/cpp/vc_cleanup/prj_dll_no_implib_simple_target_root.rb +11 -11
  109. data/tests/cpp/vc_cleanup/prj_dll_with_implib.rb +11 -11
  110. data/tests/cpp/vc_cleanup/prj_dll_with_implib_simple_target_root.rb +14 -14
  111. data/tests/cpp/vc_cleanup/prj_exe_no_implib.rb +10 -10
  112. data/tests/cpp/vc_cleanup/prj_exe_no_implib_simple_target_root.rb +11 -11
  113. data/tests/cpp/vc_cleanup/prj_lib.rb +10 -10
  114. data/tests/cpp/vc_cleanup/prj_lib_with_simple_target_root.rb +11 -11
  115. data/tests/cpp/vc_cleanup/tc_vc_cleanup.rb +23 -23
  116. data/tests/mxx_ru/binary_library/tc_binary_library.rb +57 -57
  117. data/tests/mxx_ru/binary_library/tc_binary_target_lib_methods.rb +114 -114
  118. data/tests/mxx_ru/change_default_value/ignoring_by_build_root/build.rb +8 -8
  119. data/tests/mxx_ru/change_default_value/ignoring_by_build_root/child_1.rb +5 -5
  120. data/tests/mxx_ru/change_default_value/ignoring_by_child_1/build.rb +7 -7
  121. data/tests/mxx_ru/change_default_value/ignoring_by_child_1/child_1.rb +5 -5
  122. data/tests/mxx_ru/change_default_value/ignoring_by_child_1/child_2.rb +5 -5
  123. data/tests/mxx_ru/change_default_value/ok/build.rb +8 -8
  124. data/tests/mxx_ru/change_default_value/ok/child_1.rb +8 -8
  125. data/tests/mxx_ru/lib_path/build.rb +8 -8
  126. data/tests/mxx_ru/lib_path/bye.rb +8 -8
  127. data/tests/mxx_ru/lib_path/hi.rb +8 -8
  128. data/tests/mxx_ru/lib_path/main.rb +12 -12
  129. data/tests/mxx_ru/lib_path/tc_lib_path.rb +18 -18
  130. data/tests/mxx_ru/obj_placements/tc_custom_subdir.rb +58 -58
  131. data/tests/mxx_ru/opt_lib_ext/build.rb +7 -7
  132. data/tests/mxx_ru/opt_lib_ext/hi.rb +7 -7
  133. data/tests/mxx_ru/opt_lib_ext/tc_opt_lib_ext.rb +18 -18
  134. data/tests/mxx_ru/opt_lib_ext/test-no-ext.rb +9 -9
  135. data/tests/mxx_ru/opt_lib_ext/test-with-ext.rb +13 -13
  136. data/tests/mxx_ru/plural_form_methods/tc.rb +72 -72
  137. data/tests/mxx_ru/qt_gen/tc_uic_result_subdir.rb +76 -76
  138. data/tests/mxx_ru/target_ext/prj_dll.rb +8 -8
  139. data/tests/mxx_ru/target_ext/prj_exe.rb +8 -8
  140. data/tests/mxx_ru/target_ext/prj_lib.rb +8 -8
  141. data/tests/mxx_ru/target_ext/tc_target_ext.rb +24 -24
  142. data/tests/mxx_ru/tc_makestyle_generator.rb +117 -117
  143. data/tests/mxx_ru/vc8/tc_actual_manifest.rb +230 -230
  144. data/tests/mxx_ru/vc8/tc_append_mt_commands.rb +104 -104
  145. data/tests/mxx_ru/vc8/tc_default_manifest.rb +17 -17
  146. data/tests/mxx_ru/vc8/tc_define_manifest.rb +173 -173
  147. data/tests/mxx_ru/vc8/tc_drop_default_manifest.rb +16 -16
  148. data/tests/mxx_ru/vc8/tc_invalid_params.rb +81 -81
  149. data/tests/mxx_ru/vc8/ts_vc8.rb +10 -10
  150. data/tests/qt/aclock/aclock.cpp +148 -148
  151. data/tests/qt/aclock/aclock.h +45 -45
  152. data/tests/qt/aclock/main.cpp +28 -28
  153. data/tests/qt/aclock/prj.rb +21 -21
  154. data/tests/qt/iconview/main.cpp +76 -76
  155. data/tests/qt/iconview/prj.rb +21 -21
  156. data/tests/qt/toplevel/main.cpp +9 -9
  157. data/tests/qt/toplevel/options.ui +587 -587
  158. data/tests/qt/toplevel/prj.rb +22 -22
  159. data/tests/test_with_compilation.rb +110 -110
  160. data/tests/unix/lib_linking_mode/a_shared.rb +7 -7
  161. data/tests/unix/lib_linking_mode/a_static.rb +7 -7
  162. data/tests/unix/lib_linking_mode/etalon/shared.txt +2 -2
  163. data/tests/unix/lib_linking_mode/etalon/static.txt +2 -2
  164. data/tests/unix/lib_linking_mode/main_conflict.rb +12 -12
  165. data/tests/unix/lib_linking_mode/main_conflict_2.rb +11 -11
  166. data/tests/unix/lib_linking_mode/main_shared.rb +9 -9
  167. data/tests/unix/lib_linking_mode/main_shared.ut.rb +11 -11
  168. data/tests/unix/lib_linking_mode/main_shared_2.rb +10 -10
  169. data/tests/unix/lib_linking_mode/main_shared_2.ut.rb +11 -11
  170. data/tests/unix/lib_linking_mode/main_static.rb +9 -9
  171. data/tests/unix/lib_linking_mode/main_static.ut.rb +11 -11
  172. data/tests/unix/lib_linking_mode/main_static_2.rb +10 -10
  173. data/tests/unix/lib_linking_mode/main_static_2.ut.rb +11 -11
  174. data/tests/unix/lib_linking_mode/tc_conflicted_build.rb +18 -18
  175. data/tests/unix/lib_linking_mode/tc_normal_build.rb +18 -18
  176. data/tests/unix/lib_order/tc_normal_build.rb +16 -16
  177. metadata +216 -205
@@ -1,167 +1,167 @@
1
- /*************************************************
2
- * Perl-Compatible Regular Expressions *
3
- *************************************************/
4
-
5
- /*
6
- PCRE 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.
8
-
9
- Written by: Philip Hazel <ph10@cam.ac.uk>
10
-
11
- Copyright (c) 1997-2003 University of Cambridge
12
-
13
- -----------------------------------------------------------------------------
14
- Permission is granted to anyone to use this software for any purpose on any
15
- computer system, and to redistribute it freely, subject to the following
16
- restrictions:
17
-
18
- 1. This software is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21
-
22
- 2. The origin of this software must not be misrepresented, either by
23
- explicit claim or by omission.
24
-
25
- 3. Altered versions must be plainly marked as such, and must not be
26
- misrepresented as being the original software.
27
-
28
- 4. If PCRE is embedded in any software that is released under the GNU
29
- General Purpose Licence (GPL), then the terms of that licence shall
30
- supersede any condition above with which it is incompatible.
31
- -----------------------------------------------------------------------------
32
-
33
- See the file Tech.Notes for some information on the internals.
34
- */
35
-
36
-
37
- /* This is a support program to generate the file chartables.c, containing
38
- character tables of various kinds. They are built according to the default C
39
- locale and used as the default tables by PCRE. Now that pcre_maketables is
40
- a function visible to the outside world, we make use of its code from here in
41
- order to be consistent. */
42
-
43
- #include <ctype.h>
44
- #include <stdio.h>
45
- #include <string.h>
46
-
47
- #include "internal.h"
48
-
49
- #define DFTABLES /* maketables.c notices this */
50
- #include "maketables.c"
51
-
52
-
53
- int main(int argc, char **argv)
54
- {
55
- int i;
56
- FILE *f;
57
- const unsigned char *tables = pcre_maketables();
58
-
59
- if (argc != 2)
60
- {
61
- fprintf(stderr, "dftables: one filename argument is required\n");
62
- return 1;
63
- }
64
-
65
- f = fopen(argv[1], "w");
66
- if (f == NULL)
67
- {
68
- fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
69
- return 1;
70
- }
71
-
72
- /* There are two fprintf() calls here, because gcc in pedantic mode complains
73
- about the very long string otherwise. */
74
-
75
- fprintf(f,
76
- "/*************************************************\n"
77
- "* Perl-Compatible Regular Expressions *\n"
78
- "*************************************************/\n\n"
79
- "/* This file is automatically written by the dftables auxiliary \n"
80
- "program. If you edit it by hand, you might like to edit the Makefile to \n"
81
- "prevent its ever being regenerated.\n\n");
82
- fprintf(f,
83
- "This file is #included in the compilation of pcre.c to build the default\n"
84
- "character tables which are used when no tables are passed to the compile\n"
85
- "function. */\n\n"
86
- "static unsigned char pcre_default_tables[] = {\n\n"
87
- "/* This table is a lower casing table. */\n\n");
88
-
89
- fprintf(f, " ");
90
- for (i = 0; i < 256; i++)
91
- {
92
- if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
93
- fprintf(f, "%3d", *tables++);
94
- if (i != 255) fprintf(f, ",");
95
- }
96
- fprintf(f, ",\n\n");
97
-
98
- fprintf(f, "/* This table is a case flipping table. */\n\n");
99
-
100
- fprintf(f, " ");
101
- for (i = 0; i < 256; i++)
102
- {
103
- if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
104
- fprintf(f, "%3d", *tables++);
105
- if (i != 255) fprintf(f, ",");
106
- }
107
- fprintf(f, ",\n\n");
108
-
109
- fprintf(f,
110
- "/* This table contains bit maps for various character classes.\n"
111
- "Each map is 32 bytes long and the bits run from the least\n"
112
- "significant end of each byte. The classes that have their own\n"
113
- "maps are: space, xdigit, digit, upper, lower, word, graph\n"
114
- "print, punct, and cntrl. Other classes are built from combinations. */\n\n");
115
-
116
- fprintf(f, " ");
117
- for (i = 0; i < cbit_length; i++)
118
- {
119
- if ((i & 7) == 0 && i != 0)
120
- {
121
- if ((i & 31) == 0) fprintf(f, "\n");
122
- fprintf(f, "\n ");
123
- }
124
- fprintf(f, "0x%02x", *tables++);
125
- if (i != cbit_length - 1) fprintf(f, ",");
126
- }
127
- fprintf(f, ",\n\n");
128
-
129
- fprintf(f,
130
- "/* This table identifies various classes of character by individual bits:\n"
131
- " 0x%02x white space character\n"
132
- " 0x%02x letter\n"
133
- " 0x%02x decimal digit\n"
134
- " 0x%02x hexadecimal digit\n"
135
- " 0x%02x alphanumeric or '_'\n"
136
- " 0x%02x regular expression metacharacter or binary zero\n*/\n\n",
137
- ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
138
- ctype_meta);
139
-
140
- fprintf(f, " ");
141
- for (i = 0; i < 256; i++)
142
- {
143
- if ((i & 7) == 0 && i != 0)
144
- {
145
- fprintf(f, " /* ");
146
- if (isprint(i-8)) fprintf(f, " %c -", i-8);
147
- else fprintf(f, "%3d-", i-8);
148
- if (isprint(i-1)) fprintf(f, " %c ", i-1);
149
- else fprintf(f, "%3d", i-1);
150
- fprintf(f, " */\n ");
151
- }
152
- fprintf(f, "0x%02x", *tables++);
153
- if (i != 255) fprintf(f, ",");
154
- }
155
-
156
- fprintf(f, "};/* ");
157
- if (isprint(i-8)) fprintf(f, " %c -", i-8);
158
- else fprintf(f, "%3d-", i-8);
159
- if (isprint(i-1)) fprintf(f, " %c ", i-1);
160
- else fprintf(f, "%3d", i-1);
161
- fprintf(f, " */\n\n/* End of chartables.c */\n");
162
-
163
- fclose(f);
164
- return 0;
165
- }
166
-
167
- /* End of dftables.c */
1
+ /*************************************************
2
+ * Perl-Compatible Regular Expressions *
3
+ *************************************************/
4
+
5
+ /*
6
+ PCRE 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.
8
+
9
+ Written by: Philip Hazel <ph10@cam.ac.uk>
10
+
11
+ Copyright (c) 1997-2003 University of Cambridge
12
+
13
+ -----------------------------------------------------------------------------
14
+ Permission is granted to anyone to use this software for any purpose on any
15
+ computer system, and to redistribute it freely, subject to the following
16
+ restrictions:
17
+
18
+ 1. This software is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21
+
22
+ 2. The origin of this software must not be misrepresented, either by
23
+ explicit claim or by omission.
24
+
25
+ 3. Altered versions must be plainly marked as such, and must not be
26
+ misrepresented as being the original software.
27
+
28
+ 4. If PCRE is embedded in any software that is released under the GNU
29
+ General Purpose Licence (GPL), then the terms of that licence shall
30
+ supersede any condition above with which it is incompatible.
31
+ -----------------------------------------------------------------------------
32
+
33
+ See the file Tech.Notes for some information on the internals.
34
+ */
35
+
36
+
37
+ /* This is a support program to generate the file chartables.c, containing
38
+ character tables of various kinds. They are built according to the default C
39
+ locale and used as the default tables by PCRE. Now that pcre_maketables is
40
+ a function visible to the outside world, we make use of its code from here in
41
+ order to be consistent. */
42
+
43
+ #include <ctype.h>
44
+ #include <stdio.h>
45
+ #include <string.h>
46
+
47
+ #include "internal.h"
48
+
49
+ #define DFTABLES /* maketables.c notices this */
50
+ #include "maketables.c"
51
+
52
+
53
+ int main(int argc, char **argv)
54
+ {
55
+ int i;
56
+ FILE *f;
57
+ const unsigned char *tables = pcre_maketables();
58
+
59
+ if (argc != 2)
60
+ {
61
+ fprintf(stderr, "dftables: one filename argument is required\n");
62
+ return 1;
63
+ }
64
+
65
+ f = fopen(argv[1], "w");
66
+ if (f == NULL)
67
+ {
68
+ fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
69
+ return 1;
70
+ }
71
+
72
+ /* There are two fprintf() calls here, because gcc in pedantic mode complains
73
+ about the very long string otherwise. */
74
+
75
+ fprintf(f,
76
+ "/*************************************************\n"
77
+ "* Perl-Compatible Regular Expressions *\n"
78
+ "*************************************************/\n\n"
79
+ "/* This file is automatically written by the dftables auxiliary \n"
80
+ "program. If you edit it by hand, you might like to edit the Makefile to \n"
81
+ "prevent its ever being regenerated.\n\n");
82
+ fprintf(f,
83
+ "This file is #included in the compilation of pcre.c to build the default\n"
84
+ "character tables which are used when no tables are passed to the compile\n"
85
+ "function. */\n\n"
86
+ "static unsigned char pcre_default_tables[] = {\n\n"
87
+ "/* This table is a lower casing table. */\n\n");
88
+
89
+ fprintf(f, " ");
90
+ for (i = 0; i < 256; i++)
91
+ {
92
+ if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
93
+ fprintf(f, "%3d", *tables++);
94
+ if (i != 255) fprintf(f, ",");
95
+ }
96
+ fprintf(f, ",\n\n");
97
+
98
+ fprintf(f, "/* This table is a case flipping table. */\n\n");
99
+
100
+ fprintf(f, " ");
101
+ for (i = 0; i < 256; i++)
102
+ {
103
+ if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
104
+ fprintf(f, "%3d", *tables++);
105
+ if (i != 255) fprintf(f, ",");
106
+ }
107
+ fprintf(f, ",\n\n");
108
+
109
+ fprintf(f,
110
+ "/* This table contains bit maps for various character classes.\n"
111
+ "Each map is 32 bytes long and the bits run from the least\n"
112
+ "significant end of each byte. The classes that have their own\n"
113
+ "maps are: space, xdigit, digit, upper, lower, word, graph\n"
114
+ "print, punct, and cntrl. Other classes are built from combinations. */\n\n");
115
+
116
+ fprintf(f, " ");
117
+ for (i = 0; i < cbit_length; i++)
118
+ {
119
+ if ((i & 7) == 0 && i != 0)
120
+ {
121
+ if ((i & 31) == 0) fprintf(f, "\n");
122
+ fprintf(f, "\n ");
123
+ }
124
+ fprintf(f, "0x%02x", *tables++);
125
+ if (i != cbit_length - 1) fprintf(f, ",");
126
+ }
127
+ fprintf(f, ",\n\n");
128
+
129
+ fprintf(f,
130
+ "/* This table identifies various classes of character by individual bits:\n"
131
+ " 0x%02x white space character\n"
132
+ " 0x%02x letter\n"
133
+ " 0x%02x decimal digit\n"
134
+ " 0x%02x hexadecimal digit\n"
135
+ " 0x%02x alphanumeric or '_'\n"
136
+ " 0x%02x regular expression metacharacter or binary zero\n*/\n\n",
137
+ ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
138
+ ctype_meta);
139
+
140
+ fprintf(f, " ");
141
+ for (i = 0; i < 256; i++)
142
+ {
143
+ if ((i & 7) == 0 && i != 0)
144
+ {
145
+ fprintf(f, " /* ");
146
+ if (isprint(i-8)) fprintf(f, " %c -", i-8);
147
+ else fprintf(f, "%3d-", i-8);
148
+ if (isprint(i-1)) fprintf(f, " %c ", i-1);
149
+ else fprintf(f, "%3d", i-1);
150
+ fprintf(f, " */\n ");
151
+ }
152
+ fprintf(f, "0x%02x", *tables++);
153
+ if (i != 255) fprintf(f, ",");
154
+ }
155
+
156
+ fprintf(f, "};/* ");
157
+ if (isprint(i-8)) fprintf(f, " %c -", i-8);
158
+ else fprintf(f, "%3d-", i-8);
159
+ if (isprint(i-1)) fprintf(f, " %c ", i-1);
160
+ else fprintf(f, "%3d", i-1);
161
+ fprintf(f, " */\n\n/* End of chartables.c */\n");
162
+
163
+ fclose(f);
164
+ return 0;
165
+ }
166
+
167
+ /* End of dftables.c */
data/tests/c/pcre/get.c CHANGED
@@ -1,349 +1,349 @@
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
- Written by: Philip Hazel <ph10@cam.ac.uk>
11
-
12
- Copyright (c) 1997-2003 University of Cambridge
13
-
14
- -----------------------------------------------------------------------------
15
- Permission is granted to anyone to use this software for any purpose on any
16
- computer system, and to redistribute it freely, subject to the following
17
- restrictions:
18
-
19
- 1. This software is distributed in the hope that it will be useful,
20
- but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22
-
23
- 2. The origin of this software must not be misrepresented, either by
24
- explicit claim or by omission.
25
-
26
- 3. Altered versions must be plainly marked as such, and must not be
27
- misrepresented as being the original software.
28
-
29
- 4. If PCRE is embedded in any software that is released under the GNU
30
- General Purpose Licence (GPL), then the terms of that licence shall
31
- supersede any condition above with which it is incompatible.
32
- -----------------------------------------------------------------------------
33
- */
34
-
35
- /* This module contains some convenience functions for extracting substrings
36
- from the subject string after a regex match has succeeded. The original idea
37
- for these functions came from Scott Wimer <scottw@cgibuilder.com>. */
38
-
39
-
40
- /* Include the internals header, which itself includes Standard C headers plus
41
- the external pcre header. */
42
-
43
- #include "internal.h"
44
-
45
-
46
- /*************************************************
47
- * Find number for named string *
48
- *************************************************/
49
-
50
- /* This function is used by the two extraction functions below, as well
51
- as being generally available.
52
-
53
- Arguments:
54
- code the compiled regex
55
- stringname the name whose number is required
56
-
57
- Returns: the number of the named parentheses, or a negative number
58
- (PCRE_ERROR_NOSUBSTRING) if not found
59
- */
60
-
61
- int
62
- pcre_get_stringnumber(const pcre *code, const char *stringname)
63
- {
64
- int rc;
65
- int entrysize;
66
- int top, bot;
67
- uschar *nametable;
68
-
69
- if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMECOUNT, &top)) != 0)
70
- return rc;
71
- if (top <= 0) return PCRE_ERROR_NOSUBSTRING;
72
-
73
- if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMEENTRYSIZE, &entrysize)) != 0)
74
- return rc;
75
- if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMETABLE, &nametable)) != 0)
76
- return rc;
77
-
78
- bot = 0;
79
- while (top > bot)
80
- {
81
- int mid = (top + bot) / 2;
82
- uschar *entry = nametable + entrysize*mid;
83
- int c = strcmp(stringname, (char *)(entry + 2));
84
- if (c == 0) return (entry[0] << 8) + entry[1];
85
- if (c > 0) bot = mid + 1; else top = mid;
86
- }
87
-
88
- return PCRE_ERROR_NOSUBSTRING;
89
- }
90
-
91
-
92
-
93
- /*************************************************
94
- * Copy captured string to given buffer *
95
- *************************************************/
96
-
97
- /* This function copies a single captured substring into a given buffer.
98
- Note that we use memcpy() rather than strncpy() in case there are binary zeros
99
- in the string.
100
-
101
- Arguments:
102
- subject the subject string that was matched
103
- ovector pointer to the offsets table
104
- stringcount the number of substrings that were captured
105
- (i.e. the yield of the pcre_exec call, unless
106
- that was zero, in which case it should be 1/3
107
- of the offset table size)
108
- stringnumber the number of the required substring
109
- buffer where to put the substring
110
- size the size of the buffer
111
-
112
- Returns: if successful:
113
- the length of the copied string, not including the zero
114
- that is put on the end; can be zero
115
- if not successful:
116
- PCRE_ERROR_NOMEMORY (-6) buffer too small
117
- PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
118
- */
119
-
120
- int
121
- pcre_copy_substring(const char *subject, int *ovector, int stringcount,
122
- int stringnumber, char *buffer, int size)
123
- {
124
- int yield;
125
- if (stringnumber < 0 || stringnumber >= stringcount)
126
- return PCRE_ERROR_NOSUBSTRING;
127
- stringnumber *= 2;
128
- yield = ovector[stringnumber+1] - ovector[stringnumber];
129
- if (size < yield + 1) return PCRE_ERROR_NOMEMORY;
130
- memcpy(buffer, subject + ovector[stringnumber], yield);
131
- buffer[yield] = 0;
132
- return yield;
133
- }
134
-
135
-
136
-
137
- /*************************************************
138
- * Copy named captured string to given buffer *
139
- *************************************************/
140
-
141
- /* This function copies a single captured substring into a given buffer,
142
- identifying it by name.
143
-
144
- Arguments:
145
- code the compiled regex
146
- subject the subject string that was matched
147
- ovector pointer to the offsets table
148
- stringcount the number of substrings that were captured
149
- (i.e. the yield of the pcre_exec call, unless
150
- that was zero, in which case it should be 1/3
151
- of the offset table size)
152
- stringname the name of the required substring
153
- buffer where to put the substring
154
- size the size of the buffer
155
-
156
- Returns: if successful:
157
- the length of the copied string, not including the zero
158
- that is put on the end; can be zero
159
- if not successful:
160
- PCRE_ERROR_NOMEMORY (-6) buffer too small
161
- PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
162
- */
163
-
164
- int
165
- pcre_copy_named_substring(const pcre *code, const char *subject, int *ovector,
166
- int stringcount, const char *stringname, char *buffer, int size)
167
- {
168
- int n = pcre_get_stringnumber(code, stringname);
169
- if (n <= 0) return n;
170
- return pcre_copy_substring(subject, ovector, stringcount, n, buffer, size);
171
- }
172
-
173
-
174
-
175
- /*************************************************
176
- * Copy all captured strings to new store *
177
- *************************************************/
178
-
179
- /* This function gets one chunk of store and builds a list of pointers and all
180
- of the captured substrings in it. A NULL pointer is put on the end of the list.
181
-
182
- Arguments:
183
- subject the subject string that was matched
184
- ovector pointer to the offsets table
185
- stringcount the number of substrings that were captured
186
- (i.e. the yield of the pcre_exec call, unless
187
- that was zero, in which case it should be 1/3
188
- of the offset table size)
189
- listptr set to point to the list of pointers
190
-
191
- Returns: if successful: 0
192
- if not successful:
193
- PCRE_ERROR_NOMEMORY (-6) failed to get store
194
- */
195
-
196
- int
197
- pcre_get_substring_list(const char *subject, int *ovector, int stringcount,
198
- const char ***listptr)
199
- {
200
- int i;
201
- int size = sizeof(char *);
202
- int double_count = stringcount * 2;
203
- char **stringlist;
204
- char *p;
205
-
206
- for (i = 0; i < double_count; i += 2)
207
- size += sizeof(char *) + ovector[i+1] - ovector[i] + 1;
208
-
209
- stringlist = (char **)(pcre_malloc)(size);
210
- if (stringlist == NULL) return PCRE_ERROR_NOMEMORY;
211
-
212
- *listptr = (const char **)stringlist;
213
- p = (char *)(stringlist + stringcount + 1);
214
-
215
- for (i = 0; i < double_count; i += 2)
216
- {
217
- int len = ovector[i+1] - ovector[i];
218
- memcpy(p, subject + ovector[i], len);
219
- *stringlist++ = p;
220
- p += len;
221
- *p++ = 0;
222
- }
223
-
224
- *stringlist = NULL;
225
- return 0;
226
- }
227
-
228
-
229
-
230
- /*************************************************
231
- * Free store obtained by get_substring_list *
232
- *************************************************/
233
-
234
- /* This function exists for the benefit of people calling PCRE from non-C
235
- programs that can call its functions, but not free() or (pcre_free)() directly.
236
-
237
- Argument: the result of a previous pcre_get_substring_list()
238
- Returns: nothing
239
- */
240
-
241
- void
242
- pcre_free_substring_list(const char **pointer)
243
- {
244
- (pcre_free)((void *)pointer);
245
- }
246
-
247
-
248
-
249
- /*************************************************
250
- * Copy captured string to new store *
251
- *************************************************/
252
-
253
- /* This function copies a single captured substring into a piece of new
254
- store
255
-
256
- Arguments:
257
- subject the subject string that was matched
258
- ovector pointer to the offsets table
259
- stringcount the number of substrings that were captured
260
- (i.e. the yield of the pcre_exec call, unless
261
- that was zero, in which case it should be 1/3
262
- of the offset table size)
263
- stringnumber the number of the required substring
264
- stringptr where to put a pointer to the substring
265
-
266
- Returns: if successful:
267
- the length of the string, not including the zero that
268
- is put on the end; can be zero
269
- if not successful:
270
- PCRE_ERROR_NOMEMORY (-6) failed to get store
271
- PCRE_ERROR_NOSUBSTRING (-7) substring not present
272
- */
273
-
274
- int
275
- pcre_get_substring(const char *subject, int *ovector, int stringcount,
276
- int stringnumber, const char **stringptr)
277
- {
278
- int yield;
279
- char *substring;
280
- if (stringnumber < 0 || stringnumber >= stringcount)
281
- return PCRE_ERROR_NOSUBSTRING;
282
- stringnumber *= 2;
283
- yield = ovector[stringnumber+1] - ovector[stringnumber];
284
- substring = (char *)(pcre_malloc)(yield + 1);
285
- if (substring == NULL) return PCRE_ERROR_NOMEMORY;
286
- memcpy(substring, subject + ovector[stringnumber], yield);
287
- substring[yield] = 0;
288
- *stringptr = substring;
289
- return yield;
290
- }
291
-
292
-
293
-
294
- /*************************************************
295
- * Copy named captured string to new store *
296
- *************************************************/
297
-
298
- /* This function copies a single captured substring, identified by name, into
299
- new store.
300
-
301
- Arguments:
302
- code the compiled regex
303
- subject the subject string that was matched
304
- ovector pointer to the offsets table
305
- stringcount the number of substrings that were captured
306
- (i.e. the yield of the pcre_exec call, unless
307
- that was zero, in which case it should be 1/3
308
- of the offset table size)
309
- stringname the name of the required substring
310
- stringptr where to put the pointer
311
-
312
- Returns: if successful:
313
- the length of the copied string, not including the zero
314
- that is put on the end; can be zero
315
- if not successful:
316
- PCRE_ERROR_NOMEMORY (-6) couldn't get memory
317
- PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
318
- */
319
-
320
- int
321
- pcre_get_named_substring(const pcre *code, const char *subject, int *ovector,
322
- int stringcount, const char *stringname, const char **stringptr)
323
- {
324
- int n = pcre_get_stringnumber(code, stringname);
325
- if (n <= 0) return n;
326
- return pcre_get_substring(subject, ovector, stringcount, n, stringptr);
327
- }
328
-
329
-
330
-
331
-
332
- /*************************************************
333
- * Free store obtained by get_substring *
334
- *************************************************/
335
-
336
- /* This function exists for the benefit of people calling PCRE from non-C
337
- programs that can call its functions, but not free() or (pcre_free)() directly.
338
-
339
- Argument: the result of a previous pcre_get_substring()
340
- Returns: nothing
341
- */
342
-
343
- void
344
- pcre_free_substring(const char *pointer)
345
- {
346
- (pcre_free)((void *)pointer);
347
- }
348
-
349
- /* End of get.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
+ Written by: Philip Hazel <ph10@cam.ac.uk>
11
+
12
+ Copyright (c) 1997-2003 University of Cambridge
13
+
14
+ -----------------------------------------------------------------------------
15
+ Permission is granted to anyone to use this software for any purpose on any
16
+ computer system, and to redistribute it freely, subject to the following
17
+ restrictions:
18
+
19
+ 1. This software is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22
+
23
+ 2. The origin of this software must not be misrepresented, either by
24
+ explicit claim or by omission.
25
+
26
+ 3. Altered versions must be plainly marked as such, and must not be
27
+ misrepresented as being the original software.
28
+
29
+ 4. If PCRE is embedded in any software that is released under the GNU
30
+ General Purpose Licence (GPL), then the terms of that licence shall
31
+ supersede any condition above with which it is incompatible.
32
+ -----------------------------------------------------------------------------
33
+ */
34
+
35
+ /* This module contains some convenience functions for extracting substrings
36
+ from the subject string after a regex match has succeeded. The original idea
37
+ for these functions came from Scott Wimer <scottw@cgibuilder.com>. */
38
+
39
+
40
+ /* Include the internals header, which itself includes Standard C headers plus
41
+ the external pcre header. */
42
+
43
+ #include "internal.h"
44
+
45
+
46
+ /*************************************************
47
+ * Find number for named string *
48
+ *************************************************/
49
+
50
+ /* This function is used by the two extraction functions below, as well
51
+ as being generally available.
52
+
53
+ Arguments:
54
+ code the compiled regex
55
+ stringname the name whose number is required
56
+
57
+ Returns: the number of the named parentheses, or a negative number
58
+ (PCRE_ERROR_NOSUBSTRING) if not found
59
+ */
60
+
61
+ int
62
+ pcre_get_stringnumber(const pcre *code, const char *stringname)
63
+ {
64
+ int rc;
65
+ int entrysize;
66
+ int top, bot;
67
+ uschar *nametable;
68
+
69
+ if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMECOUNT, &top)) != 0)
70
+ return rc;
71
+ if (top <= 0) return PCRE_ERROR_NOSUBSTRING;
72
+
73
+ if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMEENTRYSIZE, &entrysize)) != 0)
74
+ return rc;
75
+ if ((rc = pcre_fullinfo(code, NULL, PCRE_INFO_NAMETABLE, &nametable)) != 0)
76
+ return rc;
77
+
78
+ bot = 0;
79
+ while (top > bot)
80
+ {
81
+ int mid = (top + bot) / 2;
82
+ uschar *entry = nametable + entrysize*mid;
83
+ int c = strcmp(stringname, (char *)(entry + 2));
84
+ if (c == 0) return (entry[0] << 8) + entry[1];
85
+ if (c > 0) bot = mid + 1; else top = mid;
86
+ }
87
+
88
+ return PCRE_ERROR_NOSUBSTRING;
89
+ }
90
+
91
+
92
+
93
+ /*************************************************
94
+ * Copy captured string to given buffer *
95
+ *************************************************/
96
+
97
+ /* This function copies a single captured substring into a given buffer.
98
+ Note that we use memcpy() rather than strncpy() in case there are binary zeros
99
+ in the string.
100
+
101
+ Arguments:
102
+ subject the subject string that was matched
103
+ ovector pointer to the offsets table
104
+ stringcount the number of substrings that were captured
105
+ (i.e. the yield of the pcre_exec call, unless
106
+ that was zero, in which case it should be 1/3
107
+ of the offset table size)
108
+ stringnumber the number of the required substring
109
+ buffer where to put the substring
110
+ size the size of the buffer
111
+
112
+ Returns: if successful:
113
+ the length of the copied string, not including the zero
114
+ that is put on the end; can be zero
115
+ if not successful:
116
+ PCRE_ERROR_NOMEMORY (-6) buffer too small
117
+ PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
118
+ */
119
+
120
+ int
121
+ pcre_copy_substring(const char *subject, int *ovector, int stringcount,
122
+ int stringnumber, char *buffer, int size)
123
+ {
124
+ int yield;
125
+ if (stringnumber < 0 || stringnumber >= stringcount)
126
+ return PCRE_ERROR_NOSUBSTRING;
127
+ stringnumber *= 2;
128
+ yield = ovector[stringnumber+1] - ovector[stringnumber];
129
+ if (size < yield + 1) return PCRE_ERROR_NOMEMORY;
130
+ memcpy(buffer, subject + ovector[stringnumber], yield);
131
+ buffer[yield] = 0;
132
+ return yield;
133
+ }
134
+
135
+
136
+
137
+ /*************************************************
138
+ * Copy named captured string to given buffer *
139
+ *************************************************/
140
+
141
+ /* This function copies a single captured substring into a given buffer,
142
+ identifying it by name.
143
+
144
+ Arguments:
145
+ code the compiled regex
146
+ subject the subject string that was matched
147
+ ovector pointer to the offsets table
148
+ stringcount the number of substrings that were captured
149
+ (i.e. the yield of the pcre_exec call, unless
150
+ that was zero, in which case it should be 1/3
151
+ of the offset table size)
152
+ stringname the name of the required substring
153
+ buffer where to put the substring
154
+ size the size of the buffer
155
+
156
+ Returns: if successful:
157
+ the length of the copied string, not including the zero
158
+ that is put on the end; can be zero
159
+ if not successful:
160
+ PCRE_ERROR_NOMEMORY (-6) buffer too small
161
+ PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
162
+ */
163
+
164
+ int
165
+ pcre_copy_named_substring(const pcre *code, const char *subject, int *ovector,
166
+ int stringcount, const char *stringname, char *buffer, int size)
167
+ {
168
+ int n = pcre_get_stringnumber(code, stringname);
169
+ if (n <= 0) return n;
170
+ return pcre_copy_substring(subject, ovector, stringcount, n, buffer, size);
171
+ }
172
+
173
+
174
+
175
+ /*************************************************
176
+ * Copy all captured strings to new store *
177
+ *************************************************/
178
+
179
+ /* This function gets one chunk of store and builds a list of pointers and all
180
+ of the captured substrings in it. A NULL pointer is put on the end of the list.
181
+
182
+ Arguments:
183
+ subject the subject string that was matched
184
+ ovector pointer to the offsets table
185
+ stringcount the number of substrings that were captured
186
+ (i.e. the yield of the pcre_exec call, unless
187
+ that was zero, in which case it should be 1/3
188
+ of the offset table size)
189
+ listptr set to point to the list of pointers
190
+
191
+ Returns: if successful: 0
192
+ if not successful:
193
+ PCRE_ERROR_NOMEMORY (-6) failed to get store
194
+ */
195
+
196
+ int
197
+ pcre_get_substring_list(const char *subject, int *ovector, int stringcount,
198
+ const char ***listptr)
199
+ {
200
+ int i;
201
+ int size = sizeof(char *);
202
+ int double_count = stringcount * 2;
203
+ char **stringlist;
204
+ char *p;
205
+
206
+ for (i = 0; i < double_count; i += 2)
207
+ size += sizeof(char *) + ovector[i+1] - ovector[i] + 1;
208
+
209
+ stringlist = (char **)(pcre_malloc)(size);
210
+ if (stringlist == NULL) return PCRE_ERROR_NOMEMORY;
211
+
212
+ *listptr = (const char **)stringlist;
213
+ p = (char *)(stringlist + stringcount + 1);
214
+
215
+ for (i = 0; i < double_count; i += 2)
216
+ {
217
+ int len = ovector[i+1] - ovector[i];
218
+ memcpy(p, subject + ovector[i], len);
219
+ *stringlist++ = p;
220
+ p += len;
221
+ *p++ = 0;
222
+ }
223
+
224
+ *stringlist = NULL;
225
+ return 0;
226
+ }
227
+
228
+
229
+
230
+ /*************************************************
231
+ * Free store obtained by get_substring_list *
232
+ *************************************************/
233
+
234
+ /* This function exists for the benefit of people calling PCRE from non-C
235
+ programs that can call its functions, but not free() or (pcre_free)() directly.
236
+
237
+ Argument: the result of a previous pcre_get_substring_list()
238
+ Returns: nothing
239
+ */
240
+
241
+ void
242
+ pcre_free_substring_list(const char **pointer)
243
+ {
244
+ (pcre_free)((void *)pointer);
245
+ }
246
+
247
+
248
+
249
+ /*************************************************
250
+ * Copy captured string to new store *
251
+ *************************************************/
252
+
253
+ /* This function copies a single captured substring into a piece of new
254
+ store
255
+
256
+ Arguments:
257
+ subject the subject string that was matched
258
+ ovector pointer to the offsets table
259
+ stringcount the number of substrings that were captured
260
+ (i.e. the yield of the pcre_exec call, unless
261
+ that was zero, in which case it should be 1/3
262
+ of the offset table size)
263
+ stringnumber the number of the required substring
264
+ stringptr where to put a pointer to the substring
265
+
266
+ Returns: if successful:
267
+ the length of the string, not including the zero that
268
+ is put on the end; can be zero
269
+ if not successful:
270
+ PCRE_ERROR_NOMEMORY (-6) failed to get store
271
+ PCRE_ERROR_NOSUBSTRING (-7) substring not present
272
+ */
273
+
274
+ int
275
+ pcre_get_substring(const char *subject, int *ovector, int stringcount,
276
+ int stringnumber, const char **stringptr)
277
+ {
278
+ int yield;
279
+ char *substring;
280
+ if (stringnumber < 0 || stringnumber >= stringcount)
281
+ return PCRE_ERROR_NOSUBSTRING;
282
+ stringnumber *= 2;
283
+ yield = ovector[stringnumber+1] - ovector[stringnumber];
284
+ substring = (char *)(pcre_malloc)(yield + 1);
285
+ if (substring == NULL) return PCRE_ERROR_NOMEMORY;
286
+ memcpy(substring, subject + ovector[stringnumber], yield);
287
+ substring[yield] = 0;
288
+ *stringptr = substring;
289
+ return yield;
290
+ }
291
+
292
+
293
+
294
+ /*************************************************
295
+ * Copy named captured string to new store *
296
+ *************************************************/
297
+
298
+ /* This function copies a single captured substring, identified by name, into
299
+ new store.
300
+
301
+ Arguments:
302
+ code the compiled regex
303
+ subject the subject string that was matched
304
+ ovector pointer to the offsets table
305
+ stringcount the number of substrings that were captured
306
+ (i.e. the yield of the pcre_exec call, unless
307
+ that was zero, in which case it should be 1/3
308
+ of the offset table size)
309
+ stringname the name of the required substring
310
+ stringptr where to put the pointer
311
+
312
+ Returns: if successful:
313
+ the length of the copied string, not including the zero
314
+ that is put on the end; can be zero
315
+ if not successful:
316
+ PCRE_ERROR_NOMEMORY (-6) couldn't get memory
317
+ PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
318
+ */
319
+
320
+ int
321
+ pcre_get_named_substring(const pcre *code, const char *subject, int *ovector,
322
+ int stringcount, const char *stringname, const char **stringptr)
323
+ {
324
+ int n = pcre_get_stringnumber(code, stringname);
325
+ if (n <= 0) return n;
326
+ return pcre_get_substring(subject, ovector, stringcount, n, stringptr);
327
+ }
328
+
329
+
330
+
331
+
332
+ /*************************************************
333
+ * Free store obtained by get_substring *
334
+ *************************************************/
335
+
336
+ /* This function exists for the benefit of people calling PCRE from non-C
337
+ programs that can call its functions, but not free() or (pcre_free)() directly.
338
+
339
+ Argument: the result of a previous pcre_get_substring()
340
+ Returns: nothing
341
+ */
342
+
343
+ void
344
+ pcre_free_substring(const char *pointer)
345
+ {
346
+ (pcre_free)((void *)pointer);
347
+ }
348
+
349
+ /* End of get.c */