From 6e50d833f02cc5554d16f43bac0ca610db6b403f Mon Sep 17 00:00:00 2001 From: wlemb Date: Wed, 4 Jul 2001 22:50:37 +0000 Subject: * src/utils/indxbib/dirnamemax.c: Moved to ... * src/libs/libgroff/maxfilename.cc: Here. s/dir_name_max/file_name_max/. Add copyright. * src/include/lib.h: Add file_name_max. * src/utils/indxbib/indxbib.cc: Updated. * src/utils/indxbib/Makefile.sub, src/libs/libgroff/Makefile.sub: Updated. * src/libs/libgroff/tmpfile.cc (TMPFILE_PREFIX) [__MSDOS__]: Define as empty. (xtmpfile) [_MSC_VER]: Removed -- MSVC has mktemp(). * src/preproc/html/pre-html.cc (PAGE_TEMPLATE, PS_TEMPLATE, REGION_TEMPLATE): New macros. (createAllPages, makeTempFiles): Use them. Include `nonposix.h'. (html_system): New function. (createAllPages, createImage): Use it. Use EXE_EXT. * tmac/www.tmac: Fix typos. --- ChangeLog | 25 ++++++++++++++++++ src/include/lib.h | 6 +++-- src/libs/libgroff/Makefile.sub | 2 ++ src/libs/libgroff/tmpfile.cc | 34 +++++++----------------- src/preproc/html/pre-html.cc | 60 ++++++++++++++++++++++++++++++++++++------ src/utils/indxbib/Makefile.sub | 2 -- src/utils/indxbib/indxbib.cc | 5 ++-- tmac/www.tmac | 4 +-- 8 files changed, 96 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0468a70a..83dd52b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2001-07-04 Werner LEMBERG + + * src/utils/indxbib/dirnamemax.c: Moved to ... + * src/libs/libgroff/maxfilename.cc: Here. + s/dir_name_max/file_name_max/. + Add copyright. + * src/include/lib.h: Add file_name_max. + * src/utils/indxbib/indxbib.cc: Updated. + * src/utils/indxbib/Makefile.sub, src/libs/libgroff/Makefile.sub: + Updated. + + * src/libs/libgroff/tmpfile.cc (TMPFILE_PREFIX) [__MSDOS__]: Define + as empty. + (xtmpfile) [_MSC_VER]: Removed -- MSVC has mktemp(). + + * src/preproc/html/pre-html.cc (PAGE_TEMPLATE, PS_TEMPLATE, + REGION_TEMPLATE): New macros. + (createAllPages, makeTempFiles): Use them. + Include `nonposix.h'. + (html_system): New function. + (createAllPages, createImage): Use it. + Use EXE_EXT. + + * tmac/www.tmac: Fix typos. + 2001-07-03 Werner LEMBERG * tmac/www.tmac: Disable hyphenation in normal text only if output diff --git a/src/include/lib.h b/src/include/lib.h index b456fadb..db5277c0 100644 --- a/src/include/lib.h +++ b/src/include/lib.h @@ -43,8 +43,8 @@ int is_prime(unsigned); #include #endif -FILE *xtmpfile(char **namep=0, char *postfix=0, int do_unlink=1); -char *xtmptemplate(char *extension=0); +FILE *xtmpfile(char **namep = 0, char *postfix = 0, int do_unlink = 1); +char *xtmptemplate(char *extension = 0); #ifdef NEED_DECLARATION_POPEN @@ -58,6 +58,8 @@ extern "C" { int pclose (FILE *); } #endif /* NEED_DECLARATION_PCLOSE */ +size_t file_name_max(const char *fname); + int interpret_lf_args(const char *p); extern char illegal_char_table[]; diff --git a/src/libs/libgroff/Makefile.sub b/src/libs/libgroff/Makefile.sub index 6368f41f..ff5c655c 100644 --- a/src/libs/libgroff/Makefile.sub +++ b/src/libs/libgroff/Makefile.sub @@ -18,6 +18,7 @@ OBJS=\ lf.o \ lineno.o \ macropath.o \ + maxfilename.o \ nametoindex.o \ new.o \ prime.o \ @@ -49,6 +50,7 @@ CCSRCS=\ $(srcdir)/lf.cc \ $(srcdir)/lineno.cc \ $(srcdir)/macropath.cc \ + $(srcdir)/maxfilename.cc \ $(srcdir)/nametoindex.cc \ $(srcdir)/new.cc \ $(srcdir)/prime.cc \ diff --git a/src/libs/libgroff/tmpfile.cc b/src/libs/libgroff/tmpfile.cc index cf2bb8b1..8508c595 100644 --- a/src/libs/libgroff/tmpfile.cc +++ b/src/libs/libgroff/tmpfile.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. @@ -47,7 +48,11 @@ extern "C" { # define DEFAULT_TMPDIR "/tmp" #endif // Use this as the prefix for temporary filenames. -#define TMPFILE_PREFIX "groff" +#ifdef __MSDOS__ +#define TMPFILE_PREFIX "" +#else +#define TMPFILE_PREFIX "groff" +#endif /* * Generate a temporary name template with a postfix @@ -131,8 +136,6 @@ static void add_tmp_file(const char *name) // Open a temporary file and with fatal error on failure. -#ifndef _MSC_VER - FILE *xtmpfile(char **namep, char *postfix, int do_unlink) { char *templ = xtmptemplate(postfix); @@ -156,28 +159,9 @@ FILE *xtmpfile(char **namep, char *postfix, int do_unlink) #endif /* not HAVE_MKSTEMP */ if (do_unlink) add_tmp_file(templ); - if ((namep != 0) && ((*namep) != 0)) { + if ((namep != 0) && ((*namep) != 0)) *namep = templ; - } else { + else a_delete templ; - } - return fp; -} - -#else - -// FIXME: does MSVC have mktemp or mkstemp? If so, it should now -// use the version above, as it no longer removes an open file. -// The version below will NOT work with grohtml, since grohtml -// wants to know the name of the file opened by xtmpfile!! - -// If you're not running Unix, the following will do: -FILE *xtmpfile(char **namep, char *postfix, int do_unlink) -{ - FILE *fp = tmpfile(); - if (!fp) - fatal("couldn't create temporary file"); return fp; } - -#endif /* _MSC_VER */ diff --git a/src/preproc/html/pre-html.cc b/src/preproc/html/pre-html.cc index b41a34e1..2a36740d 100644 --- a/src/preproc/html/pre-html.cc +++ b/src/preproc/html/pre-html.cc @@ -48,6 +48,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include +#include "nonposix.h" + extern "C" const char *Version_string; #include "pre-html.h" @@ -64,6 +66,16 @@ extern "C" const char *Version_string; #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 @@ -114,7 +126,8 @@ static char *htmlFileName = NULL; // 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) @@ -122,6 +135,32 @@ void sys_fatal (const char *s) fprintf(stderr, "%s: %s: %s", program_name, s, strerror(errno)); } +/* + * 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 @@ -815,7 +854,7 @@ static int createAllPages (void) char *s; int retries = MAX_RETRIES; - imagePageStem = xtmptemplate("-page-"); + imagePageStem = xtmptemplate(PAGE_TEMPLATE); strcpy(buffer, imagePageStem); do { @@ -840,7 +879,10 @@ static int createAllPages (void) strcpy(imagePageStem, buffer); } while (1); - s = make_message("echo showpage | gs -q -dSAFER -sDEVICE=%s -r%d -sOutputFile=%s/%%d %s - > /dev/null 2>&1 \n", + s = make_message("echo showpage | " + "gs%s -q -dSAFER -sDEVICE=%s -r%d " + "-sOutputFile=%s/%%d %s -", + EXE_EXT, image_device, image_res, imagePageStem, @@ -851,7 +893,7 @@ static int createAllPages (void) fwrite(s, sizeof(char), strlen(s), stderr); fflush(stderr); #endif - system(s); + html_system(s, 1); free(s); return 0; } @@ -917,10 +959,12 @@ static void createImage (imageItem *i) 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; - s = make_message("pnmcut %d %d %d %d < %s/%d | pnmtopng %s > %s \n", + 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) @@ -929,7 +973,7 @@ static void createImage (imageItem *i) #if defined(DEBUGGING) fprintf(stderr, s); #endif - system(s); + html_system(s, 0); free(s); #if defined(DEBUGGING) } else { @@ -1326,12 +1370,12 @@ static int makeTempFiles (void) #else int fd; - if ((fd = mkstemp(psFileName = xtmptemplate("-ps-"))) == -1) { + if ((fd = mkstemp(psFileName = xtmptemplate(PS_TEMPLATE))) == -1) { sys_fatal("mkstemp"); return -1; } close(fd); - if ((fd = mkstemp(regionFileName = xtmptemplate("-regions-"))) == -1) { + if ((fd = mkstemp(regionFileName = xtmptemplate(REGION_TEMPLATE))) == -1) { sys_fatal("mkstemp"); unlink(psFileName); return -1; diff --git a/src/utils/indxbib/Makefile.sub b/src/utils/indxbib/Makefile.sub index add99eba..f45a7a79 100644 --- a/src/utils/indxbib/Makefile.sub +++ b/src/utils/indxbib/Makefile.sub @@ -4,12 +4,10 @@ XLIBS=$(LIBBIB) $(LIBGROFF) MLIB=$(LIBM) OBJS=\ indxbib.o \ - dirnamemax.o \ signal.o CCSRCS=\ $(srcdir)/indxbib.cc CSRCS=\ - $(srcdir)/dirnamemax.c \ $(srcdir)/signal.c NAMEPREFIX=$(g) diff --git a/src/utils/indxbib/indxbib.cc b/src/utils/indxbib/indxbib.cc index 358c8353..b2be9642 100644 --- a/src/utils/indxbib/indxbib.cc +++ b/src/utils/indxbib/indxbib.cc @@ -115,7 +115,6 @@ static char *get_cwd(); extern "C" { void cleanup(); - long dir_name_max(const char *); void catch_fatal_signals(); void ignore_fatal_signals(); } @@ -226,11 +225,11 @@ int main(int argc, char **argv) if (p) { char *dir = strsave(basename); dir[p - basename] = '\0'; - name_max = dir_name_max(dir); + name_max = file_name_max(dir); a_delete dir; } else - name_max = dir_name_max("."); + name_max = file_name_max("."); const char *filename = p ? p + 1 : basename; if (name_max >= 0 && long(strlen(filename) + sizeof(INDEX_SUFFIX) - 1) > name_max) diff --git a/tmac/www.tmac b/tmac/www.tmac index a19f8162..0bef6b60 100644 --- a/tmac/www.tmac +++ b/tmac/www.tmac @@ -166,7 +166,7 @@ . tl '''' \O[0]\O[1] . \} -. if \\n[www-html] .begin \{ +. if \\n[www-html] .begin \{\ . image \\$2 \\$1.png \O[0] . \} @@ -211,7 +211,7 @@ . MAKE-UNIQUE-NAME . HTML-DO-IMAGE \\*[HTML-UNIQUE-NAME] i .. -.if \\n[www-html] \{\ +.if \n[www-html] \{\ . nh . nr HY 0 .\} -- cgit v1.2.1