summaryrefslogtreecommitdiff
path: root/lib/rts.c
diff options
context:
space:
mode:
authorPrashanth Mundkur2018-09-06 14:56:07 -0700
committerPrashanth Mundkur2018-09-07 13:06:07 -0700
commit08654e675bd8f0f7ceafe4d7d74d05a2b1ee8291 (patch)
tree9fcc6f5348653a8e71b1b375d7d261feeef47491 /lib/rts.c
parent13b3fd08c7e572f0e840393006b8e02e5f608dac (diff)
C: add a usage message to the rts.
Diffstat (limited to 'lib/rts.c')
-rw-r--r--lib/rts.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/rts.c b/lib/rts.c
index 729e2a8b..c2cd8e0d 100644
--- a/lib/rts.c
+++ b/lib/rts.c
@@ -448,18 +448,30 @@ static struct option options[] = {
{"entry", required_argument, 0, 'n'},
{"image", required_argument, 0, 'i'},
{"verbosity", required_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
+static void print_usage()
+{
+ struct option *opt = options;
+ while (opt->name) {
+ printf("\t -%c\t %s\n", (char)opt->val, opt->name);
+ opt++;
+ }
+ exit(EXIT_SUCCESS);
+}
+
int process_arguments(int argc, char *argv[])
{
int c;
+ bool exe_loaded = false;
bool elf_entry_set = false;
uint64_t elf_entry;
while (true) {
int option_index = 0;
- c = getopt_long(argc, argv, "e:n:i:b:l:C:", options, &option_index);
+ c = getopt_long(argc, argv, "e:n:i:b:l:C:h", options, &option_index);
if (c == -1) break;
@@ -502,14 +514,17 @@ int process_arguments(int argc, char *argv[])
load_raw(addr, file);
free(file);
+ exe_loaded = true;
break;
case 'i':
load_image(optarg);
+ exe_loaded = true;
break;
case 'e':
load_elf(optarg);
+ exe_loaded = true;
break;
case 'n':
@@ -534,12 +549,19 @@ int process_arguments(int argc, char *argv[])
}
break;
+ case 'h':
+ print_usage();
+ break;
+
default:
fprintf(stderr, "Unrecognized option %s\n", optarg);
+ print_usage();
return -1;
}
}
+ if (!exe_loaded) print_usage();
+
// assignment to g_elf_entry is deferred until the end of file so that an
// explicit command line flag will override the address read from the ELF
// file.