sedna 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/{CHANGES → CHANGES.rdoc} +9 -0
  2. data/{README → README.rdoc} +23 -25
  3. data/Rakefile +32 -9
  4. data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
  5. data/ext/{sedna.c → sedna/sedna.c} +48 -40
  6. data/test/sedna_test.rb +9 -9
  7. data/vendor/sedna/AUTHORS +18 -0
  8. data/vendor/sedna/COPYRIGHT +90 -0
  9. data/vendor/sedna/LICENSE +202 -0
  10. data/vendor/sedna/Makefile.include +423 -0
  11. data/vendor/sedna/Makefile.platform +31 -0
  12. data/vendor/sedna/depend.sed +48 -0
  13. data/vendor/sedna/driver/c/Makefile +98 -0
  14. data/vendor/sedna/driver/c/libsedna.c +1998 -0
  15. data/vendor/sedna/driver/c/libsedna.h +199 -0
  16. data/vendor/sedna/driver/c/sednamt.def +21 -0
  17. data/vendor/sedna/driver/c/sp_defs.h +186 -0
  18. data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
  19. data/vendor/sedna/kernel/common/IntHash.h +314 -0
  20. data/vendor/sedna/kernel/common/IntList.h +224 -0
  21. data/vendor/sedna/kernel/common/Makefile +30 -0
  22. data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
  23. data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
  24. data/vendor/sedna/kernel/common/XptrHash.h +435 -0
  25. data/vendor/sedna/kernel/common/argtable.c +972 -0
  26. data/vendor/sedna/kernel/common/argtable.h +896 -0
  27. data/vendor/sedna/kernel/common/base.cpp +339 -0
  28. data/vendor/sedna/kernel/common/base.h +226 -0
  29. data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
  30. data/vendor/sedna/kernel/common/bit_set.h +55 -0
  31. data/vendor/sedna/kernel/common/commutil.h +67 -0
  32. data/vendor/sedna/kernel/common/config.h +62 -0
  33. data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
  34. data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
  35. data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
  36. data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
  37. data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
  38. data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
  39. data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
  40. data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
  41. data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
  42. data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
  43. data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
  44. data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
  45. data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
  46. data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
  47. data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
  48. data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
  49. data/vendor/sedna/kernel/common/gmm.cpp +192 -0
  50. data/vendor/sedna/kernel/common/gmm.h +29 -0
  51. data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
  52. data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
  53. data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
  54. data/vendor/sedna/kernel/common/lm_base.h +90 -0
  55. data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
  56. data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
  57. data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
  58. data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
  59. data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
  60. data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
  61. data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
  62. data/vendor/sedna/kernel/common/pping.cpp +672 -0
  63. data/vendor/sedna/kernel/common/pping.h +119 -0
  64. data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
  65. data/vendor/sedna/kernel/common/rcv_test.h +19 -0
  66. data/vendor/sedna/kernel/common/sedna.c +128 -0
  67. data/vendor/sedna/kernel/common/sedna.h +49 -0
  68. data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
  69. data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
  70. data/vendor/sedna/kernel/common/sp.c +93 -0
  71. data/vendor/sedna/kernel/common/sp.h +36 -0
  72. data/vendor/sedna/kernel/common/st/Makefile +20 -0
  73. data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
  74. data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
  75. data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
  76. data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
  77. data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
  78. data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
  79. data/vendor/sedna/kernel/common/tr_debug.h +22 -0
  80. data/vendor/sedna/kernel/common/u/Makefile +14 -0
  81. data/vendor/sedna/kernel/common/u/u.c +268 -0
  82. data/vendor/sedna/kernel/common/u/u.h +715 -0
  83. data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
  84. data/vendor/sedna/kernel/common/u/udl.h +31 -0
  85. data/vendor/sedna/kernel/common/u/uevent.c +406 -0
  86. data/vendor/sedna/kernel/common/u/uevent.h +71 -0
  87. data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
  88. data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
  89. data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
  90. data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
  91. data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
  92. data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
  93. data/vendor/sedna/kernel/common/u/ummap.h +60 -0
  94. data/vendor/sedna/kernel/common/u/umutex.c +145 -0
  95. data/vendor/sedna/kernel/common/u/umutex.h +65 -0
  96. data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
  97. data/vendor/sedna/kernel/common/u/upipe.h +74 -0
  98. data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
  99. data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
  100. data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
  101. data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
  102. data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
  103. data/vendor/sedna/kernel/common/u/usem.c +891 -0
  104. data/vendor/sedna/kernel/common/u/usem.h +83 -0
  105. data/vendor/sedna/kernel/common/u/ushm.c +222 -0
  106. data/vendor/sedna/kernel/common/u/ushm.h +46 -0
  107. data/vendor/sedna/kernel/common/u/usocket.c +541 -0
  108. data/vendor/sedna/kernel/common/u/usocket.h +118 -0
  109. data/vendor/sedna/kernel/common/u/usystem.c +57 -0
  110. data/vendor/sedna/kernel/common/u/usystem.h +46 -0
  111. data/vendor/sedna/kernel/common/u/uthread.c +259 -0
  112. data/vendor/sedna/kernel/common/u/uthread.h +95 -0
  113. data/vendor/sedna/kernel/common/u/utime.c +65 -0
  114. data/vendor/sedna/kernel/common/u/utime.h +40 -0
  115. data/vendor/sedna/kernel/common/u/uutils.c +142 -0
  116. data/vendor/sedna/kernel/common/u/uutils.h +65 -0
  117. data/vendor/sedna/kernel/common/ugc.cpp +156 -0
  118. data/vendor/sedna/kernel/common/ugc.h +15 -0
  119. data/vendor/sedna/kernel/common/utils.cpp +156 -0
  120. data/vendor/sedna/kernel/common/utils.h +133 -0
  121. data/vendor/sedna/kernel/common/version.c +16 -0
  122. data/vendor/sedna/kernel/common/version.h +21 -0
  123. data/vendor/sedna/kernel/common/wustructures.h +18 -0
  124. data/vendor/sedna/kernel/common/wutypes.h +34 -0
  125. data/vendor/sedna/kernel/common/xptr.cpp +17 -0
  126. data/vendor/sedna/kernel/common/xptr.h +211 -0
  127. data/vendor/sedna/ver +1 -0
  128. metadata +142 -14
