diff options
author | asmodai <asmodai@FreeBSD.org> | 2000-01-12 09:51:43 +0000 |
---|---|---|
committer | asmodai <asmodai@FreeBSD.org> | 2000-01-12 09:51:43 +0000 |
commit | 2e2c9047c3a8b5b6fdcdcd4585d5b114f31cd386 (patch) | |
tree | 723c5fa18b7084a4da09e4e42000ef10cbc884fa /contrib/groff/soelim | |
parent | 35cdaa022af3f495aa21a1292d85ee40b28f86fb (diff) | |
download | FreeBSD-src-2e2c9047c3a8b5b6fdcdcd4585d5b114f31cd386.zip FreeBSD-src-2e2c9047c3a8b5b6fdcdcd4585d5b114f31cd386.tar.gz |
Virgin import of FSF groff v1.15
Diffstat (limited to 'contrib/groff/soelim')
-rw-r--r-- | contrib/groff/soelim/soelim.cc | 61 | ||||
-rw-r--r-- | contrib/groff/soelim/soelim.man | 15 |
2 files changed, 70 insertions, 6 deletions
diff --git a/contrib/groff/soelim/soelim.cc b/contrib/groff/soelim/soelim.cc index 396b010..a6f63ae 100644 --- a/contrib/groff/soelim/soelim.cc +++ b/contrib/groff/soelim/soelim.cc @@ -29,23 +29,38 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "error.h" #include "stringclass.h" +static int include_list_length; +static char **include_list; + int compatible_flag = 0; extern int interpret_lf_args(const char *); int do_file(const char *filename); + +static void +include_path_append(char *path) +{ + ++include_list_length; + size_t nbytes = include_list_length * sizeof(include_list[0]); + include_list = (char **)realloc((void *)include_list, nbytes); + include_list[include_list_length - 1] = path; +} + + void usage() { - fprintf(stderr, "usage: %s [ -vC ] [ files ]\n", program_name); + fprintf(stderr, "usage: %s [ -vC ] [ -I file ] [ files ]\n", program_name); exit(1); } int main(int argc, char **argv) { program_name = argv[0]; + include_path_append("."); int opt; - while ((opt = getopt(argc, argv, "vC")) != EOF) + while ((opt = getopt(argc, argv, "CI:v")) != EOF) switch (opt) { case 'v': { @@ -57,6 +72,9 @@ int main(int argc, char **argv) case 'C': compatible_flag = 1; break; + case 'I': + include_path_append(optarg); + break; case '?': usage(); break; @@ -125,9 +143,15 @@ void do_so(const char *line) int do_file(const char *filename) { FILE *fp; - if (strcmp(filename, "-") == 0) + string whole_filename; + if (strcmp(filename, "-") == 0) { fp = stdin; - else { + whole_filename = filename; + whole_filename += '\0'; + } + else if (filename[0] == '/') { + whole_filename = filename; + whole_filename += '\0'; errno = 0; fp = fopen(filename, "r"); if (fp == 0) { @@ -135,7 +159,34 @@ int do_file(const char *filename) return 0; } } - current_filename = filename; + else { + size_t j; + for (j = 0; j < include_list_length; ++j) + { + char *path = include_list[j]; + if (0 == strcmp(path, ".")) + whole_filename = filename; + else + whole_filename = string(path) + "/" + filename; + whole_filename += '\0'; + errno = 0; + fp = fopen(whole_filename.contents(), "r"); + if (fp != 0) + break; + if (errno != ENOENT) { + error("can't open `%1': %2", + whole_filename.contents(), strerror(errno)); + return 0; + } + } + if (j >= include_list_length) + { + errno = ENOENT; + error("can't open `%1': %2", filename, strerror(errno)); + return 0; + } + } + current_filename = whole_filename.contents(); current_lineno = 1; set_location(); enum { START, MIDDLE, HAD_DOT, HAD_s, HAD_so, HAD_l, HAD_lf } state = START; diff --git a/contrib/groff/soelim/soelim.man b/contrib/groff/soelim/soelim.man index d5139ad..7026f3e 100644 --- a/contrib/groff/soelim/soelim.man +++ b/contrib/groff/soelim/soelim.man @@ -1,5 +1,5 @@ .ig \"-*- nroff -*- -Copyright (C) 1989-1995 Free Software Foundation, Inc. +Copyright (C) 1989-1999 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -25,6 +25,9 @@ the original English. .B \-Cv ] [ +.BI \-I dir +] +[ .IR files \|.\|.\|.\| ] .SH DESCRIPTION @@ -53,6 +56,16 @@ Recognize .B .so even when followed by a character other than space or newline. .TP +.BI \-I dir +This option may be used to specify a directory to search for +files (both those on the command line and those named in +.B \&.so +lines). +The current directory is always searched first. +This option may be specified more than once, +the directories will be searched in the order specified. +No directory search is performed for files specified using an absolute path. +.TP .B \-v Print the version number. .SH "SEE ALSO" |