~ubuntu-branches/ubuntu/saucy/libxml2/saucy-proposed

« back to all changes in this revision

Viewing changes to xmllint.c

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2010-03-21 09:51:17 UTC
  • mfrom: (1.1.14 upstream)
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20100321095117-1xe3ad1tzlu648h2
Tags: 2.7.7.dfsg-1
* New upstream release.
* debian/control:
  + Bump Standards-Version to 3.8.4.0.
  + Depend on a version of debhelper that provides dh and supports
    overrides.
* debian/compat: Bump to 7.
* debian/rules:
  + Don't avoid to build in example/. There is no reason to do so anymore.
  + Remove remains of WORKAROUND_MODIFIED_FILES, that was removed 2 years
    ago.
  + Change the way python libs are built. We now use configure to set
    different environment with and without python, and arrange things so
    that we don't have to build the base libxml2 library several times.
  + Deduplicate in /usr/lib/pyshared, not
    /usr/lib/python-support/python-libxml2.
  + Remove old source and diff rules that only displayed a message
    inviting to use dpkg-source -b.
  + Force -Wl,--as-needed at the beginning of the gcc command line.
  + Simplify rules by switching to dh.
  + Don't refresh COPYING during clean target, it appears not to be
    necessary anymore.
  + Use a common cache for main and python configure passes.
* debian/python-libxml2.install: Install python files from
  /usr/lib/python*/dist-packages.
* python/generator.py: Sort python generated stubs so that libxml2.py
  doesn't differ between python 2.5 and 2.6.
* doc/devhelp/Makefile.{am,in}: Properly install devhelp files when
  builddir != srcdir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
 
109
109
typedef enum {
110
110
    XMLLINT_RETURN_OK = 0,      /* No error */
111
 
    XMLLINT_ERR_UNCLASS,        /* Unclassified */
112
 
    XMLLINT_ERR_DTD,            /* Error in DTD */
113
 
    XMLLINT_ERR_VALID,          /* Validation error */
114
 
    XMLLINT_ERR_RDFILE,         /* CtxtReadFile error */
115
 
    XMLLINT_ERR_SCHEMACOMP,     /* Schema compilation */
116
 
    XMLLINT_ERR_OUT,            /* Error writing output */
117
 
    XMLLINT_ERR_SCHEMAPAT,      /* Error in schema pattern */
118
 
    XMLLINT_ERR_RDREGIS,        /* Error in Reader registration */
119
 
    XMLLINT_ERR_MEM             /* Out of memory error */
 
111
    XMLLINT_ERR_UNCLASS = 1,    /* Unclassified */
 
112
    XMLLINT_ERR_DTD = 2,        /* Error in DTD */
 
113
    XMLLINT_ERR_VALID = 3,      /* Validation error */
 
114
    XMLLINT_ERR_RDFILE = 4,     /* CtxtReadFile error */
 
115
    XMLLINT_ERR_SCHEMACOMP = 5, /* Schema compilation */
 
116
    XMLLINT_ERR_OUT = 6,        /* Error writing output */
 
117
    XMLLINT_ERR_SCHEMAPAT = 7,  /* Error in schema pattern */
 
118
    XMLLINT_ERR_RDREGIS = 8,    /* Error in Reader registration */
 
119
    XMLLINT_ERR_MEM = 9,        /* Out of memory error */
 
120
    XMLLINT_ERR_XPATH = 10      /* XPath evaluation error */
120
121
} xmllintReturnCode;
121
122
#ifdef LIBXML_DEBUG_ENABLED
122
123
static int shell = 0;
201
202
static xmlPatternPtr patternc = NULL;
202
203
static xmlStreamCtxtPtr patstream = NULL;
203
204
#endif
 
205
#ifdef LIBXML_XPATH_ENABLED
 
206
static const char *xpathquery = NULL;
 
207
#endif
204
208
static int options = XML_PARSE_COMPACT;
205
209
static int sax = 0;
206
210
static int oldxml10 = 0;
2050
2054
}
2051
2055
#endif /* LIBXML_READER_ENABLED */
2052
2056
 
 
2057
#ifdef LIBXML_XPATH_ENABLED
 
2058
/************************************************************************
 
2059
 *                                                                      *
 
2060
 *                      XPath Query                                     *
 
2061
 *                                                                      *
 
2062
 ************************************************************************/
 
