X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Foption.c;h=01237acb2e62b67446c8b8ecb582d456c9b8fd7f;hb=d888c9c8f4c3e7b4e1516fca135b5be62f7aeea3;hp=3a95a4af9b001c88bcbd475fa5cc8b3ea678df12;hpb=dc87756342c051418eccb2b7d932ffa5453c6788;p=lttv.git diff --git a/ltt/branches/poly/lttv/option.c b/ltt/branches/poly/lttv/option.c index 3a95a4af..01237acb 100644 --- a/ltt/branches/poly/lttv/option.c +++ b/ltt/branches/poly/lttv/option.c @@ -1,15 +1,16 @@ -#include +#include +#include #include typedef struct _LttvOption { - const char *long_name; + char *long_name; char char_name; - const char *description; - const char *arg_description; + char *description; + char *arg_description; LttvOptionType t; gpointer p; - LttvOptionHook h; + LttvOptionHook hook; gpointer hook_data; } LttvOption; @@ -43,7 +44,7 @@ void lttv_option_destroy() { LttvOption option; - GPtrArray list = g_ptr_array_new(); + GPtrArray *list = g_ptr_array_new(); int i; @@ -76,7 +77,7 @@ void lttv_option_add(const char *long_name, const char char_name, option->arg_description = g_strdup(arg_description); option->t = t; option->p = p; - option->h = h; + option->hook = h; option->hook_data = hook_data; g_hash_table_insert(options, option->long_name, option); } @@ -105,7 +106,7 @@ static struct poptOption endOption = { NULL, '\0', 0, NULL, 0}; static void build_popts(GPtrArray **plist, struct poptOption **ppopts, poptContext *pc, - int argv, char **argv) + int argc, char **argv) { LttvOption *option; @@ -152,7 +153,7 @@ destroy_popts(GPtrArray **plist, struct poptOption **ppopts, poptContext *pc) { g_ptr_array_free(*plist, TRUE); *plist = NULL; g_free(*ppopts); *ppopts = NULL; - poptFreeContext(*c); + poptFreeContext(*pc); } @@ -214,3 +215,32 @@ void lttv_option_parse(int argc, char **argv) destroy_popts(&list, &popts, &c); } +static void show_help(LttvOption *option) +{ + printf("--%s -%c argument: %s\n" , option->long_name, + option->char_name, + option->arg_description); + printf(" %s\n" , option->description); + +} + +void lttv_option_show_help(void) +{ + LttvOption option; + + GPtrArray *list = g_ptr_array_new(); + + int i; + + g_hash_table_foreach(options, list_options, list); + + printf("Built-in commands available:\n"); + printf("\n"); + + for(i = 0 ; i < list->len ; i++) { + show_help((LttvOption *)list->pdata[i]); + } + g_ptr_array_free(list, TRUE); + + +}