Opened 19 years ago

Closed 18 years ago

#5 closed defect (wontfix)

@response handling incomplete

Reported by: Yuri Dario Owned by: bird
Priority: normal Milestone:
Component: libc Version:
Severity: normal Keywords:
Cc:

Description

response file handling has problems: doesn't accept long lines, does not support multiple args per line, doesn't remove white spaces.

This is a partial fix

Index: lib/misc/response.c
===================================================================
RCS file: /netlabs.cvs/libc/src/emx/src/lib/misc/response.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 response.c
--- lib/misc/response.c	2004/06/08 12:03:44	1.1.1.1
+++ lib/misc/response.c	2005/10/24 14:56:24
@@ -1,6 +1,7 @@
 /* response.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
 
 #include "libc-alias.h"
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -23,7 +24,7 @@
 {
   int i, old_argc, new_argc, new_alloc;
   char **old_argv, **new_argv;
-  char line[1+512], *p;
+  char line[1+8192], *p;
   FILE *f;
 
   old_argc = *argcp; old_argv = *argvp;
@@ -47,12 +48,29 @@
           line[0] = _ARG_NONZERO|_ARG_RESPONSE;
           while (fgets (line+1, sizeof (line)-1, f) != NULL)
             {
-              p = strchr (line+1, '\n');
-              if (p != NULL) *p = 0;
-              p = strdup (line);
-              if (p == NULL)
-                goto out_of_memory;
-              RPUT (p+1);
+              char* token;
+              p = line+1;
+              // YD tokenize line, OOo uses \t to separate arguments
+              token = strtok( p, " \t\r\n");
+              while( token) {
+                char* p1 = strdup (token);
+                if (p1 == NULL)
+                  goto out_of_memory;
+                // YD strip begin/end whitespaces
+                while (isspace(p1[strlen(p1)-1]))
+                  p1[strlen(p1)-1] = 0;
+                while (isspace(*p1))
+                  p1++;
+                // YD strip begin&end quotes
+                if (*p1 == '\"' && p1[strlen(p1)-1] == '\"') {
+                  p1++;
+                  p1[strlen(p1)-1] = 0;
+                }
+                // YD don't add zero-len arguments!
+                if (strlen(p1)>0)
+                  RPUT (p1);
+                token = strtok( NULL, " \t\r\n");
+              }
             }
           if (ferror (f))
             {

Change History (2)

comment:1 Changed 19 years ago by anonymous

Component: baselayoutlibc

comment:2 Changed 18 years ago by bird

Resolution: wontfix
Status: newclosed

I've applied the read buffer bit because it doesn't really harm anylonger.

However I'm not going to apply anything else. The problem is that it will break current behaviour: 1. it should not remove empty lines, 2) it doesn't respect escaped quotes, 3) single quotes aren't considered at all but they are on the commandline, 4) there are too many strlen()'s.

If you want a responsifile reader which does something like the patch suggest, it will have to be a separate function. (The code should also be optimized, because if it isn't it will either be rejected or waste my time having to optimize it myself.) Testcase(s) would also be nice (one testcase spawning child processes of itself which checks that all the quirks works out).

Note: See TracTickets for help on using tickets.