\n"); write_node_link_html( f, node->filename, "Next:", node->next ); write_node_link_html( f, node->filename, "Prev:", node->prev ); write_node_link_html( f, node->filename, "Up:", node->up ); fprintf(f,"\n"); #else fprintf(f,"
"); write_node_link_html( f, node->filename, "Next:", node->next ); fprintf(f," | "); fprintf(f,""); write_node_link_html( f, node->filename, "Prev:", node->prev ); fprintf(f," | "); write_node_link_html( f, node->filename, "Up:", node->up ); fprintf(f," | "); fprintf(f,"
---|
statements. * Catch any *Note and *note and make into * links to other documents. Also try to catch * URLs as well. * * menus: Starts with a '* Menu' line. Goes until the * end of the node, or until the next line which * starts with something other than a '* ' or '\n'. * * end of node: The INFO_FF and INFO_COOKIE mark the end of a node. * Hitting EOF also marks the end of a node. ********************************************************************/ void dump_html_for_node( NODE *node ) { /* char *destdir; */ /* char *destfile; */ char *escaped_nodename; /* char *converted_nodename; */ char *contents_start, *contents_end; char *header_name; char *p, *q, *r, *skippnt; char *end_menu_entry; int menu_open, body_open; int seen_menu; int prev_was_blank, next_is_blank, current_is_blank; int seen_first_header; int last_output_was_header; int nskip; int we_are_in_dir_node; int i; FILE *f; /* msf - used to write each node to a separate file - now we're going */ /* to just output HTML to stdout. */ /* Each node will just be concantentated to previous */ #if 0 destdir = (char *) g_malloc ( strlen(node->filename) + strlen(HTML_ROOT) + strlen(node->filename) + 2); strcpy(destdir, HTML_ROOT); strcat(destdir, "/"); strcat(destdir, node->filename); strcat(destdir, "/"); /* check that the dir for info file exists */ make_info_dir( destdir ); /* ok, we made the dir, lets go */ destfile = (char *) g_malloc( strlen(destdir) + strlen(node->nodename) + 10); strcpy(destfile, destdir); converted_nodename = g_strdup( node->nodename ); map_spaces_to_underscores( converted_nodename ); strcat(destfile, converted_nodename); strcat(destfile, ".html"); g_free(converted_nodename); if (!(f=fopen(destfile, "w"))) { fprintf(f,"Couldnt create node html file %s\n",destfile); perror("Error was"); exit(1); } #endif /* hack - just dump to stdout for now */ f = stdout; /* see if this is THE dir node */ we_are_in_dir_node = !strcmp("Top", node->nodename) && !strcmp("dir", node->filename); #if 0 /* try and make a link between 'index.html' and 'Top.html' */ if (!strcmp("Top", node->nodename)) make_Top_link( destdir, destfile ); #endif #if 0 /* do the html header first */ write_html_header( f, node->filename, node->nodename ); #endif #if 0 /* now for the body */ start_html_content( f ); #endif /* make an anchor */ escaped_nodename = escape_html_chars( node->nodename ); map_spaces_to_underscores( escaped_nodename ); fprintf(f, "\n",escaped_nodename); g_free(escaped_nodename); /* links to other immediate nodes */ make_nav_links( f, node ); /* setup pointers to textual content of current node */ contents_start = node->contents; contents_end = node->contents+node->contlen; /* scan through all of contents and generate html on the fly */ /* p points at start of current line */ /* q points at the end of current line (at '\n' actually) */ /* r points at the start of next line */ /* we do this to catch headers */ /* scan for a header at the top of the contents */ /* if we see a '\n***'3 '*' in a row i */ /* then take previous line as a header */ header_name = NULL; p = contents_start = node->contents; q = memchr(p, '\n', contents_end - p); r=q+1; /* we have several states we could be in */ next_is_blank = 0; prev_was_blank = 0; current_is_blank = 0; seen_first_header = 0; seen_menu = 0; menu_open = 0; body_open = 0; last_output_was_header = 0; for (; q && r <= contents_end; ) { nskip = 1; skippnt = NULL; next_is_blank = (*r == '\n'); current_is_blank = (*p == '\n'); /* test some easy things first */ if (!strncmp(p, MENU_START, strlen(MENU_START))) { if (we_are_in_dir_node && !seen_menu) { if (body_open) { close_body_text_html(f); body_open = 0; } fprintf(f,"
\n"); } void close_body_text_html( FILE *f ) { fprintf(f, "\n"); } /* we have to handle '*note' and '*Note' links in body text */ /* p is ptr to start of current line */ /* q is ptr to '\n' at end of current line */ char *write_body_text_html( FILE *f, char *p, char *q, char *nodefile ) { int curlen; int ref_exists; char *tmp; char *ptr; char *match1; char *note_ptr; char *converted_nodename; char *escaped_refname; char *escaped_refnode; char *refname, *reffile, *refnode, *end; char *href; curlen = q - p; tmp = (char *) g_malloc( curlen + 1 ); memcpy( tmp, p, curlen ); *(tmp+curlen) = '\000'; /* see if there is a reference in current line */ /* and make sure this isnt a '*Note*' instead ! */ ref_exists = 0; if ((note_ptr=strstr(tmp, "*Note")) || (note_ptr=strstr(tmp, "*note"))) if (*(note_ptr+6) != '*') ref_exists = 1; if (ref_exists) { /* find the start of the link */ note_ptr = (note_ptr - tmp) + p; match1 = note_ptr + 4; /* not needed any more */ g_free(tmp); for (; 1; ) if (*(match1+1) == ' ' || *(match1+1) == '\n') match1++; else break; /* find end of the link */ if (parse_note_ref( match1, &refname, &reffile, &refnode, &end, 1)) { html_error( "Corrupt *Note link found!", p, q ); return NULL; } /* now we assume that parse_note_ref left control chars in ref* */ /* if both null, we had a '::' and have to set both */ if (reffile == NULL && refnode == NULL) { reffile = g_strdup(nodefile); refnode = g_strdup(refname); } /* otherwise we had (file)., and we set node to 'Top' */ else if (refnode == NULL) refnode = g_strdup("Top"); /* otherwise we had :nodename., and we set node to 'Top' */ else if (reffile == NULL) reffile = g_strdup(nodefile); /* write out stuff up to Note */ fwrite(p, 1, note_ptr - p, f); fprintf(f, ""); fwrite(note_ptr, 1, match1 - note_ptr, f); fprintf(f, " "); /* we need a nice nodename -> filename translation */ /* so we convert newlines to spaces */ converted_nodename = g_strdup( refnode ); convert_newlines_to_spaces( converted_nodename ); /* we don't want two spaces in a row */ strip_dupspaces( converted_nodename ); map_spaces_to_underscores( converted_nodename ); /* escape HTML chars */ escaped_refname = escape_html_chars( refname ); escaped_refnode = escape_html_chars( refnode ); /* now output the link to html doc */ #if 0 fprintf(f,"", reffile, converted_nodename); #endif href = form_info_tag_href(reffile, converted_nodename); fprintf(f,"", href); for (ptr=escaped_refname; *ptr; ptr++) if (*ptr == '\n') { fprintf(f,"\n"); fprintf(f,"", href); } else fprintf(f,"%c", *ptr); if (strcmp(refname, refnode)) { fprintf(f,": "); for (ptr=escaped_refnode; *ptr; ptr++) if (*ptr == '\n') { fprintf(f,"\n"); fprintf(f,"", href); } else fprintf(f,"%c", *ptr); fprintf(f,""); if (end > q && !(strchr(refnode, '\n'))) fprintf(f,"\n"); } else fprintf(f,""); if (href) g_free(href); if (escaped_refnode) g_free(escaped_refnode); if (escaped_refname) g_free(escaped_refname); if (converted_nodename) g_free(converted_nodename); g_free(refname); g_free(reffile); g_free(refnode); /* write out stuff at end */ if (end < q) { fwrite(end+1, 1, q - end, f); return NULL; } else return end+1; } else { fwrite(p, 1, q-p+1, f); /* not needed any more */ g_free(tmp); return NULL; } } void open_menu_html( FILE *f, char *p ) { if (*p != '\000') fprintf(f, "