#include <pakfire/string.h>
#include <pakfire/util.h>
+// Enable to get more debugging output
+//#define PAKFIRE_DEBUG_PARSER
+
struct pakfire_parser {
struct pakfire_ctx* ctx;
struct pakfire* pakfire;
if (!namespace)
namespace = "";
+#ifdef PAKFIRE_DEBUG_PARSER
if (*namespace)
DEBUG(parser->pakfire, "%p: Looking up %s.%s\n", parser, namespace, name);
else
DEBUG(parser->pakfire, "%p: Looking up %s\n", parser, name);
+#endif /* PAKFIRE_DEBUG_PARSER */
struct pakfire_parser_declaration* d;
for (unsigned i = 0; i < parser->num_declarations; i++) {
// Return if namespace and name match
if ((strcmp(d->namespace, namespace) == 0) && (strcmp(d->name, name) == 0)) {
+#ifdef PAKFIRE_DEBUG_PARSER
DEBUG(parser->pakfire, "%p: Found result = %s\n", parser, d->value);
+#endif /* PAKFIRE_DEBUG_PARSER */
return d;
}
}
+#ifdef PAKFIRE_DEBUG_PARSER
DEBUG(parser->pakfire, "%p: Nothing found\n", parser);
+#endif /* PAKFIRE_DEBUG_PARSER */
return NULL;
}
if (r)
goto ERROR;
+#ifdef PAKFIRE_DEBUG_PARSER
DEBUG(parser->pakfire, "Expanding command: %s\n", command);
+#endif /* PAKFIRE_DEBUG_PARSER */
// Update argv
argv[2] = (const char*)command;
if (r)
goto ERROR;
+#ifdef PAKFIRE_DEBUG_PARSER
DEBUG(parser->pakfire, "Expanding variable: %s\n", variable);
+#endif /* PAKFIRE_DEBUG_PARSER */
// Search for a declaration of this variable
const char* repl = pakfire_parser_get_raw(parser, namespace, (const char*)variable);
}
}
+#ifdef PAKFIRE_DEBUG_PARSER
// What is its value?
if (repl) {
DEBUG(parser->pakfire, "Replacing %%{%s} with '%s'\n", variable, repl);
} else {
DEBUG(parser->pakfire, "Replacing %%{%s} with an empty string\n", variable);
}
+#endif /* PAKFIRE_DEBUG_PARSER */
// Replace all occurrences
char* tmp = pakfire_string_replace(*buffer, (const char*)pattern, (repl) ? repl : "");