summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2020-08-05 13:18:00 +0100
committerRobin Watts <Robin.Watts@artifex.com>2020-08-06 12:03:48 +0100
commit4d94506a1a9442bd3cc51b94eb5f6a16a12588f2 (patch)
treed760c7f95d8381effc4dd61c18ac0e7f73a8a8b3
parentfe0c022fbc1906a48b5a03704d9337751b26be8a (diff)
downloadghostpdl-4d94506a1a9442bd3cc51b94eb5f6a16a12588f2.tar.gz
Add -pNAME=STRING options to gs and gpdl to accept parsed params.
This means we no longer need to rely on using -c and passing postscript fragments to configure (for example) pdfwrite.
-rw-r--r--pcl/pl/plmain.c47
-rw-r--r--pcl/pl/plmain.h1
-rw-r--r--psi/imainarg.c28
3 files changed, 76 insertions, 0 deletions
diff --git a/pcl/pl/plmain.c b/pcl/pl/plmain.c
index 6ecc256ab..11a3b9ece 100644
--- a/pcl/pl/plmain.c
+++ b/pcl/pl/plmain.c
@@ -1830,6 +1830,48 @@ pl_main_set_string_param(pl_main_instance_t * pmi, const char *arg)
}
int
+pl_main_set_parsed_param(pl_main_instance_t * pmi, const char *arg)
+{
+ char *eqp;
+ const char *value;
+ char buffer[128];
+
+ eqp = strchr(arg, '=');
+ if (!(eqp || (eqp = strchr(arg, '#')))) {
+ return -1;
+ }
+ value = eqp + 1;
+ if (!strncmp(arg, "DEVICE", 6)) {
+ dmprintf(pmi->memory, "DEVICE cannot be set by -p!\n");
+ return -1;
+ } else if (!strncmp(arg, "DefaultGrayProfile",
+ strlen("DefaultGrayProfile"))) {
+ dmprintf(pmi->memory, "DefaultGrayProfile cannot be set by -p!\n");
+ return -1;
+ } else if (!strncmp(arg, "DefaultRGBProfile",
+ strlen("DefaultRGBProfile"))) {
+ dmprintf(pmi->memory, "DefaultRGBProfile cannot be set by -p!\n");
+ return -1;
+ } else if (!strncmp(arg, "DefaultCMYKProfile",
+ strlen("DefaultCMYKProfile"))) {
+ dmprintf(pmi->memory, "DefaultCMYKProfile cannot be set by -p!\n");
+ return -1;
+ } else if (!strncmp(arg, "ICCProfileDir", strlen("ICCProfileDir"))) {
+ dmprintf(pmi->memory, "ICCProfileDir cannot be set by -p!\n");
+ return -1;
+ }
+
+ if (eqp-arg >= sizeof(buffer)-1) {
+ dmprintf1(pmi->memory, "Command line key is too long: %s\n", arg);
+ return -1;
+ }
+ strncpy(buffer, arg, eqp - arg);
+ buffer[eqp - arg] = '\0';
+
+ return pl_main_set_typed_param(pmi, pl_spt_parsed, buffer, value);
+}
+
+int
pl_main_set_typed_param(pl_main_instance_t *pmi, pl_set_param_type type, const char *param, const void *value)
{
int code = 0;
@@ -2451,6 +2493,11 @@ help:
pmi->pause = false;
break;
}
+ case 'p':
+ code = pl_main_set_parsed_param(pmi, arg);
+ if (code < 0)
+ return code;
+ break;
case 'r':
{
float res[2];
diff --git a/pcl/pl/plmain.h b/pcl/pl/plmain.h
index ff9453763..867708741 100644
--- a/pcl/pl/plmain.h
+++ b/pcl/pl/plmain.h
@@ -59,6 +59,7 @@ int pl_to_exit(gs_memory_t *mem);
int pl_main_set_param(pl_main_instance_t *minst, const char *arg);
int pl_main_set_string_param(pl_main_instance_t *minst, const char *arg);
+int pl_main_set_parsed_param(pl_main_instance_t *minst, const char *arg);
typedef enum {
pl_spt_invalid = -1,
pl_spt_null = 0, /* void * is NULL */
diff --git a/psi/imainarg.c b/psi/imainarg.c
index 95614a010..57622a967 100644
--- a/psi/imainarg.c
+++ b/psi/imainarg.c
@@ -928,6 +928,34 @@ run_stdin:
arg_free((char *)adef, minst->heap);
break;
}
+ case 'p':
+ {
+ char *adef = arg_copy(arg, minst->heap);
+ char *eqp;
+ bool isd = (sw == 'D' || sw == 'd');
+ ref value;
+
+ if (adef == NULL)
+ return gs_error_Fatal;
+ eqp = strchr(adef, '=');
+
+ if (eqp == NULL)
+ eqp = strchr(adef, '#');
+ if (eqp == NULL) {
+ outprintf(minst->heap, "Usage: -pNAME=STRING\n");
+ arg_free((char *)adef, minst->heap);
+ return gs_error_Fatal;
+ }
+ *eqp++ = 0;
+ /* Slightly uncomfortable calling back up to a higher
+ * level, but we'll live with it. */
+ code = gsapi_set_param(gs_lib_ctx_get_interp_instance(minst->heap),
+ gs_spt_parsed, adef, eqp);
+ if (code < 0) {
+ arg_free((char *)adef, minst->heap);
+ return code;
+ }
+ }
case 'u': /* undefine name */
if (!*arg) {
puts(minst->heap, "-u requires a name to undefine.");