00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #ifndef _LIBUTIL_CMD_LN_H_
00059 #define _LIBUTIL_CMD_LN_H_
00060
00061 #include <stdio.h>
00062 #include <stdarg.h>
00063
00064
00065 #include <sphinxbase_export.h>
00066 #include <prim_type.h>
00067 #include <hash_table.h>
00068
00077 #ifdef __cplusplus
00078 extern "C" {
00079 #endif
00080 #if 0
00081
00082 }
00083 #endif
00084
00089 typedef struct arg_s {
00090 char const *name;
00091 int type;
00092 char const *deflt;
00093 char const *doc;
00094 } arg_t;
00095
00099
00103 #define ARG_REQUIRED (1<<0)
00104
00107 #define ARG_INTEGER (1<<1)
00108
00111 #define ARG_FLOATING (1<<2)
00112
00115 #define ARG_STRING (1<<3)
00116
00119 #define ARG_BOOLEAN (1<<4)
00120
00124 #define REQARG_INTEGER (ARG_INTEGER | ARG_REQUIRED)
00125
00128 #define REQARG_FLOATING (ARG_FLOATING | ARG_REQUIRED)
00129
00132 #define REQARG_STRING (ARG_STRING | ARG_REQUIRED)
00133
00136 #define REQARG_BOOLEAN (ARG_BOOLEAN | ARG_REQUIRED)
00137
00141 #define ARG_INT32 ARG_INTEGER
00142
00145 #define ARG_FLOAT32 ARG_FLOATING
00146
00149 #define ARG_FLOAT64 ARG_FLOATING
00150
00153 #define REQARG_INT32 (ARG_INT32 | ARG_REQUIRED)
00154
00157 #define REQARG_FLOAT32 (ARG_FLOAT32 | ARG_REQUIRED)
00158
00161 #define REQARG_FLOAT64 (ARG_FLOAT64 | ARG_REQUIRED)
00162
00163
00164
00169 #define ARG_STRINGIFY(s) ARG_STRINGIFY1(s)
00170 #define ARG_STRINGIFY1(s) #s
00171
00176 typedef struct cmd_ln_s cmd_ln_t;
00177
00196 SPHINXBASE_EXPORT
00197 cmd_ln_t *cmd_ln_init(cmd_ln_t *inout_cmdln, arg_t const *defn, int32 strict, ...);
00198
00204 SPHINXBASE_EXPORT
00205 cmd_ln_t *cmd_ln_retain(cmd_ln_t *cmdln);
00206
00212 SPHINXBASE_EXPORT
00213 int cmd_ln_free_r(cmd_ln_t *cmdln);
00214
00234 SPHINXBASE_EXPORT
00235 cmd_ln_t *cmd_ln_parse_r(cmd_ln_t *inout_cmdln,
00237 arg_t const *defn,
00238 int32 argc,
00239 char *argv[],
00240 int32 strict
00242 );
00243
00250 SPHINXBASE_EXPORT
00251 cmd_ln_t *cmd_ln_parse_file_r(cmd_ln_t *inout_cmdln,
00253 arg_t const *defn,
00254 char const *filename,
00256 int32 strict
00258 );
00259
00263 SPHINXBASE_EXPORT
00264 anytype_t *cmd_ln_access_r(cmd_ln_t *cmdln, char const *name);
00265
00280 SPHINXBASE_EXPORT
00281 char const *cmd_ln_str_r(cmd_ln_t *cmdln, char const *name);
00282
00294 SPHINXBASE_EXPORT
00295 long cmd_ln_int_r(cmd_ln_t *cmdln, char const *name);
00296
00308 SPHINXBASE_EXPORT
00309 double cmd_ln_float_r(cmd_ln_t *cmdln, char const *name);
00310
00314 #define cmd_ln_boolean_r(c,n) (cmd_ln_int_r(c,n) != 0)
00315
00324 SPHINXBASE_EXPORT
00325 void cmd_ln_set_str_r(cmd_ln_t *cmdln, char const *name, char const *str);
00326
00334 SPHINXBASE_EXPORT
00335 void cmd_ln_set_int_r(cmd_ln_t *cmdln, char const *name, long iv);
00336
00344 SPHINXBASE_EXPORT
00345 void cmd_ln_set_float_r(cmd_ln_t *cmdln, char const *name, double fv);
00346
00350 #define cmd_ln_set_boolean_r(c,n,b) (cmd_ln_set_int_r(c,n,(b)!=0))
00351
00352
00353
00354
00355 #define cmd_ln_int32_r(c,n) cmd_ln_int_r(c,n)
00356 #define cmd_ln_float32_r(c,n) (float32)cmd_ln_float_r(c,n)
00357 #define cmd_ln_float64_r(c,n) (float64)cmd_ln_float_r(c,n)
00358 #define cmd_ln_set_int32_r(c,n,i) cmd_ln_set_int_r(c,n,i)
00359 #define cmd_ln_set_float32_r(c,n,f) cmd_ln_set_float_r(c,n,(double)f)
00360 #define cmd_ln_set_float64_r(c,n,f) cmd_ln_set_float_r(c,n,(double)f)
00361
00368 SPHINXBASE_EXPORT
00369 int cmd_ln_exists_r(cmd_ln_t *cmdln, char const *name);
00370
00375 SPHINXBASE_EXPORT
00376 void cmd_ln_print_help_r (cmd_ln_t *cmdln,
00377 FILE *fp,
00378 const arg_t *defn
00379 );
00380
00388 SPHINXBASE_EXPORT
00389 int32 cmd_ln_parse(const arg_t *defn,
00390 int32 argc,
00391 char *argv[],
00392 int32 strict
00394 );
00395
00405 SPHINXBASE_EXPORT
00406 int32 cmd_ln_parse_file(const arg_t *defn,
00407 char const *filename,
00408 int32 strict
00410 );
00411
00417 SPHINXBASE_EXPORT
00418 void cmd_ln_appl_enter(int argc,
00419 char *argv[],
00420 char const* default_argfn,
00421 const arg_t *defn
00422 );
00423
00424
00431 SPHINXBASE_EXPORT
00432 void cmd_ln_appl_exit(void);
00433
00440 SPHINXBASE_EXPORT
00441 cmd_ln_t *cmd_ln_get(void);
00442
00453 #define cmd_ln_exists(name) cmd_ln_exists_r(cmd_ln_get(), name)
00454
00461 #define cmd_ln_access(name) cmd_ln_access_r(cmd_ln_get(), name)
00462
00469 #define cmd_ln_str(name) cmd_ln_str_r(cmd_ln_get(), name)
00470
00476 #define cmd_ln_int32(name) (int32)cmd_ln_int_r(cmd_ln_get(), name)
00477
00483 #define cmd_ln_float32(name) (float32)cmd_ln_float_r(cmd_ln_get(), name)
00484
00490 #define cmd_ln_float64(name) (float64)cmd_ln_float_r(cmd_ln_get(), name)
00491
00497 #define cmd_ln_boolean(name) cmd_ln_boolean_r(cmd_ln_get(), name)
00498
00505 #define cmd_ln_set_str(n,s) cmd_ln_set_str_r(cmd_ln_get(),n,s)
00506
00512 #define cmd_ln_set_int32(n,i) cmd_ln_set_int_r(cmd_ln_get(),n,i)
00513
00519 #define cmd_ln_set_float32(n,f) cmd_ln_set_float_r(cmd_ln_get(),n,f)
00520
00526 #define cmd_ln_set_float64(n,f) cmd_ln_set_float_r(cmd_ln_get(),n,f)
00527
00533 #define cmd_ln_set_boolean(n,b) cmd_ln_set_boolean_r(cmd_ln_get(),n,b)
00534
00542 #define cmd_ln_print_help(f,d) cmd_ln_print_help_r(cmd_ln_get(),f,d)
00543
00548 SPHINXBASE_EXPORT
00549 void cmd_ln_free (void);
00550
00551
00552 #ifdef __cplusplus
00553 }
00554 #endif
00555
00556 #endif
00557
00558