[gs-cvs] gs/src
Ray Johnston
ray at casper.ghostscript.com
Wed Mar 13 12:27:41 PST 2002
Update of /cvs/ghostscript/gs/src
In directory casper:/tmp/cvs-serv8616/src
Modified Files:
files.h gs.mak iinit.c int.mak lib.mak zfile.c zfrsd.c
ziodev2.c
Added Files:
gsiodisk.c
Log Message:
Add a new optional FEATURE, diskn.dev that provides emulation of %disk
devices present on some Adobe printers. This version is NOT multiple
instance safe, but is useful for embedded printers or for server systems
with a single Ghostscript instance. Documentation is in Language.htm.
Addresses SourceForge bug #493344 for Artifex customer #411.
--- NEW FILE: gsiodisk.c ---
/* Copyright (C) 2001 artofcode LLC All rights reserved.
This software is provided AS-IS with no warranty, either express or
implied.
This software is distributed under license and may not be copied,
modified or distributed except as expressly authorized under the terms
of the license contained in the file LICENSE in this distribution.
For more information about licensing, please refer to
http://www.ghostscript.com/licensing/. For information on
commercial licensing, go to http://www.artifex.com/licensing/ or
contact Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
*/
/*$Id: gsiodisk.c,v 1.1 2002/03/13 20:27:39 ray Exp $ */
/* %disk*% IODevice implementation for Ghostscript */
[...848 lines suppressed...]
if (oldMap == NULL) {
fclose(newMap);
MapFileUnlink(root_name, TEMP_FILE_NAME);
return;
}
/* Now copy data from old to new, change file name when found */
MapFileWriteVersion(newMap, MAP_FILE_VERSION); /* Copy the version number */
while (MapFileRead(oldMap, name, &d))
if (strcmp(name, oldname))
MapFileWrite(newMap, name, d);
else
MapFileWrite(newMap, newname, d);
fclose(newMap);
fclose(oldMap);
MapFileUnlink(root_name, MAP_FILE_NAME);
MapFileRename(root_name, MAP_FILE_NAME, TEMP_FILE_NAME);
}
}
Index: files.h
===================================================================
RCS file: /cvs/ghostscript/gs/src/files.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- files.h 21 Feb 2002 22:24:51 -0000 1.6
+++ files.h 13 Mar 2002 20:27:39 -0000 1.7
@@ -132,8 +132,8 @@
/* for os_open in ziodev.c */
#ifdef iodev_proc_fopen /* in gxiodev.h */
-int file_open_stream(P7(const char *, uint, const char *, uint,
- stream **, iodev_proc_fopen_t, gs_memory_t *));
+int file_open_stream(P8(const char *, uint, const char *, uint, stream **,
+ gx_io_device *, iodev_proc_fopen_t, gs_memory_t *));
#endif
/* for zfilter.c */
Index: gs.mak
===================================================================
RCS file: /cvs/ghostscript/gs/src/gs.mak,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- gs.mak 21 Feb 2002 22:24:52 -0000 1.12
+++ gs.mak 13 Mar 2002 20:27:39 -0000 1.13
@@ -87,6 +87,9 @@
# Included automatically in the psl2 feature.
# dct - support for DCTEncode/Decode filters.
# Included automatically in the psl2 feature.
+# diskn - support for %disk IODevice emulation. Adds support
+# for %disk0 thru %disk9. Use requires setting the /Root
+# paramter for each %disk (see Language.htm).
# dps - (partial) support for Display PostScript extensions:
# see Language.htm for details.
# dpsnext - (partial) support for Display PostScript
Index: iinit.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/iinit.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- iinit.c 21 Feb 2002 22:24:53 -0000 1.5
+++ iinit.c 13 Mar 2002 20:27:39 -0000 1.6
@@ -57,7 +57,7 @@
#endif
/* The size of level2dict, if applicable, can be set in the makefile. */
#ifndef LEVEL2DICT_SIZE
-# define LEVEL2DICT_SIZE 233
+# define LEVEL2DICT_SIZE 251
#endif
/* Ditto the size of ll3dict. */
#ifndef LL3DICT_SIZE
Index: int.mak
===================================================================
RCS file: /cvs/ghostscript/gs/src/int.mak,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- int.mak 7 Mar 2002 10:52:06 -0000 1.65
+++ int.mak 13 Mar 2002 20:27:39 -0000 1.66
@@ -1712,7 +1712,18 @@
$(gsicc_h) $(estack_h) $(idict_h) $(idparam_h) $(igstate_h) $(icie_h)
$(PSCC) $(PSO_)zicc.$(OBJ) $(C_) $(PSSRC)zicc.c
+# ---------------- Support for %disk IODevices ---------------- #
+$(GLOBJ)gsiodisk.$(OBJ) : $(GLSRC)gsiodisk.c $(GXERR) $(errno__h) $(string__h)\
+ $(gp_h) $(gscdefs_h) $(gsparam_h) $(gsstruct_h) $(gxiodev_h) $(gsutil_h)
+ $(GLCC) $(GLO_)gsiodisk.$(OBJ) $(C_) $(GLSRC)gsiodisk.c
+# Note that we go ahead and create 10 %disk devices. The internal
+# overhead of any unused %disk structures is minimal.
+diskn_=$(GLOBJ)gsiodisk.$(OBJ)
+$(GLD)diskn.dev : $(LIB_MAK) $(ECHOGS_XE) $(diskn_)
+ $(SETMOD) $(GLD)diskn $(diskn_)
+ $(ADDMOD) $(GLD)diskn -iodev disk0 disk1 disk2 disk3 disk4 disk5 disk6 disk7 disk8 disk9
+ $(ADDMOD) $(GLD)diskn -ps gs_diskn
# ================================ PDF ================================ #
Index: lib.mak
===================================================================
RCS file: /cvs/ghostscript/gs/src/lib.mak,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- lib.mak 13 Mar 2002 19:50:13 -0000 1.64
+++ lib.mak 13 Mar 2002 20:27:39 -0000 1.65
@@ -746,6 +746,10 @@
$(gp_h) $(gscdefs_h) $(gsparam_h) $(gsstruct_h) $(gxiodev_h)
$(GLCC) $(GLO_)gsiodev.$(OBJ) $(C_) $(GLSRC)gsiodev.c
+$(GLOBJ)gsiodisk.$(OBJ) : $(GLSRC)gsiodisk.c $(GXERR) $(errno__h) $(string__h)\
+ $(gp_h) $(gscdefs_h) $(gsparam_h) $(gsstruct_h) $(gxiodev_h) $(gsutil_h)
+ $(GLCC) $(GLO_)gsiodisk.$(OBJ) $(C_) $(GLSRC)gsiodisk.c
+
$(GLOBJ)gsistate.$(OBJ) : $(GLSRC)gsistate.c $(GXERR)\
$(gscie_h) $(gscspace_h) $(gsstruct_h) $(gsutil_h)\
$(gxbitmap_h) $(gxcmap_h) $(gxdht_h) $(gxistate_h) $(gzht_h) $(gzline_h)
@@ -970,7 +974,7 @@
LIB4s=$(GLOBJ)gscparam.$(OBJ) $(GLOBJ)gscspace.$(OBJ) $(GLOBJ)gscssub.$(OBJ)
LIB5s=$(GLOBJ)gsdevice.$(OBJ) $(GLOBJ)gsdevmem.$(OBJ) $(GLOBJ)gsdparam.$(OBJ) $(GLOBJ)gsdfilt.$(OBJ)
LIB6s=$(GLOBJ)gsfname.$(OBJ) $(GLOBJ)gsfont.$(OBJ) $(GLOBJ)gsgdata.$(OBJ)
-LIB7s=$(GLOBJ)gsht.$(OBJ) $(GLOBJ)gshtscr.$(OBJ)
+LIB7s=$(GLOBJ)gsht.$(OBJ) $(GLOBJ)gshtscr.$(OBJ) $(GLOBJ)gsiodisk.$(OBJ)
LIB8s=$(GLOBJ)gsimage.$(OBJ) $(GLOBJ)gsimpath.$(OBJ) $(GLOBJ)gsinit.$(OBJ)
LIB9s=$(GLOBJ)gsiodev.$(OBJ) $(GLOBJ)gsistate.$(OBJ) $(GLOBJ)gsline.$(OBJ)
LIB10s=$(GLOBJ)gsmalloc.$(OBJ) $(GLOBJ)gsmatrix.$(OBJ) $(GLOBJ)gsmemlok.$(OBJ)
Index: zfile.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/zfile.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- zfile.c 7 Mar 2002 08:35:16 -0000 1.16
+++ zfile.c 13 Mar 2002 20:27:39 -0000 1.17
@@ -302,7 +302,6 @@
}
/* <template> <proc> <scratch> filenameforall - */
-/****** NOT CONVERTED FOR IODEVICES YET ******/
private int file_continue(P1(i_ctx_t *));
private int file_cleanup(P1(i_ctx_t *));
private int
@@ -310,19 +309,36 @@
{
os_ptr op = osp;
file_enum *pfen;
- int code;
+ gx_io_device *iodev = NULL;
+ gs_parsed_file_name_t pname;
+ int code = 0;
check_write_type(*op, t_string);
check_proc(op[-1]);
check_read_type(op[-2], t_string);
- /* Push a mark, the pattern, the scratch string, the enumerator, */
+ /* Push a mark, the iodev, devicenamelen, the scratch string, the enumerator, */
/* and the procedure, and invoke the continuation. */
check_estack(7);
- pfen = gp_enumerate_files_init((char *)op[-2].value.bytes, r_size(op - 2), imemory);
+ /* Get the iodevice */
+ code = parse_file_name(op - 2, &pname);
+ if (code < 0)
+ return code;
+ iodev = (pname.iodev == NULL) ? iodev_default : pname.iodev;
+
+ /* Check for several conditions that just cause us to return success */
+ if (pname.len == 0 || iodev->procs.enumerate_files == iodev_no_enumerate_files) {
+ pop(3);
+ return 0; /* no pattern, or device not found -- just return */
+ }
+ pfen = iodev->procs.enumerate_files(iodev, (char *)pname.fname,
+ pname.len, imemory);
if (pfen == 0)
return_error(e_VMerror);
push_mark_estack(es_for, file_cleanup);
- *++esp = op[-2];
+ *++esp;
+ make_istruct(esp, 0, iodev);
+ *++esp;
+ make_int(esp, r_size(op-2) - pname.len);
*++esp = *op;
++esp;
make_istruct(esp, 0, pfen);
@@ -338,19 +354,25 @@
os_ptr op = osp;
es_ptr pscratch = esp - 2;
file_enum *pfen = r_ptr(esp - 1, file_enum);
+ long devlen = esp[-3].value.intval;
+ gx_io_device *iodev = r_ptr(esp - 4, gx_io_device);
uint len = r_size(pscratch);
- uint code =
- gp_enumerate_files_next(pfen, (char *)pscratch->value.bytes, len);
+ uint code;
+ if (len < devlen)
+ return_error(e_rangecheck); /* not even room for device len */
+ memcpy((char *)pscratch->value.bytes, iodev->dname, devlen);
+ code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen,
+ len - devlen);
if (code == ~(uint) 0) { /* all done */
- esp -= 4; /* pop proc, pfen, scratch, mark */
+ esp -= 5; /* pop proc, pfen, devlen, iodev , mark */
return o_pop_estack;
} else if (code > len) /* overran string */
return_error(e_rangecheck);
else {
push(1);
ref_assign(op, pscratch);
- r_set_size(op, code);
+ r_set_size(op, code + devlen);
push_op_estack(file_continue); /* come again */
*++esp = pscratch[2]; /* proc */
return o_push_estack;
@@ -360,7 +382,9 @@
private int
file_cleanup(i_ctx_t *i_ctx_p)
{
- gp_enumerate_files_close(r_ptr(esp + 4, file_enum));
+ gx_io_device *iodev = r_ptr(esp + 2, gx_io_device);
+
+ iodev->procs.enumerate_close(r_ptr(esp + 4, file_enum));
return 0;
}
@@ -378,14 +402,21 @@
pname2.fname = 0;
code = parse_real_file_name(op, &pname2, imemory, "renamefile(to)");
if (code >= 0) {
- if (pname1.iodev != pname2.iodev ||
- (check_file_permissions(i_ctx_p, pname1.fname, pname1.len,
+ if (pname1.iodev != pname2.iodev ) {
+ if (pname1.iodev == iodev_default)
+ pname1.iodev = pname2.iodev;
+ if (pname2.iodev == iodev_default)
+ pname2.iodev = pname1.iodev;
+ }
+ if (pname1.iodev != pname2.iodev ||
+ pname1.iodev == iodev_default &&
+ ((check_file_permissions(i_ctx_p, pname1.fname, pname1.len,
"PermitFileControl") < 0 &&
!file_is_tempfile(i_ctx_p, op - 1) < 0) ||
check_file_permissions(i_ctx_p, pname2.fname, pname2.len,
"PermitFileControl") < 0 ||
check_file_permissions(i_ctx_p, pname2.fname, pname2.len,
- "PermitFileWriting") < 0 ) {
+ "PermitFileWriting") < 0 )) {
/* add a check to permit pname1 to be a tempfile */
code = gs_note_error(e_invalidfileaccess);
} else {
@@ -817,7 +848,7 @@
{
return file_open_stream(fname, len, file_access,
file_default_buffer_size, ps,
- iodev->procs.fopen, mem);
+ iodev, iodev->procs.fopen, mem);
}
/* Make a t_file reference to a stream. */
@@ -914,7 +945,7 @@
{
stream *s;
int code = file_open_stream(fname, len, "r", file_default_buffer_size,
- &s, lib_file_fopen, mem);
+ &s, (gx_io_device *)0, lib_file_fopen, mem);
char *bname;
uint blen;
@@ -990,8 +1021,8 @@
/* but don't open an OS file or initialize the stream. */
int
file_open_stream(const char *fname, uint len, const char *file_access,
- uint buffer_size, stream ** ps, iodev_proc_fopen_t fopen_proc,
- gs_memory_t *mem)
+ uint buffer_size, stream ** ps, gx_io_device *iodev,
+ iodev_proc_fopen_t fopen_proc, gs_memory_t *mem)
{
byte *buffer;
register stream *s;
@@ -1021,8 +1052,9 @@
/* Open the file, always in binary mode. */
strcpy(fmode, file_access);
strcat(fmode, gp_fmode_binary_suffix);
- /****** iodev_default IS QUESTIONABLE ******/
- code = (*fopen_proc)(iodev_default, file_name, fmode, &file,
+ if (!iodev)
+ iodev = iodev_default;
+ code = (*fopen_proc)(iodev, file_name, fmode, &file,
(char *)buffer, buffer_size);
if (code < 0) {
gs_free_object(mem, buffer, "file_open_stream(buffer)");
@@ -1065,8 +1097,8 @@
if (sst == 0)
return_error(e_VMerror);
}
- code = file_open_stream((char *)0, 0, file_access,
- buffer_size, &s, (iodev_proc_fopen_t)0, mem);
+ code = file_open_stream((char *)0, 0, file_access, buffer_size, &s,
+ (gx_io_device *)0, (iodev_proc_fopen_t)0, mem);
if (code < 0) {
gs_free_object(mem, sst, "filter_open(stream_state)");
return code;
Index: zfrsd.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/zfrsd.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- zfrsd.c 21 Feb 2002 22:24:54 -0000 1.6
+++ zfrsd.c 13 Mar 2002 20:27:39 -0000 1.7
@@ -232,8 +232,8 @@
return_error(e_invalidfileaccess); /* can't reopen */
/* Open the file again, to be independent of the source. */
code = file_open_stream((const char *)fname.data, fname.size, "r",
- fs->cbsize, &s, iodev_default->procs.fopen,
- imemory);
+ fs->cbsize, &s, iodev_default,
+ iodev_default->procs.fopen, imemory);
if (code < 0)
return code;
if (sread_subfile(s, offset, length) < 0) {
Index: ziodev2.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/ziodev2.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ziodev2.c 21 Feb 2002 22:24:54 -0000 1.5
+++ ziodev2.c 13 Mar 2002 20:27:39 -0000 1.6
@@ -52,7 +52,7 @@
return file_open_stream(gp_null_file_name,
strlen(gp_null_file_name),
access, 256 /* arbitrary */ , ps,
- iodev->procs.fopen, mem);
+ iodev, iodev->procs.fopen, mem);
}
/* ------ Operators ------ */
More information about the gs-cvs
mailing list