summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Zongker <dougz@android.com>2009-06-15 23:28:17 +0200
committerThe Android Open Source Project <initial-contribution@android.com>2009-06-15 23:28:17 +0200
commite77e091522122bed0b4f75a3abcb120e398c9abe (patch)
tree4b3d44b4b9fc35126905eb474f4972638ec5c155
parentam d9c9d10d: fixes to edify and updater script (diff)
parentadd less_than_int, greater_than_int to edify (diff)
downloadandroid_bootable_recovery-e77e091522122bed0b4f75a3abcb120e398c9abe.tar
android_bootable_recovery-e77e091522122bed0b4f75a3abcb120e398c9abe.tar.gz
android_bootable_recovery-e77e091522122bed0b4f75a3abcb120e398c9abe.tar.bz2
android_bootable_recovery-e77e091522122bed0b4f75a3abcb120e398c9abe.tar.lz
android_bootable_recovery-e77e091522122bed0b4f75a3abcb120e398c9abe.tar.xz
android_bootable_recovery-e77e091522122bed0b4f75a3abcb120e398c9abe.tar.zst
android_bootable_recovery-e77e091522122bed0b4f75a3abcb120e398c9abe.zip
-rw-r--r--edify/expr.c53
-rw-r--r--edify/main.c10
2 files changed, 63 insertions, 0 deletions
diff --git a/edify/expr.c b/edify/expr.c
index 406c67ea6..f1c555552 100644
--- a/edify/expr.c
+++ b/edify/expr.c
@@ -72,6 +72,8 @@ char* ConcatFn(const char* name, State* state, int argc, Expr* argv[]) {
char* IfElseFn(const char* name, State* state, int argc, Expr* argv[]) {
if (argc != 2 && argc != 3) {
+ free(state->errmsg);
+ state->errmsg = strdup("ifelse expects 2 or 3 arguments");
return NULL;
}
char* cond = Evaluate(state, argv[0]);
@@ -244,6 +246,54 @@ char* SequenceFn(const char* name, State* state, int argc, Expr* argv[]) {
return Evaluate(state, argv[1]);
}
+char* LessThanIntFn(const char* name, State* state, int argc, Expr* argv[]) {
+ if (argc != 2) {
+ free(state->errmsg);
+ state->errmsg = strdup("less_than_int expects 2 arguments");
+ return NULL;
+ }
+
+ char* left;
+ char* right;
+ if (ReadArgs(state, argv, 2, &left, &right) < 0) return NULL;
+
+ bool result = false;
+ char* end;
+
+ long l_int = strtol(left, &end, 10);
+ if (left[0] == '\0' || *end != '\0') {
+ fprintf(stderr, "[%s] is not an int\n", left);
+ goto done;
+ }
+
+ long r_int = strtol(right, &end, 10);
+ if (right[0] == '\0' || *end != '\0') {
+ fprintf(stderr, "[%s] is not an int\n", right);
+ goto done;
+ }
+
+ result = l_int < r_int;
+
+ done:
+ free(left);
+ free(right);
+ return strdup(result ? "t" : "");
+}
+
+char* GreaterThanIntFn(const char* name, State* state, int argc, Expr* argv[]) {
+ if (argc != 2) {
+ free(state->errmsg);
+ state->errmsg = strdup("greater_than_int expects 2 arguments");
+ return NULL;
+ }
+
+ Expr* temp[2];
+ temp[0] = argv[1];
+ temp[1] = argv[0];
+
+ return LessThanIntFn(name, state, 2, temp);
+}
+
char* Literal(const char* name, State* state, int argc, Expr* argv[]) {
return strdup(name);
}
@@ -313,6 +363,9 @@ void RegisterBuiltins() {
RegisterFunction("is_substring", SubstringFn);
RegisterFunction("stdout", StdoutFn);
RegisterFunction("sleep", SleepFn);
+
+ RegisterFunction("less_than_int", LessThanIntFn);
+ RegisterFunction("greater_than_int", GreaterThanIntFn);
}
diff --git a/edify/main.c b/edify/main.c
index 03eefc69e..0e3610847 100644
--- a/edify/main.c
+++ b/edify/main.c
@@ -143,6 +143,16 @@ int test() {
expect("if \"\" then yes endif", "", &errors);
expect("if \"\"; t then yes endif", "yes", &errors);
+ // numeric comparisons
+ expect("less_than_int(3, 14)", "t", &errors);
+ expect("less_than_int(14, 3)", "", &errors);
+ expect("less_than_int(x, 3)", "", &errors);
+ expect("less_than_int(3, x)", "", &errors);
+ expect("greater_than_int(3, 14)", "", &errors);
+ expect("greater_than_int(14, 3)", "t", &errors);
+ expect("greater_than_int(x, 3)", "", &errors);
+ expect("greater_than_int(3, x)", "", &errors);
+
printf("\n");
return errors;