testa.c
#include <stdio.h>
#include <llib/file.h>
#include <llib/str.h>
#include <llib/value.h>
#include <llib/arg.h>
static const char **incdirs;
static const char **string_args;
static int a;
static bool interactive;
PValue test(PValue *args) {
printf("gotcha! %d %d\n",value_as_int(args[1]),a);
printf("the include paths\n");
FOR_ARR (str_t,P,incdirs)
printf("'%s'\n",*P);
return NULL;
}
PValue two(PValue *args) {
double x;
char *name;
arg_get_values(args,&x,&name);
printf("x = %f, name = '%s'\n",x,name);
return NULL;
}
PValue kount(PValue *args) {
printf("kount %d\n",obj_kount());
#ifdef LLIB_DEBUG
obj_snapshot_dump();
obj_snapshot_create();
#endif
#ifdef LLIB_PTR_LIST
obj_snap_ptrs_dump();
obj_snap_ptrs_create();
#endif
return NULL;
}
PValue flag(PValue *args) {
printf("flag %f\n",value_as_float(args[1]));
return NULL;
}
PValue args[] = {
"cmd test(int i=0); // -T test command",test,
"cmd two(float x,string name); // -2 test cmd_get_values",two,
"void kount(); // -k referenced object count flag",kount,
"float flag(); // -f function flag taking float..",flag,
"string include[]; // -I include directories", &incdirs,
"int a=0; // flag value",&a,
"bool interactive=false; // -i interactive mode",&interactive,
"string #1[]; // array of string args",&string_args,
NULL
};
int main(int argc, const char **argv)
{
ArgState *state = arg_command_line(args,argv);
if (! interactive) {
if (array_len(incdirs) > 0) {
printf("the include paths\n");
FOR_ARR (str_t,P,incdirs)
printf("'%s'\n",*P);
}
if (array_len(string_args) > 0) {
printf("the string args\n");
FOR_ARR (str_t,P,string_args)
printf("'%s'\n",*P);
}
printf("flag a is %d\n",a);
} else {
char *line;
printf("> ");
while ((line = file_getline(stdin)) != NULL) {
char **parts = str_split(line," ");
PValue v = arg_process(state,(const char**)parts-1);
if (v != NULL) {
printf("%s\n",value_tostring(v));
unref(v);
}
dispose(parts,line);
printf("> ");
arg_reset_used(state);
}
}
return 0;
}