summaryrefslogtreecommitdiffstats
path: root/src/preprocessor.vala
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@gmail.com>2013-01-08 18:42:31 +0100
committerMarc-André Lureau <marcandre.lureau@gmail.com>2013-01-08 18:42:31 +0100
commit0aa239cc22c9e6085a2d09c9cdc62da6ea54a2ae (patch)
tree6280c29e364214900c34e1914ef44629327df633 /src/preprocessor.vala
parent56ea50cdbee2c0b065364522d6640424107b5c8d (diff)
wixl: add -D argument to define variables from command line
Diffstat (limited to 'src/preprocessor.vala')
-rw-r--r--src/preprocessor.vala18
1 files changed, 15 insertions, 3 deletions
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<string, string> globals;
HashTable<string, string> variables;
construct {
variables = new HashTable<string, string> (str_hash, str_equal);
}
+ public Preprocessor (HashTable<string, string> 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;
}
}