• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #define _GNU_SOURCE
17 #include <libxml/parser.h>
18 #include <libxml/xpath.h>
19 #include <libxml/xpathInternals.h>
20 #include <libxml/xpointer.h>
21 #include <stdlib.h>
22 #include <sys/types.h>
23 #include <sys/wait.h>
24 
main(int argc,char ** argv)25 int main(int argc, char **argv) {
26 #if defined(LIBXML_XPATH_ENABLED) && defined(LIBXML_XPTR_ENABLED)
27   if (argc > 2) {
28     xmlDocPtr doc;
29     xmlXPathContextPtr xpathCtx;
30     xmlInitParser();
31     /* Load XML document */
32     doc = xmlReadFile(argv[1], NULL, 0);
33     if (doc) {
34       /* Create xpath evaluation context */
35       xpathCtx = (xmlXPathContextPtr)xmlXPtrNewContext(doc, (xmlNode *)NULL,
36                                                        (xmlNode *)NULL);
37       if (xpathCtx) {
38         xmlXPathParserContextPtr pctxt =
39             xmlXPathNewParserContext((xmlChar *)argv[2], xpathCtx);
40         if (pctxt) {
41           xmlXPathEvalExpr(pctxt);
42           xmlXPathFreeContext(xpathCtx);
43         }
44         xmlFreeDoc(doc);
45       }
46       xmlCleanupParser();
47     }
48   }
49 #endif
50   return EXIT_SUCCESS;
51 }
52