Wireshark-dev: Re: [Wireshark-dev] RFC: Add fallback path to get_datafile_dir
From: Joerg Mayer <jmayer@xxxxxxxxx>
Date: Mon, 29 Aug 2011 16:57:30 +0200
And one day I will learn to attach patches directly to the mail... On Mon, Aug 29, 2011 at 04:50:25PM +0200, Joerg Mayer wrote: > as the problem recently popped up how to load auxillary files in the source > directory that have not been installed to their final paths, I've created a > patch that will add a fallback directory path to get_datafile_dir. > So far get_datafile_dir would check wether some magic variable were set to > locate generated (i.e. compiled) stuff inside the build dir instead of the > install dir. This patch allows to override this behaviour to search in the > specified directory relative to the source dir. If the fallback path is > given as NULL, the previous behaviour is used. As the path may now be > different with different invocations, the caching of the path had to go. > > Example call: > > WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1 WIRESHARK_SRC_DIR=../trunk ./wireshark > > Comments whether to commit this at all, in the current form or proposed > changes are requested. -- Joerg Mayer <jmayer@xxxxxxxxx> We are stuck with technology when what we really want is just stuff that works. Some say that should read Microsoft instead of technology.
Index: print.c =================================================================== --- print.c (revision 38773) +++ print.c (working copy) @@ -254,7 +254,7 @@ fputs("<?xml version=\"1.0\"?>\n", fh); fputs("<?xml-stylesheet type=\"text/xsl\" href=\"" PDML2HTML_XSL "\"?>\n", fh); - fprintf(fh, "<!-- You can find " PDML2HTML_XSL " in %s or at http://anonsvn.wireshark.org/trunk/wireshark/" PDML2HTML_XSL ". -->\n", get_datafile_dir()); + fprintf(fh, "<!-- You can find " PDML2HTML_XSL " in %s or at http://anonsvn.wireshark.org/trunk/wireshark/" PDML2HTML_XSL ". -->\n", get_datafile_dir(NULL)); fputs("<pdml version=\"" PDML_VERSION "\" ", fh); fprintf(fh, "creator=\"%s/%s\" time=\"%s\" capture_file=\"%s\">\n", PACKAGE, VERSION, ts, filename ? filename : ""); } Index: gtk/main_menubar.c =================================================================== --- gtk/main_menubar.c (revision 38775) +++ gtk/main_menubar.c (working copy) @@ -3305,7 +3305,7 @@ #ifndef NEW_MENU_CODE gtk_ui_manager_add_ui_from_string (ui_manager_tree_view_menu, ui_desc_tree_view_menu_popup, -1, &error); #else - gui_desc_file_name = g_strdup_printf("%s" G_DIR_SEPARATOR_S "ui" G_DIR_SEPARATOR_S "tree-view-ui.xml", get_datafile_dir()); + gui_desc_file_name = g_strdup_printf("%s" G_DIR_SEPARATOR_S "ui" G_DIR_SEPARATOR_S "tree-view-ui.xml", get_datafile_dir("gtk")); gtk_ui_manager_add_ui_from_file ( ui_manager_tree_view_menu, gui_desc_file_name, &error); #endif if (error != NULL) @@ -3347,7 +3347,7 @@ #ifndef NEW_MENU_CODE gtk_ui_manager_add_ui_from_string (ui_manager_bytes_menu, ui_desc_bytes_menu_popup, -1, &error); #else - gui_desc_file_name = g_strdup_printf("%s" G_DIR_SEPARATOR_S "ui" G_DIR_SEPARATOR_S "bytes-view-ui.xml", get_datafile_dir()); + gui_desc_file_name = g_strdup_printf("%s" G_DIR_SEPARATOR_S "ui" G_DIR_SEPARATOR_S "bytes-view-ui.xml", get_datafile_dir("gtk")); gtk_ui_manager_add_ui_from_file ( ui_manager_bytes_menu, gui_desc_file_name, &error); #endif if (error != NULL) @@ -3400,7 +3400,7 @@ #ifndef NEW_MENU_CODE gtk_ui_manager_add_ui_from_string (ui_manager_main_menubar,ui_desc_menubar, -1, &error); #else - gui_desc_file_name = g_strdup_printf("%s" G_DIR_SEPARATOR_S "ui" G_DIR_SEPARATOR_S "main-menubar-ui.xml", get_datafile_dir()); + gui_desc_file_name = g_strdup_printf("%s" G_DIR_SEPARATOR_S "ui" G_DIR_SEPARATOR_S "main-menubar-ui.xml", get_datafile_dir("gtk")); gtk_ui_manager_add_ui_from_file ( ui_manager_main_menubar, gui_desc_file_name, &error); #endif if (error != NULL) Index: gtk/about_dlg.c =================================================================== --- gtk/about_dlg.c (revision 38773) +++ gtk/about_dlg.c (working copy) @@ -403,7 +403,7 @@ g_free(path); /* global conf */ - constpath = get_datafile_dir(); + constpath = get_datafile_dir(NULL); if (constpath != NULL) { about_folders_row(table, "Global configuration", constpath, "\"dfilters\", \"preferences\", \"manuf\", ..."); Index: gtk/webbrowser.c =================================================================== --- gtk/webbrowser.c (revision 38773) +++ gtk/webbrowser.c (working copy) @@ -505,7 +505,7 @@ #endif else - file_path = g_strdup_printf("%s/%s", get_datafile_dir(), filename); + file_path = g_strdup_printf("%s/%s", get_datafile_dir(NULL), filename); /* XXX - check, if the file is really existing, otherwise display a simple_dialog about the problem */ Index: plugins/mate/mate_setup.c =================================================================== --- plugins/mate/mate_setup.c (revision 38773) +++ plugins/mate/mate_setup.c (working copy) @@ -584,7 +584,7 @@ matecfg->dbg_facility = NULL; - matecfg->mate_lib_path = g_strdup_printf("%s%c%s%c",get_datafile_dir(),DIR_SEP,DEFAULT_MATE_LIB_PATH,DIR_SEP);; + matecfg->mate_lib_path = g_strdup_printf("%s%c%s%c",get_datafile_dir(NULL),DIR_SEP,DEFAULT_MATE_LIB_PATH,DIR_SEP);; matecfg->pducfgs = g_hash_table_new(g_str_hash,g_str_equal); matecfg->gopcfgs = g_hash_table_new(g_str_hash,g_str_equal); Index: plugins/wimaxasncp/packet-wimaxasncp.c =================================================================== --- plugins/wimaxasncp/packet-wimaxasncp.c (revision 38773) +++ plugins/wimaxasncp/packet-wimaxasncp.c (working copy) @@ -3298,7 +3298,7 @@ dir = ep_strdup_printf( "%s" G_DIR_SEPARATOR_S "wimaxasncp", - get_datafile_dir()); + get_datafile_dir(NULL)); wimaxasncp_dict = wimaxasncp_dict_scan(dir, "dictionary.xml", debug_parser, &dict_error); Index: epan/dissectors/packet-diameter.c =================================================================== --- epan/dissectors/packet-diameter.c (revision 38773) +++ epan/dissectors/packet-diameter.c (working copy) @@ -1365,7 +1365,7 @@ ddict_avp_t* a; gboolean do_debug_parser = getenv("WIRESHARK_DEBUG_DIAM_DICT_PARSER") ? TRUE : FALSE; gboolean do_dump_dict = getenv("WIRESHARK_DUMP_DIAM_DICT") ? TRUE : FALSE; - char* dir = ep_strdup_printf("%s" G_DIR_SEPARATOR_S "diameter" G_DIR_SEPARATOR_S, get_datafile_dir()); + char* dir = ep_strdup_printf("%s" G_DIR_SEPARATOR_S "diameter" G_DIR_SEPARATOR_S, get_datafile_dir(NULL)); const avp_type_t* type; const avp_type_t* octetstring = &basic_types[0]; diam_avp_t* avp; Index: epan/dissectors/packet-tpncp.c =================================================================== --- epan/dissectors/packet-tpncp.c (revision 38773) +++ epan/dissectors/packet-tpncp.c (working copy) @@ -689,7 +689,7 @@ gchar *tpncp_dat_file_path; FILE *file; - tpncp_dat_file_path = ep_strdup_printf("%s" G_DIR_SEPARATOR_S"tpncp" G_DIR_SEPARATOR_S "tpncp.dat", get_datafile_dir()); + tpncp_dat_file_path = ep_strdup_printf("%s" G_DIR_SEPARATOR_S"tpncp" G_DIR_SEPARATOR_S "tpncp.dat", get_datafile_dir(NULL)); /* Open file with TPNCP data. */ if ((file = ws_fopen(tpncp_dat_file_path, "r")) == NULL) Index: epan/filesystem.c =================================================================== --- epan/filesystem.c (revision 38773) +++ epan/filesystem.c (working copy) @@ -575,16 +575,13 @@ * example). */ const char * -get_datafile_dir(void) +get_datafile_dir(const char *fallback_path) { #ifdef _WIN32 char *u3deviceexecpath; #endif static const char *datafile_dir = NULL; - if (datafile_dir != NULL) - return datafile_dir; - #ifdef _WIN32 /* * See if we are running in a U3 environment. @@ -629,7 +626,11 @@ * able to determine the directory in which the program * was found, so use that. */ - datafile_dir = progfile_dir; + if (fallback_path != NULL && getenv("WIRESHARK_SRC_DIR")) { + datafile_dir = g_strdup_printf("%s%s%s", getenv("WIRESHARK_SRC_DIR"), G_DIR_SEPARATOR_S, fallback_path); + } else { + datafile_dir = progfile_dir; + } } else { /* * Return the directory specified when the build was @@ -684,7 +685,7 @@ * on Windows, the data file directory is the directory * in which the Wireshark binary resides. */ - wspython_dir = g_strdup_printf("%s\\python\\%s", get_datafile_dir(), + wspython_dir = g_strdup_printf("%s\\python\\%s", get_datafile_dir(NULL), VERSION); /* @@ -705,7 +706,7 @@ * directory for python dissectors. */ g_free( (gpointer) wspython_dir); - wspython_dir = g_strdup_printf("%s\\python", get_datafile_dir()); + wspython_dir = g_strdup_printf("%s\\python", get_datafile_dir(NULL)); running_in_build_directory_flag = TRUE; } #else @@ -716,7 +717,7 @@ * the "python" subdirectory of the datafile directory * (the datafile directory is the build directory). */ - wspython_dir = g_strdup_printf("%s/epan/wspython/", get_datafile_dir()); + wspython_dir = g_strdup_printf("%s/epan/wspython/", get_datafile_dir(NULL)); } else { if (getenv("WIRESHARK_PYTHON_DIR") && !started_with_special_privs()) { /* @@ -780,7 +781,7 @@ * on Windows, the data file directory is the directory * in which the Wireshark binary resides. */ - plugin_dir = g_strdup_printf("%s\\plugins\\%s", get_datafile_dir(), + plugin_dir = g_strdup_printf("%s\\plugins\\%s", get_datafile_dir(NULL), VERSION); /* @@ -801,7 +802,7 @@ * directory for plugins. */ g_free( (gpointer) plugin_dir); - plugin_dir = g_strdup_printf("%s\\plugins", get_datafile_dir()); + plugin_dir = g_strdup_printf("%s\\plugins", get_datafile_dir(NULL)); running_in_build_directory_flag = TRUE; } #else @@ -812,7 +813,7 @@ * the "plugins" subdirectory of the datafile directory * (the datafile directory is the build directory). */ - plugin_dir = g_strdup_printf("%s/plugins", get_datafile_dir()); + plugin_dir = g_strdup_printf("%s/plugins", get_datafile_dir(NULL)); } else { if (getenv("WIRESHARK_PLUGIN_DIR") && !started_with_special_privs()) { /* @@ -862,7 +863,7 @@ get_systemfile_dir(void) { #ifdef _WIN32 - return get_datafile_dir(); + return get_datafile_dir(NULL); #else return "/etc"; #endif @@ -1061,7 +1062,7 @@ static char *global_profiles_dir = NULL; if (!global_profiles_dir) { - global_profiles_dir = g_strdup_printf ("%s%s%s", get_datafile_dir(), + global_profiles_dir = g_strdup_printf ("%s%s%s", get_datafile_dir(NULL), G_DIR_SEPARATOR_S, PROFILES_DIR); } @@ -1560,7 +1561,7 @@ get_datafile_path(const char *filename) { - return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_datafile_dir(), filename); + return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_datafile_dir(NULL), filename); } /* Get the personal plugin dir */ Index: epan/filesystem.h =================================================================== --- epan/filesystem.h (revision 38773) +++ epan/filesystem.h (working copy) @@ -71,7 +71,7 @@ * Get the directory in which global configuration files are * stored. */ -extern const char *get_datafile_dir(void); +extern const char *get_datafile_dir(const char *); /* * Construct the path name of a global configuration file, given the
- References:
- [Wireshark-dev] RFC: Add fallback path to get_datafile_dir
- From: Joerg Mayer
- [Wireshark-dev] RFC: Add fallback path to get_datafile_dir
- Prev by Date: [Wireshark-dev] RFC: Add fallback path to get_datafile_dir
- Next by Date: [Wireshark-dev] buildbot failure in Wireshark (development) on Windows-7-x64
- Previous by thread: [Wireshark-dev] RFC: Add fallback path to get_datafile_dir
- Next by thread: Re: [Wireshark-dev] RFC: Add fallback path to get_datafile_dir
- Index(es):