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 + +/* 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);