Some infrastructure work, and of course some debug:
[platform/upstream/libxslt.git] / libxslt / xsltproc.c
1 /*
2  * xsltproc.c: user program for the XSL Transformation 1.0 engine
3  *
4  * See Copyright for the status of this software.
5  *
6  * Daniel.Veillard@imag.fr
7  */
8
9 #include <string.h>
10 #include <libxml/xmlversion.h>
11 #include <libxml/xmlmemory.h>
12 #include <libxml/debugXML.h>
13 #include <libxslt/xslt.h>
14 #include <libxslt/xsltInternals.h>
15 #include <libxslt/transform.h>
16 #include <libxslt/xsltutils.h>
17
18 static int debug = 0;
19
20 int
21 main(int argc, char **argv) {
22     int i;
23     xsltStylesheetPtr cur;
24     xmlDocPtr doc, res;
25
26     LIBXML_TEST_VERSION
27     for (i = 1; i < argc ; i++) {
28         if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) {
29             debug++;
30         } else if ((!strcmp(argv[i], "-v")) ||
31                    (!strcmp(argv[i], "-verbose")) ||
32                    (!strcmp(argv[i], "--verbose"))) {
33             xsltSetGenericDebugFunc(stderr, NULL);
34         }
35     }
36     xmlSubstituteEntitiesDefault(1);
37     for (i = 1; i < argc ; i++) {
38         if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
39             cur = xsltParseStylesheetFile((const xmlChar *)argv[i]);
40             if (cur != NULL) {
41                 if (cur->indent == 1)
42                     xmlIndentTreeOutput = 1;
43                 else
44                     xmlIndentTreeOutput = 0;
45                 i++;
46                 break;
47             }
48         }
49     }
50     for (;i < argc ; i++) {
51         doc = xmlParseFile(argv[i]);
52         if (doc == NULL) {
53             fprintf(stderr, "unable to parse %s\n", argv[i]);
54             continue;
55         }
56         res = xsltApplyStylesheet(cur, doc);
57         xmlFreeDoc(doc);
58         if (res == NULL) {
59             fprintf(stderr, "no result for %s\n", argv[i]);
60             continue;
61         }
62 #ifdef LIBXML_DEBUG_ENABLED
63         if (debug)
64             xmlDebugDumpDocument(stdout, res);
65         else
66 #endif
67             xmlDocDump(stdout, res);
68
69         xmlFreeDoc(res);
70     }
71     if (cur != NULL)
72         xsltFreeStylesheet(cur);
73     xmlCleanupParser();
74     xmlMemoryDump();
75     return(0);
76 }
77