/*
- * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
+ * Copyright (C) 2014 Jonathan Rajotte <jonathan.r.julien@gmail.com>
*
- * 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
*/
/*
* node;b;
* node;c;
*/
-#include <stdlib.h>
+#include <assert.h>
+#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include <unistd.h>
#include <libxml/tree.h>
#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:
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);
} 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");
}
} 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",
} 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 {
xmlFreeDoc(doc);
return -1;
}
+ if (node_exist && result) {
+ fprintf(stdout, "true\n");
+ }
/* Cleanup */
xmlXPathFreeObject(xpathObj);