summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliot Lee <sopwith@src.gnome.org>2000-02-08 22:54:42 +0000
committerElliot Lee <sopwith@src.gnome.org>2000-02-08 22:54:42 +0000
commit56fbb7d42c87c94bd993299386e5af139d2fcda8 (patch)
treeab936108950380fb6837d51caa574f5122ce0515
parent1f7c88c3453164bb0e3991cd80212e1b6cfa801c (diff)
downloadyelp-56fbb7d42c87c94bd993299386e5af139d2fcda8.tar.gz
Make it look up a file location and use it, if just passed something like
* gnome-man2html2/gnome-man2html.c, gnome-man2html2/Makefile.am: Make it look up a file location and use it, if just passed something like 'ls.1' on the cmdline. Also use zlib to handle compressed manpages.
-rw-r--r--src/man2html/Makefile.am2
-rw-r--r--src/man2html/yelp-man2html.c68
2 files changed, 62 insertions, 8 deletions
diff --git a/src/man2html/Makefile.am b/src/man2html/Makefile.am
index b95b8471..eae368b3 100644
--- a/src/man2html/Makefile.am
+++ b/src/man2html/Makefile.am
@@ -5,7 +5,7 @@ INCLUDES = \
-I$(top_srcdir)/intl -I$(top_builddir)/intl
-LDADD =
+LDADD = $(Z_LIBS)
bin_PROGRAMS = gnome-man2html2
diff --git a/src/man2html/yelp-man2html.c b/src/man2html/yelp-man2html.c
index 5fc55ea2..f8d764a3 100644
--- a/src/man2html/yelp-man2html.c
+++ b/src/man2html/yelp-man2html.c
@@ -133,7 +133,8 @@
#include <time.h>
#include <sys/time.h>
#include <errno.h>
-
+#include <fcntl.h>
+#include <zlib.h>
static char *URLbasename = NULL;
@@ -361,6 +362,7 @@ static STRDEF standardchar[] = {
static char escapesym='\\', nobreaksym='\'', controlsym='.', fieldsym=0, padsym=0;
+static gzFile infh = NULL;
static char *buffer=NULL;
static int buffpos=0, buffmax=0;
static int scaninbuff=0;
@@ -427,7 +429,7 @@ static char
int bytes;
/* input from stdin */
- bytes = read(0,buf, sizeof(buf));
+ bytes = gzread(infh, buf, sizeof(buf));
while (bytes > 0) {
if (!man_buf) {
man_buf = malloc(bytes+1);
@@ -439,7 +441,7 @@ static char
memcpy(man_buf+buf_size, buf, bytes);
buf_size += bytes;
- bytes = read(0,buf, sizeof(buf));
+ bytes = gzread(infh, buf, sizeof(buf));
}
if (man_buf) {
@@ -3636,14 +3638,66 @@ int
main(int argc, char **argv)
{
char *t=NULL;
- int i;char *buf;
+ int i;
+ char *buf;
char *h = '\0';
STRDEF *stdf;
+ char *infile = NULL;
/* see if they gave us a basename for the URL references */
- if (argc > 1)
- if (!strcmp(argv[1], "-n"))
- URLbasename = strdup(argv[2]);
+
+ for(i = 1; i < argc; i++)
+ {
+ if(!strcmp(argv[i], "-n"))
+ {
+ i++;
+ if(i >= argc)
+ return 1;
+
+ URLbasename = strdup(argv[i]);
+ }
+ else if(argv[i][0] == '-')
+ return 2;
+ else
+ infile = argv[i];
+ }
+
+ if(!infile || !strcmp(infile, "-"))
+ infh = gzdopen(0, "r");
+ else
+ {
+ infh = gzopen(infile, "r");
+ if(!infh)
+ {
+ FILE *fh;
+ char cmdline[512], *ctmp, output[512];
+
+ /* Try searching for this as a man page name, instead */
+ ctmp = strrchr(infile, '.');
+ if(ctmp && (isdigit(*(ctmp+1)) || (*(ctmp+1) == 'n')) && *(ctmp+2) == '\0')
+ {
+ char section = *(ctmp+1);
+
+ *ctmp = '\0';
+
+ snprintf(cmdline, sizeof(cmdline), "man -w %c %s", section, infile);
+ }
+ else
+ snprintf(cmdline, sizeof(cmdline), "man -w %s", infile);
+
+ fh = popen(cmdline, "r");
+ fgets(output, sizeof(output), fh);
+ pclose(fh);
+
+ i = strlen(output) - 1;
+ while(isspace(output[i])) output[i--] = '\0';
+
+ if(output[0])
+ infh = gzopen(output, "r");
+ }
+ }
+ if(!infh)
+ return 3;
buf=read_man_page();
if (!buf) {