2063
 
 
2064
static void doXPathDump(xmlXPathObjectPtr cur) {
 
2065
    switch(cur->type) {
 
2066
        case XPATH_NODESET: {
 
2067
            int i;
 
2068
            xmlNodePtr node;
 
2069
#ifdef LIBXML_OUTPUT_ENABLED
 
2070
            xmlSaveCtxtPtr ctxt;
 
2071
 
 
2072
            if (cur->nodesetval->nodeNr <= 0) {
 
2073
                fprintf(stderr, "XPath set is empty\n");
 
2074
                progresult = XMLLINT_ERR_XPATH;
 
2075
                break;
 
2076
            }
 
2077
            ctxt = xmlSaveToFd(1, NULL, 0);
 
2078
            if (ctxt == NULL) {
 
2079
                fprintf(stderr, "Out of memory for XPath\n");
 
2080
                progresult = XMLLINT_ERR_MEM;
 
2081
                return;
 
2082
            }
 
2083
            for (i = 0;i < cur->nodesetval->nodeNr;i++) {
 
2084
                node = cur->nodesetval->nodeTab[i];
 
2085
                xmlSaveTree(ctxt, node);
 
2086
            }
 
2087
            xmlSaveClose(ctxt);
 
2088
#else
 
2089
            printf("xpath returned %d nodes\n", cur->nodesetval->nodeNr);
 
2090
#endif
 
2091
            break;
 
2092
        }
 
2093
        case XPATH_BOOLEAN:
 
2094
            if (cur->boolval) printf("true");
 
2095
            else printf("false");
 
2096
            break;
 
2097
        case XPATH_NUMBER:
 
2098
            switch (xmlXPathIsInf(cur->floatval)) {
 
2099
            case 1:
 
2100
                printf("Infinity");
 
2101
                break;
 
2102
            case -1:
 
2103
                printf("-Infinity");
 
2104
                break;
 
2105
            default:
 
2106
                if (xmlXPathIsNaN(cur->floatval)) {
 
2107
                    printf("NaN");
 
2108
                } else {
 
2109
                    printf("%0g", cur->floatval);
 
2110
                }
 
2111
            }
 
2112
            break;
 
2113
        case XPATH_STRING:
 
2114
            printf("%s", (const char *) cur->stringval);
 
2115
            break;
 
2116
        case XPATH_UNDEFINED:
 
2117
            fprintf(stderr, "XPath Object is uninitialized\n");
 
2118
            progresult = XMLLINT_ERR_XPATH;
 
2119
            break;
 
2120
        default:
 
2121
            fprintf(stderr, "XPath object of unexpected type\n");
 
2122
            progresult = XMLLINT_ERR_XPATH;
 
2123
            break;
 
2124
    }
 
2125
}
 
2126
 
 
2127
static void doXPathQuery(xmlDocPtr doc, const char *query) {
 
2128
    xmlXPathContextPtr ctxt;
 
2129
    xmlXPathObjectPtr res;
 
2130
 
 
2131
    ctxt = xmlXPathNewContext(doc);
 
2132
    if (ctxt == NULL) {
 
2133
        fprintf(stderr, "Out of memory for XPath\n");
 
2134
        progresult = XMLLINT_ERR_MEM;
 
2135
        return;
 
2136
    }
 
2137
    ctxt->node = xmlDocGetRootElement(doc);
 
2138
    res = xmlXPathEval(BAD_CAST query, ctxt);
 
2139
    xmlXPathFreeContext(ctxt);
 
2140
 
 
2141
    if (res == NULL) {
 
2142
        fprintf(stderr, "XPath evaluation failure\n");
 
2143
        progresult = XMLLINT_ERR_XPATH;
 
2144
        return;
 
2145
    }
 
2146
    doXPathDump(res);
 
2147
    xmlXPathFreeObject(res);
 
2148
}
 
2149
#endif /* LIBXML_XPATH_ENABLED */
 
2150
 
2053
2151
/************************************************************************
2054
2152
 *                                                                      *
2055
2153
 *                      Tree Test processing                            *
2318
2416
    }
2319
2417
#endif
2320
2418
 
 
2419
#ifdef LIBXML_XPATH_ENABLED
 
2420
    if (xpathquery != NULL) {
 
2421
        doXPathQuery(doc, xpathquery);
 
2422
    }
 
2423
#endif
 
2424
 
2321
2425
#ifdef LIBXML_DEBUG_ENABLED
2322
2426
#ifdef LIBXML_XPATH_ENABLED
2323
2427
    /*
2551
2655
 
2552
2656
                if (format)
2553
2657
                    saveOpts |= XML_SAVE_FORMAT;
 
2658
 
 
2659
#if defined(LIBXML_HTML_ENABLED) || defined(LIBXML_VALID_ENABLED)
2554
2660
                if (xmlout)
2555
2661
                    saveOpts |= XML_SAVE_AS_XML;
 
2662
#endif
2556
2663
 
2557
2664
                if (output == NULL)
2558
2665
                    ctxt = xmlSaveToFd(1, encoding, saveOpts);
2945
3052
#endif
2946
3053
    printf("\t--sax: do not build a tree but work just at the SAX level\n");
2947
3054
    printf("\t--oldxml10: use XML-1.0 parsing rules before the 5th edition\n");
 
3055
#ifdef LIBXML_XPATH_ENABLED
 
3056
    printf("\t--xpath expr: evaluate the XPath expression, inply --noout\n");
 
3057
#endif
2948
3058
 
2949
3059
    printf("\nLibxml project home page: http://xmlsoft.org/\n");
2950
3060
    printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
3285
3395
            i++;
3286
3396
            pattern = argv[i];
3287
3397
#endif
 
3398
#ifdef LIBXML_XPATH_ENABLED
 
3399
        } else if ((!strcmp(argv[i], "-xpath")) ||
 
3400
                   (!strcmp(argv[i], "--xpath"))) {
 
3401
            i++;
 
3402
            noout++;
 
3403
            xpathquery = argv[i];
 
3404
#endif
3288
3405
        } else if ((!strcmp(argv[i], "-oldxml10")) ||
3289
3406
                   (!strcmp(argv[i], "--oldxml10"))) {
3290
3407
            oldxml10++;
3516
3633
            continue;
3517
3634
        }
3518
3635
#endif
 
3636
#ifdef LIBXML_XPATH_ENABLED
 
3637
        if ((!strcmp(argv[i], "-xpath")) ||
 
3638
            (!strcmp(argv[i], "--xpath"))) {
 
3639
            i++;
 
3640
            continue;
 
3641
        }
 
3642
#endif
3519
3643
        if ((timing) && (repeat))
3520
3644
            startTimer();
3521
3645
        /* Remember file names.  "-" means stdin.  <sven@zen.org> */