-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathttgetopt.h
277 lines (239 loc) · 8.44 KB
/
ttgetopt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Universal Permissive License v 1.0 as shown
* at http://oss.oracle.com/licenses/upl
*/
#ifndef TTC_GETOPTIONS_H_INCLUDED
#define TTC_GETOPTIONS_H_INCLUDED
/**
* structures
*/
#ifndef TTC_DllExport
#define TTC_DllExport
#endif
#ifndef TTC_DllImport
#define TTC_DllImport
#endif
#include <stdarg.h>
/*
* Options sent to ttc_getoptions.
* They are a bitmask, so each value should be a power of two.
*/
/** TTC_OPT_NONE means accept the defaults. */
#define TTC_OPT_NONE 0
/**
* If TTC_OPT_ABBREV is specified, options can be abbreviated
* to the point of uniqueness. For instance, "-n", "-nu",
* "-num", etc. match a specification of "number=i", unless there
* is some other specification that begins with "n", "nu", or "num".
*
* NOTE: abbreviations are not used for negate-able options, or for
* special options like \<HELP\>.
*/
#define TTC_OPT_ABBREV 1
/**
* Normally matches are not case sensitive for multi-character options
* (they are for single character options). TTC_OPT_CASE_SENSITIVE
* makes all comparisons case sensitive.
*/
#define TTC_OPT_CASE_SENSITIVE 2
/**
* If TTC_OPT_IGNORE_UNKNOWNS is given, unknown options will
* just be skipped over, and no error generated.
* However, there are a couple of potential problems.
* First, the index returned is no longer very useful as an
* index into the argv array. The functions do not strip off
* the known options and leave others behind. Also, if
* the unknown option has an option-argument, that will usually
* cause the functions to think the options have ended.
*/
#define TTC_OPT_IGNORE_UNKNOWNS 4
/**
* Normally \<HELP\> and \<VERSION\> exit after printing their messages.
* With TTC_OPT_NO_EXIT, they do not exit.
*/
#define TTC_OPT_NO_EXIT 8
/**
* If TTC_OPT_PRINT_ERRS is given, error messages are printed
* out to stderr (normally they are just put into the error
* message buffer).
*/
#define TTC_OPT_PRINT_ERRS 16
/**
* Normally an error will be given if \<DSN\> or \<CONNSTR\> is specified,
* but no dsn or connection string were found in the argv list. With
* TTC_OPT_NO_CONNSTR_OK, no error is flagged.
*/
#define TTC_OPT_NO_CONNSTR_OK 32
/**
* Normally an error will be given if a =S option is specified, and the
* option was given without any arguments. With TTC_OPT_EMPTY_LIST_OK,
* no error is signalled.
*/
#define TTC_OPT_EMPTY_LIST_OK 64
/**
* Normally if \<DSN\> or \<CONNSTR\> is specified, but no dsn or
* connection string were found, the environment variable TT_CONNSTR
* is considered to see if it has a valid dsn. With TTC_OPT_NO_CONNSTR_ENV,
* the environment variable is ignored.
*/
#define TTC_OPT_IGNORE_CONNSTR_ENV 128
/**
* Mask of TTC_OPT_ constants.
*/
typedef int Ttc_getopt_options;
/*
* Example:
* int main(int argc, char * const argv[])
* {
* char errmsg[256];
* ac = ttc_getoptions(argc, argv,
* TTC_OPT_NONE,
* errmsg, sizeof(errmsg),
* "v", &verbose,
* "n=i", &n1,
* "<INTEGER>", &n2,
* "dbl=d", &d1,
* "<REAL>", &d2,
* "uval=u", &u,
* "s=s", &s, S_SIZE,
* "H=p", printInfo,
* "<VERSION>", "6.6Beta6",
* "<HELP>", usage String,
* NULL);
* if (ac == -1) { ... handle error ... }
* for (; ac < argc ++ac) { ... handle argv[ac] ... }
* ...
* }
*/
/*
* ttc_getoptions -
* Parse the given argv array using the given list
* of option specifiers.
*/
extern TTC_DllImport
int
ttc_getoptions(int argc, /* # args in argv */
char * const argv[], /* argument array */
Ttc_getopt_options options, /* bitwise-OR of TTOPT values */
char* errmsgbuf, /* buffer for error messages */
int errmsgbuflen, /* size of errmsgbuf */
... /* NULL-terminated list of option
* specifiers and pointers */
);
/*
* ttc_vgetoptions -
* Same as ttc_vgetoptions, but taking a va_list.
*/
extern TTC_DllImport
int
ttc_vgetoptions(int argc, /* # args in argv */
char * const argv[], /* argument array */
Ttc_getopt_options options, /* bitwise-OR of TTOPT values */
char* errmsgbuf, /* buffer for error messages */
int errmsgbuflen, /* size of errmsgbuf */
va_list ap /* NULL-terminated va-list of option
* specifiers and pointers */
);
/*
* ttc_filegetoptions -
* Same as ttc_getoptions, but arguments from a file instead of
* an argv list. *pargc and *pargv are filled in with argc/argv
* values read from the file.
*/
extern TTC_DllImport
int
ttc_filegetoptions(const char* filename, /* name of input file */
int* pargc, /* # args in argv (output) */
char*** pargv, /* argument array (output) */
Ttc_getopt_options options, /* bitwise-OR of TTOPT values */
char* errmsgbuf, /* buffer for error messages */
int errmsgbuflen, /* size of errmsgbuf */
... /* NULL-terminated list of option
* specifiers and pointers */
);
/*
* ttc_filegetoptions_free
* Free argv list obtained from ttc_filegetoptions.
*/
extern TTC_DllImport
void
ttc_filegetoptions_free(char** argv);
/*
* ttc_strgetoptions -
* Same as ttc_getoptions, but arguments from a string instead of
* an argv list. *pargc and *pargv are filled in with argc/argv
* values read from the file. One way this can be used is to
* initialize an argv list from an environment variable (as in
* ttIsql).
*/
extern TTC_DllImport
int
ttc_strgetoptions(const char* str, /* input string */
const char* name, /* name used as argv[0] */
int* pargc, /* # args in argv (output) */
char*** pargv, /* argument array (output) */
Ttc_getopt_options options, /* bitwise-OR of TTOPT values */
char* errmsgbuf, /* buffer for error messages */
int errmsgbuflen, /* size of errmsgbuf */
... /* NULL-terminated list of option
* specifiers and pointers */
);
/*
* ttc_strgetoptions_free
* Free argv list obtained from ttc_strgetoptions.
*/
extern TTC_DllImport
void
ttc_strgetoptions_free(char** argv);
/*
* ttc_cleanargv
* Looks for and hides password arguments in the command line.
* Note that this doesn't actually accomplish anything on many
* platforms, for example modern Solarises, HP-UX, and Windows.
* The intent is to make any passwords given on the command line
* not visible by users running ps.
*/
extern TTC_DllImport
void
ttc_cleanargv(int argc, char** argv, ...);
/*
* ttc_dump_help
* Dump a usage message, replacing any occurrence of <CMD>
* with the given cmdname.
*/
extern TTC_DllImport
void
ttc_dump_help(FILE* fp, const char* cmdname, const char* msg);
/*
* ttc_getcmdname
* Return argv[0] with any leading path information, and any
* trailing 'Cmd' or '.exe' stripped off. Fills the specified
* buffer up to the specified length.
*/
extern TTC_DllImport
const char*
ttc_getcmdname(const char* argv0, char* buf, int buflen);
/*
* ttc_get_version_name
* Return a consistent form of the version name,
* looking like 'TimesTen Release 5.6.7'.
* Fills the specified buffer up to the specified length.
*/
extern TTC_DllImport
const char*
ttc_get_version_name(char* buf, int buflen);
/*
* Return a true value if the argument looks like a DSN.
*/
extern TTC_DllImport
int
ttc_opt_looks_like_dsn(const char* str);
/*
* Return a true value if the argument looks like a connection string.
*/
extern TTC_DllImport
int
ttc_opt_looks_like_connstr(const char* str);
#endif /* TTC_GETOPTIONS_H_INCLUDED */