Commit 48028ea3 authored by Jonathan Blandford's avatar Jonathan Blandford Committed by Jonathan Blandford
Browse files

support Footnotes. Make much more robust. General improvements.

2000-02-07  Jonathan Blandford  <jrb@redhat.com>

	* gnome-db2html2/sect-elements.c: support Footnotes.  Make much
	more robust.  General improvements.
parent 7b726aa6
2000-02-07 Jonathan Blandford <jrb@redhat.com>
* gnome-db2html2/sect-elements.c: support Footnotes. Make much
more robust. General improvements.
2000-02-03 Jonathan Blandford <jrb@redhat.com>
* gnome-db2html2/README: added README
......
......@@ -15,6 +15,65 @@ article_end_element (Context *context, const gchar *name)
g_print ("</BODY>\n</HTML>\n");
}
void
ulink_start_element (Context *context, const gchar *name, const xmlChar **atrs)
{
gint url_found = FALSE;
GSList *list;
gchar **atrs_ptr;
ElementIndex index;
list = g_slist_prepend (NULL, GINT_TO_POINTER (FOOTNOTE));
index = find_first_parent (context, list);
atrs_ptr = (gchar **) atrs;
while (atrs_ptr && *atrs_ptr) {
if (!strcasecmp (*atrs_ptr, "url")) {
atrs_ptr++;
if (index == UNDEFINED) {
g_print ("<A HREF=\"%s\">", *atrs_ptr);
} else {
GString *footnote;
list = g_slist_last (context->footnotes);
footnote = (GString *) list->data;
g_string_append (footnote, "<A HREF=\"");
g_string_append (footnote, *atrs_ptr);
g_string_append (footnote, "\">");
}
url_found = TRUE;
break;
}
atrs_ptr += 2;
}
if (!url_found)
g_print ("<A>");
}
void
ulink_end_element (Context *context, const gchar *name)
{
GSList *list;
ElementIndex index;
list = g_slist_prepend (NULL, GINT_TO_POINTER (FOOTNOTE));
index = find_first_parent (context, list);
if (index == UNDEFINED) {
g_print ("</A>\n");
} else {
GString *footnote;
list = g_slist_last (context->footnotes);
footnote = (GString *) list->data;
g_string_append (footnote, "</A>\n");
}
}
void
artheader_start_element (Context *context, const gchar *name, const xmlChar **atrs)
{
......@@ -27,11 +86,25 @@ write_characters (Context *context,
int len)
{
char *temp;
GSList *list;
ElementIndex index;
temp = g_strndup (chars, len);
g_print ("chars:%s:\n", temp);
g_free (temp);
list = g_slist_prepend (NULL, GINT_TO_POINTER (FOOTNOTE));
index = find_first_parent (context, list);
if (index == UNDEFINED) {
temp = g_strndup (chars, len);
g_print ("%s\n", temp);
g_free (temp);
} else {
GString *footnote;
list = g_slist_last (context->footnotes);
footnote = (GString *) list->data;
temp = g_strndup (chars, len);
g_string_append (footnote, temp);
g_free (temp);
}
}
StackElement *
......@@ -246,6 +319,11 @@ parse_file (gchar *filename, gchar *section)
if (xmlSAXUserParseFile (&parser, context, context->base_file) < 0) {
g_print ("error\n");
};
if (section) {
/* WHY IS THIS NECESSARY???? */
sect_article_end_element (context, "article");
}
}
int
......@@ -260,7 +338,7 @@ main (int argc, char *argv[])
}
for (ptr = argv[1]; *ptr; ptr++){
if (*ptr == '#') {
if (*ptr == '?') {
*ptr = '\000';
if (*(ptr + 1))
section = ptr + 1;
......
......@@ -71,6 +71,8 @@ struct _Context {
gint sect3;
gint sect4;
gint sect5;
GSList *footnotes;
};
/* useful structs */
......@@ -96,6 +98,8 @@ void article_end_element (Context *context, const gchar *name);
void artheader_start_element (Context *context, const gchar *name, const xmlChar **atrs);
void para_start_element (Context *context, const gchar *name, const xmlChar **atrs);
void para_end_element (Context *context, const gchar *name);
void ulink_start_element (Context *context, const gchar *name, const xmlChar **atrs);
void ulink_end_element (Context *context, const gchar *name);
void write_characters (Context *context, const gchar *chars, int len);
StackElement *find_first_element (Context *context, GSList *args);
ElementIndex find_first_parent (Context *context, GSList *args);
......
......@@ -15,13 +15,12 @@ struct _SectContext {
HeaderInfo *header;
gchar *prev;
gchar *previd;
gchar *top;
gchar *topid;
SectContextState state;
/* A list full of GStrings. */
GList *footnotes;
};
static void sect_write_characters (Context *context, const gchar *chars, int len);
static void sect_sect_start_element (Context *context, const gchar *name, const xmlChar **atrs);
static void sect_sect_end_element (Context *context, const gchar *name);
static void sect_para_start_element (Context *context, const gchar *name, const xmlChar **atrs);
......@@ -35,9 +34,12 @@ static void sect_copyright_characters (Context *context, const gchar *chars, int
static void sect_title_start_element (Context *context, const gchar *name, const xmlChar **atrs);
static void sect_title_end_element (Context *context, const gchar *name);
static void sect_title_characters (Context *context, const gchar *chars, int len);
static void sect_ulink_start_element (Context *context, const gchar *name, const xmlChar **atrs);
static void sect_ulink_end_element (Context *context, const gchar *name);
static void sect_footnote_start_element (Context *context, const gchar *name, const xmlChar **atrs);
ElementInfo sect_elements[] = {
{ ARTICLE, "article", (startElementSAXFunc) article_start_element, (endElementSAXFunc) article_end_element, NULL},
{ ARTICLE, "article", (startElementSAXFunc) article_start_element, (endElementSAXFunc) sect_article_end_element, NULL},
{ BOOK, "book", NULL, NULL, NULL},
{ SECTION, "section", (startElementSAXFunc) sect_sect_start_element, (endElementSAXFunc) sect_sect_end_element, NULL},
{ SECT1, "sect1", (startElementSAXFunc) sect_sect_start_element, (endElementSAXFunc) sect_sect_end_element, NULL},
......@@ -62,16 +64,14 @@ ElementInfo sect_elements[] = {
{ HOLDER, "holder", NULL, NULL, (charactersSAXFunc) sect_copyright_characters},
{ TITLE, "title", (startElementSAXFunc) sect_title_start_element, (endElementSAXFunc) sect_title_end_element, (charactersSAXFunc) sect_title_characters },
{ SUBTITLE, "subtitle", (startElementSAXFunc) sect_title_start_element, (endElementSAXFunc) sect_title_end_element, (charactersSAXFunc) sect_title_characters },
{ ULINK, "ulink", NULL, NULL, NULL},
{ ULINK, "ulink", (startElementSAXFunc) sect_ulink_start_element, (endElementSAXFunc) sect_ulink_end_element, (charactersSAXFunc) sect_write_characters},
{ XREF, "xref", NULL, NULL, NULL},
{ FOOTNOTE, "footnote", NULL, NULL, NULL},
{ FOOTNOTE, "footnote", (startElementSAXFunc) sect_footnote_start_element, NULL, NULL},
{ FIGURE, "figure", NULL, NULL, NULL},
{ GRAPHIC, "graphic", NULL, NULL, NULL},
{ UNDEFINED, NULL, NULL, NULL, NULL}
};
gpointer
sect_init_data (void)
{
......@@ -81,6 +81,38 @@ sect_init_data (void)
return (gpointer) retval;
}
static void
sect_write_characters (Context *context,
const gchar *chars,
int len)
{
if (!IS_IN_SECT (context))
return;
write_characters (context, chars, len);
}
void
sect_article_end_element (Context *context, const gchar *name)
{
if (context->footnotes) {
GSList *list;
gint i = 1;
g_print ("<HR>");
g_print ("<H4>Notes:</H4>");
g_print ("<TABLE BORDER=\"0\" WIDTH=\"100%%\">\n\n");
for (list = context->footnotes; list; list = list->next) {
g_print ("<TR><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"5%%\">\n");
g_print ("<A HREF=\"#HEADNOTE%d\" NAME=\"FOOTNOTE%d\">[%d]</A></TD>\n", i, i, i);
g_print ("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"95%%\">\n%s\n</TD></TR>\n", ((GString *)list->data)->str);
i++;
}
g_print ("</TABLE>");
}
g_print ("</BODY>\n</HEAD>\n");
}
static void
sect_para_start_element (Context *context, const gchar *name, const xmlChar **atrs)
{
......@@ -159,17 +191,16 @@ sect_para_end_element (Context *context, const gchar *name)
};
}
static void
sect_para_characters (Context *context,
const gchar *chars,
int len)
{
if (IS_IN_SECT (context)) {
gchar *temp;
temp = g_strndup (chars, len);
g_print ("%s", temp);
g_free (temp);
}
if (!IS_IN_SECT (context))
return;
write_characters (context, chars, len);
}
......@@ -483,19 +514,31 @@ sect_title_characters (Context *context,
if (((SectContext *)context->data)->state == LOOKING_FOR_SECT_TITLE) {
SectContext *sect_context = (SectContext *)context->data;
StackElement *stack_el;
element_list = g_slist_prepend (element_list, GINT_TO_POINTER (SECT1));
element_list = g_slist_prepend (element_list, GINT_TO_POINTER (SECT2));
element_list = g_slist_prepend (element_list, GINT_TO_POINTER (SECT3));
element_list = g_slist_prepend (element_list, GINT_TO_POINTER (SECT4));
element_list = g_slist_prepend (element_list, GINT_TO_POINTER (SECT5));
element_list = g_slist_prepend (element_list, GINT_TO_POINTER (SECTION));
stack_el = find_first_element (context, element_list);
temp = g_strndup (chars, len);
g_print ("<TITLE>%s</TITLE>\n</HEAD>\n", temp);
g_print ("<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" LINK=\"#0000FF\" VLINK=\"#840084\" ALINK=\"#0000FF\">\n");
if (sect_context->top == NULL)
if (stack_el == NULL)
g_print ("<A href=\"%s\"><font size=3>Up to Table of Contents</font></A><BR>\n",
context->base_file);
#if 0
else
g_print ("<A href=\"%s#%s\"><font size=3>Up to %s</font></A><BR>\n",
context->base_file,
sect_context->topid,
sect_context->top);
#endif
g_print ("<H1>%s</H1>\n", temp);
((SectContext *)context->data)->state = IN_SECT;
g_free (temp);
......@@ -544,3 +587,38 @@ sect_title_characters (Context *context,
g_slist_free (element_list);
}
void
sect_ulink_start_element (Context *context, const gchar *name, const xmlChar **atrs)
{
if (!IS_IN_SECT (context))
return;
ulink_start_element (context, name, atrs);
}
void
sect_ulink_end_element (Context *context, const gchar *name)
{
if (!IS_IN_SECT (context))
return;
ulink_end_element (context, name);
}
static void
sect_footnote_start_element (Context *context, const gchar *name, const xmlChar **atrs)
{
GString *footnote;
gint i;
if (!IS_IN_SECT (context))
return;
footnote = g_string_new (NULL);
context->footnotes = g_slist_append (context->footnotes, footnote);
i = g_slist_length (context->footnotes);
g_print ("<A NAME=\"HEADNOTE%d\" HREF=\"#FOOTNOTE%d\">[%d]</A>", i, i, i);
}
......@@ -6,5 +6,6 @@
extern ElementInfo sect_elements[];
gpointer sect_init_data (void);
void sect_article_end_element (Context *context, const gchar *name);
#endif
......@@ -19,7 +19,7 @@ static void toc_title_characters (Context *context, const gchar *chars, int len)
ElementInfo toc_elements[] = {
{ ARTICLE, "article", (startElementSAXFunc) article_start_element, (endElementSAXFunc) article_end_element, NULL},
{ ARTICLE, "article", (startElementSAXFunc) article_start_element, NULL, NULL},
{ BOOK, "book", NULL, NULL, NULL},
{ SECTION, "section", (startElementSAXFunc) toc_sect_start_element, (endElementSAXFunc) toc_sect_end_element, NULL},
{ SECT1, "sect1", (startElementSAXFunc) toc_sect_start_element, (endElementSAXFunc) toc_sect_end_element, NULL},
......@@ -44,7 +44,7 @@ ElementInfo toc_elements[] = {
{ HOLDER, "holder", NULL, NULL, (charactersSAXFunc) toc_copyright_characters},
{ TITLE, "title", (startElementSAXFunc) toc_title_start_element, (endElementSAXFunc) toc_title_end_element, (charactersSAXFunc) toc_title_characters },
{ SUBTITLE, "subtitle", (startElementSAXFunc) toc_title_start_element, (endElementSAXFunc) toc_title_end_element, (charactersSAXFunc) toc_title_characters },
{ ULINK, "ulink", NULL, NULL, NULL},
{ ULINK, "ulink", (startElementSAXFunc) ulink_start_element, (endElementSAXFunc) ulink_end_element, (charactersSAXFunc) write_characters},
{ XREF, "xref", NULL, NULL, NULL},
{ FOOTNOTE, "footnote", NULL, NULL, NULL},
{ FIGURE, "figure", NULL, NULL, NULL},
......@@ -64,7 +64,6 @@ toc_init_data (void)
}
static void
toc_sect_start_element (Context *context,
const gchar *name,
......@@ -299,7 +298,7 @@ toc_title_start_element (Context *context,
if (context->sect4 > 0) g_print (".%d", context->sect4);
if (context->sect5 > 0) g_print (".%d", context->sect5);
g_print (".&nbsp;&nbsp;");
g_print ("<A href=\"%s#", context->base_file);
g_print ("<A href=\"%s?", context->base_file);
atrs_ptr = (stack_el->atrs);
while (atrs_ptr && *atrs_ptr) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment