15f798d785
- drop 8bit, fix15, devutf8, grn patches - sync the rest of patches with current release - spec cleanup
341 lines
7.9 KiB
Diff
341 lines
7.9 KiB
Diff
--- groff-1.19.1/src/roff/troff/Makefile.sub.gzip 2004-01-06 23:49:05.000000000 +0100
|
|
+++ groff-1.19.1/src/roff/troff/Makefile.sub 2005-01-12 13:49:11.542476528 +0100
|
|
@@ -1,6 +1,6 @@
|
|
PROG=troff$(EXEEXT)
|
|
MAN1=troff.n
|
|
-XLIBS=$(LIBGROFF)
|
|
+XLIBS=-lz $(LIBGROFF)
|
|
MLIB=$(LIBM)
|
|
OBJS=\
|
|
dictionary.$(OBJEXT) \
|
|
--- groff-1.19.1/src/roff/troff/input.cpp.gzip 2005-01-12 13:49:11.516480480 +0100
|
|
+++ groff-1.19.1/src/roff/troff/input.cpp 2005-01-12 13:57:40.615085728 +0100
|
|
@@ -41,6 +41,8 @@ Foundation, 59 Temple Place - Suite 330,
|
|
|
|
#include "nonposix.h"
|
|
|
|
+#include <zlib.h>
|
|
+
|
|
#ifdef NEED_DECLARATION_PUTENV
|
|
extern "C" {
|
|
int putenv(const char *);
|
|
@@ -190,6 +192,130 @@ void restore_escape_char()
|
|
skip_line();
|
|
}
|
|
|
|
+enum opq_fp_zmode { OPQ_FP_STDIO, OPQ_FP_ZLIB, OPQ_FP_GUESS };
|
|
+
|
|
+class opaque_fp {
|
|
+ private:
|
|
+ FILE * stdio_fp;
|
|
+ gzFile zlib_fp;
|
|
+ int is_zipped;
|
|
+ // We need this because zlib has no ungetc.
|
|
+ int char_pending;
|
|
+ char saved_char;
|
|
+ int popened;
|
|
+ public:
|
|
+ opaque_fp(const char *,
|
|
+ const char *,
|
|
+ enum opq_fp_zmode = OPQ_FP_STDIO);
|
|
+ opaque_fp(FILE *, int = 0);
|
|
+ ~opaque_fp();
|
|
+ int active();
|
|
+ int xgetc();
|
|
+ int unxgetc(int);
|
|
+};
|
|
+
|
|
+int opaque_fp::active()
|
|
+{
|
|
+ if (is_zipped) {
|
|
+ return zlib_fp!=NULL;
|
|
+ } else {
|
|
+ return stdio_fp!=NULL;
|
|
+ }
|
|
+}
|
|
+
|
|
+// This constructor is guaranteed to set is_zipped to 0 or 1, and set the
|
|
+// corresponding fp to something non-rubbish.
|
|
+opaque_fp::opaque_fp(const char * fn, const char * mode, enum opq_fp_zmode z)
|
|
+{
|
|
+ switch (z) {
|
|
+ case OPQ_FP_STDIO :
|
|
+ stdio_fp=fopen(fn,mode);
|
|
+ is_zipped=0;
|
|
+ break;
|
|
+
|
|
+ case OPQ_FP_ZLIB :
|
|
+ zlib_fp=gzopen(fn,mode);
|
|
+ is_zipped=1;
|
|
+ char_pending=0;
|
|
+ break;
|
|
+
|
|
+ case OPQ_FP_GUESS :
|
|
+ stdio_fp=fopen(fn,mode);
|
|
+ is_zipped=0;
|
|
+ if (active()) {
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ // Yes, I'm a C addict
|
|
+ char * s;
|
|
+ s=(char*)malloc(strlen(fn)+4);
|
|
+ sprintf(s,"%s.gz",fn);
|
|
+ zlib_fp=gzopen(s,mode);
|
|
+ char_pending=0;
|
|
+ is_zipped=1;
|
|
+ free(s);
|
|
+ break;
|
|
+ }
|
|
+}
|
|
+
|
|
+opaque_fp::opaque_fp(FILE *fp, int p)
|
|
+{
|
|
+ stdio_fp=fp;
|
|
+ is_zipped=0;
|
|
+ popened=p;
|
|
+}
|
|
+
|
|
+opaque_fp::~opaque_fp()
|
|
+{
|
|
+ if (is_zipped) {
|
|
+ if (zlib_fp!=NULL) {
|
|
+ gzclose(zlib_fp);
|
|
+ zlib_fp=NULL;
|
|
+ }
|
|
+ } else {
|
|
+ if (stdio_fp!=NULL) {
|
|
+ if (popened) {
|
|
+ pclose(stdio_fp);
|
|
+ } else if (stdio_fp!=stdin) {
|
|
+ fclose(stdio_fp);
|
|
+ } else {
|
|
+ clearerr(stdin);
|
|
+ }
|
|
+ stdio_fp=NULL;
|
|
+ }
|
|
+ }
|
|
+}
|
|
+
|
|
+// These routines must be called only if active() is true
|
|
+int opaque_fp::xgetc()
|
|
+{
|
|
+ if (is_zipped) {
|
|
+ if (char_pending) {
|
|
+ char_pending--;
|
|
+ return saved_char;
|
|
+ } else {
|
|
+ return gzgetc(zlib_fp);
|
|
+ }
|
|
+ } else {
|
|
+ return getc(stdio_fp);
|
|
+ }
|
|
+}
|
|
+
|
|
+int opaque_fp::unxgetc(int c)
|
|
+{
|
|
+ if (is_zipped) {
|
|
+ if (char_pending) {
|
|
+ return EOF;
|
|
+ } else {
|
|
+ char_pending++;
|
|
+ saved_char=c;
|
|
+ return c;
|
|
+ }
|
|
+ } else {
|
|
+ return ungetc(c,stdio_fp);
|
|
+ }
|
|
+}
|
|
+
|
|
class input_iterator {
|
|
public:
|
|
input_iterator();
|
|
@@ -209,7 +335,7 @@ private:
|
|
virtual int get_location(int, const char **, int *) { return 0; }
|
|
virtual void backtrace() {}
|
|
virtual int set_location(const char *, int) { return 0; }
|
|
- virtual int next_file(FILE *, const char *) { return 0; }
|
|
+ virtual int next_file(opaque_fp *, const char *) { return 0; }
|
|
virtual void shift(int) {}
|
|
virtual int is_boundary() {return 0; }
|
|
virtual int internal_level() { return 0; }
|
|
@@ -250,7 +376,7 @@ public:
|
|
};
|
|
|
|
class file_iterator : public input_iterator {
|
|
- FILE *fp;
|
|
+ opaque_fp *fp;
|
|
int lineno;
|
|
const char *filename;
|
|
int popened;
|
|
@@ -259,7 +385,9 @@ class file_iterator : public input_itera
|
|
enum { BUF_SIZE = 512 };
|
|
unsigned char buf[BUF_SIZE];
|
|
void close();
|
|
+ void ctor_end(void);
|
|
public:
|
|
+ file_iterator(opaque_fp *, const char *, int = 0);
|
|
file_iterator(FILE *, const char *, int = 0);
|
|
~file_iterator();
|
|
int fill(node **);
|
|
@@ -267,18 +395,30 @@ public:
|
|
int get_location(int, const char **, int *);
|
|
void backtrace();
|
|
int set_location(const char *, int);
|
|
- int next_file(FILE *, const char *);
|
|
+ int next_file(opaque_fp *, const char *);
|
|
int is_file();
|
|
};
|
|
|
|
-file_iterator::file_iterator(FILE *f, const char *fn, int po)
|
|
+file_iterator::file_iterator(opaque_fp *f, const char *fn, int po)
|
|
: fp(f), lineno(1), filename(fn), popened(po),
|
|
newline_flag(0), seen_escape(0)
|
|
{
|
|
- if ((font::use_charnames_in_special) && (fn != 0)) {
|
|
+ ctor_end();
|
|
+}
|
|
+
|
|
+file_iterator::file_iterator(FILE * f, const char * fn, int po)
|
|
+: fp(new opaque_fp(f,po)), lineno(1), filename(fn), popened(po),
|
|
+ newline_flag(0), seen_escape(0)
|
|
+{
|
|
+ ctor_end();
|
|
+}
|
|
+
|
|
+void file_iterator::ctor_end(void)
|
|
+{
|
|
+ if ((font::use_charnames_in_special) && (filename != 0)) {
|
|
if (!the_output)
|
|
init_output();
|
|
- the_output->put_filename(fn);
|
|
+ the_output->put_filename(filename);
|
|
}
|
|
}
|
|
|
|
@@ -289,6 +429,8 @@ file_iterator::~file_iterator()
|
|
|
|
void file_iterator::close()
|
|
{
|
|
+ delete fp;
|
|
+#if 0
|
|
if (fp == stdin)
|
|
clearerr(stdin);
|
|
#ifndef POPEN_MISSING
|
|
@@ -297,6 +439,7 @@ void file_iterator::close()
|
|
#endif /* not POPEN_MISSING */
|
|
else
|
|
fclose(fp);
|
|
+#endif
|
|
}
|
|
|
|
int file_iterator::is_file()
|
|
@@ -304,7 +447,7 @@ int file_iterator::is_file()
|
|
return 1;
|
|
}
|
|
|
|
-int file_iterator::next_file(FILE *f, const char *s)
|
|
+int file_iterator::next_file(opaque_fp *f, const char *s)
|
|
{
|
|
close();
|
|
filename = s;
|
|
@@ -327,7 +470,7 @@ int file_iterator::fill(node **)
|
|
ptr = p;
|
|
unsigned char *e = p + BUF_SIZE;
|
|
while (p < e) {
|
|
- int c = getc(fp);
|
|
+ int c = fp->xgetc();
|
|
if (c == EOF)
|
|
break;
|
|
if (invalid_input_char(c))
|
|
@@ -354,13 +497,13 @@ int file_iterator::fill(node **)
|
|
|
|
int file_iterator::peek()
|
|
{
|
|
- int c = getc(fp);
|
|
+ int c = fp->xgetc();
|
|
while (invalid_input_char(c)) {
|
|
warning(WARN_INPUT, "invalid input character code %1", int(c));
|
|
- c = getc(fp);
|
|
+ c = fp->xgetc();
|
|
}
|
|
if (c != EOF)
|
|
- ungetc(c, fp);
|
|
+ fp->unxgetc(c);
|
|
return c;
|
|
}
|
|
|
|
@@ -406,7 +549,7 @@ public:
|
|
static int set_location(const char *, int);
|
|
static void backtrace();
|
|
static void backtrace_all();
|
|
- static void next_file(FILE *, const char *);
|
|
+ static void next_file(opaque_fp *, const char *);
|
|
static void end_file();
|
|
static void shift(int n);
|
|
static void add_boundary();
|
|
@@ -583,7 +726,7 @@ int input_stack::set_location(const char
|
|
return 0;
|
|
}
|
|
|
|
-void input_stack::next_file(FILE *fp, const char *s)
|
|
+void input_stack::next_file(opaque_fp *fp, const char *s)
|
|
{
|
|
input_iterator **pp;
|
|
for (pp = ⊤ *pp != &nil_iterator; pp = &(*pp)->next)
|
|
@@ -669,10 +812,11 @@ void next_file()
|
|
input_stack::end_file();
|
|
else {
|
|
errno = 0;
|
|
- FILE *fp = include_search_path.open_file_cautious(nm.contents());
|
|
- if (!fp)
|
|
+ opaque_fp *fp = new opaque_fp(nm.contents(), "r");
|
|
+ if (!fp->active()) {
|
|
+ delete fp;
|
|
error("can't open `%1': %2", nm.contents(), strerror(errno));
|
|
- else
|
|
+ } else
|
|
input_stack::next_file(fp, nm.contents());
|
|
}
|
|
tok.next();
|
|
@@ -5463,11 +5607,12 @@ void source()
|
|
error("won't source non-file `%1' without -U flag", path);
|
|
else {
|
|
errno = 0;
|
|
- FILE *fp = fopen(path, "r");
|
|
- if (fp)
|
|
+ opaque_fp *fp = new opaque_fp(nm.contents(), "r",OPQ_FP_GUESS);
|
|
+ if (fp->active()) {
|
|
input_stack::push(new file_iterator(fp, nm.contents()));
|
|
- else
|
|
- error("can't open `%1': %2", path, strerror(errno));
|
|
+ } else {
|
|
+ delete fp;
|
|
+ }
|
|
}
|
|
tok.next();
|
|
}
|
|
@@ -6856,16 +7001,18 @@ void macro_source()
|
|
|
|
static void process_input_file(const char *name)
|
|
{
|
|
- FILE *fp;
|
|
+ opaque_fp *fp;
|
|
if (strcmp(name, "-") == 0) {
|
|
clearerr(stdin);
|
|
- fp = stdin;
|
|
+ fp = new opaque_fp(stdin);
|
|
}
|
|
else {
|
|
errno = 0;
|
|
- fp = include_search_path.open_file_cautious(name);
|
|
- if (!fp)
|
|
+ fp = new opaque_fp(name, "r", OPQ_FP_GUESS);
|
|
+ if (!fp->active()) {
|
|
+ delete fp;
|
|
fatal("can't open `%1': %2", name, strerror(errno));
|
|
+ }
|
|
}
|
|
input_stack::push(new file_iterator(fp, name));
|
|
tok.next();
|