diff options
author | wlemb <wlemb> | 2000-06-18 10:13:50 +0000 |
---|---|---|
committer | wlemb <wlemb> | 2000-06-18 10:13:50 +0000 |
commit | 0970054b23ca95cd320c2b2e88f813d71398ada3 (patch) | |
tree | ae63d1b17504d1f5f262bdd1baa8bb2e9e7892ce /src/utils | |
parent | d98dd82860df3e6e59efbe4c102dbcf2e7da573b (diff) | |
download | groff-0970054b23ca95cd320c2b2e88f813d71398ada3.tar.gz |
* src/utils/tfmtodit/tfmtodit.cc: #include nonposix.h.
(tfm::load, gf::load): Open tfm and gf files in binary mode: these
are binary files.
(main): Support non-Posix systems with several different styles of
slash characters in file names.
* src/utils/pfbtops/pfbtops.c: #include nonposix.h.
(main) [SET_BINARY]: Switch stdin into binary mode.
* src/utils/indxbib/indxbib.cc: #include nonposix.h.
(main): Support file names with several possible slash-type
characters, as given by DIR_SEPS[] in nonposix.h.
(main) [__MSDOS__]: If renaming the temporary index file fails
because it has more than one dot in its trunk, replace the dot
with an underscore and try again.
(do_file): Use FOPEN_RB instead of "r". Skip every CR before a
Newline.
[__MSDOS__ || _MSC_VER]: Stop at the first ^Z character.
* src/utils/hpftodit/hpftodit.cc: #include nonposix.h.
(File::File): Open the input file in binary mode. Strip CR
characters from each CR-LF pair.
(xbasename): Support file names with several possible slash-type
characters, as given by DIR_SEPS[] in nonposix.h.
* src/include/Makefile.sub (HDRS): Add nonposix.h.
* src/roff/troff/node.cc [HAVE_UNISTD_H]: Include <unistd.h>.
(WIFEXITED, WEXITSTATUS, WTERMSIG, WIFSTOPPED, WSTOPSIG)
[!_POSIX_VERSION]: Define for traditional Unix systems.
(real_output_file::real_output_file): Remove the MSVC-specific
call to popen, use instead POPEN_WT, appropriately defined on
nonposix.h. #include nonposix.h.
(real_output_file::~real_output_file): Remove the MSVC-specific
call to pclose, a suitable macro is now defined on nonposix.h.
Use the portable macros WIFEXITED, WIFSIGNALED, WTERMSIG, WSTOPSIG
and WEXITSTATUS instead of assuming traditional Unix
interpretation of the status returned by pclose.
* src/roff/troff/input.cc (pipe_source): Remove the MSVC-specific
call to popen, use POPEN_RT instead (appropriately defined on
nonposix.h). #include nonposix.h.
(ps_bbox_request): Open the PostScript file in binary mode.
Close the file after processing it.
(getpid) [_MSC_VER]: Remove; a suitable macro is now defined on
nonposix.h.
* src/roff/groff/pipeline.c (run_pipeline) [__MSDOS__ || _WIN32]:
A version of run_pipeline that doesn't use `fork'.
(signal_catcher) [__MSDOS__ || _WIN32]: New function.
(system_shell_name, system_shell_dash_c)
(is_system_shell) [__MSDOS__ || _WIN32]: New functions, to hide
the ugliness of testing DOS/Windows file names for equality, and
support both stock shells and ports of Unix shells.
* src/roff/groff/groff.cc: #include nonposix.h.
(BSHELL): Definition moved to nonposix.h.
(main): Use PATH_SEP[0] instead of literal ':'. Use BSHELL_DASH_C
instead of a literal "-c".
(xbasename): Support file names with several possible slash-type
characters, as given by DIR_SEPS[] in nonposix.h.
(possible_command::print): Use BSHELL_DASH_C and IS_BSHELL instead
of literal strings.
* src/preproc/soelim/soelim.cc: #include nonposix.h.
(do_file): Use IS_ABSOLUTE instead of testing for a literal '/'.
* src/preproc/pic/Makefile.sub (YTABH): Change pic.tab.h to
pic_tab.h.
* src/preproc/pic/lex.cc: Change pic.tab.h to pic_tab.h.
* src/preproc/eqn/Makefile.sub (YTABH): Rename eqn.tab.h to
eqn_tab.h.
* src/preproc/eqn/lex.cc: #include eqn_tab.h, not eqn.tab.h.
* src/libs/libgroff/tmpfile.cc (DEFAULT_TMPDIR) [P_tmpdir]: If
P_tmpdir is defined, use it instead of the literal "/tmp".
(remove_tmp_files, add_tmp_file): New functions.
(xtmpfile): Record temporary files and register an atexit function
to delete them explicitly, instead of relying on the OS to do
that, which doesn't work on non-Unix systems.
* src/libs/libgroff/searchpath.cc: #include nonposix.h.
(search_path::search_path): Use PATH_SEP instead of a literal
colon.
(search_path::command_line_dir): Ditto.
(search_path::open_file): Use IS_ABSOLUTE, PATH_SEP and DIR_SEPS,
to support non-Posix systems.
* src/libc/libbib/search.cc: #include nonposix.h.
(search_list::add_file): Open the file in binary mode.
* src/libs/libbib/linear.cc: #include nonposix.h.
(file_buffer::load): Remove r characters preceding n from the
loaded buffer.
* src/libs/libbib/index.cc: #include nonposix.h.
(make_index_search_item): Open index_filename in O_BINARY mode.
(index_search_item_iterator::get_tag): Ditto. Remove r
characters before n characters.
(index_search_item::check_files): Open files in binary mode.
(index_search_item::munge_filename): Support DOS-style file names
with backslashes and drive letters, use IS_ABSOLUTE.
* src/devices/grops/ps.cc: #include nonposix.h.
(main) [SET_BINARY]: Switch stdout to binary mode.
* src/devices/grolj4/lj4.cc: #include nonposix.h.
(main) [SET_BINARY]: Switch stdout to binary mode.
* src/devices/grolbp/lbp.cc: #include nonposix.h
(fill_pattern) [SET_BINARY]: Switch stdout to binary mode.
* src/devices/grodvi/dvi.cc: #include nonposix.h.
[_MSC_VER]: Remove inclusion of Windows-specific headers (done by
nonposix.h).
(main) [SET_BINARY]: Switch stdout to binary mode.
[_MSC_VER]: Remove an explicit call to _setmode.
* src/include/nonposix.h: New file.
* Makefile.in (ENVSETUP): New variable, to set up case-sensitive
operation when building with DJGPP.
($(TARGETS), dot, $(LIBDIRS), $(CPROGDIRS), $(CCPROGDIRS))
($(DEVDIRS), $(TTYDEVDIRS), $(INCDIRS), $(OTHERDIRS)): Use
ENVSETUP.
* Makefile.comm: mv y.tab.[ch] to y_tab.[ch], to make it work on
MS-DOS.
(.man.n): Replace `;' with `|', since FONTPATH, MACROPATH,
etc. can include a semi-colon on DOS/Windows.
(depend.temp): Use depend1.temp instead of depend.temp1, to
prevent files from overerwiting each other on 8+3 filesystems.
* gendef.sh (t): Change definition to work with DOS/Windows.
doc/groff.texinfo: Apart of some typo corrections, I also changed
some index entris, to make them more non-ambiguous, and also put
@ignore around some parts that are not yet written, to allow the
Info output be readable.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/hpftodit/hpftodit.cc | 37 | ||||
-rw-r--r-- | src/utils/indxbib/indxbib.cc | 50 | ||||
-rw-r--r-- | src/utils/pfbtops/pfbtops.c | 5 | ||||
-rw-r--r-- | src/utils/tfmtodit/tfmtodit.cc | 18 |
4 files changed, 101 insertions, 9 deletions
diff --git a/src/utils/hpftodit/hpftodit.cc b/src/utils/hpftodit/hpftodit.cc index af0738c4..2e5978c1 100644 --- a/src/utils/hpftodit/hpftodit.cc +++ b/src/utils/hpftodit/hpftodit.cc @@ -39,6 +39,7 @@ put filename in error messages (or fix lib) #include "errarg.h" #include "error.h" #include "cset.h" +#include "nonposix.h" #define SIZEOF(v) (sizeof(v)/sizeof(v[0])) @@ -273,7 +274,9 @@ void usage() File::File(const char *s) { - int fd = open(s, O_RDONLY); + // We need to read the file in binary mode because hpftodit relies + // on byte counts. + int fd = open(s, O_RDONLY | O_BINARY); if (fd < 0) fatal("cannot open `%1': %2", s, strerror(errno)); current_filename = s; @@ -290,6 +293,24 @@ File::File(const char *s) fatal("read unexpected number of bytes"); ptr_ = buf_; end_ = buf_ + sb.st_size; + // These are actually text files, so we must get rid of the `\r' + // characters. This is also enabled for Posix systems, in case the + // input came from Windows... + unsigned char *p = buf_, *q = buf_; + while (q < end_) + { + if (*q == '\r') + { + if (*++q != '\n') + *p++ = '\r'; + } +#if defined(__MSDOS__) || defined(_MSC_VER) + if (*q == '\032') // ^Z means ``software EOF'' + break; +#endif + *p++ = *q++; + } + end_ = p; } void File::skip(int n) @@ -774,6 +795,18 @@ int read_map(const char *file) static const char *xbasename(const char *s) { - const char *b = strrchr(s, '/'); + // DIR_SEPS[] are possible directory separator characters, see + // nonposix.h. We want the rightmost separator of all possible + // ones. Example: d:/foo\\bar. + const char *b = strrchr(s, DIR_SEPS[0]), *b1; + const char *sep = &DIR_SEPS[1]; + + while (*sep) + { + b1 = strrchr(s, *sep); + if (b1 && (!b || b1 > b)) + b = b1; + sep++; + } return b ? b + 1 : s; } diff --git a/src/utils/indxbib/indxbib.cc b/src/utils/indxbib/indxbib.cc index 4b28d983..bd4780d7 100644 --- a/src/utils/indxbib/indxbib.cc +++ b/src/utils/indxbib/indxbib.cc @@ -35,6 +35,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "defs.h" #include "index.h" +#include "nonposix.h" + extern "C" { // Sun's stdlib.h fails to declare this. char *mktemp(char *); @@ -198,7 +200,15 @@ int main(int argc, char **argv) read_common_words_file(); if (!basename) basename = optind < argc ? argv[optind] : DEFAULT_INDEX_NAME; - const char *p = strrchr(basename, '/'); + const char *p = strrchr(basename, DIR_SEPS[0]), *p1; + const char *sep = &DIR_SEPS[1]; + while (*sep) + { + p1 = strrchr(basename, *sep); + if (p1 && (!p || p1 > p)) + p = p1; + sep++; + } long name_max; if (p) { char *dir = strsave(basename); @@ -232,7 +242,7 @@ int main(int argc, char **argv) #endif if (fd < 0) fatal("can't create temporary index file: %1", strerror(errno)); - indxfp = fdopen(fd, "w"); + indxfp = fdopen(fd, FOPEN_WB); if (indxfp == 0) fatal("fdopen failed"); if (fseek(indxfp, sizeof(index_header), 0) < 0) @@ -281,7 +291,22 @@ int main(int argc, char **argv) strcat(index_file, INDEX_SUFFIX); #ifdef HAVE_RENAME if (rename(temp_index_file, index_file) < 0) - fatal("can't rename temporary index file: %1", strerror(errno)); + { +#ifdef __MSDOS__ + // RENAME could fail on plain MSDOS filesystems because + // INDEX_FILE is an invalid filename, e.g. it has multiple dots. + char *fname = p ? index_file + (p - basename) : 0; + char *dot = 0; + + // Replace the dot with an underscore and try again. + if (fname + && (dot = strchr(fname, '.')) != 0 + && strcmp(dot, INDEX_SUFFIX) != 0) + *dot = '_'; + if (rename(temp_index_file, index_file) < 0) +#endif + fatal("can't rename temporary index file: %1", strerror(errno)); + } #else /* not HAVE_RENAME */ ignore_fatal_signals(); if (unlink(index_file) < 0) { @@ -429,7 +454,9 @@ static int do_whole_file(const char *filename) static int do_file(const char *filename) { errno = 0; - FILE *fp = fopen(filename, "r"); + // Need binary I/O for MS-DOS/MS-Windows, because indxbib relies on + // byte counts to be consistent with fseek. + FILE *fp = fopen(filename, FOPEN_RB); if (fp == 0) { error("can't open `%1': %2", filename, strerror(errno)); return 0; @@ -459,6 +486,21 @@ static int do_file(const char *filename) int c = getc(fp); if (c == EOF) break; + // We opened the file in binary mode, so we need to skip + // every CR character before a Newline. + if (c == '\r') { + int peek = getc(fp); + if (peek = '\n') { + byte_count++; + c = peek; + } + else + ungetc(peek, fp); + } +#if defined(__MSDOS__) || defined(_MSC_VER) + else if (c == 0x1a) // ^Z means EOF in text files + break; +#endif byte_count++; switch (state) { case START: diff --git a/src/utils/pfbtops/pfbtops.c b/src/utils/pfbtops/pfbtops.c index ece8193a..9aaeeccf 100644 --- a/src/utils/pfbtops/pfbtops.c +++ b/src/utils/pfbtops/pfbtops.c @@ -3,6 +3,8 @@ #include <stdio.h> #include <getopt.h> +#include "nonposix.h" + /* Binary bytes per output line. */ #define BYTES_PER_LINE (64/2) #define HEX_DIGITS "0123456789abcdef" @@ -52,6 +54,9 @@ int main(argc, argv) perror(argv[optind]); exit(1); } +#ifdef SET_BINARY + SET_BINARY(fileno(stdin)); +#endif for (;;) { int type, c, i; diff --git a/src/utils/tfmtodit/tfmtodit.cc b/src/utils/tfmtodit/tfmtodit.cc index 16752742..ab3ab38f 100644 --- a/src/utils/tfmtodit/tfmtodit.cc +++ b/src/utils/tfmtodit/tfmtodit.cc @@ -57,6 +57,7 @@ both be zero. */ #include "error.h" #include "assert.h" #include "cset.h" +#include "nonposix.h" /* Values in the tfm file should be multiplied by this. */ @@ -273,7 +274,7 @@ int read4(unsigned char *&s) int tfm::load(const char *file) { errno = 0; - FILE *fp = fopen(file, "r"); + FILE *fp = fopen(file, FOPEN_RB); if (!fp) { error("can't open `%1': %2", file, strerror(errno)); return 0; @@ -413,7 +414,7 @@ int gf::load(const char *file) int left_adj, right_adj; const int gf_id_byte = 131; errno = 0; - FILE *fp = fopen(file, "r"); + FILE *fp = fopen(file, FOPEN_RB); if (!fp) { error("can't open `%1': %2", file, strerror(errno)); return 0; @@ -750,7 +751,18 @@ int main(int argc, char **argv) int len = strlen(internal_name); if (len > 4 && strcmp(internal_name + len - 4, ".tfm") == 0) internal_name[len - 4] = '\0'; - char *s = strrchr(internal_name, '/'); + // DIR_SEPS[] are possible directory separator characters, see nonposix.h. + // We want the rightmost separator of all possible ones. + // Example: d:/foo\\bar. + const char *s = strrchr(internal_name, DIR_SEPS[0]), *s1; + const char *sep = &DIR_SEPS[1]; + while (*sep) + { + s1 = strrchr(internal_name, *sep); + if (s1 && (!s || s1 > s)) + s = s1; + sep++; + } printf("internalname %s\n", s ? s + 1 : internal_name); int n; if (t.get_param(2, &n)) { |