Index: modules/ChangeLog
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/ChangeLog,v
retrieving revision 1.1182
diff -u -u -r1.1182 ChangeLog
--- modules/ChangeLog	10 Feb 2006 12:33:22 -0000	1.1182
+++ modules/ChangeLog	10 Feb 2006 23:32:34 -0000
@@ -1,3 +1,28 @@
+2006-02-11  Renato Caldas  <seventhguardian@gmail.com>
+
+	* FvwmIdent/FvwmIdent.c:
+	* FvwmForm/FvwmForm.c:
+	* FvwmGtk/FvwmGtk.c:
+	Replaced global vars for name and name length for a ModuleArgs
+	struct pointed by "module".
+	main() changed to copy the global fd's for comunication with fvwm
+	from the struct.
+	main() changed to use ParseModuleArgs instead of the "manual"
+	parsing methods.
+	main() changed to use the struct's user_argc and user_argv for
+	parsing command line options.
+	Small misc changes to use module->name for error messages.
+
+	* FvwmIdent/FvwmIdent.c:
+	Replaced the app window global var (app_win) for module->window.
+
+	* FvwmForm/FvwmForm.c (ParseConfigLine):
+	(ReadConfig):
+	(ParseActiveMessage):
+	* FvwmGtk/FvwmGtk.c (parse_config_line):
+	(parse_options):
+	Changed functions to use CatString3 and module->name.
+
 2006-02-10  George Potapov <nephrite@inbox.ru>
 
 	* modules/FvwmButtons/FvwmButtons.1.in
Index: modules/FvwmForm/FvwmForm.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmForm/FvwmForm.c,v
retrieving revision 1.114
diff -u -u -r1.114 FvwmForm.c
--- modules/FvwmForm/FvwmForm.c	26 Nov 2005 21:55:12 -0000	1.114
+++ modules/FvwmForm/FvwmForm.c	10 Feb 2006 23:32:39 -0000
@@ -77,8 +77,7 @@
 char endDefaultsRead = 'n';
 char *font_names[4];
 char *screen_background_color;
-char *MyName;
-int MyNameLen;
+static ModuleArgs *module;
 int Channel[2];
 Bool Swallowed = False;
 
@@ -344,15 +343,15 @@
     LoadColorset(&buf[8]);
     return;
   }
-  if (strncasecmp(buf, MyName, MyNameLen) != 0) {/* If its not for me */
+  if (strncasecmp(buf, CatString3("*",module->name,0), module->namelen+1) != 0) {/* If its not for me */
     return;
   } /* Now I know its for me. */
-  p = buf+MyNameLen;                  /* jump to end of my name */
+  p = buf+module->namelen+1;                  /* jump to end of my name */
   /* at this point we have recognized "*FvwmForm" */
   FormVarsCheck(&p);
   e = FindToken(p,ct_table,struct CommandTable);/* find cmd in table */
   if (e == 0) {                       /* if no match */
-    fprintf(stderr,"%s: unknown command: %s\n",MyName+1,buf);
+    fprintf(stderr,"%s: unknown command: %s\n",module->name,buf);
     return;
   }
 
@@ -397,7 +396,7 @@
   int i,j;
   if (strlen(cp) > 5) {
     fprintf(stderr,"%s: arg for ActivateOnPress (%s) too long\n",
-	    MyName+1,cp);
+	    module->name,cp);
     return;
   }
   for (i=0,j=0;i<strlen(cp);i++) {
@@ -417,7 +416,7 @@
     CF.activate_on_press = 0;
   } else {
     fprintf(stderr,"%s: arg for ActivateOnPress (%s/%s) invalid\n",
-	    MyName+1,option,cp);
+	    module->name,option,cp);
   }
 }
 static void ct_GrabServer(char *cp)
@@ -783,7 +782,7 @@
   new_dt->dt_color_names[c_item_fg] = safestrdup(match_item_fore);
   new_dt->dt_color_names[c_item_bg] = safestrdup(match_item_back);
   new_dt->dt_used = 0;                  /* show nothing allocated */
