+/* This file is part of the Linux Trace Toolkit viewer
+ * Copyright (C) 2003-2004 Michel Dagenais
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
#include <popt.h>
#include <glib.h>
+#include <lttv/module.h>
#include <lttv/option.h>
-#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
-#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
-
typedef struct _LttvOption {
char *long_name;
char char_name;
}
-void lttv_option_init(int argc, char **argv)
-{
- g_info("Init option.c");
- options = g_hash_table_new(g_str_hash, g_str_equal);
-}
-
-
-void lttv_option_destroy()
-{
- LttvOption option;
-
- GPtrArray *list = g_ptr_array_new();
-
- int i;
-
- g_info("Destroy option.c");
- g_hash_table_foreach(options, list_options, list);
- g_hash_table_destroy(options);
-
- for(i = 0 ; i < list->len ; i++) {
- free_option((LttvOption *)list->pdata[i]);
- }
- g_ptr_array_free(list, TRUE);
-}
-
-
void lttv_option_add(const char *long_name, const char char_name,
const char *description, const char *arg_description,
const LttvOptionType t, void *p,
{
LttvOption *option;
- g_info("Add option %s", long_name);
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Add option %s", long_name);
if(g_hash_table_lookup(options, long_name) != NULL) {
g_warning("duplicate option");
return;
{
LttvOption *option = g_hash_table_lookup(options, long_name);
- g_info("Remove option %s", long_name);
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Remove option %s", long_name);
if(option == NULL) {
g_warning("trying to remove unknown option %s", long_name);
return;
if(rc > 0) {
option = (LttvOption *)(list->pdata[rc - 1]);
- g_info("Option %s encountered", option->long_name);
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Option %s encountered",
+ option->long_name);
if(option->hook != NULL) {
- g_info("Option %s hook called", option->long_name);
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Option %s hook called",
+ option->long_name);
option->hook(option->hook_data);
}
i++;
}
else if(rc == POPT_ERROR_BADOPT && i != first_arg) {
- g_info("Option %s not recognized, rescan options with new additions",
- poptBadOption(c,0));
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
+ "Option %s not recognized, rescan options with new additions",
+ poptBadOption(c,0));
/* Perhaps this option is newly added, restart parsing */
for(i = 0; i < first_arg; i++) {
rc = poptGetNextOpt(c);
option = (LttvOption *)(list->pdata[rc - 1]);
- g_info("Option %s rescanned, skipped", option->long_name);
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Option %s rescanned, skipped",
+ option->long_name);
}
}
destroy_popts(&list, &popts, &c);
}
+/* CHECK */
static void show_help(LttvOption *option)
{
printf("--%s -%c argument: %s\n" , option->long_name,
}
+static void init()
+{
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Init option.c");
+ options = g_hash_table_new(g_str_hash, g_str_equal);
+}
+
+
+static void destroy()
+{
+ LttvOption option;
+
+ GPtrArray *list = g_ptr_array_new();
+
+ int i;
+
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Destroy option.c");
+ g_hash_table_foreach(options, list_options, list);
+ g_hash_table_destroy(options);
+
+ for(i = 0 ; i < list->len ; i++) {
+ free_option((LttvOption *)list->pdata[i]);
+ }
+ g_ptr_array_free(list, TRUE);
+}
+
+LTTV_MODULE("option", "Command line options processing", \
+ "Functions to add, remove and parse command line options", \
+ init, destroy)