From 0aa239cc22c9e6085a2d09c9cdc62da6ea54a2ae Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Tue, 8 Jan 2013 18:42:31 +0100 Subject: wixl: add -D argument to define variables from command line --- src/preprocessor.vala | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/preprocessor.vala') diff --git a/src/preprocessor.vala b/src/preprocessor.vala index 6953aa5..ff904cb 100644 --- a/src/preprocessor.vala +++ b/src/preprocessor.vala @@ -2,23 +2,35 @@ namespace Wixl { class Preprocessor: Object { + HashTable globals; HashTable variables; construct { variables = new HashTable (str_hash, str_equal); } + public Preprocessor (HashTable globals) { + this.globals = globals; + } + public void define_variable (string name, string value) { variables.insert (name, value); } - public string get_variable (string str, File? file) throws GLib.Error { + public string? lookup_variable (string name) { + return variables.lookup (name) ?? globals.lookup (name); + } + + public string eval_variable (string str, File? file) throws GLib.Error { var var = str.split (".", 2); if (var.length != 2) throw new Wixl.Error.FAILED ("invalid variable %s", str); switch (var[0]) { case "var": - return variables.lookup (var[1]); + var val = lookup_variable (var[1]); + if (val == null) + throw new Wixl.Error.FAILED ("Undefined variable %s", var[1]); + return val; case "env": return Environment.get_variable (var[1]); case "sys": @@ -55,7 +67,7 @@ namespace Wixl { var substring = remainder[1:closing]; if (substring.index_of ("(") != -1) throw new Wixl.Error.FIXME ("unsupported function"); - result += get_variable (substring, file); + result += eval_variable (substring, file); end += closing + 1; } } -- cgit