From c646c4611feebb406b50dee8db36f34f50887c94 Mon Sep 17 00:00:00 2001 From: Elliot Lee Date: Wed, 16 Feb 2000 23:40:29 +0000 Subject: Fixups for VFS usage. Search info path for files. * components/html/ntl-web-browser.c: Fixups for VFS usage. * components/help/converters/gnome-info2html2/main.c: Search info path for files. --- src/info2html/main.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/src/info2html/main.c b/src/info2html/main.c index 3ac12cc6..c7be431a 100644 --- a/src/info2html/main.c +++ b/src/info2html/main.c @@ -5,6 +5,10 @@ #include #include #include +#include +#include +#include +#include #include "data.h" #include "html.h" @@ -24,6 +28,13 @@ static struct poptOption options[] = { {NULL} }; +static int +file_exists(const char *fn) +{ + struct stat sbuf; + return (stat(fn, &sbuf) == 0); +} + int main(int argc, char **argv) { @@ -32,23 +43,74 @@ main(int argc, char **argv) poptContext ctx; int result; int foundit=0; + int i, n; char convanc[1024]; NODE *node; const char **args; + char *fixup_args[512]; int curarg; if (!be_quiet) printf("info2html Version %s\n",INFO2HTML_VERSION); - ctx = poptGetContext("gnome-info2html2", argc, argv, options, 0); + ctx = poptGetContext("gnome-info2html2", argc, (const char **)argv, options, 0); while(poptGetNextOpt(ctx) >= 0) /**/ ; args = poptGetArgs(ctx); curarg = 0; + if(!args) + return 1; + + for(n = 0; args[n]; n++) /* */; + if(n == 1 && !file_exists(args[0])) + { + char *ctmp, *infopath = getenv("INFOPATH"); + char *dirs[64], *ext; + int ndirs; + char buf[PATH_MAX]; + + /* First, find the directory that the info file is in. */ + dirs[0] = "/usr/info"; + if(infopath) + for(ndirs = 0, ctmp = strtok((char *)args[0], ":"); ndirs < 64 && ctmp; ndirs++, ctmp = strtok(NULL, ":")) + dirs[ndirs] = strdup(ctmp); + + for(i = 0; i < ndirs; i++) + { + ext = ""; + sprintf(buf, "%s/%s.info", dirs[i], args[0]); + if(file_exists(buf)) + break; + ext = ".gz"; + sprintf(buf, "%s/%s.info.gz", dirs[i], args[0]); + if(file_exists(buf)) + break; + } + if(i >= ndirs) + return 2; + + n = i; + + for(i = 0; ; i++) + { + if(i) + sprintf(buf, "%s/%s.info-%d%s", dirs[n], args[0], i, ext); + else + sprintf(buf, "%s/%s.info%s", dirs[n], args[0], ext); + if(!file_exists(buf)) + { + fixup_args[i] = NULL; + break; + } + + fixup_args[i] = strdup(buf); + } + args = (const char **)fixup_args; + } if(requested_nodename) { @@ -72,7 +134,6 @@ main(int argc, char **argv) work_line_number = 0; - /* hack, just send to stdout for now */ fprintf(stdout, "\n"); -- cgit v1.2.1