00001
00011 #ifndef _CMDPARAMS_H
00012 #define _CMDPARAMS_H
00013
00014 #include "hash_table.h"
00015 #include "hcontainer.h"
00016 #include "list.h"
00017 #include <stdlib.h>
00018
00019 #ifdef FLIB
00020
00021 #include "cfortran.h"
00022 #include "inthandles.h"
00023 #define kgModCmdParams 1
00024 #define kgModCmdParamsStr "1"
00025 #endif
00026
00027 #define CMDPARAMS_INITBUFSZ (4096)
00028 #define CMDPARAMS_MAXLINE (1024)
00029 #define CMDPARAMS_MAXNEST (10)
00030 #define CMDPARAMS_MAXARGNAME (512)
00031 #define CMDPARAMS_MAGICSTR "CpUnNamEDaRg"
00032
00033
00034 #define CMDPARAMS_SUCCESS (0)
00035 #define CMDPARAMS_FAILURE (-1)
00036 #define CMDPARAMS_QUERYMODE (-2)
00037 #define CMDPARAMS_NODEFAULT (-3)
00038 #define CMDPARAMS_UNKNOWN_PARAM (-4)
00039 #define CMDPARAMS_INVALID_CONVERSION (-5)
00040 #define CMDPARAMS_OUTOFMEMORY (-6)
00041
00042 typedef uint64_t CmdParams_Mask64_t;
00043
00044
00045 typedef enum {
00047 ARG_END = 0,
00049 ARG_FLAG,
00051 ARG_TIME,
00053 ARG_INT,
00055 ARG_FLOAT,
00057 ARG_DOUBLE,
00059 ARG_STRING,
00061 ARG_VOID,
00063 ARG_INTS,
00065 ARG_FLOATS,
00067 ARG_DOUBLES,
00068
00069 ARG_STRINGS,
00071 ARG_NUME,
00073 ARG_DATASET,
00075 ARG_DATASERIES,
00077 ARG_NEWDATA,
00079 ARG_NUMARGS
00080 } ModuleArgs_Type_t;
00081
00083 struct ModuleArgs_struct {
00085 ModuleArgs_Type_t type;
00087 char *name;
00089 char *value;
00091 char *description;
00093 char *range;
00094 };
00099 typedef struct ModuleArgs_struct ModuleArgs_t;
00100
00101
00102
00103
00104 struct CmdParams_Arg_struct
00105 {
00106 char *name;
00107
00108 int unnamednum;
00109 char *cmdlinestr;
00110
00111 ModuleArgs_Type_t type;
00112
00113
00114 char *strval;
00115 void *actvals;
00116
00117 int nelems;
00118 int8_t accessed;
00119 int8_t casesensitive;
00120
00121
00122
00123
00124
00125
00126
00127 };
00128
00129 typedef struct CmdParams_Arg_struct CmdParams_Arg_t;
00130
00132 struct CmdParams_struct {
00133 HContainer_t *args;
00134 CmdParams_Arg_t **argarr;
00135
00136 int szargs;
00137 int argc;
00138 char **argv;
00139 int numargs;
00140 int numunnamed;
00141 HContainer_t *reserved;
00142
00143 HContainer_t *defps;
00144 };
00146 typedef struct CmdParams_struct CmdParams_t;
00147
00292 int cmdparams_parse (CmdParams_t *parms, int argc, char *argv[]);
00293
00294 int cmdparams_parsefile (CmdParams_t *parms, char *filename, int depth);
00295 CmdParams_Arg_t *cmdparams_set (CmdParams_t *parms, const char *name, const char *value);
00296 int cmdparams_exists (CmdParams_t *parms, char *name);
00297 void cmdparams_printall (CmdParams_t *parms);
00298 const char *cmdparams_getarg (CmdParams_t *parms, int num);
00299 const char *cmdparams_getargument(CmdParams_t *parms,
00300 int num,
00301 const char **name,
00302 const char **value,
00303 const char **cmdlinestr,
00304 int *accessed);
00305 void cmdparams_usage (char *name);
00306 int cmdparams_numargs (CmdParams_t *parms);
00307
00312
00320 int cmdparams_isflagset (CmdParams_t *parms, char *name);
00321 int params_isflagset (CmdParams_t *parms, char *name);
00322
00323
00324
00330
00342 int8_t cmdparams_get_int8 (CmdParams_t *parms, char *name, int *status);
00343 int16_t cmdparams_get_int16 (CmdParams_t *parms, char *name, int *status);
00344 int32_t cmdparams_get_int32 (CmdParams_t *parms, char *name, int *status);
00345 int64_t cmdparams_get_int64 (CmdParams_t *parms, char *name, int *status);
00346 CmdParams_Mask64_t cmdparams_get_mask64(CmdParams_t *parms, const char *name, int *status);
00347 float cmdparams_get_float (CmdParams_t *parms, char *name, int *status);
00348 double cmdparams_get_double (CmdParams_t *parms, const char *name, int *status);
00349 int cmdparams_get_dblarr(CmdParams_t *parms, char *name, double **arr, int *status);
00350
00351 int cmdparams_get_int (CmdParams_t *parms, char *name, int *status);
00352 int cmdparams_get_intarr(CmdParams_t *parms, char *name, int **arr, int *status);
00353 int cmdparams_get_int64arr(CmdParams_t *parms, char *name, int64_t **arr, int *status);
00354
00365 const char *cmdparams_get_str (CmdParams_t *parms, const char *name, int *status);
00366
00367 int cmdparams_get_strarr(CmdParams_t *parms, char *name, char ***arr, int *status);
00368
00373 double cmdparams_get_time (CmdParams_t *parms, char *name, int *status);
00374
00375
00376
00377 void cmdparams_get_argv(CmdParams_t *params, char *const **argv, int *argc);
00378
00379 void cmdparams_reserve(CmdParams_t *params, const char *reserved, const char *owner);
00380
00381 int cmdparams_isreserved(CmdParams_t *params, const char *key);
00382
00383 HContainer_t *cmdparams_get_argscont(CmdParams_t *params);
00384 static inline const char *cmdparams_get_argname(CmdParams_Arg_t *arg)
00385 {
00386 return (const char *)arg->name;
00387 }
00388
00396
00401 const char *params_get_str (CmdParams_t *parms, char *name);
00402 int8_t params_get_int8 (CmdParams_t *parms, char *name);
00403 int16_t params_get_int16 (CmdParams_t *parms, char *name);
00404 int32_t params_get_int32 (CmdParams_t *parms, char *name);
00405 int64_t params_get_int64 (CmdParams_t *parms, char *name);
00406 float params_get_float (CmdParams_t *parms, char *name);
00407 double params_get_double (CmdParams_t *parms, char *name);
00408 double params_get_time (CmdParams_t *parms, char *name);
00409 char params_get_char (CmdParams_t *parms, char *name);
00410 short params_get_short (CmdParams_t *parms, char *name);
00411 int params_get_int (CmdParams_t *parms, char *name);
00412
00413
00414 void cmdparams_freeall (CmdParams_t *parms);
00415
00416 #ifdef FLIB
00417
00422
00423
00428 void f_cmdparams_get_str(pFHandleCmdParams handle,
00429 const char *name,
00430 char *ret,
00431 int size,
00432 int *status);
00433 void f_cmdparams_get_int(pFHandleCmdParams handle, const char *name, int *ret, int *status);
00434 void f_cmdparams_get_int8(pFHandleCmdParams handle, const char *name, int8_t *ret, int *status);
00435 void f_cmdparams_get_int16(pFHandleCmdParams handle, const char *name, int16_t *ret, int *status);
00436 void f_cmdparams_get_int32(pFHandleCmdParams handle, const char *name, int32_t *ret, int *status);
00437 void f_cmdparams_get_int64(pFHandleCmdParams handle, const char *name, long long *ret, int *status);
00438 void f_cmdparams_get_float(pFHandleCmdParams handle, char *name, float *ret, int *status);
00439 void f_cmdparams_get_double(pFHandleCmdParams handle, char *name, double *ret, int *status);
00440 void f_cmdparams_get_time(pFHandleCmdParams handle, char *name, double *ret, int *status);
00441
00442 void f_params_get_str(pFHandleCmdParams handle, const char *name, char *ret, int size);
00443 void f_params_get_int(pFHandleCmdParams handle, const char *name, int *ret);
00444 void f_params_get_int8(pFHandleCmdParams handle, const char *name, int8_t *ret);
00445 void f_params_get_int16(pFHandleCmdParams handle, const char *name, int16_t *ret);
00446 void f_params_get_int32(pFHandleCmdParams handle, const char *name, int32_t *ret);
00447 void f_params_get_int64(pFHandleCmdParams handle, const char *name, long long *ret);
00448 void f_params_get_char(pFHandleCmdParams handle, char *name, signed char *ret);
00449 void f_params_get_short(pFHandleCmdParams handle, char *name, short *ret);
00450 void f_params_get_float(pFHandleCmdParams handle, char *name, float *ret);
00451 void f_params_get_double(pFHandleCmdParams handle, char *name, double *ret);
00452 void f_params_get_time(pFHandleCmdParams handle, char *name, double *ret);
00453
00457 void f_cmdparams_isflagset(pFHandleCmdParams handle, const char *name, int *ret);
00458
00462 void f_params_isflagset(pFHandleCmdParams handle, const char *name, int *ret);
00463
00464
00465 #endif
00466
00467 #endif