declaration->name, declaration->value, declaration->flags);
}
-static const char* pakfire_parser_find_template(struct pakfire_parser* parser,
- char* template, size_t size, const char* namespace) {
+static int pakfire_parser_find_template(struct pakfire_parser* parser,
+ char* template, const size_t length, const char* namespace) {
DEBUG(parser->pakfire, "Looking up template in namespace '%s'\n", namespace);
struct pakfire_parser_declaration* d = pakfire_parser_get_declaration(
const char* value = (d && *d->value) ? d->value : "MAIN";
- snprintf(template, size, "packages.template:%s", value);
-
- return template;
+ // Format full variable name
+ return __pakfire_string_format(template, length, "packages.template:%s", value);
}
static const char* pakfire_parser_get_raw(struct pakfire_parser* parser, const char* namespace, const char* name) {
struct pakfire_parser_declaration* d = NULL;
+ char template[NAME_MAX];
+ int r;
// First, perform a simple lookup
d = pakfire_parser_get_declaration_recursive(parser, namespace, name);
if (d && d->value)
return d->value;
- char template[NAME_MAX] = "";
-
// If we couldn't find anything, we check if there is a template, and if that
// has our value...
if (namespace && pakfire_string_startswith(namespace, "packages.package:")) {
- pakfire_parser_find_template(parser, template, sizeof(template) - 1, namespace);
+ r = pakfire_parser_find_template(parser, template, sizeof(template), namespace);
+ if (r)
+ return NULL;
- if (*template) {
- d = pakfire_parser_find_declaration(parser, template, name);
- if (d && d->value)
- return d->value;
- }
+ d = pakfire_parser_find_declaration(parser, template, name);
+ if (d && d->value)
+ return d->value;
}
// Otherwise we walk up the namespace to find a match
#include <pakfire/package.h>
#include <pakfire/parser.h>
#include <pakfire/repo.h>
+#include <pakfire/string.h>
#include <pakfire/util.h>
#include "../testsuite.h"
int r = EXIT_FAILURE;
while (*makefile) {
- r = snprintf(path, sizeof(path) - 1, "%s/%s", TEST_SRC_PATH, *makefile);
- ASSERT(r >= 0);
+ ASSERT_SUCCESS(pakfire_string_format(path, "%s/%s", TEST_SRC_PATH, *makefile));
// Open file
FILE* f = fopen(path, "r");
#include <string.h>
#include <pakfire/parser.h>
+#include <pakfire/string.h>
#include <pakfire/util.h>
#include "../testsuite.h"
int r = EXIT_FAILURE;
while (*file) {
- r = snprintf(path, sizeof(path) - 1, "%s/%s", TEST_SRC_PATH, *file);
- ASSERT(r >= 0);
+ ASSERT_SUCCESS(pakfire_string_format(path, "%s/%s", TEST_SRC_PATH, *file));
// Create a new parser
struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);