Created Debian package
[xmldoc.git] / xp.c
diff --git a/xp.c b/xp.c
index e56e35a..52a6491 100644 (file)
--- a/xp.c
+++ b/xp.c
@@ -23,9 +23,6 @@
 #include <libxml/debugXML.h>
 #include <libxml/HTMLtree.h>
 #include <libxml/xmlIO.h>
-#ifdef LIBXML_DOCB_ENABLED
-#include <libxml/DOCBparser.h>
-#endif
 #ifdef LIBXML_XINCLUDE_ENABLED
 #include <libxml/xinclude.h>
 #endif
@@ -40,7 +37,7 @@
 #include <libxslt/xsltutils.h>
 #include <libxslt/extensions.h>
 
-#include <libexslt/exsltconfig.h>
+#include <libexslt/exslt.h>
 
 
 #ifndef HAVE_STAT
@@ -58,6 +55,9 @@ xmlParserInputPtr xmlNoNetExternalEntityLoader(const char *URL,
                                               const char *ID,
                                               xmlParserCtxtPtr ctxt);
 
+#define LIBXML_DEBUG_ENABLED
+//#define DEBUG
+
 static int debug = 0;
 static int novalid = 0;
 static int noout = 0;
@@ -68,15 +68,13 @@ static int docbook = 0;
 #ifdef LIBXML_HTML_ENABLED
 static int html = 0;
 #endif
-#ifdef LIBXML_XINCLUDE_ENABLED
-static int xinclude = 0;
-#endif
-static int profile = 0;
 
 static const char *params[16 + 1];
 static int nbparams = 0;
 static const char *output = NULL;
 
+void LatexEscape(xmlNodePtr node);
+
 /*
  *  The LaTeX translation table. Translate unicodes to LaTeX escape sequences.
  */
@@ -93,14 +91,15 @@ struct
    {  '$',     "\\$"              },
    {  '%',     "\\%"              },
    {  '&',     "\\&"              },
-   {  '<',     "\\verb+<+"        },
-   {  '>',     "\\verb+>+"        },
+   {  '<',     "$<$"              },
+   {  '>',     "$>$"              },
    {  '\\',    "$\\backslash$"    },
-   {  '^',     "\\verb+^+"        },
+   {  '^',     "$\\wedge$"        },
    {  '_',     "\\_"              },
    {  '{',     "\\{"              },
+   {  '|',     "$\\mid$"          },
    {  '}',     "\\}"              },
-   {  '~',     "\\verb+~+"        },
+   {  '~',     "$\\sim$"          },
    {  160,     "~"                },
    {  161,     "!`"               },
    {  162,     "..."              },