-  new_dt->dt_Ffont = FlocaleLoadFont(dpy, new_dt->dt_font_name, MyName+1);
+  new_dt->dt_Ffont = FlocaleLoadFont(dpy, new_dt->dt_font_name, module->name);
   FlocaleAllocateWinString(&new_dt->dt_Fstr);
 
   myfprintf((stderr,"Created drawtable with %s %s %s %s %s\n",
@@ -1128,7 +1127,7 @@
      before the choice. At least a core dump is avoided. */
   if (cur_sel == 0) {                   /* need selection for a choice */
     fprintf(stderr,"%s: Need selection for choice %s\n",
-	    MyName+1, cp);
+	    module->name, cp);
     return;
   }
   bg_state = 'u';                       /* indicate b/g color now used. */
@@ -1294,7 +1293,7 @@
 {
   char *line_buf;                       /* ptr to curr config line */
 
-  InitGetConfigLine(Channel,MyName);
+  InitGetConfigLine(Channel,CatString3("*",module->name,0));
   while (GetConfigLine(Channel,&line_buf),line_buf) { /* get config from fvwm */
     ParseConfigLine(line_buf);          /* process config lines */
   }
@@ -2181,11 +2180,11 @@
 	       KeyPressMask | ExposureMask | StructureNotifyMask |
 	       VisibilityChangeMask);
   if (!CF.title) {
-    CF.title = MyName+1;
+    CF.title = module->name;
   }
   XStoreName(dpy, CF.frame, CF.title);
   XSetWMHints(dpy, CF.frame, &wmh);
-  myclasshints.res_name = MyName+1;
+  myclasshints.res_name = module->name;
   myclasshints.res_class = "FvwmForm";
   XSetClassHint(dpy,CF.frame,&myclasshints);
   sh.width = CF.max_width;
@@ -2432,12 +2431,12 @@
 		FScreenConfigureModule(buf + sizeof(XINERAMA_CONFIG_STRING)-1);
 		return;
 	}
-	if (strncasecmp(buf, MyName, MyNameLen) != 0)
+	if (strncasecmp(buf, CatString3("*",module->name,0), module->namelen+1) != 0)
 	{
 		/* If its not for me */
 		return;
 	} /* Now I know its for me. */
-	p = buf+MyNameLen;                  /* jump to end of my name */
+	p = buf+module->namelen+1;                  /* jump to end of my name */
 	/* at this point we have recognized "*FvwmForm" */
 	e = FindToken(p,am_table,struct CommandTable);/* find cmd in table */
 	if (e == 0)
@@ -2447,7 +2446,7 @@
 		if (FindToken(p, ct_table, struct CommandTable) == 0)
 			fprintf(
 				stderr,"%s: Active command unknown: %s\n",
-				MyName+1,buf);
+				module->name,buf);
 		return;                             /* ignore it */
 	}
 
