[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch] Fix to let a2ps handle FlateDecode from its delegates
From: |
Jason McCarty |
Subject: |
[patch] Fix to let a2ps handle FlateDecode from its delegates |
Date: |
Wed, 18 Sep 2002 12:44:18 -0400 |
User-agent: |
Mutt/1.3.28i |
Hi,
I sent this to the bug-a2ps address last month, but it looks like this
might be a better list to send it to.
Thanks,
Jason McCarty
----- Forwarded message from Jason McCarty <address@hidden> -----
To: address@hidden
Subject: [patch] Fix to let a2ps handle FlateDecode from its delegates
From: Jason McCarty <address@hidden>
Hi,
I changed the ImageMagick settings in /etc/a2ps.cfg to output postscript
level 3, which seems to produce better output on my system. However, I
found that a2ps can't handle null zeroes in the output of its delegates,
which convert's PS3 output produces in the form of FlateDecode.
The problem is due to using a fgets()/fputs() loop, so lines containing
null zeroes get truncated.
I fixed src/delegate.c to handle zeroes correctly, so convert now works
through a2ps. If a2ps's library files contained binary data (such as PS3
images), then lib/{output.c, pathwalk.c, prolog.c} would need to be
changed similarly. I changed pathwalk.c since it was trivial, but I
didn't modify the other two, since I think they would have needed large
changes, and I guess a2ps doesn't have any binary library files ATM.
Please CC me on replies, as I'm not subscribed.
Thanks.
Jason McCarty
diff -urN a2ps-4.13b.orig/lib/Makefile.am a2ps-4.13b/lib/Makefile.am
--- a2ps-4.13b.orig/lib/Makefile.am Mon Oct 18 16:47:00 1999
+++ a2ps-4.13b/lib/Makefile.am Sat Aug 24 16:24:17 2002
@@ -40,14 +40,14 @@
gen.h printers.h psstat.h caret.h metaseq.h options.h \
dsc.h fonts.h ppd.h prange.h stream.h document.h \
fjobs.h common.h madir.h filalign.h lexppd.h \
-system.h a2ps.h liba2ps.h yy2ppd.h
+system.h a2ps.h liba2ps.h yy2ppd.h fngets.h
liba2pssources = encoding.c media.c jobs.c output.c \
routines.c psgen.c prolog.c faces.c confg.c useropt.c \
gen.c printers.c psstat.c caret.c metaseq.c options.c \
dsc.c fonts.l ppd.c prange.c stream.c document.c \
fjobs.c common.c madir.c filalign.c lexppd.l \
-parseppd.y
+parseppd.y fngets.c
mylibitheaders = msg.h msg.c message.h xstrrpl.h getshline.h pathwalk.h
\
darray.h dstring.h printlen.h pair_ht.h filtdir.h str_ht.h \
diff -urN a2ps-4.13b.orig/lib/fngets.c a2ps-4.13b/lib/fngets.c
--- a2ps-4.13b.orig/lib/fngets.c Wed Dec 31 19:00:00 1969
+++ a2ps-4.13b/lib/fngets.c Sat Aug 24 18:15:53 2002
@@ -0,0 +1,46 @@
+/*
+ * fngets.c
+ *
+ * Replacement for fgets()
+ * Copyright (c) 2002 Jason McCarty
+ */
+
+/*
+ * This file is part of a2ps.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "fngets.h"
+
+/* Behave like fgets(), but return the number of bytes read. To be more
+ * precise:
+ *
+ * Read at most size - 1 bytes from stream into s, terminating after newline
+ * or at EOF, and store '\0' after the last character.
+ * Return value: the number of bytes read.
+ */
+int fngets (char *s, int size, FILE *stream)
+{
+ int byte = 0, index = 0;
+
+ while ((byte != '\n' ) && (index < (size - 1)) && (byte != EOF))
+ if ((byte = fgetc(stream)) != EOF)
+ s[index++] = (char) byte;
+
+ s[index] = '\0';
+ return index;
+}
diff -urN a2ps-4.13b.orig/lib/fngets.h a2ps-4.13b/lib/fngets.h
--- a2ps-4.13b.orig/lib/fngets.h Wed Dec 31 19:00:00 1969
+++ a2ps-4.13b/lib/fngets.h Sat Aug 24 18:09:18 2002
@@ -0,0 +1,34 @@
+/*
+ * fngets.h
+ *
+ * Replacement for fgets()
+ * Copyright (c) 2002 Jason McCarty
+ */
+
+/*
+ * This file is part of a2ps.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _FNGETS_H_
+#define _FNGETS_H_
+#include <stdio.h>
+
+/* Behave like fgets(), but return the number of bytes read */
+int fngets (char *s, int size, FILE *stream);
+
+#endif /* _FNGETS_H_ */
diff -urN a2ps-4.13b.orig/lib/pathwalk.c a2ps-4.13b/lib/pathwalk.c
--- a2ps-4.13b.orig/lib/pathwalk.c Tue Nov 30 03:10:22 1999
+++ a2ps-4.13b/lib/pathwalk.c Sat Aug 24 18:41:44 2002
@@ -36,6 +36,7 @@
#include "strverscmp.h"
#include "quotearg.h"
#include "dirname.h"
+#include "fngets.h"
/*---------------------------------.
| Alloca D to contain "DIR/FILE". |
@@ -373,6 +374,7 @@
char * fullpath;
FILE * fp;
int line = 0;
+ int bytes_read;
message (msg_pw,
(stderr, "pw: pasting `%s%s'\n", name, suffix ? suffix : ""));
@@ -398,7 +400,7 @@
/* Dump rest of file. */
#define INCL_TAG "% -- include file:"
- while ((fgets (buf, sizeof (buf), fp)))
+ while (bytes_read = fngets (buf, sizeof (buf), fp))
{
line++;
if (strnequ (buf, INCL_TAG, strlen (INCL_TAG)))
@@ -414,7 +416,7 @@
_("cannot find file `%s'"), quotearg (file));
continue;
}
- fputs (buf, stdout);
+ fwrite (buf, 1, bytes_read, stdout);
}
fclose (fp);
diff -urN a2ps-4.13b.orig/src/delegate.c a2ps-4.13b/src/delegate.c
--- a2ps-4.13b.orig/src/delegate.c Mon Oct 18 16:22:27 1999
+++ a2ps-4.13b/src/delegate.c Sat Aug 24 16:13:27 2002
@@ -38,6 +38,7 @@
#include "buffer.h"
#include "lister.h"
#include "quotearg.h"
+#include "fngets.h"
/* Priviledge access to job and delegations */
extern struct a2ps_job *job;
@@ -219,6 +220,7 @@
FILE *in_stream, *out_stream;
int lines_read = 0;
char buf[512];
+ int bytes_read;
/* Here we store the type of the last %%??Resource: tag we saw,
* to be ready to handle continuation (%%+ ) */
@@ -277,7 +279,7 @@
/* Now, read the file, update the PS info, and store the result in
* out_stream */
- while (fgets (buf, sizeof (buf), in_stream))
+ while (bytes_read = fngets (buf, sizeof (buf), in_stream))
{
/* This is not exactely the number of lines,
* but anyway it is only used to be sure something was read,
@@ -330,7 +332,7 @@
}
/* The content should be left untouched */
- fputs (buf, out_stream);
+ fwrite (buf, 1, bytes_read, out_stream);
}
pclose (in_stream);
----- End forwarded message -----
- [patch] Fix to let a2ps handle FlateDecode from its delegates,
Jason McCarty <=
Re: [patch] Fix to let a2ps handle FlateDecode from its delegates, Akim Demaille, 2002/09/24