/* * file_html.c -- html export filter for hnb * * Copyright (C) 2001-2003 Øyvind Kolås * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #if HAVE_CONFIG_H #include #endif #include #include #include #include "cli.h" #include "tree.h" #include "file.h" #include "query.h" #include "util_string.h" #define indent(count,char) {int j;for(j=0;j", ">", "ø", "ø", "Ø", "Ø", "å", "å", "Å", "Å", "æ", "æ", "Æ", "Æ",NULL }; /* *INDENT-ON* */ static int export_html (int argc, char **argv, void *data) { Node *node = (Node *) data; char *filename = argc==2?argv[1]:""; Node *tnode; int level, flags, startlevel, lastlevel, cnt; char *cdata; FILE *file; if (!strcmp (filename, "-")) file = stdout; else file = fopen (filename, "w"); if (!file) { cli_outfunf ("html export, unable to open \"%s\"", filename); return (int) node; } startlevel = nodes_left (node); tnode = node; lastlevel = 0; fprintf (file, "\n\ \n\ \n\ tree exported from hnb\n\ \n\ \n\
    \n"); while ((tnode != 0) & (nodes_left (tnode) >= startlevel)) { level = nodes_left (tnode) - startlevel; flags = node_getflags (tnode); cdata = fixnullstring (node_get (tnode, TEXT)); if (level > lastlevel) { indent (level - 1, "\t"); fprintf (file, "
      \n"); } if (level < lastlevel) { int level_diff = lastlevel - level; for (; level_diff; level_diff--) { indent (level + level_diff - 1, "\t"); fprintf (file, "
    \n"); } } indent (level, "\t"); if (cdata[0] != 0) { char *quoted=string_replace(cdata,htmlquote); fprintf (file, "
  • %s
  • \n", quoted); free(quoted); } else { fprintf (file, "\n"); } lastlevel = level; tnode = node_recurse (tnode); } level = 0; { int level_diff = lastlevel - level; for (; level_diff; level_diff--) { for (cnt = 0; cnt <= level + level_diff - 1; cnt++) fprintf (file, "\t"); fprintf (file, "
\n"); } } fprintf (file, "\n"); if (file != stdout) fclose (file); cli_outfunf ("html export, saved output in \"%s\"", filename); return (int) node; } static void htmlcss_export_nodes (FILE * file, Node *node, int level) { while (node) { char *data = fixnullstring (node_get (node, TEXT)); char *quoted=string_replace(data,htmlquote); fprintf (file, "\n"); indent (level, "\t"); fprintf (file, "
",level+1); fprintf (file, "%s", quoted); free(quoted); if (node_right (node)) { htmlcss_export_nodes (file, node_right (node), level + 1); fprintf (file, "\n"); indent (level, "\t"); fprintf (file, "
"); } else { fprintf (file, ""); } node = node_down (node); } } static int export_htmlcss (int argc, char **argv, void *data) { Node *node = (Node *) data; char *filename = argc==2?argv[1]:""; FILE *file; if (!strcmp (filename, "-")) file = stdout; else file = fopen (filename, "w"); if (!file) { cli_outfunf ("html export, unable to open \"%s\"", filename); return (int) node; } fprintf (file, "\n\ \n\ \n\ \n\ tree exported from hnb\n\ \n\ \n\ \n"); htmlcss_export_nodes (file, node, 0); fprintf (file, "\n\n"); if (file != stdout) fclose (file); cli_outfunf ("html css export, saved output in \"%s\"", filename); return (int) node; } /* !init_file_html(); */ void init_file_html () { cli_add_command ("export_html", export_html, ""); cli_add_command ("export_htmlcss", export_htmlcss, ""); }