diff options
-rw-r--r-- | hardinfo2/Makefile.in | 8 | ||||
-rw-r--r-- | hardinfo2/hardinfo.c | 46 | ||||
-rw-r--r-- | hardinfo2/hardinfo.h | 6 | ||||
-rw-r--r-- | hardinfo2/shell.c | 2 | ||||
-rw-r--r-- | hardinfo2/util.c | 201 |
5 files changed, 177 insertions, 86 deletions
diff --git a/hardinfo2/Makefile.in b/hardinfo2/Makefile.in index 8a37f674..f8fef304 100644 --- a/hardinfo2/Makefile.in +++ b/hardinfo2/Makefile.in @@ -27,13 +27,13 @@ benchmark.so: benchmark.c @echo "[01;34m--- Module: $< ($@)[00m" $(CCSLOW) $(CFLAGS) -o $@ -shared $< $(GTK_FLAGS) $(GTK_LIBS) \ $(GLADE_LIBS) $(GLADE_FLAGS) - mv -f $@ modules + ln -sf ../$@ modules %.so: %.c @echo "[01;34m--- Module: $< ($@)[00m" $(CC) $(CFLAGS) -o $@ -shared $< $(GTK_FLAGS) $(GTK_LIBS) \ $(GLADE_LIBS) $(GLADE_FLAGS) - mv -f $@ modules + ln -sf ../$@ modules clean: rm -rf .xvpics pixmaps/.xvpics *.o *.so hardinfo modules/*.so report @@ -68,10 +68,10 @@ install: all cp hardinfo ${DESTDIR}/usr/bin/hardinfo @echo '[01;34m*** Installing modules...[00m' - cp -r modules/*.so ${DESTDIR}/usr/lib/hardinfo/modules + cp -Lr modules/*.so ${DESTDIR}/usr/lib/hardinfo/modules @echo '[01;34m*** Installing pixmaps...[00m' - cp -r pixmaps/* ${DESTDIR}/usr/share/hardinfo/pixmaps + cp -Lr pixmaps/* ${DESTDIR}/usr/share/hardinfo/pixmaps @echo '[01;34m*** Installing misc data...[00m' cp uidefs.xml ${DESTDIR}/usr/share/hardinfo diff --git a/hardinfo2/hardinfo.c b/hardinfo2/hardinfo.c index 6619afa1..e2a4a91c 100644 --- a/hardinfo2/hardinfo.c +++ b/hardinfo2/hardinfo.c @@ -33,34 +33,59 @@ main(int argc, char **argv) { GSList *modules; + /* parse all command line parameters */ parameters_init(&argc, &argv, ¶ms); + /* show version information and quit */ if (params.show_version) { g_print("HardInfo version " VERSION "\n"); g_print("Copyright (C) 2003-2006 Leandro A. F. Pereira. See COPYING for details.\n"); + return 0; } + /* initialize the binreloc library, so we can load program data */ + if (!binreloc_init(FALSE)) + g_error("Failed to find runtime data.\n\n" + "\342\200\242 Is HardInfo correctly installed?\n" + "\342\200\242 See if %s and %s exists and you have read permision.", + PREFIX, LIBPREFIX); + + /* list all module names */ + if (params.list_modules) { + GSList *modules = modules_load_all(); + + g_print("Module Name\t\tDynamic Loadable Module\n"); + for (; modules; modules = modules->next) { + ShellModule *module = (ShellModule *) modules->data; + + g_print("%s\t\t%s\n", module->name, g_module_name(module->dll)); + } + + return 0; + } + if (!params.create_report) { /* we only try to open the UI if the user didn't asked for a report. */ params.gui_running = ui_init(&argc, &argv); - /* if GTK+ initialization failed, assume the user wants a - report. */ + /* as a fallback, if GTK+ initialization failed, run in report + generation mode. */ if (!params.gui_running) params.create_report = TRUE; } - if (!binreloc_init(FALSE)) - g_error("Failed to find runtime data.\n\n" - "\342\200\242 Is HardInfo correctly installed?\n" - "\342\200\242 See if %s and %s exists and you have read permision.", - PREFIX, LIBPREFIX); - - modules = modules_load(); - + if (params.use_modules) { + /* load only selected modules */ + modules = modules_load_selected(); + } else { + /* load all modules */ + modules = modules_load_all(); + } + if (params.gui_running) { + /* initialize gui and start gtk+ main loop */ icon_cache_init(); stock_icons_init(); @@ -68,6 +93,7 @@ main(int argc, char **argv) gtk_main(); } else if (params.create_report) { + /* generate report */ gchar *report; report = report_create_from_module_list_format(modules, diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h index 1a5a4b97..17c9719b 100644 --- a/hardinfo2/hardinfo.h +++ b/hardinfo2/hardinfo.h @@ -29,8 +29,11 @@ struct _ProgramParameters { gboolean create_report; gboolean show_version; gboolean gui_running; + gboolean list_modules; + gint report_format; + gchar **use_modules; gchar *path_lib; gchar *path_data; }; @@ -67,7 +70,8 @@ gpointer file_types_get_data_by_name(FileTypes *file_types, gchar *name); inline gchar *size_human_readable(gfloat size); void nonblock_sleep(guint msec); void open_url(gchar *url); -GSList *modules_load(void); +GSList *modules_load_selected(void); +GSList *modules_load_all(void); /* BinReloc stuff */ gboolean binreloc_init(gboolean try_hardcoded); diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index aa616d56..d6290419 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -597,7 +597,7 @@ shell_init(GSList *modules) shell_status_set_enabled(TRUE); shell_status_update("Loading modules..."); - shell->tree->modules = modules ? modules : modules_load(); + shell->tree->modules = modules ? modules : modules_load_all(); g_slist_foreach(shell->tree->modules, add_modules_to_gui, shell->tree); gtk_tree_view_expand_all(GTK_TREE_VIEW(shell->tree->view)); diff --git a/hardinfo2/util.c b/hardinfo2/util.c index 49252a33..67fd39e8 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/util.c @@ -258,9 +258,11 @@ log_handler(const gchar * log_domain, void parameters_init(int *argc, char ***argv, ProgramParameters * param) { - static gboolean create_report = FALSE; - static gboolean show_version = FALSE; - static gchar *report_format = NULL; + static gboolean create_report = FALSE; + static gboolean show_version = FALSE; + static gboolean list_modules = FALSE; + static gchar *report_format = NULL; + static gchar **use_modules = NULL; static GOptionEntry options[] = { { @@ -278,6 +280,20 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param) .description = "chooses a report format (text, html)" }, { + .long_name = "list-modules", + .short_name = 'l', + .arg = G_OPTION_ARG_NONE, + .arg_data = &list_modules, + .description = "lists modules" + }, + { + .long_name = "load-modules", + .short_name = 'm', + .arg = G_OPTION_ARG_STRING_ARRAY, + .arg_data = &use_modules, + .description = "load only selected modules" + }, + { .long_name = "version", .short_name = 'v', .arg = G_OPTION_ARG_NONE, @@ -300,6 +316,8 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param) param->create_report = create_report; param->report_format = REPORT_FORMAT_TEXT; param->show_version = show_version; + param->list_modules = list_modules; + param->use_modules = use_modules; if (report_format && g_str_equal(report_format, "html")) param->report_format = REPORT_FORMAT_HTML; @@ -348,7 +366,87 @@ gchar *strreplace(gchar * string, gchar * replace, gchar new_char) return string; } -GSList *modules_load(void) +static ShellModule *module_load(gchar *name, gchar *filename) { + ShellModule *module; + gchar *tmp; + + module = g_new0(ShellModule, 1); + module->name = g_strdup(name); + + if (params.gui_running) { + tmp = g_strdup_printf("%s.png", filename); + module->icon = icon_cache_get_pixbuf(tmp); + g_free(tmp); + } + + tmp = g_strdup_printf("%s.so", filename); + filename = tmp; + + tmp = g_build_filename(params.path_lib, "modules", filename, NULL); + module->dll = g_module_open(tmp, G_MODULE_BIND_LAZY); + g_free(tmp); + + if (module->dll) { + gint(*n_entries) (void); + gint i; + + if (!g_module_symbol(module->dll, "hi_n_entries", (gpointer) & n_entries)) + goto failed; + + gint j = n_entries(); + for (i = 0; i <= j; i++) { + GdkPixbuf *(*shell_icon) (gint); + const gchar *(*shell_name) (gint); + ShellModuleEntry *entry = g_new0(ShellModuleEntry, 1); + + if (params.gui_running + && g_module_symbol(module->dll, "hi_icon", + (gpointer) & (shell_icon))) { + entry->icon = shell_icon(i); + } + if (g_module_symbol + (module->dll, "hi_name", (gpointer) & (shell_name))) { + entry->name = g_strdup(shell_name(i)); + } + g_module_symbol(module->dll, "hi_info", + (gpointer) & (entry->func)); + g_module_symbol(module->dll, "hi_reload", + (gpointer) & (entry->reloadfunc)); + g_module_symbol(module->dll, "hi_more_info", + (gpointer) & (entry->morefunc)); + g_module_symbol(module->dll, "hi_get_field", + (gpointer) & (entry->fieldfunc)); + + entry->number = i; + + module->entries = g_slist_append(module->entries, entry); + } + } else { + failed: + g_free(module->name); + g_free(module); + module = NULL; + } + + return module; +} + +static gboolean module_in_module_list(gchar *module, gchar **module_list) +{ + int i = 0; + + if (!module_list) + return TRUE; + + for (; module_list[i]; i++) { + if (g_str_equal(module_list[i], module)) + return TRUE; + } + + return FALSE; +} + +static GSList *modules_load(gchar **module_list) { gchar *modules_conf; GKeyFile *keyfile = g_key_file_new(); @@ -367,80 +465,43 @@ GSList *modules_load(void) gchar **cat = g_key_file_get_keys(keyfile, "categories", &categories, NULL); for (i = 0; i < categories; i++) { - ShellModule *module; - gchar *tmp, *iname; - - module = g_new0(ShellModule, 1); - module->name = g_strdup(cat[i]); - iname = g_key_file_get_value(keyfile, "categories", cat[i], NULL); - - if (params.gui_running) { - tmp = g_strdup_printf("%s.png", iname); - module->icon = icon_cache_get_pixbuf(tmp); - g_free(tmp); - } - - tmp = g_strdup_printf("%s.so", iname); - g_free(iname); - iname = tmp; - - tmp = g_build_filename(params.path_lib, "modules", iname, NULL); - module->dll = g_module_open(tmp, G_MODULE_BIND_LAZY); - g_free(tmp); + if (module_in_module_list(cat[i], module_list)) { + ShellModule *module; + gchar *name; - if (module->dll) { - gint(*n_entries) (void); - gint i; - - if (!g_module_symbol - (module->dll, "hi_n_entries", (gpointer) & n_entries)) - continue; - - gint j = n_entries(); - for (i = 0; i <= j; i++) { - GdkPixbuf *(*shell_icon) (gint); - const gchar *(*shell_name) (gint); - ShellModuleEntry *entry = g_new0(ShellModuleEntry, 1); - - if (params.gui_running - && g_module_symbol(module->dll, "hi_icon", - (gpointer) & (shell_icon))) { - entry->icon = shell_icon(i); - } - if (g_module_symbol - (module->dll, "hi_name", (gpointer) & (shell_name))) { - entry->name = g_strdup(shell_name(i)); - } - g_module_symbol(module->dll, "hi_info", - (gpointer) & (entry->func)); - g_module_symbol(module->dll, "hi_reload", - (gpointer) & (entry->reloadfunc)); - g_module_symbol(module->dll, "hi_more_info", - (gpointer) & (entry->morefunc)); - g_module_symbol(module->dll, "hi_get_field", - (gpointer) & (entry->fieldfunc)); - - entry->number = i; - module->entries = g_slist_append(module->entries, entry); - } - - modules = g_slist_append(modules, module); - } else { - g_free(module->name); - g_free(module); - } - - g_free(iname); + name = g_key_file_get_value(keyfile, "categories", cat[i], NULL); + module = module_load(cat[i], name); + + if (module) + modules = g_slist_append(modules, module); + + g_free(name); + } } g_strfreev(cat); g_key_file_free(keyfile); if (g_slist_length(modules) == 0) { - g_error - ("No module could be loaded. Check permissions on %s and try again.", - params.path_lib); + if (params.use_modules == NULL) { + g_error("No module could be loaded. Check permissions on \"%s\" and try again.", + params.path_lib); + } else { + g_error("No module could be loaded. Please use hardinfo -l to list all avai" + "lable modules and try again with a valid module list."); + + } } return modules; } + +GSList *modules_load_selected(void) +{ + return modules_load(params.use_modules); +} + +GSList *modules_load_all(void) +{ + return modules_load(NULL); +} |