diff options
| author | Prashanth Mundkur | 2018-09-06 14:56:07 -0700 |
|---|---|---|
| committer | Prashanth Mundkur | 2018-09-07 13:06:07 -0700 |
| commit | 08654e675bd8f0f7ceafe4d7d74d05a2b1ee8291 (patch) | |
| tree | 9fcc6f5348653a8e71b1b375d7d261feeef47491 /lib/rts.c | |
| parent | 13b3fd08c7e572f0e840393006b8e02e5f608dac (diff) | |
C: add a usage message to the rts.
Diffstat (limited to 'lib/rts.c')
| -rw-r--r-- | lib/rts.c | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -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. |