@@ -351,17 +350,20 @@ static void
 xsltProcess(xmlDocPtr doc, xsltStylesheetPtr cur, const char *filename) {
     xmlDocPtr res;
 
-#ifdef LIBXML_XINCLUDE_ENABLED
-    if (xinclude) {
-       xmlXIncludeProcess(doc);
-    }
+    xmlXIncludeProcessFlags(doc, XSLT_PARSE_OPTIONS);
+
+#ifdef DEBUG
+    xmlDebugDumpDocument(stdout, doc);
 #endif
+
+    if (latex)
+    {
+       LatexEscape(xmlDocGetRootElement(doc));
+    }
+
     if (output == NULL) {
-       if (profile) {
-           res = xsltProfileStylesheet(cur, doc, params, stderr);
-       } else {
-           res = xsltApplyStylesheet(cur, doc, params);
-       }
+       res = xsltApplyStylesheet(cur, doc, params);
+
        xmlFreeDoc(doc);
        if (res == NULL) {
            fprintf(stderr, "no result for %s\n", filename);
@@ -405,6 +407,7 @@ xsltProcess(xmlDocPtr doc, xsltStylesheetPtr cur, const char *filename) {
 void LatexEscape(xmlNodePtr node)
 {
    xmlNodePtr  child;
+   xmlAttrPtr  attribute;
    xmlChar     *byte;
    int         unicode;
 
@@ -412,11 +415,14 @@ void LatexEscape(xmlNodePtr node)
    int            textlen;
    int            i;
 
+#ifdef DEBUG
+      fprintf(stderr, "\n-------- Node type %d\n", node->type);
+#endif
    if (xmlNodeIsText(node))
    {
 #ifdef DEBUG
-      fprintf(stderr, "\n-------- Text node (%d bytes):\n%s",
-                      strlen(node->content), node->content);
+      fprintf(stderr, "\n-------- Text node at %p (%d bytes):\n%s",
+                      node, strlen(node->content), node->content);
 #endif
 
       textlen = strlen(node->content);
@@ -499,9 +505,13 @@ void LatexEscape(xmlNodePtr node)
    }
    else
    {
+      for (attribute = node->properties; attribute != 0; attribute = attribute->next)
+      {
+         LatexEscape(attribute->children);
+      }
       for (child = node->children; child != 0; child = child->next)
       {
-         if (strcmp(child->name, "verbatim") != 0)
+         if (strcmp(child->name, "verbatim") != 0 && strcmp(child->name, "example") != 0)
          {
             LatexEscape(child);
          }
@@ -535,10 +545,6 @@ static void usage(const char *name)
     printf("\t             otherwise XML Catalogs starting from \n");
     printf("\t         file:///etc/xml/catalog are activated by default\n");
 #endif
-#ifdef LIBXML_XINCLUDE_ENABLED
-    printf("\t--xinclude : do XInclude processing on document intput\n");
-#endif
-    printf("\t--profile or --norman : dump profiling informations \n");
 }
 
 int
@@ -597,22 +603,11 @@ main(int argc, char **argv)
         } else if ((!strcmp(argv[i], "-noout")) ||
                    (!strcmp(argv[i], "--noout"))) {
             noout++;
-#ifdef LIBXML_DOCB_ENABLED
-        } else if ((!strcmp(argv[i], "-docbook")) ||
-                   (!strcmp(argv[i], "--docbook"))) {
-            docbook++;
-#endif
 #ifdef LIBXML_HTML_ENABLED
         } else if ((!strcmp(argv[i], "-html")) ||
                    (!strcmp(argv[i], "--html"))) {
             html++;
 #endif
-        } else if ((!strcmp(argv[i], "-profile")) ||
-                   (!strcmp(argv[i], "--profile"))) {
-            profile++;
-        } else if ((!strcmp(argv[i], "-norman")) ||
-                   (!strcmp(argv[i], "--norman"))) {
-            profile++;
         } else if ((!strcmp(argv[i], "-nonet")) ||
                    (!strcmp(argv[i], "--nonet"))) {
             xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
@@ -628,12 +623,6 @@ main(int argc, char **argv)
                 xmlLoadCatalogs(catalogs);
             }
 #endif
-#ifdef LIBXML_XINCLUDE_ENABLED
-        } else if ((!strcmp(argv[i], "-xinclude")) ||
-                   (!strcmp(argv[i], "--xinclude"))) {
-            xinclude++;
-            xsltSetXIncludeDefault(1);
-#endif
         } else if ((!strcmp(argv[i], "-param")) ||
                    (!strcmp(argv[i], "--param"))) {
             i++;
@@ -660,6 +649,7 @@ main(int argc, char **argv)
     }
     params[nbparams] = NULL;
 
+    xsltSetXIncludeDefault(1);
     /*
      * Replace entities with their content.
      */
@@ -730,20 +720,11 @@ main(int argc, char **argv)
                 doc = htmlParseFile(argv[i], NULL);
             else
 #endif
-#ifdef LIBXML_DOCB_ENABLED
-            if (docbook)
-                doc = docbParseFile(argv[i], NULL);
-            else
-#endif
                 doc = xmlParseFile(argv[i]);
             if (doc == NULL) {
                 fprintf(stderr, "unable to parse %s\n", argv[i]);
                 continue;
             }
-            if (latex)
-            {
-               LatexEscape(xmlDocGetRootElement(doc));
-            }
            xsltProcess(doc, cur, argv[i]);
         }
     }