X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=tests%2Fregression%2Ftools%2Fmi%2Fextract_xml.c;h=32c57e60a93c3f462069623f994ae2056ecf8e14;hb=9d16b343fb9e781fc8d8fa3c448a3f382306dd33;hp=ddf8c16773331b9786b2018c4cbf2d7fb5a651e5;hpb=41af1adf5100627c2e11565e7d9e4b9c5a8b9fac;p=lttng-tools.git diff --git a/tests/regression/tools/mi/extract_xml.c b/tests/regression/tools/mi/extract_xml.c index ddf8c1677..32c57e60a 100644 --- a/tests/regression/tools/mi/extract_xml.c +++ b/tests/regression/tools/mi/extract_xml.c @@ -1,17 +1,8 @@ /* - * Copyright (C) 2014 - Jonathan Rajotte + * Copyright (C) 2014 Jonathan Rajotte * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2 only, as - * published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * 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., 51 */ /* @@ -33,10 +24,11 @@ * node;b; * node;c; */ -#include +#include +#include #include +#include #include -#include #include #include @@ -47,9 +39,9 @@ #if defined(LIBXML_XPATH_ENABLED) - -int opt_verbose; -int node_exist; +static int opt_verbose; +static int node_exist; +static bool result = false; /** * print_xpath_nodes: @@ -86,7 +78,7 @@ static int print_xpath_nodes(xmlDocPtr doc, xmlNodeSetPtr nodes, FILE *output) node_child_value_string = xmlNodeListGetString(doc, cur->children, 1); if (node_exist) { - fprintf(output, "true\n"); + result = true; } else if (opt_verbose) { fprintf(output, "%s;%s;\n", cur->name, node_child_value_string); @@ -98,7 +90,7 @@ static int print_xpath_nodes(xmlDocPtr doc, xmlNodeSetPtr nodes, FILE *output) } else { /* We don't want to print non-final element */ if (node_exist) { - fprintf(output, "true\n"); + result = true; } else { fprintf(stderr, "ERR:%s\n", "Xpath expression return non-final xml element"); @@ -108,7 +100,7 @@ static int print_xpath_nodes(xmlDocPtr doc, xmlNodeSetPtr nodes, FILE *output) } } else { if (node_exist) { - fprintf(output, "true\n"); + result = true; } else { /* We don't want to print non-final element */ fprintf(stderr, "ERR:%s\n", @@ -121,7 +113,7 @@ static int print_xpath_nodes(xmlDocPtr doc, xmlNodeSetPtr nodes, FILE *output) } else { cur = nodes->nodeTab[i]; if (node_exist) { - fprintf(output, "true\n"); + result = true; } else if (opt_verbose) { fprintf(output, "%s;%s;\n", cur->parent->name, cur->content); } else { @@ -155,8 +147,8 @@ static int register_lttng_namespace(xmlXPathContextPtr xpathCtx) } ret = xmlXPathRegisterNs(xpathCtx, prefix, ns); - xmlFree(prefix); end: + xmlFree(prefix); xmlFree(ns); return ret; } @@ -221,6 +213,9 @@ static int extract_xpath(const char *xml_path, const xmlChar *xpath) xmlFreeDoc(doc); return -1; } + if (node_exist && result) { + fprintf(stdout, "true\n"); + } /* Cleanup */ xmlXPathFreeObject(xpathObj);