summaryrefslogtreecommitdiff
path: root/pcl
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2022-11-21 13:46:15 +0000
committerKen Sharp <ken.sharp@artifex.com>2022-11-21 16:34:12 +0000
commitbe2c3d0d315fe944368c5a5b83bb7f59fcb2a4ea (patch)
treec74428b92eccae2d95928b92e8cdf3711b264b35 /pcl
parentc3f882ec0aef0a6a3094999a6b03ad093ee6ec04 (diff)
downloadghostpdl-be2c3d0d315fe944368c5a5b83bb7f59fcb2a4ea.tar.gz
Allow @file syntax to include files in the ROM file system
This started as a customer request, where the customer wanted to store a file in the ROM file system with a bunch of command line parameters in it, and then use the @file syntax to run that file and setup the interpreter. In essence a 'canned' setup stored in the ROM file system. That didn't work, at all, because of a dichotomy in the logic of argument processing. The code used 'lib_file_open' in order to find the file using the search path which, on Ghostscript, includes all the iodevices, Rom file system, RAM file system etc. That function returns a stream which the calling function 'lib_fopen' would then reach inside and pull out the pointer to the underlying gp__file *, and return, because the argument processing was written to use a gp_file *, not a stream *. But.... For the ROM file system, what we store in the 'file' member of the stream is not a gp_file *, its a 'node' *. Trying to use that as a gp_file * rapidly leads to a seg fault. So this commit reworks the argument processing to use a stream * instead of a gp_file *. In reality there is no real difference to the logic we simply use a different call. There are a lot of fiddly references to change unfortunately. There are some consequences; we need to pass stream * around instead of gp_file *, and in particular the 'encoding' functions, which are OS-specific need to use a stream *. This isn't a problem for the interpreters and graphics library, but mkromfs *also* uses those OS-specific files, and it does not have the stream library available. Rather than trying to include it, we note that we don't actually need to use these functions for mkromfs and we do the same hackery as for other missing functionality; we define a stub function that does nothing but will permit the compile to complete.
Diffstat (limited to 'pcl')
-rw-r--r--pcl/pl/pl.mak4
-rw-r--r--pcl/pl/plapi.c17
-rw-r--r--pcl/pl/plmain.c8
-rw-r--r--pcl/pl/plmain.h2
4 files changed, 16 insertions, 15 deletions
diff --git a/pcl/pl/pl.mak b/pcl/pl/pl.mak
index 549fffa24..06e5b050d 100644
--- a/pcl/pl/pl.mak
+++ b/pcl/pl/pl.mak
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2021 Artifex Software, Inc.
+# Copyright (C) 2001-2022 Artifex Software, Inc.
# All Rights Reserved.
#
# This software is provided AS-IS with no warranty, either express or
@@ -278,7 +278,7 @@ $(PLOBJ)pllfont.$(OBJ): $(PLSRC)pllfont.c $(pllfont_h) $(AK)\
$(gxfapi_h) $(plufstlp_h) $(plvocab_h) $(PL_MAK) $(MAKEDIRS)
$(PLCCC) $(PLSRC)pllfont.c $(PLO_)pllfont.$(OBJ)
-$(PLOBJ)plapi.$(OBJ): $(PLSRC)plapi.c $(plmain_h) $(plapi_h)\
+$(PLOBJ)plapi.$(OBJ): $(PLSRC)plapi.c $(plmain_h) $(plapi_h) $(stream_h)\
$(gsmchunk_h) $(gsmalloc_h) $(gserrors_h) $(gsexit_h)\
$(PL_MAK) $(MAKEDIRS)
$(PLCCC) $(PLSRC)plapi.c $(PLO_)plapi.$(OBJ)
diff --git a/pcl/pl/plapi.c b/pcl/pl/plapi.c
index 2f8c18a10..aa4cadab9 100644
--- a/pcl/pl/plapi.c
+++ b/pcl/pl/plapi.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2021 Artifex Software, Inc.
+/* Copyright (C) 2001-2022 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -23,6 +23,7 @@
#include "gp.h"
#include "gscdefs.h"
#include "gsmemory.h"
+#include "stream.h"
/* Return revision numbers and strings of Ghostscript. */
/* Used for determining if wrong GSDLL loaded. */
@@ -213,7 +214,7 @@ gsapi_get_default_device_list(void *instance, char **list, int *listlen)
return gs_lib_ctx_get_default_device_list(ctx->memory, list, listlen);
}
-static int utf16le_get_codepoint(gp_file *file, const char **astr)
+static int utf16le_get_codepoint(stream *s, const char **astr)
{
int c;
int rune;
@@ -229,11 +230,11 @@ static int utf16le_get_codepoint(gp_file *file, const char **astr)
* be wrong. */
do {
- if (file) {
- rune = gp_fgetc(file);
+ if (s) {
+ rune = spgetc(s);
if (rune == EOF)
return EOF;
- c = gp_fgetc(file);
+ c = spgetc(s);
if (c == EOF)
return EOF;
rune += c<<8;
@@ -255,11 +256,11 @@ static int utf16le_get_codepoint(gp_file *file, const char **astr)
lead: /* We've just read a leading surrogate */
rune -= 0xD800;
rune <<= 10;
- if (file) {
- trail = gp_fgetc(file);
+ if (s) {
+ trail = spgetc(s);
if (trail == EOF)
return EOF;
- c = gp_fgetc(file);
+ c = spgetc(s);
if (c == EOF)
return EOF;
trail += c<<8;
diff --git a/pcl/pl/plmain.c b/pcl/pl/plmain.c
index d6fb95f20..8aaf9c313 100644
--- a/pcl/pl/plmain.c
+++ b/pcl/pl/plmain.c
@@ -201,7 +201,7 @@ static pl_interp_implementation_t
int len);
/* Process the options on the command line. */
-static gp_file *pl_main_arg_fopen(const char *fname, void *mem);
+static stream *pl_main_arg_fopen(const char *fname, void *mem);
/* Process the options on the command line, including making the
initial device and setting its parameters. */
@@ -1451,11 +1451,11 @@ pl_top_create_device(pl_main_instance_t * pti)
}
/* Process the options on the command line. */
-static gp_file *
+static stream *
pl_main_arg_fopen(const char *fname, void *data)
{
- const gs_memory_t *mem = (const gs_memory_t *)data;
- return gp_fopen(mem, fname, "r");
+ gs_memory_t *mem = (gs_memory_t *)data;
+ return sfopen(fname, "r", mem);
}
static void
diff --git a/pcl/pl/plmain.h b/pcl/pl/plmain.h
index 883dfc6e9..b0b5410f5 100644
--- a/pcl/pl/plmain.h
+++ b/pcl/pl/plmain.h
@@ -109,7 +109,7 @@ void pl_main_get_forced_geometry(const gs_memory_t *mem, const float **resolutio
int pl_main_get_scanconverter(const gs_memory_t *mem);
pl_main_instance_t *pl_main_get_instance(const gs_memory_t *mem);
-typedef int pl_main_get_codepoint_t(gp_file *, const char **);
+typedef int pl_main_get_codepoint_t(stream *, const char **);
void pl_main_set_arg_decode(pl_main_instance_t *minst,
pl_main_get_codepoint_t *get_codepoint);