Package: ppdfilt
Version: 2:0.10-4
Severity: wishlist
Tags: patch

I want to use ppdfilt from magicfilter from LPRng. LPRng condenses all
-Z options given to a single argument seperated by comma, so it would
be nice if ppdfilt could parse them.
magicfilter puts that argument in an environment variable, so to
avoiding complicated statements there it would be nice if I could
just put a -Z "$ZOPT" in there, but that fails when there are no
arguments so it would be nice if ppdfilt could ignore empty arguments
to -Z.

Attached patch implements both by ignoring empty arguments and splitting
arguments at the commas.

Hochachtungsvoll,
        Bernhard R. Link
diff -r -u -p libppd-0.10.original/src/ppdfilt.c libppd-0.10/src/ppdfilt.c
--- libppd-0.10.original/src/ppdfilt.c	2001-11-05 22:22:42.000000000 +0100
+++ libppd-0.10/src/ppdfilt.c	2007-05-08 11:39:09.000000000 +0200
@@ -341,7 +341,7 @@ int main(int argc, char *argv[])
       {"help", no_argument, NULL, '?'},
       {0, 0, 0, 0}
     };
-    char *cur;
+    char *cur, *next;
     copies = 1;
     num_options = 0;
     options = NULL;
@@ -358,16 +358,27 @@ int main(int argc, char *argv[])
 	break;
       case 'o':
       case 'Z':
-	if ((cur = strchr(optarg, ':')) == NULL) {
-	  fprintf(stderr, "Bad option format: %s\n", optarg);
-	  exit(2);
-	}
-	*cur = 0;		// break the string
-	cur++;			// point cur to the value
-	/* MLP: skip past leading spaces. */
-	while (cur && (cur[0] == ' '))
-	  cur++;
-	num_options = cupsAddOption(optarg, cur, num_options, &options);
+	/* Ignore empty argument (to ease usage in magicfilter rules) */
+	if (optarg[0] == '\0')
+		break;
+	do {
+	  if ((cur = strchr(optarg, ':')) == NULL) {
+	    fprintf(stderr, "Bad option format: %s\n", optarg);
+	    exit(2);
+	  }
+	  *cur = 0;		// break the string
+	  cur++;		// point cur to the value
+	  /* MLP: skip past leading spaces. */
+	  while (cur && (cur[0] == ' '))
+	    cur++;
+	  /* allow comma seperated values to ease usage from LPRng */
+	  if ((next = strchr(cur, ',')) != NULL) {
+	    *next = 0;		// break the string
+	    next++;
+	  }
+	  num_options = cupsAddOption(optarg, cur, num_options, &options);
+	  optarg = next;
+	} while (next != NULL);
 	break;
       case 'p':
 	ppdfilename = optarg;

Reply via email to