Ethereal-dev: [Ethereal-dev] Patch for better finding of plugins under Win32

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Dr.-Ing. Gerrit Gehnen" <G.Gehnen@xxxxxxxx>
Date: Wed, 15 Aug 2001 09:36:21 +0200
Hello,

since using the Win32-installer for ethereal all users of non-english
versions of Windows are facing the problem, that the installer installs
ethereal under the standard program file location, but ethereal uses
a hardcoded path for the plugin folder.
For example the standard program location on my System is
"F:\Programme\".
Attached you find a patch for epan\plugins.c to replace the hardcoded
path c:\Program Files... with a path derived from the argv[0] argument,
pointing to the actual location of ethereal.exe.
That should fix any problems with finding the plugins under Win32.

Also I included a small patch to tetereal.exe to provide the argv[0]
argument to other parts of the program.

  Gerrit
*** tethereal.c	Fri Jul 13 15:52:26 2001
--- /POOL/POOL/GERRIT/ethereal_patch/tethereal.c	Mon Aug  6 22:00:18 2001
***************
*** 147,152 ****
--- 147,153 ----
  static int promisc_mode = TRUE;
  #endif
  
+ gchar       *ethereal_path = NULL;
  static void 
  print_usage(void)
  {
***************
*** 233,238 ****
--- 234,240 ----
    e_prefs             *prefs;
    char                 badopt;
  
+   ethereal_path = argv[0];
    /* Register all dissectors; we must do this before checking for the
       "-G" flag, as the "-G" flag dumps a list of fields registered
       by the dissectors, and we must do it before we read the preferences,
*** epan/plugins.c	Fri Jul 13 15:52:28 2001
--- /POOL/POOL/GERRIT/ethereal_patch/plugins.c	Tue Aug 14 22:12:00 2001
***************
*** 71,78 ****
  plugin *plugin_list;
  
  #ifdef WIN32
! static gchar std_plug_dir[] = "c:/program files/ethereal/plugins/" VERSION;
  static gchar local_plug_dir[] = "c:/ethereal/plugins/" VERSION;
  #else
  static gchar std_plug_dir[] = "/usr/lib/ethereal/plugins/" VERSION;
  static gchar local_plug_dir[] = "/usr/local/lib/ethereal/plugins/" VERSION;
--- 71,80 ----
  plugin *plugin_list;
  
  #ifdef WIN32
! #include <stdio.h>
! static gchar std_plug_dir[_MAX_PATH+2] ; //= "c:/program files/ethereal/plugins/" VERSION;
  static gchar local_plug_dir[] = "c:/ethereal/plugins/" VERSION;
+ extern gchar *ethereal_path;
  #else
  static gchar std_plug_dir[] = "/usr/lib/ethereal/plugins/" VERSION;
  static gchar local_plug_dir[] = "/usr/local/lib/ethereal/plugins/" VERSION;
***************
*** 277,282 ****
--- 279,287 ----
  init_plugins(const char *plugin_dir)
  {
      struct stat std_dir_stat, local_dir_stat, plugin_dir_stat;
+ #ifdef WIN32
+ 	char * path_pointer;
+ #endif
  
      if (plugin_list == NULL)      /* ensure init_plugins is only run once */
      {
***************
*** 406,411 ****
--- 411,433 ----
  	patable.p_prefs_register_enum_preference = prefs_register_enum_preference;
  #endif
  
+ #ifdef WIN32
+ 	strcpy(std_plug_dir,ethereal_path); /* get the actual path from argv[0] */
+ 	path_pointer=strrchr(std_plug_dir,'\\'); /* cut the program name from the path */
+ 	if (path_pointer!=NULL)
+ 		{
+ 		*(++path_pointer)='\0';
+ 		}
+ 	else
+ 		{
+ 		*std_plug_dir='\0'; /* oh, no absolute path.... */
+ 		}
+ 	if ((strlen(std_plug_dir)+strlen("plugins/"VERSION)+2)<_MAX_PATH)
+ 		{
+ 		strcat(std_plug_dir,"plugins/"VERSION); /* add the plugindir */
+ 		
+ 		}
+ #endif
  	plugins_scan_dir(std_plug_dir);
  	plugins_scan_dir(local_plug_dir);
  	if ((strcmp(std_plug_dir, plugin_dir) != 0) &&