[gs-cvs] rev 8051 - trunk/gs/src

alexcher at ghostscript.com alexcher at ghostscript.com
Thu Jun 14 15:06:26 PDT 2007


Author: alexcher
Date: 2007-06-14 15:06:25 -0700 (Thu, 14 Jun 2007)
New Revision: 8051

Modified:
   trunk/gs/src/gsargs.c
   trunk/gs/src/gsargs.h
   trunk/gs/src/imainarg.c
Log:
Implement quoting in GS_OPTIONS environment variable. Bug 688965.

DETAILS:
Old code treated quotes in GS_OPTIONS as regular characters
and not used them for quoting spaces. New code distinguish
between a single already parsed argument, retrieved by a previous
call to arg_next() and unparsed list of arguments from GS_OPTIONS.
Thanks to SaGS for the patch.

DIFFERENCES:
None



Modified: trunk/gs/src/gsargs.c
===================================================================
--- trunk/gs/src/gsargs.c	2007-06-13 23:21:11 UTC (rev 8050)
+++ trunk/gs/src/gsargs.c	2007-06-14 22:06:25 UTC (rev 8051)
@@ -37,7 +37,7 @@
 
 /* Push a string onto an arg list. */
 int
-arg_push_memory_string(arg_list * pal, char *str, gs_memory_t * mem)
+arg_push_memory_string(arg_list * pal, char *str, bool parsed, gs_memory_t * mem)
 {
     arg_source *pas;
 
@@ -47,6 +47,7 @@
     }
     pas = &pal->sources[pal->depth];
     pas->is_file = false;
+    pas->u.s.parsed = parsed;
     pas->u.s.chars = str;
     pas->u.s.memory = mem;
     pas->u.s.str = str;
@@ -92,6 +93,22 @@
     }
     if (pas->is_file)
 	f = pas->u.file, endc = EOF;
+    else if (pas->u.s.parsed)
+	/* this	string is a "pushed-back" argument		     */
+	/* (retrieved by a precedeing arg_next(), but not processed) */
+	if (strlen(pas->u.s.str) >= arg_str_max) {
+	    errprintf("Command too long: %s\n", pas->u.s.str);
+	    *code = gs_error_Fatal;
+	    return NULL;
+	} else {
+	    strcpy(pal->cstr, pas->u.s.str);
+	    result = pal->cstr;
+	    if (pas->u.s.memory)
+		gs_free_object(pas->u.s.memory,	pas->u.s.chars,	"arg_next");
+	    pal->depth--;
+	    pas--;
+	    goto at;
+	}
     else
 	astr = pas->u.s.str, f = NULL, endc = 0;
     result = cstr = pal->cstr;
@@ -172,9 +189,9 @@
 	    *code = gs_error_Fatal;
 	    return NULL;
 	}
-	/* If input is coming from an @-file, allow quotes */
-	/* to protect whitespace. */
-	if (c == '"' && f != NULL)
+	/* Allow quotes to protect whitespace. */
+	/* (special cases have already been handled and don't reach this point) */
+	if (c == '"')
 	    in_quote = !in_quote;
 	else
 	    cstr[i++] = c;

Modified: trunk/gs/src/gsargs.h
===================================================================
--- trunk/gs/src/gsargs.h	2007-06-13 23:21:11 UTC (rev 8050)
+++ trunk/gs/src/gsargs.h	2007-06-14 22:06:25 UTC (rev 8051)
@@ -29,6 +29,7 @@
     bool is_file;
     union _u {
 	struct _su {
+	    bool parsed;	/* true for "pushed-back" argument, not to be parsed again */
 	    char *chars;	/* original string */
 	    gs_memory_t *memory;  /* if non-0, free chars when done with it */
 	    const char *str;	/* string being read */
@@ -57,13 +58,11 @@
  * This may also be used (once) to "unread" the last argument.
  * If mem != 0, it is used to free the string when we are done with it.
  * Return 0 on success, non-zero on failure
- * NB: pushing args has the side effect of changing the parsing algoritm to
- * space delimited instead of argument string delimited.
  */
-int arg_push_memory_string(arg_list * pal, char *str, gs_memory_t * mem);
+int arg_push_memory_string(arg_list * pal, char *str, bool parsed, gs_memory_t * mem);
 
-#define arg_push_string(pal, str)\
-  arg_push_memory_string(pal, str, (gs_memory_t *)0);
+#define arg_push_string(pal, str, parsed)\
+  arg_push_memory_string(pal, str, parsed, (gs_memory_t *)0);
 
 /* Clean up an arg list before exiting. */
 void arg_finit(arg_list * pal);

Modified: trunk/gs/src/imainarg.c
===================================================================
--- trunk/gs/src/imainarg.c	2007-06-13 23:21:11 UTC (rev 8050)
+++ trunk/gs/src/imainarg.c	2007-06-14 22:06:25 UTC (rev 8051)
@@ -190,7 +190,7 @@
 	    (char *)gs_alloc_bytes(minst->heap, len, "GS_OPTIONS");
 
 	    gp_getenv(GS_OPTIONS, opts, &len);	/* can't fail */
-	    if (arg_push_memory_string(&args, opts, minst->heap))
+	    if (arg_push_memory_string(&args, opts, false, minst->heap))
 		return e_Fatal;
 	}
     }
@@ -362,7 +362,7 @@
 		    char *p = arg_copy(arg, minst->heap);
 		    if (p == NULL)
 			return e_Fatal;
-		    arg_push_string(pal, p);
+		    arg_push_string(pal, p, true);
 		}
 		pal->expand_ats = ats;
 		break;



More information about the gs-cvs mailing list