diff options
Diffstat (limited to 'contrib/groff/src/preproc')
24 files changed, 525 insertions, 141 deletions
diff --git a/contrib/groff/src/preproc/eqn/eqn.man b/contrib/groff/src/preproc/eqn/eqn.man index 381d97d..bc7dc7e 100644 --- a/contrib/groff/src/preproc/eqn/eqn.man +++ b/contrib/groff/src/preproc/eqn/eqn.man @@ -1,5 +1,5 @@ -.ig \"-*- nroff -*- -Copyright (C) 1989-2000 Free Software Foundation, Inc. +.ig +Copyright (C) 1989-2000, 2001 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -880,3 +880,7 @@ beginning of the input line. .BR @g@troff (@MAN1EXT@), .BR groff_font (@MAN5EXT@), .I The\ \*(txbook +. +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/contrib/groff/src/preproc/eqn/lex.cc b/contrib/groff/src/preproc/eqn/lex.cc index 25faec2..e14053d 100644 --- a/contrib/groff/src/preproc/eqn/lex.cc +++ b/contrib/groff/src/preproc/eqn/lex.cc @@ -1,5 +1,6 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001 + Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -251,7 +252,7 @@ static struct { void init_table(const char *device) { - int i; + unsigned int i; for (i = 0; i < sizeof(token_table)/sizeof(token_table[0]); i++) { definition *def = new definition; def->is_macro = 0; diff --git a/contrib/groff/src/preproc/eqn/main.cc b/contrib/groff/src/preproc/eqn/main.cc index 6dc03f0..f53ffa3 100644 --- a/contrib/groff/src/preproc/eqn/main.cc +++ b/contrib/groff/src/preproc/eqn/main.cc @@ -30,6 +30,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define STARTUP_FILE "eqnrc" extern int yyparse(); +extern "C" const char *Version_string; static char *delim_search (char *, int); static int inline_equation (FILE *, string &, string &); @@ -303,7 +304,6 @@ int main(int argc, char **argv) break; case 'v': { - extern const char *Version_string; printf("GNU eqn (groff) version %s\n", Version_string); exit(0); break; diff --git a/contrib/groff/src/preproc/eqn/neqn.man b/contrib/groff/src/preproc/eqn/neqn.man index bca7dc2..27261c4 100644 --- a/contrib/groff/src/preproc/eqn/neqn.man +++ b/contrib/groff/src/preproc/eqn/neqn.man @@ -1,3 +1,21 @@ +.ig +Copyright (C) 2001 Free Software Foundation, Inc. + +Permission is granted to make and distribute verbatim copies of +this manual provided the copyright notice and this permission notice +are preserved on all copies. + +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided that the +entire resulting derived work is distributed under the terms of a +permission notice identical to this one. + +Permission is granted to copy and distribute translations of this +manual into another language, under the above conditions for modified +versions, except that this permission notice may be included in +translations approved by the Free Software Foundation instead of in +the original English. +.. .TH @G@NEQN @MAN1EXT@ "@MDATE@" "Groff Version @VERSION@" .SH NAME @g@neqn \- format equations for ascii output @@ -19,3 +37,7 @@ does not support low-resolution, typewriter-like devices (although it may work adequately for very simple input). .SH "SEE ALSO" .BR @g@eqn (@MAN1EXT@) +. +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/contrib/groff/src/preproc/eqn/neqn.sh b/contrib/groff/src/preproc/eqn/neqn.sh index 8f6bc8b..08346b0 100644 --- a/contrib/groff/src/preproc/eqn/neqn.sh +++ b/contrib/groff/src/preproc/eqn/neqn.sh @@ -3,7 +3,8 @@ # GNU eqn with groff -Tascii|-Tlatin1|-Tutf8|-Tcp1047 is supported. : ${GROFF_BIN_PATH=@BINDIR@} -export PATH=$GROFF_BIN_PATH:$PATH +PATH=$GROFF_BIN_PATH:$PATH +export PATH exec @g@eqn -Tascii ${1+"$@"} # eof diff --git a/contrib/groff/src/preproc/eqn/over.cc b/contrib/groff/src/preproc/eqn/over.cc index 06b0321..4c544d1 100644 --- a/contrib/groff/src/preproc/eqn/over.cc +++ b/contrib/groff/src/preproc/eqn/over.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2001 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -65,7 +65,7 @@ int over_box::compute_metrics(int style) set_script_size(); printf(".nr " SMALL_SIZE_FORMAT " \\n[.s]\n", uid); } - int mark_uid; + int mark_uid = 0; int res = num->compute_metrics(style); if (res) mark_uid = num->uid; diff --git a/contrib/groff/src/preproc/grn/grn.man b/contrib/groff/src/preproc/grn/grn.man index f2613da..82e43cf 100644 --- a/contrib/groff/src/preproc/grn/grn.man +++ b/contrib/groff/src/preproc/grn/grn.man @@ -1,5 +1,6 @@ -.ig \"-*- nroff -*- -Copyright (C) 2000 Free Software Foundation, Inc. +'\" t +.ig +Copyright (C) 2000, 2001 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -634,3 +635,7 @@ David Slattengren and Barry Roitblat wrote the original Berkeley .PP Daniel Senderowicz and Werner Lemberg modified it for .IR groff . +. +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/contrib/groff/src/preproc/grn/main.cc b/contrib/groff/src/preproc/grn/main.cc index 92e64c6..efb33a9 100644 --- a/contrib/groff/src/preproc/grn/main.cc +++ b/contrib/groff/src/preproc/grn/main.cc @@ -82,6 +82,8 @@ #include "error.h" #include "defs.h" +extern "C" const char *Version_string; + /* database imports */ extern void HGPrintElt(ELT *element, int baseline); @@ -282,7 +284,6 @@ main(int argc, case '-': if (strcmp(*argv,"--version")==0) { case 'v': - extern const char *Version_string; printf("GNU grn (groff) version %s\n", Version_string); exit(0); break; diff --git a/contrib/groff/src/preproc/html/Makefile.sub b/contrib/groff/src/preproc/html/Makefile.sub index 9d5045a..8ecd332 100644 --- a/contrib/groff/src/preproc/html/Makefile.sub +++ b/contrib/groff/src/preproc/html/Makefile.sub @@ -4,4 +4,3 @@ MAN1= XLIBS=$(LIBGROFF) OBJS=pre-html.o pushbackbuffer.o CCSRCS=$(srcdir)/pre-html.cc $(srcdir)/pushbackbuffer.cc -NAMEPREFIX=$(g) diff --git a/contrib/groff/src/preproc/html/pre-html.cc b/contrib/groff/src/preproc/html/pre-html.cc index 8357dd6..2a36740 100644 --- a/contrib/groff/src/preproc/html/pre-html.cc +++ b/contrib/groff/src/preproc/html/pre-html.cc @@ -23,7 +23,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <stdio.h> #include <signal.h> #include <ctype.h> -#include <string.h> #include <assert.h> #include <stdlib.h> #include <errno.h> @@ -47,7 +46,11 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define PID_T int #endif /* not _POSIX_VERSION */ -extern char *strerror(); +#include <stdarg.h> + +#include "nonposix.h" + +extern "C" const char *Version_string; #include "pre-html.h" #include "pushbackbuffer.h" @@ -59,9 +62,20 @@ extern char *strerror(); #define IMAGE_BOARDER_PIXELS 0 #define MAX_WIDTH 8 // inches #define INLINE_LEADER_CHAR '\\' +#define MAX_RETRIES 4096 // number of different page directory names to try before giving up #define TRANSPARENT "-background \"#FFF\" -transparent \"#FFF\"" +#ifdef __MSDOS__ +#define PAGE_TEMPLATE "pg" +#define PS_TEMPLATE "ps" +#define REGION_TEMPLATE "rg" +#else +#define PAGE_TEMPLATE "-page-" +#define PS_TEMPLATE "-ps-" +#define REGION_TEMPLATE "-regions-" +#endif + #if 0 # define DEBUGGING # define DEBUG_HTML @@ -82,20 +96,21 @@ static int stdoutfd = 1; // output file descriptor - norm // -1 means closed static int copyofstdoutfd =-1; // a copy of stdout, so we can restore stdout when // writing to post-html -static char *psFileName = 0; // name of postscript file -static char *regionFileName = 0; // name of file containing all image regions -static char *imagePageStem = 0; // stem of all files containing page images +static char *psFileName = NULL; // name of postscript file +static char *regionFileName = NULL; // name of file containing all image regions +static char *imagePageStem = NULL; // stem of all files containing page images static char *image_device = "pnmraw"; static int image_res = DEFAULT_IMAGE_RES; static int vertical_offset= DEFAULT_VERTICAL_OFFSET; -static char *image_template = 0; // image template filename +static char *image_template = NULL; // image template filename static int troff_arg = 0; // troff arg index -static char *command_prefix = 0; // optional prefix for some installations. -static char *troff_command = 0; +static char *command_prefix = NULL; // optional prefix for some installations. +static char *troff_command = NULL; +static char *image_dir = NULL; // user specified image directory #if defined(DEBUGGING) static int debug = FALSE; -static char *troffFileName = 0; // output of pre-html output which is sent to troff -Tps -static char *htmlFileName = 0; // output of pre-html output which is sent to troff -Thtml +static char *troffFileName = NULL; // output of pre-html output which is sent to troff -Tps +static char *htmlFileName = NULL; // output of pre-html output which is sent to troff -Thtml #endif @@ -111,7 +126,8 @@ static char *htmlFileName = 0; // output of pre-html output whi static int do_file(const char *filename); /* - * sys_fatal - writes a fatal error message. Taken from src/roff/groff/pipeline.c + * sys_fatal - writes a fatal error message. + * Taken from src/roff/groff/pipeline.c. */ void sys_fatal (const char *s) @@ -120,6 +136,222 @@ void sys_fatal (const char *s) } /* + * html_system - a wrapper for system() + */ +void html_system(const char *s, int redirect_stdout) +{ + // Redirect standard error to the null device. This is more + // portable than using "2> /dev/null", since it doesn't require a + // Unixy shell. + int save_stderr = dup(2); + int save_stdout = dup(1); + int fdnull = open(NULL_DEV, O_WRONLY|O_BINARY, 0666); + if (save_stderr > 2 && fdnull > 2) + dup2(fdnull, 2); + if (redirect_stdout && save_stdout > 1 && fdnull > 1) + dup2(fdnull, 1); + if (fdnull >= 0) + close(fdnull); + int status = system(s); + dup2(save_stderr, 2); + if (redirect_stdout) + dup2(save_stdout, 1); + if (status == -1) + fprintf(stderr, "Calling `%s' failed\n", s); + else if (status) + fprintf(stderr, "Calling `%s' returned status %d\n", s, status); +} + +#if 0 + +/* + * if/when vsnprintf becomes available on all *NIX machines we can use this function, + * until then we must use the more complex function below which performs hand built + * %d, %s and %%. + */ + +/* + * make_message - taken from man printf(3), creates a string via malloc + * and places the result of the va args into string. + * Finally the new string is returned. + */ + +char * +make_message (const char *fmt, ...) +{ + /* Guess we need no more than 100 bytes. */ + int n, size = 100; + char *p; + char *np; + va_list ap; + if ((p = (char *)malloc (size)) == NULL) + return NULL; + while (1) { + /* Try to print in the allocated space. */ + va_start(ap, fmt); + n = vsnprintf (p, size, fmt, ap); + va_end(ap); + /* If that worked, return the string. */ + if (n > -1 && n < size) { + if (size > n+1) { + np = strdup(p); + if (np == NULL) + sys_fatal("strdup"); + free(p); + return np; + } + return p; + } + /* Else try again with more space. */ + if (n > -1) /* glibc 2.1 */ + size = n+1; /* precisely what is needed */ + else /* glibc 2.0 */ + size *= 2; /* twice the old size */ + if ((np = (char *)realloc (p, size)) == NULL) { + free(p); /* realloc failed, free old, p. */ + return NULL; + } + p = np; /* use realloc'ed, p */ + } +} +#else + +/* + * lengthOfintToStr - returns the length of the proposed string value of i. + * Hand built log10. + */ + +int +lengthOfintToStr (int i) +{ + int n=0; + + if (i < 0) + sys_fatal("expecting positive integer value"); + + do { + i /= 10; + n++; + } while (i > 0); + return n; +} + +/* + * intToStr - returns a string containing the positive value of i. + * (int i is assumed to be positive). + */ + +char * +intToStr (int i) +{ + int n=lengthOfintToStr(i)+1; + char *p = (char *)malloc(n); + + if (p == NULL) + sys_fatal("malloc"); + + if (i < 0) + sys_fatal("expecting positive integer value"); + + n--; + p[n] = (char)0; + do { + n--; + p[n] = (char)((i % 10) + (int)'0'); + i /= 10; + } while (i > 0); + return( p ); +} + +/* + * make_message - returns a string built from a format specifier. + * This function does not use vsnprintf; it only + * understands primitive %%, %s, and %d specifiers. + */ + +char * +make_message (const char *fmt, ...) +{ + char *p = strdup(fmt); /* so we can splat a nul anywhere in the string */ + char *np; + char *l; + char *s; + char *num; + int search=0; + va_list ap; + + if (p == NULL) + sys_fatal("strdup"); + + va_start(ap, fmt); + while (p) { + int lenp=strlen(p); + char *f = strchr(p+search, '%'); + + search = f-p; + np = p; + + if (f == NULL) { + va_end(ap); + return p; + } + switch (*(f+1)) { + + case 'd': + l = strdup(f+2); + if (l == NULL) + sys_fatal("strdup"); + *f = (char)0; + num = intToStr(va_arg(ap, int)); + np = (char *)malloc(strlen(p)+strlen(num)+strlen(l)+1); + if (np == NULL) + sys_fatal("malloc"); + strcpy(np, p); + strcat(np, num); + strcat(np, l); + search += strlen(np)-lenp; + free(num); + free(l); + break; + case 's': + /* concat */ + l = f+2; + if (l == NULL) + sys_fatal("strdup"); + s = va_arg(ap, char *); + *f = (char)0; + np = (char *)malloc(strlen(l)+1+strlen(p)+strlen(s)); + if (np == NULL) + sys_fatal("malloc"); + strcpy(np, p); + strcat(np, s); + strcat(np, l); + search += strlen(s); + break; + case '%': + /* remove one of the two % that we have seen */ + *f = (char)0; + l = f+1; + np = (char *)malloc(strlen(l)+1+strlen(p)); + if (np == NULL) + sys_fatal("malloc"); + strcpy(np, p); + strcat(np, l); + search++; + break; + default: + sys_fatal("unexpected format specifier"); + return NULL; + } + free(p); + p = np; + } + va_end(ap); + return NULL; +} +#endif + +/* * the class and methods for retaining ascii text */ @@ -174,7 +406,7 @@ char_buffer::char_buffer() char_buffer::~char_buffer() { - while (head != 0) { + while (head != NULL) { char_block *temp = head; head = head->next; delete temp; @@ -187,12 +419,10 @@ char_buffer::~char_buffer() int char_buffer::read_file (FILE *fp) { - int i=0; - unsigned int old_used; int n; while (! feof(fp)) { - if (tail == 0) { + if (tail == NULL) { tail = new char_block; head = tail; } else { @@ -246,14 +476,55 @@ static void writeString (char *s) * makeFileName - creates the image filename template. */ -void makeFileName () +static void makeFileName (void) { - char buffer[8192]; + char *s; + + if ((image_dir != NULL) && (strchr(image_dir, '%') != NULL)) { + error("cannot use a `%%' within the image directory name"); + exit(1); + } - sprintf(buffer, "grohtml-%d", (int)getpid()); - strcat(buffer, "-%d"); - image_template = (char *)malloc(strlen(buffer)+1); - strcpy(image_template, buffer); + if ((image_template != NULL) && (strchr(image_template, '%') != NULL)) { + error("cannot use a `%%' within the image template"); + exit(1); + } + + if (image_dir == NULL) { + image_dir = ""; + } else if ((strlen(image_dir)>0) && (image_dir[strlen(image_dir)-1] != '/')) { + image_dir = make_message("%s/", image_dir); + if (image_dir == NULL) + sys_fatal("make_message"); + } + + if (image_template == NULL) + s = make_message("%sgrohtml-%d", image_dir, (int)getpid()); + else { + s = make_message("%s%s", image_dir, image_template); + } + if (s == NULL) + sys_fatal("make_message"); + + image_template = (char *)malloc(strlen("-%d")+strlen(s)+1); + if (image_template == NULL) + sys_fatal("malloc"); + strcpy(image_template, s); + strcat(image_template, "-%d"); + free(s); +} + +/* + * checkImageDir - checks to see whether the image directory is available. + */ + +static void checkImageDir (void) +{ + if ((image_dir != NULL) && (strcmp(image_dir, "") != 0)) + if (! ((mkdir(image_dir, 0700) == 0) || (errno == EEXIST))) { + error("cannot create directory `%1'", image_dir); + exit(1); + } } /* @@ -266,12 +537,12 @@ static void write_end_image (int is_html) /* * emit image name and enable output */ - writeString("\\O2\\O1\\O4\n"); + writeString("\\O[2]\\O[1]\\O[4]\n"); } else { /* * postscript, therefore emit image boundaries */ - writeString("\\O2\\O4\n"); + writeString("\\O[2]\\O[4]\n"); } } @@ -286,8 +557,8 @@ static void write_end_image (int is_html) static void write_start_image (IMAGE_ALIGNMENT pos, int is_html) { if (pos == INLINE) { - writeString("\\O3\\O5'"); - writeString(image_template); writeString(".png'"); + writeString("\\O[3]\\O[5 "); + writeString(image_template); writeString(".png]"); } else { writeString(".begin \\{\\\n"); switch (pos) { @@ -310,10 +581,10 @@ static void write_start_image (IMAGE_ALIGNMENT pos, int is_html) writeString("\\}\n"); } if (is_html) { - writeString("\\O0\n"); + writeString("\\O[0]\n"); } else { // reset min/max registers - writeString("\\O0\\O1\n"); + writeString("\\O[0]\\O[1]\n"); } } @@ -456,10 +727,9 @@ void char_buffer::skip_to_newline (char_block **t, int *i) void char_buffer::write_file_troff (void) { char_block *t=head; - int r; int i=0; - if (t != 0) { + if (t != NULL) { do { /* * remember to check the shortest string last @@ -479,7 +749,7 @@ void char_buffer::write_file_troff (void) } else { write_upto_newline(&t, &i, FALSE); } - } while (t != 0); + } while (t != NULL); } if (close(stdoutfd) < 0) sys_fatal("close"); @@ -526,7 +796,7 @@ imageItem::imageItem (int x1, int y1, int x2, int y2, int page, int res, int max resolution = res; maxx = max_width; imageName = name; - next = 0; + next = NULL; } /* @@ -567,7 +837,7 @@ imageList::imageList () imageList::~imageList () { - while (head != 0) { + while (head != NULL) { imageItem *i = head; head = head->next; delete i; @@ -578,21 +848,54 @@ imageList::~imageList () * createAllPages - creates a set of images, one per page. */ -static void createAllPages (void) +static int createAllPages (void) { char buffer[4096]; + char *s; + int retries = MAX_RETRIES; + + imagePageStem = xtmptemplate(PAGE_TEMPLATE); + strcpy(buffer, imagePageStem); - sprintf(buffer, - "echo showpage | gs -q -dSAFER -sDEVICE=%s -r%d -sOutputFile=%s%%d %s - > /dev/null 2>&1 \n", - image_device, - image_res, - imagePageStem, - psFileName); + do { + if (mktemp(imagePageStem) == NULL) { + sys_fatal("mktemp"); + return -1; + } + if (mkdir(imagePageStem, 0700) == 0) break; + if (errno == EEXIST) { + // directory already exists, try another name + retries--; + if (retries == 0) { + // time to give up + sys_fatal("mkdir"); + return -1; + } + } else { + // another error, quit + sys_fatal("mkdir"); + return -1; + } + strcpy(imagePageStem, buffer); + } while (1); + + s = make_message("echo showpage | " + "gs%s -q -dSAFER -sDEVICE=%s -r%d " + "-sOutputFile=%s/%%d %s -", + EXE_EXT, + image_device, + image_res, + imagePageStem, + psFileName); + if (s == NULL) + sys_fatal("make_message"); #if defined(DEBUGGING) - fwrite(buffer, sizeof(char), strlen(buffer), stderr); + fwrite(s, sizeof(char), strlen(s), stderr); fflush(stderr); #endif - system(buffer); + html_system(s, 1); + free(s); + return 0; } /* @@ -602,30 +905,22 @@ static void createAllPages (void) static void removeAllPages (void) { #if !defined(DEBUGGING) - char buffer[4096]; + char *s=NULL; int i=1; do { - sprintf(buffer, "%s%d", imagePageStem, i); + if (s) + free(s); + s = make_message("%s/%d", imagePageStem, i); + if (s == NULL) + sys_fatal("make_message"); i++; - } while (remove(buffer) == 0); + } while (unlink(s) == 0); + rmdir(imagePageStem); #endif } /* - * abs - returns the absolute value. - */ - -int abs (int x) -{ - if (x < 0) { - return( -x ); - } else { - return( x ); - } -} - -/* * min - returns the minimum of two numbers. */ @@ -658,23 +953,28 @@ int max (int x, int y) static void createImage (imageItem *i) { if (i->X1 != -1) { - char buffer[4096]; + char *s; int x1 = max(min(i->X1, i->X2)*image_res/POSTSCRIPTRES-1*IMAGE_BOARDER_PIXELS, 0); int y1 = max((image_res*vertical_offset/72)+min(i->Y1, i->Y2)*image_res/POSTSCRIPTRES-IMAGE_BOARDER_PIXELS, 0); int x2 = max(i->X1, i->X2)*image_res/POSTSCRIPTRES+1*IMAGE_BOARDER_PIXELS; int y2 = (image_res*vertical_offset/72)+max(i->Y1, i->Y2)*image_res/POSTSCRIPTRES+1*IMAGE_BOARDER_PIXELS; - sprintf(buffer, - "pnmcut %d %d %d %d < %s%d | pnmtopng %s > %s \n", - x1, y1, x2-x1+1, y2-y1+1, - imagePageStem, - i->pageNo, - TRANSPARENT, - i->imageName); + s = make_message("pnmcut%s %d %d %d %d < %s/%d | pnmtopng%s %s > %s \n", + EXE_EXT, + x1, y1, x2-x1+1, y2-y1+1, + imagePageStem, + i->pageNo, + EXE_EXT, + TRANSPARENT, + i->imageName); + if (s == NULL) + sys_fatal("make_message"); + #if defined(DEBUGGING) - fprintf(stderr, buffer); + fprintf(stderr, s); #endif - system(buffer); + html_system(s, 0); + free(s); #if defined(DEBUGGING) } else { fprintf(stderr, "ignoring image as x1 coord is -1\n"); @@ -691,7 +991,7 @@ void imageList::add (int x1, int y1, int x2, int y2, int page, int res, int maxx { imageItem *i = new imageItem(x1, y1, x2, y2, page, res, maxx, name); - if (head == 0) { + if (head == NULL) { head = i; tail = i; } else { @@ -712,10 +1012,9 @@ static imageList listOfImages; // list of images defined by the region file. void char_buffer::write_file_html (void) { char_block *t =head; - char *name; int i=0; - if (t != 0) { + if (t != NULL) { stop(); do { /* @@ -737,7 +1036,7 @@ void char_buffer::write_file_html (void) } else { write_upto_newline(&t, &i, TRUE); } - } while (t != 0); + } while (t != NULL); } if (close(stdoutfd) < 0) sys_fatal("close"); @@ -760,7 +1059,6 @@ void char_buffer::write_file_html (void) static void generateImages (char *regionFileName) { pushBackBuffer *f=new pushBackBuffer(regionFileName); - char ch; while (f->putPB(f->getPB()) != eof) { if (f->isString("grohtml-info:page")) { @@ -775,10 +1073,10 @@ static void generateImages (char *regionFileName) listOfImages.add(x1, y1, x2, y2, page, res, maxx, name); while ((f->putPB(f->getPB()) != '\n') && (f->putPB(f->getPB()) != eof)) { - ch = f->getPB(); + (void)f->getPB(); } if (f->putPB(f->getPB()) == '\n') { - ch = f->getPB(); + (void)f->getPB(); } } else { /* @@ -931,6 +1229,9 @@ char **addps4html (int argc, char *argv[]) char **new_argv = (char **)malloc((argc+2)*sizeof(char *)); int i=0; + if (new_argv == NULL) + sys_fatal("malloc"); + while (i<argc) { new_argv[i] = argv[i]; i++; @@ -1006,13 +1307,15 @@ static char_buffer inputFile; void usage(FILE *stream) { - fprintf(stream, "usage: %s troffname [-P-o vertical_image_offset] [-P-i image_resolution] [troff flags] [files]\n", program_name); + fprintf(stream, "usage: %s troffname [-Iimage_name] [-Dimage_directory] [-P-o vertical_image_offset] [-P-i image_resolution] [troff flags] [files]\n", program_name); fprintf(stream, " vertical_image_offset (default %d/72 of an inch)\n", vertical_offset); fprintf(stream, " image_resolution (default %d) pixels per inch\n", image_res); + fprintf(stream, " image_name is the name of the stem for all images (default is grohtml-<pid>)\n"); + fprintf(stream, " place all png files into image_directory\n"); } /* - * scanArguments - scans for -P-i and -P-o arguments. + * scanArguments - scans for -P-i, -P-o, -P-D and -P-I arguments. */ int scanArguments (int argc, char **argv) @@ -1020,13 +1323,16 @@ int scanArguments (int argc, char **argv) int i=1; while (i<argc) { - if (strncmp(argv[i], "-i", 2) == 0) { + if (strncmp(argv[i], "-D", 2) == 0) { + image_dir = (char *)(argv[i]+2); + } else if (strncmp(argv[i], "-I", 2) == 0) { + image_template = (char *)(argv[i]+2); + } else if (strncmp(argv[i], "-i", 2) == 0) { image_res = atoi((char *)(argv[i]+2)); } else if (strncmp(argv[i], "-o", 2) == 0) { vertical_offset = atoi((char *)(argv[i]+2)); } else if ((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--version") == 0)) { - extern const char *Version_string; printf("GNU pre-grohtml (groff) version %s\n", Version_string); exit(0); } else if ((strcmp(argv[i], "-h") == 0) @@ -1034,7 +1340,7 @@ int scanArguments (int argc, char **argv) || (strcmp(argv[i], "-?") == 0)) { usage(stdout); exit(0); - } else if (strcmp(argv[i], "troff") == 0) { + } else if (strcmp(argv[i], troff_command) == 0) { /* remember troff argument number */ troff_arg = i; #if defined(DEBUGGING) @@ -1053,7 +1359,7 @@ int scanArguments (int argc, char **argv) * makeTempFiles - name the temporary files */ -static void makeTempFiles (void) +static int makeTempFiles (void) { #if defined(DEBUGGING) psFileName = "/tmp/prehtml-ps"; @@ -1062,10 +1368,21 @@ static void makeTempFiles (void) troffFileName = "/tmp/prehtml-troff"; htmlFileName = "/tmp/prehtml-html"; #else - psFileName = mktemp(xtmptemplate("-ps-")); - regionFileName = mktemp(xtmptemplate("-regions-")); - imagePageStem = mktemp(xtmptemplate("-page-")); + int fd; + + if ((fd = mkstemp(psFileName = xtmptemplate(PS_TEMPLATE))) == -1) { + sys_fatal("mkstemp"); + return -1; + } + close(fd); + if ((fd = mkstemp(regionFileName = xtmptemplate(REGION_TEMPLATE))) == -1) { + sys_fatal("mkstemp"); + unlink(psFileName); + return -1; + } + close(fd); #endif + return 0; } /* @@ -1075,8 +1392,8 @@ static void makeTempFiles (void) static void removeTempFiles (void) { #if !defined(DEBUGGING) - remove(psFileName); - remove(regionFileName); + unlink(psFileName); + unlink(regionFileName); #endif } @@ -1091,6 +1408,9 @@ static void findPrefix (void) if (!command_prefix) command_prefix = PROG_PREFIX; troff_command = (char *)malloc(strlen("troff")+strlen(command_prefix)+1); + if (troff_command == NULL) + sys_fatal("malloc"); + strcpy(troff_command, command_prefix); strcat(troff_command, "troff"); } @@ -1104,8 +1424,9 @@ int main(int argc, char **argv) int ok=1; findPrefix(); - makeFileName(); i = scanArguments(argc, argv); + checkImageDir(); + makeFileName(); while (i < argc) { if (argv[i][0] != '-') { /* found source file */ @@ -1123,13 +1444,16 @@ int main(int argc, char **argv) if (! found) { do_file("-"); } - makeTempFiles(); + if (makeTempFiles()) + return 1; ok = inputFile.do_image(argc, argv); if (ok == 0) { - createAllPages(); - generateImages(regionFileName); - ok = inputFile.do_html(argc, argv); - removeAllPages(); + ok = createAllPages(); + if (ok == 0) { + generateImages(regionFileName); + ok = inputFile.do_html(argc, argv); + removeAllPages(); + } } removeTempFiles(); return ok; @@ -1155,6 +1479,6 @@ static int do_file(const char *filename) if (fp != stdin) fclose(fp); - current_filename = 0; + current_filename = NULL; return 1; } diff --git a/contrib/groff/src/preproc/html/pushbackbuffer.cc b/contrib/groff/src/preproc/html/pushbackbuffer.cc index 1d380f4..4bea451 100644 --- a/contrib/groff/src/preproc/html/pushbackbuffer.cc +++ b/contrib/groff/src/preproc/html/pushbackbuffer.cc @@ -48,7 +48,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ # define FALSE (1==0) #endif -# define ERROR(X) (fprintf(stderr, "%s:%d error %s\n", __FILE__, __LINE__, X) && \ +# define ERROR(X) (void)(fprintf(stderr, "%s:%d error %s\n", __FILE__, __LINE__, X) && \ (fflush(stderr)) && localexit(1)) @@ -195,7 +195,6 @@ int pushBackBuffer::isString (char *s) { int length=strlen(s); int i=0; - int j; while ((i<length) && (putPB(getPB())==s[i])) { if (getPB() != s[i]) { @@ -230,10 +229,12 @@ static int isDigit (char ch) * isHexDigit - returns TRUE if the character, ch, is a hex digit. */ +#if 0 static int isHexDigit (char ch) { return( (isDigit(ch)) || ((ch>='a') && (ch<='f')) ); } +#endif /* * readInt - returns an integer from the input stream. diff --git a/contrib/groff/src/preproc/pic/main.cc b/contrib/groff/src/preproc/pic/main.cc index 87d2b93..b795d48 100644 --- a/contrib/groff/src/preproc/pic/main.cc +++ b/contrib/groff/src/preproc/pic/main.cc @@ -21,6 +21,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "pic.h" extern int yyparse(); +extern "C" const char *Version_string; output *out; @@ -568,7 +569,6 @@ int main(int argc, char **argv) break; case 'v': { - extern const char *Version_string; printf("GNU pic (groff) version %s\n", Version_string); exit(0); break; diff --git a/contrib/groff/src/preproc/pic/pic.cc b/contrib/groff/src/preproc/pic/pic.cc index f6d97bb..6e6c527 100644 --- a/contrib/groff/src/preproc/pic/pic.cc +++ b/contrib/groff/src/preproc/pic/pic.cc @@ -1,6 +1,6 @@ #ifndef lint /*static char yysccsid[] = "from: @(#)yaccpar 1.9 (Berkeley) 02/21/93";*/ -static char yyrcsid[] = "$Id: pic.cc,v 1.3 2000/11/14 20:40:28 wlemb Exp $"; +static char yyrcsid[] = "$Id: pic.cc,v 1.4 2001/04/19 14:01:55 wlemb Exp $"; #endif #define YYBYACC 1 #define YYMAJOR 1 @@ -3217,7 +3217,8 @@ void define_variable(const char *name, double val) if (strcmp(name, "scale") == 0) { // When the scale changes, reset all scaled pre-defined variables to // their default values. - for (int i = 0; i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) + for (unsigned int i = 0; + i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) if (defaults_table[i].scaled) define_variable(defaults_table[i].name, val*defaults_table[i].val); } @@ -3236,7 +3237,8 @@ void parse_init() void reset(const char *nm) { - for (int i = 0; i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) + for (unsigned int i = 0; + i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) if (strcmp(nm, defaults_table[i].name) == 0) { double val = defaults_table[i].val; if (defaults_table[i].scaled) { @@ -3256,7 +3258,8 @@ void reset_all() // aren't scaled because `scale' is not scaled, and changing the // value of `scale' will reset all the pre-defined variables that // are scaled. - for (int i = 0; i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) + for (unsigned int i = 0; + i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) if (!defaults_table[i].scaled) define_variable(defaults_table[i].name, defaults_table[i].val); } diff --git a/contrib/groff/src/preproc/pic/pic.man b/contrib/groff/src/preproc/pic/pic.man index e187021..ea53074 100644 --- a/contrib/groff/src/preproc/pic/pic.man +++ b/contrib/groff/src/preproc/pic/pic.man @@ -1,5 +1,5 @@ -.ig \"-*- nroff -*- -Copyright (C) 1989-2000 Free Software Foundation, Inc. +.ig +Copyright (C) 1989-2000, 2001 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -881,3 +881,7 @@ is incompatible with the pic in 10th edition Unix, which interprets 0 as black and 1 as white. .LP PostScript\*R is a registered trademark of Adobe Systems Incorporation. +. +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/contrib/groff/src/preproc/pic/pic.y b/contrib/groff/src/preproc/pic/pic.y index 38b960a..c0a7315 100644 --- a/contrib/groff/src/preproc/pic/pic.y +++ b/contrib/groff/src/preproc/pic/pic.y @@ -1,4 +1,5 @@ -/* Copyright (C) 1989, 1990, 1991, 1992, 2000 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001 + Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -1622,7 +1623,8 @@ void define_variable(const char *name, double val) if (strcmp(name, "scale") == 0) { // When the scale changes, reset all scaled pre-defined variables to // their default values. - for (int i = 0; i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) + for (unsigned int i = 0; + i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) if (defaults_table[i].scaled) define_variable(defaults_table[i].name, val*defaults_table[i].val); } @@ -1641,7 +1643,8 @@ void parse_init() void reset(const char *nm) { - for (int i = 0; i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) + for (unsigned int i = 0; + i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) if (strcmp(nm, defaults_table[i].name) == 0) { double val = defaults_table[i].val; if (defaults_table[i].scaled) { @@ -1661,7 +1664,8 @@ void reset_all() // aren't scaled because `scale' is not scaled, and changing the // value of `scale' will reset all the pre-defined variables that // are scaled. - for (int i = 0; i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) + for (unsigned int i = 0; + i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) if (!defaults_table[i].scaled) define_variable(defaults_table[i].name, defaults_table[i].val); } diff --git a/contrib/groff/src/preproc/refer/command.cc b/contrib/groff/src/preproc/refer/command.cc index 004189e..bf88c89d 100644 --- a/contrib/groff/src/preproc/refer/command.cc +++ b/contrib/groff/src/preproc/refer/command.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2001 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -755,7 +755,8 @@ static int check_args(const char *types, const char *name, static void execute_command(const char *name, int argc, argument *argv) { - for (int i = 0; i < sizeof(command_table)/sizeof(command_table[0]); i++) + for (unsigned int i = 0; + i < sizeof(command_table)/sizeof(command_table[0]); i++) if (strcmp(name, command_table[i].name) == 0) { if (check_args(command_table[i].arg_types, name, argc, argv)) (*command_table[i].func)(argc, argv); diff --git a/contrib/groff/src/preproc/refer/ref.cc b/contrib/groff/src/preproc/refer/ref.cc index c3517b1..9c04078 100644 --- a/contrib/groff/src/preproc/refer/ref.cc +++ b/contrib/groff/src/preproc/refer/ref.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2001 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -327,13 +327,13 @@ void sortify_title(const char *s, int len, string &key) break; } if (ptr < end) { - int first_word_len = ptr - s - 1; + unsigned int first_word_len = ptr - s - 1; const char *ae = articles.contents() + articles.length(); for (const char *a = articles.contents(); a < ae; a = strchr(a, '\0') + 1) if (first_word_len == strlen(a)) { - int j; + unsigned int j; for (j = 0; j < first_word_len; j++) if (a[j] != cmlower(s[j])) break; @@ -951,7 +951,7 @@ static int find_month(const char *start, const char *end) while (ptr < end && csalpha(*ptr)) ptr++; if (ptr - start >= 3) { - for (int i = 0; i < sizeof(months)/sizeof(months[0]); i++) { + for (unsigned int i = 0; i < sizeof(months)/sizeof(months[0]); i++) { const char *q = months[i]; const char *p = start; for (; p < ptr; p++, q++) diff --git a/contrib/groff/src/preproc/refer/refer.cc b/contrib/groff/src/preproc/refer/refer.cc index b6cefc5..c39def7 100644 --- a/contrib/groff/src/preproc/refer/refer.cc +++ b/contrib/groff/src/preproc/refer/refer.cc @@ -25,6 +25,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "search.h" #include "command.h" +extern "C" const char *Version_string; + const char PRE_LABEL_MARKER = '\013'; const char POST_LABEL_MARKER = '\014'; const char LABEL_MARKER = '\015'; // label_type is added on @@ -344,7 +346,6 @@ int main(int argc, char **argv) } if (strcmp(opt,"-version")==0) { case 'v': - extern const char *Version_string; printf("GNU refer (groff) version %s\n", Version_string); exit(0); break; diff --git a/contrib/groff/src/preproc/refer/refer.man b/contrib/groff/src/preproc/refer/refer.man index 13708cf..d8468bb 100644 --- a/contrib/groff/src/preproc/refer/refer.man +++ b/contrib/groff/src/preproc/refer/refer.man @@ -1,5 +1,5 @@ -.ig \"-*- nroff -*- -Copyright (C) 1989-2000 Free Software Foundation, Inc. +.ig +Copyright (C) 1989-2000, 2001 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -1300,3 +1300,7 @@ In label expressions, expressions are ignored inside .BI . char expressions. +. +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/contrib/groff/src/preproc/refer/token.cc b/contrib/groff/src/preproc/refer/token.cc index 1cf6890..e9fac5d 100644 --- a/contrib/groff/src/preproc/refer/token.cc +++ b/contrib/groff/src/preproc/refer/token.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2001 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -181,7 +181,7 @@ const token_info *lookup_token(const char *start, const char *end) for (;;) { if (token_table[n].tok == 0) break; - if (strlen(token_table[n].tok) == end - start + if (strlen(token_table[n].tok) == size_t(end - start) && memcmp(token_table[n].tok, start, end - start) == 0) return &(token_table[n].ti); if (n == 0) diff --git a/contrib/groff/src/preproc/soelim/soelim.cc b/contrib/groff/src/preproc/soelim/soelim.cc index e05f240..a604004 100644 --- a/contrib/groff/src/preproc/soelim/soelim.cc +++ b/contrib/groff/src/preproc/soelim/soelim.cc @@ -30,12 +30,13 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "stringclass.h" #include "nonposix.h" -static int include_list_length; +static size_t include_list_length; static char **include_list; int compatible_flag = 0; extern int interpret_lf_args(const char *); +extern "C" const char *Version_string; int do_file(const char *filename); @@ -77,7 +78,6 @@ int main(int argc, char **argv) switch (opt) { case 'v': { - extern const char *Version_string; printf("GNU soelim (groff) version %s\n", Version_string); exit(0); break; @@ -183,18 +183,18 @@ int do_file(const char *filename) { char *path = include_list[j]; if (0 == strcmp(path, ".")) - whole_filename = filename; + whole_filename = filename; else - whole_filename = string(path) + "/" + filename; + whole_filename = string(path) + "/" + filename; whole_filename += '\0'; errno = 0; fp = fopen(whole_filename.contents(), "r"); if (fp != 0) - break; + break; if (errno != ENOENT) { - error("can't open `%1': %2", + error("can't open `%1': %2", whole_filename.contents(), strerror(errno)); - return 0; + return 0; } } if (j >= include_list_length) diff --git a/contrib/groff/src/preproc/soelim/soelim.man b/contrib/groff/src/preproc/soelim/soelim.man index b97ea61..cf363d5 100644 --- a/contrib/groff/src/preproc/soelim/soelim.man +++ b/contrib/groff/src/preproc/soelim/soelim.man @@ -1,5 +1,5 @@ -.ig \"-*- nroff -*- -Copyright (C) 1989-2000 Free Software Foundation, Inc. +.ig +Copyright (C) 1989-2000, 2001 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -83,3 +83,7 @@ No directory search is performed for files specified using an absolute path. Print the version number. .SH "SEE ALSO" .BR groff (@MAN1EXT@) +. +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/contrib/groff/src/preproc/tbl/main.cc b/contrib/groff/src/preproc/tbl/main.cc index a08ea0b..b1b14a7 100644 --- a/contrib/groff/src/preproc/tbl/main.cc +++ b/contrib/groff/src/preproc/tbl/main.cc @@ -25,6 +25,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define MAX_POINT_SIZE 99 #define MAX_VERTICAL_SPACING 72 +extern "C" const char *Version_string; + static int compatible_flag = 0; class table_input { @@ -731,7 +733,7 @@ format *process_format(table_input &in, options *opt, int pre_vline = 0; int got_format = 0; int got_period = 0; - format_type t; + format_type t = FORMAT_LEFT; for (;;) { if (c == EOF) { error("end of input while processing format"); @@ -1470,7 +1472,6 @@ int main(int argc, char **argv) break; case 'v': { - extern const char *Version_string; printf("GNU tbl (groff) version %s\n", Version_string); exit(0); break; diff --git a/contrib/groff/src/preproc/tbl/tbl.man b/contrib/groff/src/preproc/tbl/tbl.man index 6016ddf..42dac25 100644 --- a/contrib/groff/src/preproc/tbl/tbl.man +++ b/contrib/groff/src/preproc/tbl/tbl.man @@ -1,5 +1,5 @@ -.ig \"-*- nroff -*- -Copyright (C) 1989-1995 Free Software Foundation, Inc. +.ig +Copyright (C) 1989-1995, 2001 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -176,3 +176,7 @@ A\e*a;B .SH "SEE ALSO" .BR groff (@MAN1EXT@), .BR @g@troff (@MAN1EXT@) +. +.\" Local Variables: +.\" mode: nroff +.\" End: |