From 1f7c88c3453164bb0e3991cd80212e1b6cfa801c Mon Sep 17 00:00:00 2001 From: Elliot Lee Date: Fri, 3 Dec 1999 17:02:49 +0000 Subject: info2html now should grok all info pages. info2html now should grok all info pages. --- src/info2html/Makefile.am | 2 +- src/info2html/main.c | 216 ++++++++++++++++++++++------------------------ src/info2html/parse.c | 13 +-- src/info2html/parse.h | 6 +- 4 files changed, 116 insertions(+), 121 deletions(-) diff --git a/src/info2html/Makefile.am b/src/info2html/Makefile.am index 03a764f8..0db75f6e 100644 --- a/src/info2html/Makefile.am +++ b/src/info2html/Makefile.am @@ -6,7 +6,7 @@ INCLUDES = \ $(GNOME_CFLAGS) LDADD = \ - $(GNOMEUI_LIBS) + $(GNOME_LIBS) $(Z_LIBS) bin_PROGRAMS = gnome-info2html2 diff --git a/src/info2html/main.c b/src/info2html/main.c index 4bae84aa..3ac12cc6 100644 --- a/src/info2html/main.c +++ b/src/info2html/main.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "data.h" #include "html.h" @@ -15,90 +17,61 @@ static int be_quiet=1; /* line_number we're on */ static int work_line_number; +static char *requested_nodename=NULL; +static struct poptOption options[] = { + {NULL, 'a', POPT_ARG_STRING, &requested_nodename}, + {NULL, 'b', POPT_ARG_STRING, &OverrideBaseFilename}, + {NULL} +}; int main(int argc, char **argv) { - FILE *f; + gzFile f = NULL; char line[250]; - - char *requested_nodename=NULL; - int aptr; + poptContext ctx; int result; int foundit=0; char convanc[1024]; - NODE *node; + + const char **args; + int curarg; if (!be_quiet) printf("info2html Version %s\n",INFO2HTML_VERSION); - - /* simplistic command line parsing for now */ - aptr = argc; - while (aptr > 2) { - if (!strcmp(argv[argc-aptr+1], "-a")) { - char *s, *t; - int len; - - requested_nodename = strdup(argv[argc-aptr+2]); - /* strip off quotes */ - for (s=requested_nodename; *s == '\"'; ) { - len = strlen( s ); - memmove(s, s+1, len); - } - - t = s + strlen(s) - 1; - while (*t == '\"') - t--; - - *(t+1) = '\0'; - - /* convert anchor so matching works */ - map_spaces_to_underscores(requested_nodename); -#ifdef DEBUG - fprintf(stderr, "outputting node %s\n", - requested_nodename); -#endif - aptr -= 2; - } else if (!strcmp(argv[argc-aptr+1], "-b")) { - OverrideBaseFilename = strdup(argv[argc-aptr+2]); -#ifdef DEBUG - fprintf(stderr, "outputting basefile %s\n", - OverrideBaseFilename); -#endif - aptr -= 2; - } - } - if (aptr == 1) { - f = stdin; - strcpy(work_filename, "STDIN"); - } else { - if ((f=fopen(argv[argc-aptr+1], "r"))==NULL) { - fprintf(stderr, "File %s not found.\n",argv[1]); - exit(1); - } - strcpy(work_filename, argv[1]); - } + ctx = poptGetContext("gnome-info2html2", argc, argv, options, 0); - work_line_number = 0; + while(poptGetNextOpt(ctx) >= 0) + /**/ ; + args = poptGetArgs(ctx); + curarg = 0; + + if(requested_nodename) + { + char *s, *t; + int len; + /* strip off quotes */ + for (s=requested_nodename; *s == '\"'; ) { + len = strlen( s ); + memmove(s, s+1, len); + } + + t = s + strlen(s) - 1; + while (*t == '\"') + t--; + + *(t+1) = '\0'; + + /* convert anchor so matching works */ + map_spaces_to_underscores(requested_nodename); + } + + work_line_number = 0; - /* scan for start of real data */ - for (;1;) { - fgets(line,250,f); - if (feof(f)) - { - fprintf(stderr,"Info file had no contents\n"); - exit(1); - } - - work_line_number++; - if (*line == INFO_COOKIE) - break; - - } /* hack, just send to stdout for now */ fprintf(stdout, "\n"); @@ -108,68 +81,85 @@ main(int argc, char **argv) /* No need to store all nodes, etc since we let web server */ /* handle resolving tags! */ for (;1 || !foundit || !requested_nodename;) { - fgets(line,250,f); - if (feof(f)) - break; + if(!f) { + if(args && args[curarg]) + { + f = gzopen(args[curarg++], "r"); + if(!f) + break; + num_files_left = args[curarg]?1:0; + for(work_line_number = 0, gzgets(f, line, sizeof(line)); *line != INFO_COOKIE; + gzgets(f, line, sizeof(line)), work_line_number++) + /**/ ; + } + else + break; + } + if(!gzgets(f, line, sizeof(line))) + { + gzclose(f); + f = NULL; + continue; + } - work_line_number++; + work_line_number++; /* found a node definition line */ - if (!strncmp(line, "File:", 5)) { - node = alloc_node(); - result=read_node( f, line, node ); - if ( result == READ_ERR ) { - fprintf(stderr, "Error reading the node " - "contents\n"); - fprintf(stderr, "line was |%s|\n",line); - continue; - } + if (!strncmp(line, "File:", 5)) { + node = alloc_node(); + result=read_node( f, line, node ); + if ( result == READ_ERR ) { + fprintf(stderr, "Error reading the node " + "contents\n"); + fprintf(stderr, "line was |%s|\n",line); + continue; + } - /* see if this is the requested node name */ - strncpy(convanc, node->nodename, sizeof(convanc)); - map_spaces_to_underscores(convanc); - if (requested_nodename && - strcmp(requested_nodename, convanc)) { + /* see if this is the requested node name */ + strncpy(convanc, node->nodename, sizeof(convanc)); + map_spaces_to_underscores(convanc); + if (requested_nodename && + strcmp(requested_nodename, convanc)) { #ifdef DEBUG - fprintf(stderr, "skipping ->%s<-\n", - node->nodename); + fprintf(stderr, "skipping ->%s<-\n", + node->nodename); #endif - continue; - } + continue; + } - foundit = 1; - strcpy(work_node,node->nodename); + foundit = 1; + strcpy(work_node,node->nodename); - BaseFilename = node->filename; + BaseFilename = node->filename; #ifdef DEBUG - printf("NEW NODE\n"); - printf("\tFile:|%s|\n\tNode:|%s|\n\tNext:|%s|\n", - node->filename, node->nodename,node->next); - printf("\tPrev:|%s|\n\tUp:|%s|\n\n", - node->prev, node->up); - printf("-------------------------------------------" - "-----------\n"); + printf("NEW NODE\n"); + printf("\tFile:|%s|\n\tNode:|%s|\n\tNext:|%s|\n", + node->filename, node->nodename,node->next); + printf("\tPrev:|%s|\n\tUp:|%s|\n\n", + node->prev, node->up); + printf("-------------------------------------------" + "-----------\n"); #endif - /* now lets make some html */ - dump_html_for_node( node ); + /* now lets make some html */ + dump_html_for_node( node ); - if (node) { - if ( node->contents ) - free(node->contents); + if (node) { + if ( node->contents ) + free(node->contents); - free(node); - BaseFilename = NULL; - } - } - else - continue; + free(node); + BaseFilename = NULL; + } + } + else + continue; } if (!foundit && requested_nodename) { - fprintf(stderr, "Requested node %s not found\n", - requested_nodename); - exit(1); + fprintf(stderr, "Requested node %s not found\n", + requested_nodename); + exit(1); } fprintf(stdout, "\n"); diff --git a/src/info2html/parse.c b/src/info2html/parse.c index 67575c87..5f19012d 100644 --- a/src/info2html/parse.c +++ b/src/info2html/parse.c @@ -5,14 +5,17 @@ #include #include #include +#include #include "parse.h" #include "data.h" #include "utils.h" +int num_files_left; + /* main routine to read in a node once we found its start in file f */ /* assumes NODE has already been allocated */ -int read_node (FILE *f, char *line, NODE *node) +int read_node (gzFile f, char *line, NODE *node) { /* we found a node line */ if (!parse_node_line( node, line )) @@ -112,7 +115,7 @@ char *parse_node_label( char **line, char *label, int allow_eof ) #define SEARCH_BUF_SIZE 1024 #define CONTENTS_BUF_INCR 1024 -int read_node_contents( FILE *f, NODE *node ) +int read_node_contents( gzFile f, NODE *node ) { int nread; int found; @@ -135,14 +138,14 @@ int read_node_contents( FILE *f, NODE *node ) /* and save contents as we go along */ for ( found=0 ; !found ; ) { - status=fgets( searchbuf, SEARCH_BUF_SIZE, f); + status=gzgets(f, searchbuf, SEARCH_BUF_SIZE); linelen = strlen( searchbuf ); for (found=0, ptr = searchbuf; *ptr && !found; ptr++) if (*ptr == INFO_FF || *ptr == INFO_COOKIE) found=1; /* if we didn't find the magic character, but hit eof, same deal */ - if (!found && feof(f)) + if (!found && gzeof(f)) { found = 1; continue; @@ -156,7 +159,7 @@ int read_node_contents( FILE *f, NODE *node ) memcpy(tmpcontents+nread, searchbuf, linelen); nread += linelen; - if (!feof(f)) + if (!gzeof(f) || num_files_left) *(tmpcontents+nread) = '\14'; } diff --git a/src/info2html/parse.h b/src/info2html/parse.h index 10119f00..9f539a3c 100644 --- a/src/info2html/parse.h +++ b/src/info2html/parse.h @@ -1,6 +1,7 @@ #ifndef PARSE_H #define PARSE_H +#include #include "data.h" #define READ_OK 1 @@ -17,9 +18,10 @@ int parse_note_ref( char *line, char **refname, char **reffile, char **refnode, char **end_of_link, int span_lines); -int read_node_contents( FILE *f, NODE *node ); -int read_node (FILE *f, char *line, NODE *node); +int read_node_contents( gzFile f, NODE *node ); +int read_node (gzFile f, char *line, NODE *node); int is_a_hdr_line (char *r); +extern int num_files_left; #endif /* PARSE_H */ -- cgit v1.2.1