summaryrefslogtreecommitdiffstats
path: root/contrib/groff/soelim/soelim.cc
diff options
context:
space:
mode:
authorasmodai <asmodai@FreeBSD.org>2000-01-12 09:51:43 +0000
committerasmodai <asmodai@FreeBSD.org>2000-01-12 09:51:43 +0000
commit2e2c9047c3a8b5b6fdcdcd4585d5b114f31cd386 (patch)
tree723c5fa18b7084a4da09e4e42000ef10cbc884fa /contrib/groff/soelim/soelim.cc
parent35cdaa022af3f495aa21a1292d85ee40b28f86fb (diff)
downloadFreeBSD-src-2e2c9047c3a8b5b6fdcdcd4585d5b114f31cd386.zip
FreeBSD-src-2e2c9047c3a8b5b6fdcdcd4585d5b114f31cd386.tar.gz
Virgin import of FSF groff v1.15
Diffstat (limited to 'contrib/groff/soelim/soelim.cc')
-rw-r--r--contrib/groff/soelim/soelim.cc61
1 files changed, 56 insertions, 5 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;
OpenPOWER on IntegriCloud