00001 #include "jsoc.h"
00002 #include "cmdparams.h"
00003
00004 ModuleArgs_t module_args[] = {
00005 {ARG_FLAG, "p", NULL, "Test flag.", NULL},
00006 {ARG_STRING, "strarg1", NULL, "Test string arg with no default", NULL},
00007 {ARG_STRING, "strarg2", "jicama", "Test string arg with default", NULL},
00008 {ARG_INT, "intarg", NULL, "Test int arg with no default", NULL},
00009 {ARG_INT, "intargrange", NULL, "Test int arg with no default", "[7,10]"},
00010 {ARG_FLOAT, "fltarg", "23.7", "Test float arg with default", NULL},
00011 {ARG_DOUBLE, "dblarg", "67.237627", "", NULL},
00012 {ARG_INTS, "intsarg", "[1,2,6,2,6,7,3,78]", "Test int-array arg with default", NULL},
00013 {ARG_FLOATS, "fltsarg", "[20.2,26.26,62.10]", "Test float-array arg with default", NULL},
00014 {ARG_DOUBLES, "dblsarg", NULL, "Test double-array arg with no default", NULL},
00015 {ARG_NUME, "numearg", "blue", "Test enumerated argument type with default.", "red,orange,yellow,green,blue,violet"},
00016 {ARG_END, NULL, NULL, NULL, NULL}
00017 };
00018
00019 ModuleArgs_t *gModArgs = module_args;
00020
00021 static void Argprint(const void *data)
00022 {
00023 CmdParams_Arg_t *arg = (CmdParams_Arg_t *)data;
00024
00025 char *name = arg->name;
00026 int unnamednum = arg->unnamednum;
00027 char *value = arg->strval;
00028
00029 if (name)
00030 {
00031 printf("%s=\"%s\"\n", name, value);
00032 }
00033 else
00034 {
00035 printf("unnamed_arg_%03d=\"%s\"\n", unnamednum, value);
00036 }
00037 }
00038
00039 int main(int argc, char **argv)
00040 {
00041 int err = 0;
00042 char reservebuf[128];
00043 CmdParams_t cmdparams;
00044 int status = CMDPARAMS_SUCCESS;
00045
00046 memset(&cmdparams, 0, sizeof(CmdParams_t));
00047
00048
00049 snprintf(reservebuf, sizeof(reservebuf), "L,Q,V" );
00050 cmdparams_reserve(&cmdparams, reservebuf, "cptest");
00051
00052
00053 status = cmdparams_parse(&cmdparams, argc, argv);
00054
00055 if (status == CMDPARAMS_QUERYMODE)
00056 {
00057 cmdparams_usage("cptest");
00058 return 0;
00059 }
00060 else if (status == CMDPARAMS_NODEFAULT)
00061 {
00062 fprintf(stderr, "For usage, type %s [-H|--help]\n", argv[0]);
00063 err = 1;
00064 }
00065 else if (status < 0)
00066 {
00067 fprintf(stderr, "Error: Command line parsing failed. Aborting.\n");
00068 fprintf(stderr, "For usage, type %s [-H|--help]\n", "cptest");
00069 err = 1;
00070 }
00071
00072 if (!err)
00073 {
00074 int iarg = 0;
00075 const char *argname = NULL;
00076 const char *argval = NULL;
00077
00078
00079 fprintf(stdout, "Printing out entire CmdParams_t struct.\n");
00080 hcon_map(cmdparams.args, Argprint);
00081 fprintf(stdout, "\n");
00082
00083 fprintf(stdout, "Using cmdparams_getargument() to print all arguments as strings.\n");
00084 while (cmdparams_getargument(&cmdparams, iarg, &argname, &argval, NULL, NULL))
00085 {
00086 fprintf(stdout, "arg %d: %s='%s'\n", iarg, argname, argval);
00087 iarg++;
00088 }
00089 }
00090
00091
00092 int8_t val8 = cmdparams_get_int8(&cmdparams, "intarg", &status);
00093 int16_t val16 = cmdparams_get_int16(&cmdparams, "intarg", &status);
00094 int32_t val32 = cmdparams_get_int32(&cmdparams, "intarg", &status);
00095 int64_t val64 = cmdparams_get_int64(&cmdparams, "intarg", &status);
00096 uint64_t mask = cmdparams_get_mask64(&cmdparams, "intarg", &status);
00097
00098 printf("8-bit signed int: %hhd\n", val8);
00099 printf("16-bit signed int: %hd\n", val16);
00100 printf("32-bit signed int: %d\n", val32);
00101
00102 printf("64-bit signed int: %lld\n", (long long)val64);
00103 printf("64-bit mask (uint64_t): %llu\n", (unsigned long long)mask);
00104
00105 cmdparams_freeall(&cmdparams);
00106
00107 return err;
00108 }