continue;
parser = grub2_parser_create(dc);
- grub2_parser_parse(parser, buf, len);
+ grub2_parser_parse(parser, *filename, buf, len);
talloc_free(buf);
talloc_free(parser);
break;
struct list symtab;
struct discover_context *ctx;
struct discover_boot_option *opt;
+ const char *filename;
unsigned int n_options;
};
/* external parser api */
struct grub2_parser *grub2_parser_create(struct discover_context *ctx);
-void grub2_parser_parse(struct grub2_parser *parser, char *buf, int len);
+void grub2_parser_parse(struct grub2_parser *parser, const char *filename,
+ char *buf, int len);
#endif /* GRUB2_H */
return parser;
}
-void grub2_parser_parse(struct grub2_parser *parser, char *buf, int len)
+void grub2_parser_parse(struct grub2_parser *parser, const char *filename,
+ char *buf, int len)
{
YY_BUFFER_STATE bufstate;
int rc;
+ parser->script->filename = filename;
+
bufstate = yy_scan_bytes(buf, len - 1, parser->scanner);
yyset_lineno(1, parser->scanner);
static void init_env(struct grub2_script *script)
{
struct env_entry *env;
+ char *prefix, *sep;
list_init(&script->environment);
+ /* use location of the parsed config file to determine the prefix */
env = talloc(script, struct env_entry);
+
+ prefix = NULL;
+ if (script->filename) {
+ sep = strrchr(script->filename, '/');
+ if (sep)
+ prefix = talloc_strndup(env, script->filename,
+ sep - script->filename);
+ }
+
env->name = talloc_strdup(env, "prefix");
- env->value = talloc_strdup(env, default_prefix);
+ if (prefix)
+ env->value = prefix;
+ else
+ env->value = talloc_strdup(env, default_prefix);
list_add(&script->environment, &env->list);
}
void script_execute(struct grub2_script *script)
{
+ init_env(script);
statements_execute(script, script->statements);
}
script = talloc_zero(parser, struct grub2_script);
- init_env(script);
script->ctx = ctx;
list_init(&script->symtab);
test-grub2-load-env \
test-grub2-save-env \
test-grub2-saved-default \
+ test-grub2-nondefault-prefix \
test-grub2-f18-ppc64 \
test-grub2-ubuntu-13_04-x86 \
test-grub2-lexer-error \
--- /dev/null
+
+#include "parser-test.h"
+
+#if 0 /* PARSER_EMBEDDED_CONFIG */
+menuentry 'test option' {
+ linux ${prefix}/vmlinux
+}
+#endif
+
+
+
+void run_test(struct parser_test *test)
+{
+ struct discover_boot_option *opt;
+ struct discover_context *ctx;
+
+ test_read_conf_embedded(test, "/grub/grub.cfg");
+
+ test_run_parser(test, "grub2");
+
+ ctx = test->ctx;
+
+ check_boot_option_count(ctx, 1);
+ opt = get_boot_option(ctx, 0);
+
+ check_name(opt, "test option");
+ check_resolved_local_resource(opt->boot_image, ctx->device,
+ "/grub/vmlinux");
+}