Subject: Patch to FvwmForm

From: Daniel Henninger <[email-masked]>
Date: Fri, 22 Mar 2002 00:41:15 -0500 (EST)

Hi!  Attached is a patch (generated using cvs diff -u this time) that
fixes the problems discussed previously, namely:

1. There were unnecessary checks for multiple Timeout commands that
   were never implemented.  Those are gone now.

2. There was no support for multi-word commands inside quotes.  That
   should work fine now.

Also, I cleaned up the code to do some more error checking "just in case".
Let me know if you see any more problems or have any other suggestions.

Daniel

-- 
/\\\----------------------------------------------------------------------///\
\ \\\      Daniel Henninger           http://www.vorpalcloud.org/        /// /
 \_\\\      North Carolina State University - Systems Programmer        ///_/
    \\\                   Information Technology <IT>                  ///
     """--------------------------------------------------------------"""
Index: modules/ChangeLog
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/ChangeLog,v
retrieving revision 1.820
diff -u -u -r1.820 ChangeLog
--- modules/ChangeLog	2002/03/18 10:56:03	1.820
+++ modules/ChangeLog	2002/03/22 05:34:04
@@ -1,3 +1,11 @@
+2002-03-21  Daniel Henninger  <[email-masked]>
+
+	* FvwmForm/FvwmForm.c:
+	* FvwmForm/FvwmForm.h:
+	Took out pointless multiple Timeout command support.
+	Better line parsing error checking for Timeout.
+	Fixed command parsing to allow for quoted commands.
+
 2002-03-18  Dominik Vogt  <[email-masked]>
 
 	* FvwmWinList/FvwmWinList.c (main):
Index: modules/FvwmForm/FvwmForm.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmForm/FvwmForm.c,v
retrieving revision 1.91
diff -u -u -r1.91 FvwmForm.c
--- modules/FvwmForm/FvwmForm.c	2002/03/16 20:14:32	1.91
+++ modules/FvwmForm/FvwmForm.c	2002/03/22 05:34:04
@@ -870,29 +870,38 @@
   }
   timer = item;
 
-  while (!isspace((unsigned char)*cp)) cp++; /* skip timeout */
-  while (isspace((unsigned char)*cp)) cp++; /* move up to command */
+  while (*cp && *cp != '\n' && !isspace((unsigned char)*cp)) cp++;
+							/* skip timeout */
+  while (*cp && *cp != '\n' && isspace((unsigned char)*cp)) cp++;
+							/* move up to command */
 
-  tmpbuf = safestrdup(cp);
-  tmpcp = tmpbuf;
-  while (!isspace((unsigned char)*tmpcp)) tmpcp++;
-  /* question */
-  /* This next piece assumes the command is one word, That no
-     good, treat it as a word or a quoted string. */
-  *tmpcp = '\0';                        /* cutoff command at first word */
-  /* question */
-  /* This pretends that there can be more than one command
-     per timeout, but I don't see how. */
-  item->timeout.timeout_array_size += TIMEOUT_COMMAND_EXPANSION;
-  item->timeout.commands =
-    (char **)saferealloc((void *)item->timeout.commands,
-			   sizeof(char *) *
-			   item->timeout.timeout_array_size);
-  item->timeout.commands[item->timeout.numcommands++] = safestrdup(tmpbuf);
-  free(tmpbuf);
+  if (!*cp || *cp == '\n') {
+    fprintf(stderr,"Improper arguments specified for FvwmForm Timeout.\n");
+    return;
+  }
+
+  if (*cp == '\"') {
+    item->timeout.command = CopyQuotedString(++cp);
+    /* skip over the whole quoted string to continue parsing */
+    cp += strlen(item->timeout.command);
+  }
+  else {
+    tmpbuf = safestrdup(cp);
+    tmpcp = tmpbuf;
+    while (!isspace((unsigned char)*tmpcp)) tmpcp++;
+    *tmpcp = '\0';                        /* cutoff command at first word */
+    item->timeout.command = safestrdup(tmpbuf);
+    free(tmpbuf);
+    while (!isspace((unsigned char)*cp)) cp++; /* move past command again */
+  }
+
+  while (*cp && *cp != '\n' && isspace((unsigned char)*cp)) cp++;
+						/* move up to next arg */
 
-  while (!isspace((unsigned char)*cp)) cp++; /* move past command again */
-  while (isspace((unsigned char)*cp)) cp++; /* move up to start of text */
+  if (!*cp || *cp == '\n') {
+    fprintf(stderr,"Improper arguments specified for FvwmForm Timeout.\n");
+    return;
+  }
 
   if (*cp == '\"') {
     item->timeout.text = CopyQuotedString(++cp);
@@ -2277,8 +2286,9 @@
 static RETSIGTYPE
 TimerHandler(int sig)
 {
-  int k, dn;
+  int dn;
   char *sp;
+  char *parsed_command;
 
   timer->timeout.timeleft--;
   if (timer->timeout.timeleft <= 0) {
@@ -2288,19 +2298,15 @@
       /* hm, what can we do now? just ignore this situation. */
     }
 
-    for (k = 0; k < timer->timeout.numcommands; k++) {
-      char *parsed_command;
-      /* construct command */
-      parsed_command = ParseCommand(0, timer->timeout.commands[k],
-                                    '\0', &dn, &sp);
-      myfprintf((stderr, "Final command[%d]: [%s]\n", k, parsed_command));
-
-      /* send command */
-      if ( parsed_command[0] == '!') {    /* If command starts with ! */
-        system(parsed_command+1);         /* Need synchronous execution */
-      } else {
-        SendText(Channel,parsed_command, ref);
-      }
+    /* construct command */
+    parsed_command = ParseCommand(0, timer->timeout.command, '\0', &dn, &sp);
+    myfprintf((stderr, "Final command: %s\n", parsed_command));
+
+    /* send command */
+    if ( parsed_command[0] == '!') {    /* If command starts with ! */
+      system(parsed_command+1);         /* Need synchronous execution */
+    } else {
+      SendText(Channel,parsed_command, ref);
     }
 
     /* post-command */
Index: modules/FvwmForm/FvwmForm.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmForm/FvwmForm.h,v
retrieving revision 1.23
diff -u -u -r1.23 FvwmForm.h
--- modules/FvwmForm/FvwmForm.h	2002/03/16 20:14:32	1.23
+++ modules/FvwmForm/FvwmForm.h	2002/03/22 05:34:05
@@ -140,14 +140,12 @@
     int button_array_size;              /* current size of next array */
     char **commands;    /* Fvwm command to execute */
   } button;
-  struct {
+  struct {		/* I_TIMEOUT */
     struct _head head;
     int timeleft;       /* seconds left on timer */
     int len;            /* text length */
     char *text;         /* text string */
-    int numcommands;	/* # of commands */
-    int timeout_array_size;  /* current size of next array */
-    char **commands;    /* Fvwm command(s) to execute */
+    char *command;    /* Fvwm command(s) to execute */
   } timeout;
 } Item;