diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-07-10 10:39:00 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-07-11 15:49:14 +0200 |
commit | 7e6ce0f718202856ae349970d199bbe95811a1b2 (patch) | |
tree | 8b2f32c86f18c8e47d1fad452d6d83776db8898e /main.c | |
parent | b1817b3b62280d813e86dafe27e74bfe565a372a (diff) |
main: introduce new flag `-x` to allow disabling specific functions
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -40,7 +40,7 @@ print_usage(const char *app) { printf( "Usage\n\n" - " # %s [-t] [-l] [-r] [-S] [-R] [-e '[prefix=]{\"var\": ...}'] [-E [prefix=]env.json] {-i <file> | -s \"ucode script...\"}\n" + " # %s [-t] [-l] [-r] [-S] [-R] [-x function [-x ...]] [-e '[prefix=]{\"var\": ...}'] [-E [prefix=]env.json] {-i <file> | -s \"ucode script...\"}\n" " -h, --help Print this help\n" " -i file Execute the given ucode script file\n" " -s \"ucode script...\" Execute the given string as ucode script\n" @@ -51,6 +51,7 @@ print_usage(const char *app) " -R Enable raw code mode\n" " -e Set global variables from given JSON object\n" " -E Set global variables from given JSON file\n" + " -x Disable given function\n" " -m Preload given module\n", basename(app)); } @@ -218,7 +219,7 @@ main(int argc, char **argv) ucv_object_add(uc_vm_scope_get(&vm), "ARGV", o); /* parse options */ - while ((opt = getopt(argc, argv, "hlrtSRe:E:i:s:m:")) != -1) + while ((opt = getopt(argc, argv, "hlrtSRe:E:i:s:m:x:")) != -1) { switch (opt) { case 'h': @@ -340,6 +341,16 @@ main(int argc, char **argv) case 't': uc_vm_trace_set(&vm, 1); break; + + case 'x': + o = ucv_object_get(uc_vm_scope_get(&vm), optarg, NULL); + + if (ucv_is_callable(o)) + ucv_object_delete(uc_vm_scope_get(&vm), optarg); + else + fprintf(stderr, "Unknown function %s specified\n", optarg); + + break; } } |