diff options
author | wlemb <wlemb> | 2003-10-21 12:32:03 +0000 |
---|---|---|
committer | wlemb <wlemb> | 2003-10-21 12:32:03 +0000 |
commit | 7bb589f208378e994f34b44c6a27a020635e14fb (patch) | |
tree | c8bdee92ee1aa4f649048e14a79442de433ce582 | |
parent | 5c8cf2ba47505276ee4bc94c975e9fd02d0a71c7 (diff) | |
download | groff-7bb589f208378e994f34b44c6a27a020635e14fb.tar.gz |
* src/libs/libgroff/tmpfile.cpp [__MSDOS__, _Win32]
(WIN32_TMPDIR_ENVVAR, MSDOS_TMPDIR_ENVVAR): New macros, providing
default directory names for temporary files.
[__MSDOS__, _Win32] (temp_init::temp_init): Use them.
* src/roff/groff/pipeline.c [__MSDOS__]: Include stdlib.h.
[__MSDOS__] (run_pipeline): Honour environment variables.
Don't use `tmpnam' but `tempnam' to work around messy
implementation.
* README.MinGW: New file.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | README.MinGW | 276 | ||||
-rw-r--r-- | src/libs/libgroff/tmpfile.cpp | 32 | ||||
-rw-r--r-- | src/roff/groff/pipeline.c | 19 |
4 files changed, 331 insertions, 10 deletions
@@ -1,3 +1,17 @@ +2003-10-20 Keith Marshall <keith.d.marshall@ntlworld.com> + + * src/libs/libgroff/tmpfile.cpp [__MSDOS__, _Win32] + (WIN32_TMPDIR_ENVVAR, MSDOS_TMPDIR_ENVVAR): New macros, providing + default directory names for temporary files. + [__MSDOS__, _Win32] (temp_init::temp_init): Use them. + + * src/roff/groff/pipeline.c [__MSDOS__]: Include stdlib.h. + [__MSDOS__] (run_pipeline): Honour environment variables. + Don't use `tmpnam' but `tempnam' to work around messy + implementation. + + * README.MinGW: New file. + 2003-10-16 Werner LEMBERG <wl@gnu.org> * src/preproc/html/pre-html.cpp (write_upto_newline): Don't use diff --git a/README.MinGW b/README.MinGW new file mode 100644 index 00000000..88b37e40 --- /dev/null +++ b/README.MinGW @@ -0,0 +1,276 @@ + README.MinGW + ============ + + Contributed by Keith Marshall (keith.d.marshall@ntlworld.com) + + + INTRODUCTION + ------------ + + This file provides recommendations for building a Win32 implementation of + GNU Groff, using the MinGW port of GCC for Microsoft (TM) Windows-32 + platforms. It is intended to supplement the standard installation + instructions (see file INSTALL); it does not replace them. + + You require both the MinGW implementation of GCC and its supporting MSYS + toolkit, which provides a Win-32 implementation of the GNU bash shell, and a + few other essential utilities; these may be obtained from + + http://sourceforge.net/projects/mingw + + by following the appropriate download links, where they are available as + self-extracting executable installation packages. Iif installing both from + scratch, it is recommended that MinGW is installed first, as the MSYS + installer can then automatically set up the proper environment for running + MinGW. + + Additionally, if you wish to compile groff with support for its HTML output + capability, some additional tools are required as decribed in the section + PREREQUISITES FOR HTML OUTPUT later in this file. + + + BUILDING GROFF WITH MINGW + ------------------------- + + Assuming that you have obtained the appropriate groff distribution, and that + you are already running an MSYS shell, then the configuration, compilation, + and installation of groff, using MinGW, is performed in much the same way as + it is described in the INSTALL file, which is provided with the groff + distribution. The installation steps are summarised below: + + 1. Change working directory to any suitable location where you may unpack + the groff distribution; you must be authorized for write access. + Approximately 30MB of free disk space are needed. + + 2. Unpack the groff distribution: + + tar xzf <download-path>/groff-<version>.tar.gz + + This creates a new sub-directory, groff-<version>, containing an image of + the groff source tree. You should now change directory, to make this + ./groff-<version> your working directory. + + 3. If you are intending to build groff with support for HTML output, then + you must now ensure that the prerequisites described in the later section + PREREQUISITES FOR HTML OUTPUT are satisfied, before proceeding to build + groff; in particular, please ensure that all required support programs + are installed in the current PATH. + + 4. You are now ready to configure, build, and install groff. This is + accomplished using the conventional procedure, as described in the file + INSTALL, i.e. + + ./configure --prefix=<win32-install-path> ... + make + make install + + Please observe the syntax for the configure command, indicated above; the + default value for --prefix is not suitable for use with MinGW, so the + --prefix=<win32-install-path> option must be specified, where + <win32-install-path> is the chosen MS-Windows directory in which the + groff application files are to be installed (see the later section + entitled CHOOSING AN INSTALLATION PATH). Any other desired configuration + options may also be specified, as described in the standard groff + installation instructions. + + 5. After completing the above, groff should be successfully installed; the + build directory is no longer required; it may be simply deleted in its + entirety. Alternatively, you may choose to keep it, but to remove all + files which can be reproduced later, by repeating the configure, make and + make install steps; this is readily accomplished by the command + + make distclean + + + This completes the installation of groff; please read the final sections of + this file, GROFF RUNTIME ENVIRONMENT and CAVEATS AND BUGS, for advice on + setting up the runtime environment, and avoiding known runtime problems, + before running groff. + + + CHOOSING AN INSTALLATION PATH + ----------------------------- + + It may be noted that the above instructions indicate that the ./configure + command must be invoked with an argument specifying a preference for + --prefix=<win32-install-path>, whereas the standard groff installation + instructions indicate that this may be omitted, in which case it defaults to + --prefix=/usr/local. + + In the case of building with MinGW, the default behaviour of configure is + not appropriate for the following reasons. + + o The MSYS environment creates a virtual UNIX-like file system, with its + root mapped to the actual MS-Windows directory where MSYS itself is + installed; /usr is also mapped to this MSYS installation directory. + + o All of the MSYS tools, and the MinGW implementation of GCC, refer to files + via this virtual file system representation; thus, if the + --prefix=<win32-install-path> is not specified when groff is configured, + `make install' causes groff to be installed in <MSYS-install-path>/local. + + o groff needs to know its own installation path, so that it can locate its + own installed components. This information is compiled in, using the + exact form specified with the --prefix=<win32-install-path> option to + configure. + + o Knowledge of the MSYS virtual file system is not imparted to groff; it + expects the compiled-in path to its components to be a fully qualified + MS-Windows path name (although UNIX-style slashes are permitted, and + preferred to the MS-Windows style backslashes, to demarcate the directory + hierarchy). Thus, when configuring groff, if + --prefix=<win32-install-path> is not correctly specified, then the + installed groff application looks for its components in /usr/local, and + most likely doesn't find them, because they are actually installed in + <MSYS-install-path>/local. + + It is actually convenient, but by no means a requirement, to have groff + installed in the /usr/local directory of the MSYS virtual file system; this + makes it easy to invoke groff from the MSYS shell, since the virtual + /usr/local/bin is normally added automatically to the PATH (the default + PATH, as set in MSYS's /etc/profile), when MSYS is started. + + In order to install groff into MSYS's /usr/local directory, it is necessary + to specify the fully qualified absolute MS-Windows path to this directory, + when configuring groff, i.e. + + ./configure --prefix=<MSYS-install-path>/local ... + + For example, on a system where MSYS is installed in the MS-Windows directory + D:\MSYS\1.0, the MSYS virtual path /usr/local resolves to the absolute + MS-Windows native path D:\MSYS\1.0\local (the /usr component of the MSYS + virtual path does not appear in the resolved absolute native path name since + MSYS maps this directly to the root of the MSYS virtual file system). Thus, + the --prefix option should be specified to configure as + + ./configure --prefix=D:/MSYS/1.0/local ... + + Note that the backslash characters, which appear in the native MS-Windows + form of the path name, are replaced by UNIX-style slashes in the argument to + configure; this is the preferred syntax. + + Also note that the MS-Windows device designator (D: in this instance) is + prepended to the specified path, in the normal MS-Windows format, and that, + since upper and lower case distinctions are ignored in MS-Windows path + names, any combination of upper and lower case is acceptable. + + + PREREQUISITES FOR HTML OUTPUT + ----------------------------- + + If you intend to use groff for production of HTML output, then there are a + few dependencies which must be satisfied. Ideally, these should be resolved + before attempting to configure and build groff, since the configuration + script does check them. + + In order to produce HTML output, you first require a working implementation + of Ghostscript; either the AFPL Ghostscript or the GNU Ghostscript + implementation for MS-Windows should be suitable, depending on your + licensing preference. It is highly recommended to use version 8.11 or + higher due to bugs in older versions. These may be obtained, in the form of + self-installing binary packages, by following the download links for the + chosen licensing option, from http://sourceforge.net/projects/ghostscript. + + Please note that these packages install the Ghostscript interpreter required + by groff in the ./bin subdirectory of the Ghostscript installation + directory, with the name gswin32c.exe. However, groff expects this + interpreter to be located in the system PATH, with the name gs.exe. Thus, + to ensure that groff can correctly locate the Ghostscript interpreter, it is + recommended that the file gswin32c.exe should be copied from the Ghostscript + installation directory to the MSYS /usr/local/bin directory, where it should + be renamed to gs.exe. + + In addition to a working Ghostscript interpreter, you also require several + image manipulation utilities, all of which may be scavenged from various + packages available from http://sourceforge.net/projects/gnuwin32, and which + should be installed in the MSYS /usr/local/bin directory, or any other + suitable directory which is specified in the PATH. These additional + prerequisites are + + 1. from the netpbm-<version>-bin.zip package: + + netpbm.dll + pnmcrop.exe + pnmcut.exe + pnmtopng.exe + + 2. from the libpng-<version>-bin.zip package: + + libpng.dll + + 3. from the zlib-<version>-bin.zip package: + + zlib-1.dll, which must be renamed to zlib.dll + + 4. from the psutils-<version>-bin.zip package: + + psselect.exe + + Note that it is not necessary to install the above four packages in their + entirety; of course, you may do so if you wish. + + + GROFF RUNTIME ENVIRONMENT + ------------------------- + + The runtime environment, provided to groff by MSYS, is essentially the same + as would be provided under a UNIX or GNU/Linux operating system; thus, any + environment variables which may be used to customize the groff runtime + environment has similar effects under MSYS, as they would in UNIX or + GNU/Linux, with the exception that any variable specifying a path should + adopt the same syntax as a native MS-Windows PATH specification. + + There is, however, one known problem which is associated with the + implementation of the MS-Windows file system, and the manner in which the + Microsoft runtime library (which is used by the MinGW implementation of GCC) + generates names for temporary files. This known problem arises when groff + is invoked with a current working directory which refers to a network share, + for which the user does not have write access in the root directory, and + there is no environment variable set to define a writeable location for + creating temporary files. When these conditions arise, groff fails with a + `permission denied' error, as soon as it tries to create any temporary file. + + To specify the location for creating temporary files, the standard UNIX or + GNU/Linux implementation of groff provides the GROFF_TMPDIR or TMPDIR + environment variables, whereas MS-Windows applications generally use TMP or + TEMP; furthermore, the MS-Windows implementations of Ghostscript apparently + support the use of only TEMP or TMPDIR. + + To avoid problems with creation of temporary files, it is recommended that + you ensure that both TMP and TEMP are defined, with identical values, to + point to a suitable location for creating temporary files; many MS-Windows + boxes have them set already, and groff has been adapted to honour them, when + built in accordance with the preceding instructions, using MinGW. + + + CAVEATS AND BUGS + ---------------- + + There are two known issues, observed when running groff in the MinGW/MSYS + environment, which would not affect groff in its native UNIX environment: + + o Running groff with the working directory set to a subdirectory of a + network share, where the user does not have write permission in the root + directory of the share, causes groff to fail with a `permission denied' + exception, if the TMP environment variable is not appropriately defined; + it may also be necessary to define the TEMP environment variable, to avoid + a similar failure mode, when using the -Thtml output mode of groff. This + problem is more fully discussed in the preceding section, GROFF RUNTIME + ENVIRONMENT. + + o When running groff (or nroff) to process standard input, where the + standard input stream is obtained directly from the RXVT console provided + with MSYS, groff cannot detect the end-of-file condition for the standard + input stream, and hangs. This appears to be caused by a fault in the MSYS + implementation of RXVT; it may be worked around by either starting MSYS + without RXVT (see the comments in the MSYS.BAT startup script); in this + case standard input is terminated by typing <Ctrl-Z> followed by <RETURN>, + on a new input line. Alternatively, if you prefer to use MSYS with RXVT, + you can enter the interactive groff command in the form + + cat | groff ... + + in which case <Ctrl-D> terminates the standard input stream, in just the + same way it does on a UNIX system; the cat executable provided with MSYS + does seem to trap the end-of-file condition, and properly signals groff + that the input stream has terminated. diff --git a/src/libs/libgroff/tmpfile.cpp b/src/libs/libgroff/tmpfile.cpp index 41b7f064..d24b137b 100644 --- a/src/libs/libgroff/tmpfile.cpp +++ b/src/libs/libgroff/tmpfile.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2003 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -33,6 +33,13 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define GROFF_TMPDIR_ENVVAR "GROFF_TMPDIR" // otherwise if this is set, create temporary files there #define TMPDIR_ENVVAR "TMPDIR" +// otherwise, on MS-DOS or MS-Windows ... +#if defined(__MSDOS__) || defined(_WIN32) +// if either of these is set, create temporary files there +// (giving priority to WIN32_TMPDIR_ENVVAR) +#define WIN32_TMPDIR_ENVVAR "TMP" +#define MSDOS_TMPDIR_ENVVAR "TEMP" +#endif // otherwise if P_tmpdir is defined, create temporary files there #ifdef P_tmpdir # define DEFAULT_TMPDIR P_tmpdir @@ -55,12 +62,23 @@ struct temp_init { temp_init::temp_init() { - const char *tem = getenv(GROFF_TMPDIR_ENVVAR); - if (!tem) { - tem = getenv(TMPDIR_ENVVAR); - if (!tem) - tem = DEFAULT_TMPDIR; - } + // First, choose a location for creating temporary files... + const char *tem; + // using the first match for any of the environment specs in listed order. + if ( + (tem = getenv(GROFF_TMPDIR_ENVVAR)) == NULL + && (tem = getenv(TMPDIR_ENVVAR)) == NULL +#if defined(__MSDOS__) || defined(_WIN32) + // If we didn't find a match for either of the above + // (which are preferred, regardless of the host operating system), + // and we are hosted on either MS-Windows or MS-DOS, + // then try the Microsoft conventions. + && (tem = getenv(WIN32_TMPDIR_ENVVAR)) == NULL + && (tem = getenv(MSDOS_TMPDIR_ENVVAR)) == NULL +#endif + ) + // If we didn't find an environment spec fall back to this default. + tem = DEFAULT_TMPDIR; size_t tem_len = strlen(tem); const char *tem_end = tem + tem_len - 1; int need_slash = strchr(DIR_SEPS, *tem_end) == NULL ? 1 : 0; diff --git a/src/roff/groff/pipeline.c b/src/roff/groff/pipeline.c index ed6c17ee..eaf16339 100644 --- a/src/roff/groff/pipeline.c +++ b/src/roff/groff/pipeline.c @@ -108,6 +108,7 @@ static char *i_to_a P((int)); #include <fcntl.h> #include <ctype.h> #include <string.h> +#include <stdlib.h> #include "nonposix.h" @@ -309,13 +310,25 @@ run_pipeline(int ncommands, char ***commands, int no_pipe) int save_stdin = dup(0); int save_stdout = dup(1); char *tmpfiles[2]; - char tem1[L_tmpnam], tem2[L_tmpnam]; int infile = 0; int outfile = 1; int i, f, ret = 0; - tmpfiles[0] = tmpnam(tem1); - tmpfiles[1] = tmpnam(tem2); + /* Choose names for a pair of temporary files to implement the pipeline. + Microsoft's `tempnam' uses the directory specified by `getenv("TMP")' + if it exists; in case it doesn't, try the GROFF alternatives, or + `getenv("TEMP")' as last resort -- at least one of these had better + be set, since Microsoft's default has a high probability of failure. */ + char *tmpdir; + if ((tmpdir = getenv("GROFF_TMPDIR")) == NULL + && (tmpdir = getenv("TMPDIR")) == NULL) + tmpdir = getenv("TEMP"); + + /* Don't use `tmpnam' here: Microsoft's implementation yields unusable + file names if current directory is on network share with read-only + root. */ + tmpfiles[0] = tempnam(tmpdir, NULL); + tmpfiles[1] = tempnam(tmpdir, NULL); for (i = 0; i < ncommands; i++) { int exit_status; |