From b4d41e9d68bd20a3f0925fbad17bca0be8a8f013 Mon Sep 17 00:00:00 2001 From: Mikael Hallendal Date: Sun, 4 Aug 2002 13:40:32 +0000 Subject: - GNOME indentation - Support info files that doesn't have the name 2002-08-04 Mikael Hallendal * help-converters/info/main.c: - GNOME indentation - Support info files that doesn't have the name 'name.info.gz' but instead 'name.gz'. Fixes #85324. --- src/info2html/main.c | 359 +++++++++++++++++++++++++++------------------------ 1 file changed, 191 insertions(+), 168 deletions(-) diff --git a/src/info2html/main.c b/src/info2html/main.c index d2142a7a..26b2497e 100644 --- a/src/info2html/main.c +++ b/src/info2html/main.c @@ -35,18 +35,18 @@ static int work_line_number; static char *requested_nodename=NULL; static char *requested_section=NULL; static struct poptOption options[] = { - {NULL, 'a', POPT_ARG_STRING, &requested_nodename}, - {NULL, 'b', POPT_ARG_STRING, &OverrideBaseFilename}, - {NULL, 'g', POPT_ARG_NONE, &galeon_mode}, - {NULL} + {NULL, 'a', POPT_ARG_STRING, &requested_nodename}, + {NULL, 'b', POPT_ARG_STRING, &OverrideBaseFilename}, + {NULL, 'g', POPT_ARG_NONE, &galeon_mode}, + {NULL} }; static int file_exists(const char *fn) { - struct stat sbuf; + struct stat sbuf; - return (stat(fn, &sbuf) == 0); + return (stat(fn, &sbuf) == 0); } int @@ -59,6 +59,7 @@ main(int argc, const char **argv) int foundit=0; int i, n; char *cptr; + gboolean no_info = FALSE; char convanc[1024]; NODE *node; @@ -73,12 +74,12 @@ main(int argc, const char **argv) ctx = poptGetContext("gnome-info2html2", argc, argv, options, 0); while(poptGetNextOpt(ctx) >= 0) - /**/ ; + /**/ ; args = poptGetArgs(ctx); curarg = 0; if(!args) - return 1; + return 1; for(n = 0; args[n]; n++) /* */; @@ -86,107 +87,132 @@ main(int argc, const char **argv) filename?section instead of passing it in with the -a option */ for (cptr = args [0]; *cptr != '\0'; cptr++) { - if (*cptr == '?') { - *cptr++ = '\0'; - requested_section = g_strdup (cptr); - break; - } + if (*cptr == '?') { + *cptr++ = '\0'; + requested_section = g_strdup (cptr); + break; + } } /* requested_section now contains the requested section, if at all ... */ - if(n == 1 && !file_exists(args[0])) - { - /* As strtok destroys the string it parses and g_getenv returns a pointer to - the actually env var, we have to duplicate the var before parsing it. */ - char *ctmp, *infopath = g_strdup(g_getenv("INFOPATH")); - char *dirs[64], *ext = NULL; - int ndirs; - char buf[PATH_MAX]; - - /* First, find the directory that the info file is in. */ - dirs[0] = "/usr/info"; - dirs[1] = "/usr/share/info"; - /* We now have at least one directory to look in. This is - * necessary because we may not have an 'INFOPATH' set */ - ndirs = 2; - if(infopath) - for(ndirs = 2, ctmp = strtok(infopath, ":"); 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(n == 1 && !file_exists(args[0])) { + /* As strtok destroys the string it parses and g_getenv returns a pointer to + the actually env var, we have to duplicate the var before parsing it. */ + char *ctmp, *infopath = g_strdup(g_getenv("INFOPATH")); + char *dirs[64], *ext = NULL; + int ndirs; + char buf[PATH_MAX]; + + /* First, find the directory that the info file is in. */ + dirs[0] = "/usr/info"; + dirs[1] = "/usr/share/info"; + /* We now have at least one directory to look in. This is + * necessary because we may not have an 'INFOPATH' set */ + ndirs = 2; + if(infopath) { + for (ndirs = 2, ctmp = strtok(infopath, ":"); 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; + sprintf(buf, "%s/%s", dirs[i], args[0]); + if(file_exists(buf)) { + no_info = TRUE; + break; + } + + ext = ".gz"; + sprintf(buf, "%s/%s.info.gz", dirs[i], args[0]); + if(file_exists(buf)) + break; + sprintf(buf, "%s/%s.gz", dirs[i], args[0]); + if(file_exists(buf)) { + no_info = TRUE; + break; + } #ifdef HAVE_LIBBZ2 - ext = ".bz2"; - sprintf(buf, "%s/%s.info.bz2", dirs[i], args[0]); - if(file_exists(buf)) { - break; - } + ext = ".bz2"; + sprintf(buf, "%s/%s.info.bz2", dirs[i], args[0]); + if(file_exists(buf)) + break; + + sprintf(buf, "%s/%s.bz2", dirs[i], args[0]); + if(file_exists(buf)) { + no_info = TRUE; + break; + } #endif - } - if(i >= ndirs) { - printf ("Document not found\n" - "The info document \"%s\" could not be found. It may have been removed from your system.\n" - "\n", args[0]); - 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(i >= ndirs) { + printf ("Document not found\n" + "The info document \"%s\" could not be found. It may have been removed from your system.\n" + "\n", args[0]); + return 2; + } + + n = i; + + for(i = 0; ; i++) { + gchar *path; + + if (no_info) { + path = g_strdup_printf ("%s/%s", + dirs[n], args[0]); + } else { + path = g_strdup_printf ("%s/%s.info", + dirs[n], args[0]); + } + + if(i) { + sprintf(buf, "%s-%d%s", path, i, ext); + } else { + sprintf(buf, "%s%s", path, ext); + } + + if(!file_exists(buf)) { + fixup_args[i] = NULL; + break; + } + + fixup_args[i] = strdup(buf); + } + args = (const char **)fixup_args; + } - 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); - } else { - /* since no node has been asked for, it might have been passed in - as filename?section. In that case, set requested_nodename - to what is in requested_section, if that is NULL, set requested_nodename - to "Top" to display only the "Top" Node */ - if (requested_section) { - requested_nodename = requested_section; - } else { - requested_nodename = top_string; - } - } + 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); + } else { + /* since no node has been asked for, it might have been passed in + as filename?section. In that case, set requested_nodename + to what is in requested_section, if that is NULL, set requested_nodename + to "Top" to display only the "Top" Node */ + if (requested_section) { + requested_nodename = requested_section; + } else { + requested_nodename = top_string; + } + } work_line_number = 0; /* hack, just send to stdout for now */ @@ -197,87 +223,84 @@ main(int argc, const char **argv) /* No need to store all nodes, etc since we let web server */ /* handle resolving tags! */ for (;1 || !foundit || !requested_nodename;) { - if(!f) - { - if(args && args[curarg]) - { - f = readbuf_open (args[curarg++]); - if(!f) { - break; - } - num_files_left = args[curarg]?1:0; - for(work_line_number = 0, readbuf_gets(f,line,sizeof(line)); *line != INFO_COOKIE; - readbuf_gets(f,line,sizeof(line)), work_line_number++) - /**/ ; - } - else - break; - } - if(!readbuf_gets(f,line,sizeof(line))) - { - readbuf_close(f); - f = NULL; - continue; - } + if(!f) { + if(args && args[curarg]) { + f = readbuf_open (args[curarg++]); + if(!f) { + break; + } + num_files_left = args[curarg]?1:0; + for (work_line_number = 0, readbuf_gets(f,line,sizeof(line)); *line != INFO_COOKIE; + readbuf_gets(f,line,sizeof(line)), work_line_number++) + /**/ ; + } else { + break; + } + } + if(!readbuf_gets(f,line,sizeof(line))) { + readbuf_close(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); - g_free(node); - BaseFilename = NULL; - } - } - else - continue; + g_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"); -- cgit v1.2.1