@@ -0,0 +1,896 @@
1
+ /*********************************************************************
2
+ This file is part of the argtable library. It contains the declarations
3
+ of the argtable library functions.
4
+
5
+ Copyright (C) 2003,2004 ISP RAS (modis@ispras.ru)
6
+ Copyright (C) 1998,1999,2001 Stewart Heitmann (sheitmann@users.sourceforge.net)
7
+
8
+ The argtable library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Library General Public License as
10
+ published by the Free Software Foundation; either version 2 of the
11
+ License, or (at your option) any later version.
12
+
13
+ This software is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ Library General Public License for more details.
17
+
18
+ You should have received a copy of the GNU Library General Public
19
+ License along with this library; if not, write to the Free Software
20
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21
+ USA.
22
+ *********************************************************************/
23
+ #ifndef ARGTABLE
24
+ #define ARGTABLE
25
+
26
+ #include <stdio.h>
27
+ #define ARGTABLE_VERSION 1.3
28
+
29
+ #ifdef ARGTABLE_COMPATIBILITY_10
30
+ #define arg_scanargv(a,b,c,d,e,f,g) arg_scanargv_10(a,b,c,d,e,f,g)
31
+ #endif
32
+
33
+ #define ARGTABLE_NO_DEFAULT_VALUE arg_no_default_value
34
+
35
+ #ifdef __cplusplus
36
+ extern "C" {
37
+ #endif
38
+
39
+ /**
40
+ * arg_type enums are used in the argument table to define
41
+ * the data type of a command line argument.
42
+ */
43
+ typedef enum
44
+ {
45
+ arg_int=0, /**< Integer value. */
46
+ arg_dbl, /**< Double value. */
47
+ arg_str, /**< Ascii string; may be quoted or un-quoted.*/
48
+ arg_bool, /**< Boolean; accepts the keywords \em yes, \em no, \em true, \em false, \em on , or \em off and converts them into an integer value of 0 (negative) or 1 (affirmative) accordingly. */
49
+ arg_lit /**< Literal; returns 1 if a given literal string was present on the command line otherwise returns the default value. */
50
+ } arg_type;
51
+
52
+ /**
53
+ * A fixed array of strings that are used when arguments are
54
+ * given NULL names.
55
+ * The array is indexed by arg_type, with each name describing
56
+ * the corresponding data type.
57
+ * \code
58
+ * arg_str[arg_int] = "<int>";
59
+ * arg_str[arg_dbl] = "<double>";
60
+ * arg_str[arg_str] = "<string>";
61
+ * arg_str[arg_bool] = "<bool>";
62
+ * arg_str[arg_lit] = "";
63
+ * \endcode
64
+ */
65
+ extern const char* arg_typestr[];
66
+
67
+ /**
68
+ * An argument table is defined an array of arg_rec structs
69
+ * having one entry for each command line argument that is expected.
70
+ * It is most conveniently defined and initialised as a
71
+ * static array (but need not be so).
72
+ *
73
+ * \code
74
+ * //command line arguments will be written into these variables
75
+ * int x,y,z,verbose,debug;
76
+ * double radius;
77
+ * char infname[100];
78
+ * char outfname[100];i
79
+ *
80
+ * //The argument table.
81
+ * arg_rec argtable[] =
82
+ * // TAG NAME TYPE STORAGE DEFAULT DESCRIPTION
83
+ * {
84
+ * { NULL, "x", arg_int, &x, NULL, "x coord" },
85
+ * { NULL, "y", arg_int, &y, NULL, "y coord" },
86
+ * { NULL, "z", arg_int, &z, "0", "z coord" },
87
+ * { "-r ", NULL, arg_dbl, &radius, "1.0", "radius" },
88
+ * { "-o ", "<outfile>", arg_str, outfname, "-", "output file" },
89
+ * { "-verbose", NULL, arg_lit, &verbose, "0", "verbose output" },
90
+ * { NULL, "<infile>", arg_str, infname, NULL, "input file" },
91
+ * { "debug=", "<on/off>", arg_bool, &debug, "off", NULL },
92
+ * };
93
+ * const size_t narg = sizeof(argtable)/sizeof(arg_rec);
94
+ * \endcode
95
+ */
96
+ typedef struct
97
+ {
98
+ /**
99
+ * The argument tag string defines the tag that identifies the argument on the command line.
100
+ * Tags may be any string you choose provided they have no whitespace.
101
+ * Examples of common tag string styles are "mytag:", "-mytag", "mytag=".
102
+ * An argument can be specified without a tag by setting the tag string to NULL.
103
+ * Untagged argument are taken from the command line from left to right after
104
+ * all the tagged arguments (if any) have first been extracted.
105
+ */
106
+ const char *tagstr;
107
+ /**
108
+ * The argument name has no effect on the argument processing.
109
+ * It is simply a descriptive name used to represent the argument in the
110
+ * output of the arg_syntax() and arg_glossary() functions.
111
+ * The argument name can be whatever you want, and is a convenient place
112
+ * to communicate the default value to the user if you so wish,
113
+ * for example "\<size\>=1024".
114
+ * If a NULL name string is given, it is automatically replaced by the
115
+ * argument's data type enclosed in angled brackets, as in "\<integer\>".
116
+ * If you dislike such behaviour, you can effectively suppress the name by
117
+ * defining it as an empty string.
118
+ */
119
+ const char *argname;
120
+ /**
121
+ * This defines the data type associated with a command line argument.
122
+ * It supports integer, double, string and boolean data types as well
123
+ * as literal argument strings.
124
+ *
125
+ * Strings may appear on the command line either quoted or unquoted.
126
+ *
127
+ * Booleans expect one of the keywords "true", "false", "yes", "no",
128
+ * "on", or "off" to appear on the command line. These are converted to 0
129
+ * (false,no,off) or 1 (true,yes,on) and stored as an integer.
130
+ *
131
+ * Literals are command line arguments with no associated data value,
132
+ * they are used to define keyword strings that can be used as command line switches.
133
+ * The string literal can be defined in either the tag string or the name string
134
+ * fields. If you use the tag string then the literal, like other tagged
135
+ * arguments, may appear anywhere on the command line. On the other hand,
136
+ * if you use the name string, then the literal must appear in that
137
+ * argument's position just as for normal untagged arguments.
138
+ * When a string literal is succesfully scanned, an integer value of 1 is
139
+ * written into its user-suplied program variable, otherwise it is assigned
140
+ * the default value (if it has one). If there is no default value, then the
141
+ * literal is regarded as a mandatory argument the same as for any other
142
+ * argument.
143
+ *
144
+ */
145
+ arg_type argtype;
146
+ /**
147
+ * Points to a user-defined variable into which the command line value will
148
+ * be written.
149
+ * It is imperative that the data type of the user-defined variable matches
150
+ * the argtype field, otherwise you can expect very spurious behaviour.
151
+ * \li \em arg_int arguments require \em int storage.
152
+ * \li \em arg_double arguments require \em double storage.
153
+ * \li \em arg_str arguments require a \em char buffer big enough to store
154
+ * the expected result (you'll have to guess what big enough is!).
155
+ * \li \em arg_bool arguments require \em int storage.
156
+ * \li \em arg_lit arguments require \em int storage.
157
+ *
158
+ * Lastly, a NULL placed in this field will cause the argument value to be scanned
159
+ * in the normal way, but the resulting value will be discarded.
160
+ */
161
+ void *valueptr;
162
+ /**
163
+ * The default string contains an optional default value to be used
164
+ * should the argument be missing from the command line. All defaults are
165
+ * defined as strings (as they would appear on the command line) and converted
166
+ * to the appropriate data type during processing.
167
+ *
168
+ * If a default is specified as NULL then that argument is regarded as
169
+ * mandatory, meaning that a parse error will result if the argument
170
+ * was not given on the command line.
171
+ *
172
+ * Alternatively one may specify ARGTABLE_NO_DEFAULT_VALUE. When this
173
+ * special value is encountered, defaults assignment is suppressed.
174
+ * If the argument was not given on the command line storage pointed
175
+ * by valueptr is not changed.
176
+ */
177
+ const char *defaultstr;
178
+ /**
179
+ * The argument description string, like the name string, does not
180
+ * affect argument processing. The arg_glossary() function
181
+ * uses it to display additional descriptions of command line arguments.
182
+ * Arguments with NULL description strings are omitted from the glossary
183
+ * altogether.
184
+ */
185
+ const char *argdescrip;
186
+ } arg_rec;
187
+
188
+ /**
189
+ * \brief Parse the command line as per a given argument table.
190
+ *
191
+ * Attempts to resolve the argv[] command line arguments
192
+ * (ignoring argv[0]) with the specifications given in the argument table.
193
+ * The values scanned from the command line are written directly into
194
+ * the program variables nominated by each argument table entry.
195
+ *
196
+ * During the process, a copy of the command line is written
197
+ * (as a single line of space separated arguments) into the
198
+ * user-supplied string at *CmdLine in case it is needed in future
199
+ * for error reporting.
200
+ *
201
+ * Should there be any conflict between the command line arguments
202
+ * and the argument table specifications, an error message and
203
+ * corresponding error marker are written into the user-supplied
204
+ * strings at *ErrMsg and *ErrMark respectively, after which the
205
+ * function returns zero. The error marker string is used to store
206
+ * a string of tilde characters formated in such a way that the tildes
207
+ * underscore the exact location of the error in *CmdLine when the
208
+ * strings are aligned one above the other. This can be useful for
209
+ * including in on-line error messages to help the user quickly
210
+ * pinpoint the cause of the error.
211
+ *
212
+ * If, on the other hand, all arguments were resolved successfully
213
+ * then *ErrMsg and *ErrMark are set to empty strings and the
214
+ * function returns 1.
215
+ * Either way, CmdLine, ErrMsg, or ErrMark can be safely ignored
216
+ * by passing them as NULL.
217
+ *
218
+ * \returns 1 upon success, 0 upon failure.
219
+ */
220
+ int arg_scanargv(int argc, /**< number of entries in argv[]. */
221
+ char **argv, /**< command line arguments. */
222
+ arg_rec *argtable, /**< pointer to the argument table. */
223
+ int n, /**< number of entries in argtable[]. */
224
+ char* CmdLine, /**< pointer to storage for command line (may be NULL). */
225
+ char* ErrMsg, /**< pointer to storage for error message (may be NULL). */
226
+ char* ErrMark /**< pointer to storage for error marker (may be NULL). */
227
+ );
228
+
229
+ /**
230
+ * \brief Parse a string as per a given argument table.
231
+ *
232
+ * This function is much like arg_scanargv() except that is scans
233
+ * the arguments from the string at *str rather than from argv[].
234
+ * The string is expected to contain a single line, space separated
235
+ * list of arguments, like that generated by arg_catargs().
236
+ *
237
+ * In a departure from \b arg_scanargv, this function erases the scanned
238
+ * arguments from \em *str by overwriting them with spaces once they have been
239
+ * successfully scanned.
240
+ * Furthermore, this function does not throw an error if there are still
241
+ * arguments remaining in *str after the argtable has been fully processed.
242
+ * Thus, complicated argument usages can be achieved by invoking this
243
+ * function multiple times on the same command line string,
244
+ * each time applying a different argument table until the arguments
245
+ * have been exhausted, or an error has been detected.
246
+ *
247
+ * \returns 1 upon success, 0 upon failure.
248
+ */
249
+ int arg_scanstr(char* str, /**< pointer to command line string. */
250
+ arg_rec *argtable, /**< pointer to the argument table. */
251
+ int n, /**< number of array elements in argtable[]. */
252
+ char* ErrMsg, /**< pointer to storage for error message (may be NULL). */
253
+ char* ErrMark /**< pointer to storage for error marker (may be NULL). */
254
+ );
255
+
256
+
257
+ /**
258
+ * \brief Generates a 'usage' syntax string from an argument table
259
+ *
260
+ * Builds a syntactical description of the allowable command line arguments
261
+ * specified by the 'argtable' array.
262
+ * The resulting string is stored in static data within the local scope of
263
+ * this function. Its contents are overwritten by subsequent calls.
264
+ *
265
+ * The syntactical description is generated as a single line of space
266
+ * separated argument descriptors, each comprising of the argument's tag
267
+ * string and name string concatenated together. For example,
268
+ *
269
+ * "myprog x y [z] [-r <double>] [-o <outfile>] [-verbose] <infile> [debug=<on/off>]"
270
+ *
271
+ * If an argument is optional (has a non-NULL default value) then its
272
+ * descriptor is enclosed in square brackets.
273
+ * NULL name strings are substituted with the argument's data type enclosed
274
+ * in angled brackets, as in <int>, <double>, or <string>.
275
+ * If both the tag and the name are empty strings ("") then the argument is
276
+ * omitted from the description altogether. This allows the suppression of
277
+ * individual arguments that you do not want to appear.
278
+ *
279
+ * \returns a pointer to the internal string.
280
+ */
281
+ const char* arg_syntax(const arg_rec* argtable, /**< pointer to the argument table */
282
+ int n /**< number of array elements in argtable[] */
283
+ );
284
+
285
+ /**
286
+ * \brief Generate a glossary string from an argument table.
287
+ *
288
+ * Returns a pointer to an internal 'glossary' string which
289
+ * contains a multi-line description of each of the argument table
290
+ * entres that have a non-NULL \<description\> field.
291
+ * The contents of the glossary string remain unaltered up until the
292
+ * next invocation of this function.
293
+ * Each line of the glossary string is formatted as
294
+ *
295
+ * "\<prefix\>\<tag\>\<name\>\<description\>"
296
+ *
297
+ * The 'prefix' string is useful for adding indenting spaces
298
+ * before each line in the description to improve the look of
299
+ * the glossary string, or it can be given as NULL in which
300
+ * case it is ignored.
301
+ *
302
+ * If 'prefix' string starts with '\001', the leading character
303
+ * is stripped and remaining part is interpreted as format string
304
+ * in the form "%s%s\n". First %s is substituted with concatenated
305
+ * tag and name, and second %s is substituted with description.
306
+ * If you like description lines to be aligned, pass something like
307
+ * this: "\001 %-30s %s\n".
308
+ *
309
+ * Any NULL \<tag\> fields in the argument table will appear in the
310
+ * glosssary as empty strings.
311
+ *
312
+ * Any NULL \<name\> fields will be substituted by a description of
313
+ * that argument's data type, enclosed in angled brackets, as in
314
+ * \<int\> and \<double\>.
315
+ * A name can effectively be suppressed from the glossary by defining
316
+ * it as an empty string in the argument table.
317
+ *
318
+ * \returns a pointer to the internal string.
319
+ */
320
+ const char* arg_glossary(const arg_rec* argtable, /**< pointer to the argument table */
321
+ int n, /**< number of array elements in argtable[] */
322
+ const char* prefix /**< a string to be prefixed to each line of the output */
323
+ );
324
+
325
+ /**
326
+ * \brief Concatenate all argv[] arguments into a single string.
327
+ *
328
+ * Concatenates all of the arguments in the argv[] array and writes the
329
+ * result into *str as a single line, space separated string.
330
+ *
331
+ * Any argv[] entries that contain whitespace are automatically
332
+ * encapsulated by single quotes prior to the concatenation to preserve
333
+ * their word grouping.
334
+ * A trailing space is always appended to the resulting string as a
335
+ * safety precaution in lieu of scanning for string literals that expect
336
+ * trailing space.
337
+ * It is assumed that *str is big enough to store the result.
338
+ */
339
+ extern void arg_catargs(int argc, /**< number of arguments in argv[] */
340
+ char **argv, /**< command line arguments */
341
+ char *str /**< pointer to destination string */
342
+ );
343
+
344
+
345
+ /**
346
+ * \brief Builds and returns an argument table record.
347
+ *
348
+ * Returns an arg_rec structure containing the values passed to
349
+ * the function. It is useful for building argument tables dynamically.
350
+ */
351
+ arg_rec arg_record(char *tagstr, /**< argument tag string */
352
+ char *argname, /**< argument name string */
353
+ arg_type argtype, /**< argument data type */
354
+ void *valueptr, /**< pointer to user-supplied storage location */
355
+ char *defaultstr, /**< default argument value, as a string */
356
+ char *argdescrip /**< argument description string */
357
+ );
358
+
359
+ /**
360
+ * \brief Print the contents of an argument table.
361
+ *
362
+ * The contents of the argument table, and the user-supplied
363
+ * variables it references, are printed to the stream 'fp'.
364
+ * This can be useful for debugging argument tables.
365
+ */
366
+ void arg_dump(FILE* fp, /**< output stream */
367
+ const arg_rec* argtable, /**< pointer to the argument table */
368
+ int n /**< number of array elements in argtable[] */
369
+ );
370
+
371
+ extern const char *arg_no_default_value;
372
+
373
+ #ifdef __cplusplus
374
+ }
375
+ #endif
376
+
377
+
378
+
379
+ /**
380
+ \mainpage Introduction to Argtable
381
+
382
+ \section LegalNotice Legal notice.
383
+ The argtable library and accompanying documentation is copyright
384
+ 1998, 1999, 2001 Stewart Heitmann (sheitmann@users.sourceforge.net).
385
+ Argtable is free
386
+ software; you can redistribute it and/or modify it under the terms of
387
+ the <b>GNU Library General Public License</b> as published by the Free
388
+ Software Foundation; either version 2 of the License, or (at your
389
+ option) any later version.
390
+
391
+ This software is distributed in the hope that it will be useful, but
392
+ WITHOUT ANY WARRANTY; without even the implied warranty of
393
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
394
+ See the GNU
395
+ Library General Public License for more details.
396
+
397
+ You should have received a copy of the GNU Library General Public
398
+ License along with this library; if not, write to the Free Software
399
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
400
+ USA.
401
+
402
+ \section Overview Overview.
403
+ Argtable (http://argtable.sourceforge.net) is a freely available programmer's library for parsing
404
+ the command line arguments of any C/C++ program. It allows the
405
+ programmer to specify the desired format of the command line
406
+ arguments in one or more statically defined arrays known as argument
407
+ tables. Each row of an argument table specifies the data type of
408
+ an expected argument and nominates a user-defined program variable as
409
+ storage for the incoming argument value. If arguments require default
410
+ values, then these too are specified in the argument table.
411
+
412
+ Once an argument table has been established, parsing the command line is
413
+ simply a matter of calling the library's arg_scanargv() function which
414
+ attempts to resolve the contents of \b argv[] with the entries
415
+ of the argument table. If successful, the command line arguments are
416
+ now known to be valid and their values are ready and available for
417
+ use in their nominated program variables.
418
+
419
+ If the arguments could not be successfully resolved then
420
+ \b arg_scanargv returns an error message string describing the
421
+ reason for the failure and showing the location of the error in
422
+ the command line. The program can simply print the error message
423
+ to stdout or stderr and exit.
424
+ \code
425
+ ERROR: myprog grad:13 99 uh oh
426
+ ^^ unexpected argument
427
+ \endcode
428
+
429
+ Alternatively, if the program has multiple command line usages then
430
+ it may choose to call \b arg_scanargv several times each with a different
431
+ argument table until a successful match is found or all argument tables
432
+ are exhausted.
433
+
434
+ Auxilliary functions arg_glossary() and arg_syntax() generate plain text
435
+ descriptions of the arguments defined in an argument table and their
436
+ command line syntax.
437
+ These make it easy to generate on-line help facilities that are always current.
438
+
439
+ \section ArgStyles Styles of command line arguments.
440
+ Argtable supports both \em tagged and \em untagged command line arguments.
441
+ Tagged arguments are identified by a prefix tag, as in
442
+ <b>-o file</b> or <b>title:mystuff</b>. The tag enables these arguments to
443
+ appear anywhere on the command line, and in any order. The programmer
444
+ may implement any style of argument tag desired, including such common
445
+ styles as <b>-title mystuff</b>, <b>title:mystuff</b>, <b>--title mystuff</b>,
446
+ or <b>title=mystuff</b>.
447
+ Untagged arguments on the other hand have no prefix; they are identified
448
+ strictly by their ordering on the command line.
449
+ The two styles of arguments may be freely mixed,
450
+ whereupon the tagged arguments are always processed first, leaving
451
+ any remaining (untagged) arguments to be scanned from left to
452
+ right.
453
+
454
+ A command line argument may be of type \b integer,
455
+ \b double, \b string, or \b boolean. Doubles are accepted in
456
+ in either floating point or scientific notation, and strings may be
457
+ either quoted or unquoted. Booleans will accept any of the keywords
458
+ \b on, \b off, \b yes, \b no, \b true, or \b false
459
+ and yield an integer value of 0 (negative) or 1 (affirmative)
460
+ accordingly.
461
+
462
+ A special argument type called \b literal is also provided;
463
+ it yields an integer value according to the presence or
464
+ absence of a given string literal on the command line. It is useful
465
+ for specifying unparameterised command line switches such as \b -verbose
466
+ and \b -help.
467
+
468
+ \section OptionalArgs Optional arguments and default values.
469
+ Arguments may be assigned default values that take effect when
470
+ no matching command line argument could be found. When a
471
+ default value is specified for an argument you are, in effect,
472
+ declaring that argument as being optional.
473
+ Arguments without defaults are, by definition, regarded as mandatory arguments.
474
+
475
+ \section Platforms Supported platforms.
476
+ Argtable conforms to ansi C requirements and should compile on
477
+ any standard ansi C compiler. To date, it has been successfully
478
+ compiled on:
479
+ \li MIPSpro C/C++ on IRIX 6.2, 6.3 and IRIX64 6.2
480
+ \li DEC C/C++ on Digital Unix V4.0 (OSF/1)
481
+ \li GNU gcc/g++ on DEC Digital Unix V4.0 (OSF/1); IRIX 6.2, 6.3;
482
+ IRIX64 6.2; Linux 2.0.30; and SunOS 5.5.1.
483
+
484
+ Please let me know if you have successfully used argtable on other platforms.
485
+
486
+ \section InstallSection Installing Argtable
487
+ The fastest and easiest way to use argtable is simply to copy
488
+ the \b argtable.h and \b argtable.c files into your project and compile
489
+ them with the rest of your code.
490
+
491
+ If you are a system administrator, you may wish to install argtable
492
+ on your system as a programmer's library, complete with man pages and
493
+ html documentation.
494
+ This is easy to do as the makefiles follow the usual \b autoconf procedure.
495
+ -# \b cd to the argtable package directory and type
496
+ \b ./configure to configure it for your system.
497
+ -# Type \b make to compile the package.
498
+ -# Optionally, type \b make \b check to run the self-tests.
499
+ -# \b su as root user.
500
+ -# Type \b make \b install to install the programs and documentation.
501
+ By default the package installs into \b /usr/local/ but a different location
502
+ may be specified when configuring the package. Type \b ./configure \b --help
503
+ for the full list of configuration options.
504
+ -# logout from root user.
505
+ -# Type \b make \b clean to remove the temporary binaries created during compilation.
506
+
507
+ \section GetStarted Getting started.
508
+ \ref Tutorial is the best place to get started.
509
+ Then look at the example code supplied with the distribution.
510
+
511
+ \section Others Similar packages.
512
+ Here are some other command line parsing tools that I am aware of.
513
+ Apologies for any I may have omitted.
514
+ \li \b clig: The Command Line Interpreter Generator:
515
+ http://wsd.iitb.fhg.de/~kir/clighome/
516
+
517
+ \li \b opt: The Options and Parameter parsing Toolkit:
518
+ ftp://ftp.lanl.gov/pub/users/jt/Software/opt/opt_toc.html
519
+
520
+ \li \b getopt: The GNU-style options parser.
521
+ This comes as standard on most unix systems.
522
+ */
523
+
524
+
525
+
526
+ /**
527
+ \page Tutorial The Argtable Tutorial
528
+ Imagine we have written a program called \b myprog and we wish
529
+ to implement the following command line usage syntax for it:
530
+ \verbatim
531
+ myprog [-tit <title>] grad:gradient [y-int]
532
+ -tit <title> your title
533
+ grad:gradient line gradient
534
+ y-int y-intercept
535
+ \endverbatim
536
+
537
+ We will create a single argument table in our program
538
+ that defines the argument properties, and pass that
539
+ table along with \b argc and \b argv[] to the
540
+ arg_scanargv() function to do the parsing.
541
+
542
+ \section Argtable Defining the argument table.
543
+ An argument table is just an array of \b arg_rec structs, with each
544
+ array element pertaining to a single command line argument. The
545
+ arg_rec struct is defined in argtable.h as:
546
+ \code
547
+ typedef enum {arg_int=0,arg_dbl,arg_str,arg_bool,arg_lit} arg_type;
548
+ typedef struct
549
+ {
550
+ const char *tagstr; // argument tag string
551
+ const char *argname; // argument name string
552
+ arg_type argtype; // argument data type
553
+ void *valueptr; // ptr to user storage location
554
+ const char *defaultstr; // default value, as a string
555
+ const char *argdescrip; // argument description string
556
+ } arg_rec;
557
+ \endcode
558
+
559
+ Thus we may define our argument table statically in the code as follows:
560
+ \code
561
+ int main(int argc, char **argv)
562
+ {
563
+ static char str[50];
564
+ static double grad;
565
+ static int c;
566
+ arg_rec argtable[] =
567
+ {
568
+ {"-tit ", "<title>", arg_str, str, "noname", "\t\t your title"},
569
+ {"grad:", "gradient", arg_dbl, &grad, NULL, "\t line gradient"},
570
+ {NULL, "y-int", arg_int, &c, "0", "\t\t y-intercept"}
571
+ };
572
+ const size_t narg = sizeof(argtable)/sizeof(arg_rec);
573
+ ...
574
+ }
575
+ \endcode
576
+
577
+ Defining the tables statically is a programming convenience but not a
578
+ requirement; the table could equally well have been dynamically allocated
579
+ and initialized at runtime.
580
+ Notice that I also chose to define the argument table within
581
+ the main() block because that's the only place where it is
582
+ used so there is no need to promote it to a higher namespace. However
583
+ you may define it in the global namespace if you prefer.
584
+
585
+ Our argument table has three rows, one for each command line argument
586
+ <b>-tit \<title\></b>, <b>grad:gradient</b>, and <b>y-int</b>.
587
+ The behaviour of the argument parsing is governed entirely by the
588
+ contents of the various fields (columns) of the argument table. Lets
589
+ step through each field one by one.
590
+
591
+ \par The tag string:
592
+ The first field is the argument's tag string.
593
+ It defines the prefix literal that identifies a tagged argument and
594
+ should contain at least one non-whitespace character unless
595
+ the argument is untagged whereupon the field should be NULL.
596
+ In our example, <b>-tit \<title\></b> and <b>grad:gradient</b> are
597
+ tagged arguments but <b>y-int</b> is untagged so it has a NULL
598
+ tag string.
599
+
600
+ \par The name string:
601
+ The second field is the argument's name string.
602
+ It is not actually used to process the command line
603
+ arguments, rather it defines the name of the argument as it appears
604
+ in the description strings generated by the \b arg_syntax and
605
+ \b arg_glossary functions. Those functions
606
+ automatically substitute any NULL names with the argument's data
607
+ type enclosed in angled brackets, as in "\<int\>" or "\<string\>".
608
+
609
+ \par The data type:
610
+ The third field is an enumerated type that
611
+ defines the data type of the command line argument. Possible values
612
+ are \b arg_int, \b arg_dbl, \b arg_str, \b arg_bool, and \b arg_lit.
613
+ They represent integer, double, string, boolean, and literal arguments
614
+ respectively. In our example <b>-tit \<title\></b> expects
615
+ \em \<title\> to be substituted by a string value,
616
+ <b>grad:gradient</b> expects \em gradient to be a double, and
617
+ <b>y-int</b> is expected to be an integer.
618
+
619
+ \par The data pointer:
620
+ The fourth field is a pointer-to-void
621
+ that gives the address of the user-defined program variable used to
622
+ store the argument's value. A NULL pointer here causes the value to
623
+ be discarded once is has been scanned. Take care that the data
624
+ type of of the target memory location matches that specified in the
625
+ previous column. Arguments of type \b arg_int, \b arg_bool,
626
+ and \b arg_lit must each point to an \em integer variable.
627
+ Those of type \b arg_dbl must point to a \em double and those
628
+ of \b arg_str must point to a \em char \em array.
629
+ In our example, the string value associated with <b>-tit \<title\></b>
630
+ is written into the \em char \em str[50] buffer, the double value
631
+ associated with \b grad:gradient is written into \em double \em grad,
632
+ and the integer value associated with <b>y-int</b> is written into
633
+ \em int \em c.
634
+
635
+ \par The default value:
636
+ The fifth field is a string which contains an optional default value
637
+ for the argument. It is defined as a string and automatically cast to
638
+ the appropriate data type at run time. A NULL value indicates no default.
639
+ In our example, <b>-tit \<title\></b> and <b>y-int</b> have default values of "noname"
640
+ and zero respectively, whereas <b>grad:gradient</b> has no default
641
+ and is thus regarded as a mandatory argument.
642
+
643
+ \par The description string:
644
+ The sixth and final field allows
645
+ the programmer to enter a brief description of the argument. It is
646
+ these descriptions that are output by the arg_glossary() function.
647
+ A NULL value causes that entry to be omitted from the glossary output.
648
+
649
+ \section Parsing Parsing the command line.
650
+ Having defined the argument table, we can now use it to parse the command line
651
+ arguments in argv[]. There are several ways to do this, but the
652
+ simplest is to use the \b arg_scanargv function.
653
+ \code
654
+ int arg_scanargv(int argc,
655
+ char** argv,
656
+ arg_rec *argtable,
657
+ int n,
658
+ char* CmdLine,
659
+ char* ErrMsg,
660
+ char* ErrMark);
661
+ \endcode
662
+
663
+ It takes as input the command line arguments in \b argv[]
664
+ (there are \b argc of them) and a pointer to the argument table in
665
+ \b argtable (which has \b n rows). It proceeds to scan the argv[]
666
+ arguments (skipping argv[0]) and tries to resolve them with
667
+ the entries given in the argument table. If this can be done
668
+ successfully then all argument values are written into the program
669
+ variables as designated by the argument table and the function
670
+ returns 1. If not, the function returns 0 to indicate failure.
671
+
672
+ The three string pointers \b CmdLine, \b ErrMsg, and \b ErrMark
673
+ refer to user defined string buffers in which \b arg_scanargv
674
+ returns information about the parsing. They are optional parameters
675
+ in the sense that they may be given as NULL if you do not wish to use them.
676
+
677
+ \b CmdLine is always assigned a copy of the orginal command line,
678
+ concatenated into a single space-separated string.
679
+
680
+ \b ErrMsg and \b ErrMark are only used when \b arg_scanargv detects a
681
+ parse error in the command line.
682
+ In those cases, \b ErrMsg is assigned an explantory error message string,
683
+ and \b ErrMark is assigned a string of tilde characters which have been
684
+ formatted in such a way as to highlight the exact location of the error
685
+ in \b CmdLine when printed one atop the other.
686
+
687
+ The code fragment below demonstrates the use of \b arg_scanargv.
688
+ It presumes that \em argc, \em argv, \em argtable, and \em narg are
689
+ as defined in the example above.
690
+ \code
691
+ {
692
+ char cmdline[200], errmsg[200], errmark[200];
693
+
694
+ if (!arg_scanargv(argc,argv,argtable,narg,cmdline,errmsg,errmark))
695
+ {
696
+ // arg error occurred, print error message and exit
697
+ printf("ERROR: %s\n", cmdline);
698
+ printf(" %s %s\n", errmark, errmsg);
699
+ return 1;
700
+ }
701
+
702
+ // only get here if the arguments were scanned successfully
703
+
704
+ }
705
+ \endcode
706
+
707
+ And here are some examples of the console output that this code produces when
708
+ \b arg_scanargv detects a parse error.
709
+ \code
710
+ $ myprog grad:oops
711
+ ERROR: myprog grad:oops
712
+ ^ invalid grad:gradient argument
713
+ $ myprog grad:13 nope
714
+ ERROR: myprog grad:13 nope
715
+ ^^^^ unexpected argument
716
+ $ myprog grad:13 99 uh oh
717
+ ERROR: myprog grad:13 99 uh oh
718
+ ^^ unexpected argument
719
+ \endcode
720
+
721
+ \section OnlineHelp Generating online help.
722
+ The arg_syntax() and arg_glossary() functions take an argument table
723
+ and generate plain text descriptions of its command line syntax as
724
+ well as descriptions of the individual arguments.
725
+ These are useful for displaying help text to the user.
726
+
727
+ \code
728
+ const char* arg_syntax(const arg_rec* argtable, int n);
729
+ const char* arg_glossary(const arg_rec* argtable, int n, const char* prefix);
730
+ \endcode
731
+
732
+ The \b arg_syntax function returns a pointer to an internal
733
+ string buffer that contains a plain text description of the usage
734
+ syntax of the argument table it was passed. The string comprises a
735
+ space separated list of the tag and name strings of each argument
736
+ table entries concatenated into a single line string. Optional
737
+ command line arguments are automatically enclosed in square brackets.
738
+ Calling \b arg_syntax on our example argument table would
739
+ return the string:
740
+ \verbatim
741
+ [-tit <title>] grad:gradient [y-int]
742
+ \endverbatim
743
+
744
+ The calling program would ordinarily prepend the program
745
+ name from argv[0] to this to get the full command line usage syntax.
746
+
747
+ The \b arg_glossary function is similar, except it generates a
748
+ multi-line text string with one argument per line. Each line includes
749
+ the argument's tag, its name string, and its description string as
750
+ given in the argument table. Arguments that have a NULL description
751
+ string are omitted. Each line of the glossary string is prefixed with
752
+ the string given in the prefix parameter; it useful for
753
+ indenting each line of the string. Calling \b arg_glossary with
754
+ our example argument table results in the following multi-line
755
+ string:
756
+ \verbatim
757
+ -tit \<title\> your title
758
+ grad:gradient line gradient
759
+ y-int y-intercept
760
+ \endverbatim
761
+
762
+ \section Altogether Putting it all together.
763
+ Lets return to our example program and put it all together in its
764
+ entirety.
765
+ Our program, when executed without any arguments
766
+ (argc==1), will print the argument usage syntax and a glossary
767
+ on stdout, then exit.
768
+ When given a valid set of arguments, it will
769
+ display the resulting argument values as they are stored in the local
770
+ program variables. Otherwise, it echoes the erroneous command line
771
+ together with an appropriate error message and terminates
772
+ with error code 1.
773
+
774
+ \code
775
+ #include "common/argtable.h"
776
+
777
+ int main(int argc, char **argv)
778
+ {
779
+ static char str[50];
780
+ static double grad;
781
+ static int c;
782
+ arg_rec argtable[] =
783
+ {
784
+ {"-tit ", "<title>", arg_str, str, "noname", "\t\t your title"},
785
+ {"grad:", "gradient", arg_dbl, &grad, NULL, "\t line gradient"},
786
+ {NULL, "y-int", arg_int, &c, "0", "\t\t y-intercept"}
787
+ };
788
+ const size_t narg = sizeof(argtable)/sizeof(arg_rec);
789
+
790
+ // process the command line args
791
+ if (argc==1)
792
+ {
793
+ // display program usage and exit.
794
+ printf("Usage: %s %s\n", argv[0], arg_syntax(argtable,narg));
795
+ printf("%s\n",arg_glossary(argtable,narg," "));
796
+ return 0;
797
+ }
798
+ else
799
+ {
800
+ // scan command line arguments from argv[]
801
+ char cmdline[200], errmsg[200], errmark[200];
802
+ if (!arg_scanargv(argc, argv, argtable, narg, cmdline, errmsg, errmark))
803
+ {
804
+ // arg error occurred, print error message and exit
805
+ printf("ERROR: %s\n", cmdline);
806
+ printf(" %s %s\n", errmark, errmsg);
807
+ return 1;
808
+ }
809
+ }
810
+
811
+ // get here only if command line args ok
812
+ printf("title: \"%s\"\n",str);
813
+ printf("gradient: %f\n",grad);
814
+ printf("y-intercept: %d\n",c);
815
+
816
+ return 0;
817
+ }
818
+ \endcode
819
+
820
+ Here are some results of running myprog with various command
821
+ line arguments.
822
+ \verbatim
823
+ $ myprog
824
+ Usage: myprog [-tit <title>] grad:gradient [y-int]
825
+ -tit <title> your title
826
+ grad:gradient line gradient
827
+ y-int y-intercept
828
+
829
+ $ myprog grad:10
830
+ title: "noname"
831
+ gradient: 10.000000
832
+ y-intercept: 0
833
+
834
+ $ myprog 7 grad:1.234
835
+ title: "noname"
836
+ gradient: 1.234000
837
+ y-intercept: 7
838
+
839
+ $ myprog -tit "hello world" grad:3.33 11
840
+ title: "hello world"
841
+ gradient: 3.330000
842
+ y-intercept: 11
843
+ \endverbatim
844
+
845
+ */
846
+
847
+
848
+ /**
849
+ \page Release Release Notes.
850
+
851
+ \par Argtable-2.0 coming eventually.
852
+ Argtable-2.0 will be a major overhaul of the code. The
853
+ changes are required to address the most common complaint about
854
+ argtable; the potential for buffer overruns as argtable writes into
855
+ fixed size string buffers. The redesign will bring some inevitable
856
+ changes to the library interface, but the basic look and feel of the
857
+ argument tables will stay the same.
858
+ I been promising to finish Argtable-2.0 for a very long time.
859
+ Well, one of the days....
860
+
861
+ \par Argtable-1.3 released December 20, 2001.
862
+ Moved argtable to a new home on the \b sourceforge site and revamped
863
+ the documentation.
864
+ Documentation is now created with \b Doxygen instead of \b c2man.
865
+ Also fixed some minor bugs in the Makefiles.
866
+ The source code itself is unaltered.
867
+
868
+ \par Argtable-1.2 released August 5, 1999.
869
+ The original makefiles have been replaced by autoconf makefiles.
870
+ The char pointers in the argument table have been redefined as
871
+ pointers to const char.
872
+ Some of argtable's internal string buffers have been made larger to
873
+ accommodate long command lines, and a bug that occurred when program
874
+ names contained whitespace has been fixed. The documentation has
875
+ also been revised.
876
+
877
+ \par Argtable-1.1 released January 20, 1999.
878
+ This version fixes some cross-platform compilation errors, and saw
879
+ the introduction of the multi-platform configuration.
880
+ It also saw the addition of the arg_record() function and a change
881
+ to the arg_scanargv() function so that it no longer requires argv[0]
882
+ to be the first entry of the argument table.
883
+ To maintain backwards compatibility, programs
884
+ written for version 1.0 should now define the macro #define
885
+ ARGTABLE_COMPATIBILITY_10 prior to including the argtable.h header file.
886
+
887
+ \par Argtable-1.0 released November 13, 1998.
888
+ Argtable's debut!
889
+ */
890
+
891
+ #endif
892
+
893
+
894
+
895
+
896
+