@@ -2573,7 +2572,6 @@
 int main (int argc, char **argv)
 {
   int i;
-  char *s;
   char cmd[200];
 
 #ifdef DEBUGTOFILE
@@ -2582,25 +2580,10 @@
 
   FlocaleInit(LC_CTYPE, "", "", "FvwmForm");
 
-  /* From FvwmAnimate start */
-  /* Save our program  name - for error events */
-  if ((s=strrchr(argv[0], '/')))        /* strip path */
-    s++;
-  else                          /* no slash */
-    s = argv[0];
-  if(argc>=7)                         /* if override name */
-    s = argv[6];                      /* use arg as name */
-  MyNameLen=strlen(s)+1;                /* account for '*' */
-  MyName = safemalloc(MyNameLen+1);     /* account for \0 */
-  *MyName='*';
-  strcpy(MyName+1, s);          /* append name */
-
-  myfprintf((stderr,"%s: Starting, argv[0] is %s, len %d\n",MyName+1,
-	     argv[0],MyNameLen));
-
-  if (argc < 6) {                       /* Now MyName is defined */
-    fprintf(stderr,"%s Version "VERSION" should only be executed by fvwm!\n",
-	    MyName+1);
+  module = ParseModuleArgs(argc,argv,1); /* allow an alias */
+  if (module == NULL)
+  {
+    fprintf(stderr,"FvwmForm Version "VERSION" should only be executed by fvwm!\n");
     exit(1);
   }
 
@@ -2637,12 +2620,12 @@
 #endif
 #endif
 
-  Channel[0] = atoi(argv[1]);
-  Channel[1] = atoi(argv[2]);
+  Channel[0] = module->to_fvwm;
+  Channel[1] = module->from_fvwm;
 
   dpy = XOpenDisplay("");
   if (dpy==NULL) {
-    fprintf(stderr,"%s: could not open display\n",MyName+1);
+    fprintf(stderr,"%s: could not open display\n",module->name);
     exit(1);
   }
   /* From FvwmAnimate end */
@@ -2679,8 +2662,8 @@
   InitConstants();
   ReadDefaults();                       /* get config from fvwm */
 
-  if (strcasecmp(MyName+1,"FvwmForm") != 0) { /* if not already read */
-    sprintf(cmd,"read %s Quiet",MyName+1); /* read quiet modules config */
+  if (strcasecmp(module->name,"FvwmForm") != 0) { /* if not already read */
+    sprintf(cmd,"read %s Quiet",module->name); /* read quiet modules config */
     SendText(Channel,cmd,0);
   }
 
@@ -2723,6 +2706,6 @@
   if (FRenderGetErrorCodeBase() + FRenderBadPicture == event->error_code)
     return 0;
 
-  PrintXErrorAndCoredump(dpy, event, MyName+1);
+  PrintXErrorAndCoredump(dpy, event, module->name);
   return 0;
 }
Index: modules/FvwmGtk/FvwmGtk.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmGtk/FvwmGtk.c,v
retrieving revision 1.39
diff -u -u -r1.39 FvwmGtk.c
--- modules/FvwmGtk/FvwmGtk.c	29 Jun 2003 19:53:25 -0000	1.39
+++ modules/FvwmGtk/FvwmGtk.c	10 Feb 2006 23:32:39 -0000
@@ -48,8 +48,7 @@
 
 
 int fvwm_fd[2] = { -1, -1 };
-char *my_name = NULL;
-int my_name_len = 0;
+static ModuleArgs *module;
 char *image_path = NULL;
 GHashTable *widgets = NULL;
 GtkWidget *current = NULL;
@@ -280,9 +279,9 @@
 	{
 		buf[strlen(buf)-1] = '\0';
 	}
-	if (strncasecmp(buf, my_name, my_name_len) == 0)
+	if (strncasecmp(buf, CatString3("*",module->name,0), module->namelen+1) == 0)
 	{
-		p = buf + my_name_len;
+		p = buf + module->namelen+1;
 		if ((e = FindToken(p, table, char*)))
 		{
 			p += strlen(*e);
@@ -292,7 +291,7 @@
 		else
 		{
 			fprintf(stderr, "%s: unknown command: %s\n",
-				my_name + 1, buf);
+				module->name, buf);
 		}
 	}
 	else if (strncasecmp(buf, "ImagePath", 9) == 0)
@@ -310,7 +309,8 @@
 {
 	char *buf;
 
-	InitGetConfigLine(fvwm_fd,my_name);   /* only my config lines needed */
+	/* only my config lines needed */
+	InitGetConfigLine(fvwm_fd,CatString3("*",module->name,0));
 	while (GetConfigLine(fvwm_fd, &buf), buf != NULL)
 	{
 		parse_config_line(buf);
@@ -449,35 +449,17 @@
 
 int main(int argc, char **argv)
 {
-	char *s;
-
-	if ((s = strrchr(argv[0], '/')))
-	{
-		s++;
-	}
-	else
-	{
-		s = argv[0];
-	}
-	if (argc == 7)
-	{
-		s = argv[6];
-	}
-	my_name_len = strlen(s) + 1;
-	my_name = safemalloc(my_name_len + 1);
-	*my_name = '*';
-	strcpy(my_name + 1, s);
-
-	if ((argc != 6) && (argc != 7)) /* Now MyName is defined */
+	module = ParseModuleArgs(argc,argv,1);
+	if (module == NULL)
 	{
 		fprintf(stderr,
-			"%s version %s should only be executed by fvwm!\n",
-			my_name + 1, VERSION);
+			"FvwmGtk version %s should only be executed by fvwm!\n",
+			VERSION);
 		exit(1);
 	}
 
-	fvwm_fd[0] = atoi(argv[1]);
-	fvwm_fd[1] = atoi(argv[2]);
+	fvwm_fd[0] = module->to_fvwm;
+	fvwm_fd[1] = module->from_fvwm;
 
 #ifdef GDK_IMLIB
 	gdk_init(&argc, &argv);
Index: modules/FvwmIdent/FvwmIdent.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmIdent/FvwmIdent.c,v
retrieving revision 1.93
diff -u -u -r1.93 FvwmIdent.c
--- modules/FvwmIdent/FvwmIdent.c	26 Nov 2005 21:55:12 -0000	1.93
+++ modules/FvwmIdent/FvwmIdent.c	10 Feb 2006 23:32:41 -0000
@@ -61,7 +61,7 @@
 
 static RETSIGTYPE TerminateHandler(int);
 
-static char *MyName;
+static ModuleArgs *module;
 static fd_set_size_t fd_width;
 static int fd[2];
 
@@ -88,7 +88,6 @@
 static Pixel fore_pix;
 static Pixel back_pix;
 static Window main_win;
-static Window app_win;
 static Bool UsePixmapDrawing = False; /* if True draw everything in a pixamp
 				       * and set the window background. Use
 				       * this with Xft */
@@ -125,30 +124,17 @@
  */
 int main(int argc, char **argv)
 {
-	char *temp, *s;
 	char *display_name = NULL;
-	int Clength;
 	char *tline;
 
 	FlocaleInit(LC_CTYPE, "", "", "FvwmIdent");
 
-	/* Save the program name for error messages and config parsing */
-	temp = argv[0];
-	s=strrchr(argv[0], '/');
-	if (s != NULL)
-		temp = s + 1;
-
-	MyName = safemalloc(strlen(temp)+2);
-	strcpy(MyName,"*");
-	strcat(MyName, temp);
-	Clength = strlen(MyName);
-
-	if((argc != 6)&&(argc != 7))
+	module = ParseModuleArgs(argc,argv,0); /* no alias */
+	if (module == NULL)
 	{
 		fprintf(
 			stderr,
-			"%s Version %s should only be executed by fvwm!\n",
-			MyName,
+			"FvwmIdent Version %s should only be executed by fvwm!\n",
 			VERSION);
 		exit(1);
 	}
@@ -199,16 +185,13 @@
 #endif
 #endif
 
-	fd[0] = atoi(argv[1]);
-	fd[1] = atoi(argv[2]);
-
-	/* An application window may have already been selected - look for it */
-	sscanf(argv[4],"%x",(unsigned int *)&app_win);
+	fd[0] = module->to_fvwm;
+	fd[1] = module->from_fvwm;
 
 	/* Open the Display */
 	if (!(dpy = XOpenDisplay(display_name)))
 	{
-		fprintf(stderr,"%s: can't open display %s", MyName,
+		fprintf(stderr,"%s: can't open display %s", module->name,
 			XDisplayName(display_name));
 		exit (1);
 	}
@@ -232,7 +215,7 @@
 	/* scan config file for set-up parameters */
 	/* Colors and fonts */
 
-	InitGetConfigLine(fd,MyName);
+	InitGetConfigLine(fd,CatString3("*",module->name,0));
 	GetConfigLine(fd,&tline);
 
 	while (tline != (char *)0)
@@ -241,9 +224,11 @@
 		{
 			continue;
 		}
-		if (strncasecmp(tline, MyName, Clength) == 0)
+		if (strncasecmp(tline,
+				CatString3("*",module->name,0),
+				module->namelen+1) == 0)
 		{
-			tline += Clength;
+			tline += (module->namelen +1);
 			if (strncasecmp(tline, "Font", 4) == 0)
 			{
 				CopyStringWithQuotes(&font_string, &tline[4]);
@@ -299,9 +284,9 @@
 		GetConfigLine(fd, &tline);
 	}
 
-	if(app_win == 0)
+	if(module->window == 0)
 	{
-		fvwmlib_get_target_window(dpy, screen, MyName, &app_win, True);
+		fvwmlib_get_target_window(dpy, screen, module->name, &(module->window), True);
 	}
 
 	fd_width = GetFdWidth();
@@ -313,7 +298,7 @@
 
 	/* tell fvwm we're running */
 	SendFinishedStartupNotification(fd);
-	if (app_win == Root)
+	if (module->window == Root)
 	{
 		exit(0);
 	}
@@ -400,11 +385,11 @@
 {
 	struct ConfigWinPacket  *cfgpacket = (void *) body;
 
-	if((app_win == cfgpacket->frame)||(app_win == cfgpacket->w)
-	   ||((cfgpacket->icon_w != 0)&&(app_win == cfgpacket->icon_w))
-	   ||((cfgpacket->icon_pixmap_w)&&(app_win == cfgpacket->icon_pixmap_w)))
+	if((module->window == cfgpacket->frame)||(module->window == cfgpacket->w)
+	   ||((cfgpacket->icon_w != 0)&&(module->window == cfgpacket->icon_w))
+	   ||((cfgpacket->icon_pixmap_w)&&(module->window == cfgpacket->icon_pixmap_w)))
 	{
-		app_win = cfgpacket->frame;
+		module->window = cfgpacket->frame;
 		target.id = cfgpacket->w;
 		target.frame = cfgpacket->frame;
 		target.frame_x = cfgpacket->frame_x;
@@ -442,7 +427,7 @@
  */
 void list_window_name(unsigned long *body)
 {
-	if((app_win == (Window)body[1])||(app_win == (Window)body[0]))
+	if((module->window == (Window)body[1])||(module->window == (Window)body[0]))
 	{
 		strncpy(target.name,(char *)&body[3],255);
 	}
@@ -455,7 +440,7 @@
  */
 void list_icon_name(unsigned long *body)
 {
-	if((app_win == (Window)body[1])||(app_win == (Window)body[0]))
+	if((module->window == (Window)body[1])||(module->window == (Window)body[0]))
 	{
 		strncpy(target.icon_name,(char *)&body[3],255);
 	}
@@ -469,7 +454,7 @@
  */
 void list_class(unsigned long *body)
 {
-	if((app_win == (Window)body[1])||(app_win == (Window)body[0]))
+	if((module->window == (Window)body[1])||(module->window == (Window)body[0]))
 	{
 		strncpy(target.class,(char *)&body[3],255);
 	}
@@ -483,7 +468,7 @@
  */
 void list_res_name(unsigned long *body)
 {
-	if((app_win == (Window)body[1])||(app_win == (Window)body[0]))
+	if((module->window == (Window)body[1])||(module->window == (Window)body[0]))
 	{
 		strncpy(target.res,(char *)&body[3],255);
 	}
@@ -646,8 +631,8 @@
 					XDestroyWindow(dpy, main_win);
 					DestroyList();
 					fvwmlib_get_target_window(
-						dpy, screen, MyName, &app_win,
-						True);
+						dpy, screen, module->name,
+						 &(module->window), True);
 					found = 0;
 					return 1;
 				}
@@ -756,9 +741,9 @@
 	/* tell fvwm to only send config messages */
 	SetMessageMask(fd, M_CONFIG_INFO | M_SENDCONFIG);
 
-	if ((Ffont = FlocaleLoadFont(dpy, font_string, MyName)) == NULL)
+	if ((Ffont = FlocaleLoadFont(dpy, font_string, module->name)) == NULL)
 	{
-		fprintf(stderr,"%s: cannot load font, exiting\n", MyName);
+		fprintf(stderr,"%s: cannot load font, exiting\n", module->name);
 		exit(1);
 	}
 
@@ -867,7 +852,7 @@
 	}
 
 	XSelectInput(dpy, main_win, mw_events);
-	change_window_name(&MyName[1]);
+	change_window_name(module->name);
 
 	gcm = GCForeground;
 	gcv.foreground = fore_pix;
@@ -1046,7 +1031,7 @@
 
 	if (XStringListToTextProperty(&str,1,&name) == 0)
 	{
-		fprintf(stderr,"%s: cannot allocate window name",MyName);
+		fprintf(stderr,"%s: cannot allocate window name",module->name);
 		return;
 	}
 	XSetWMName(dpy,main_win,&name);
@@ -1428,6 +1413,6 @@
 	}
 #endif
 
-	PrintXErrorAndCoredump(d, event, MyName);
+	PrintXErrorAndCoredump(d, event, module->name);
 	return 0;
 }
