| 159 | } |
| 160 | |
| 161 | int main(int argc, char **argv) |
| 162 | { |
| 163 | struct { |
| 164 | // Mandatory |
| 165 | const char *fmd_filename; |
| 166 | const char *fmap_filename; |
| 167 | |
| 168 | // Optional |
| 169 | const char *header_filename; |
| 170 | const char *region_filename; |
| 171 | } args = {NULL, NULL, NULL, NULL}; |
| 172 | |
| 173 | bool show_usage = false; |
| 174 | int each_arg; |
| 175 | while (!show_usage && (each_arg = getopt(argc, argv, ":h:R:")) != -1) { |
| 176 | switch (each_arg) { |
| 177 | case 'h': |
| 178 | args.header_filename = optarg; |
| 179 | break; |
| 180 | case 'R': |
| 181 | args.region_filename = optarg; |
| 182 | break; |
| 183 | case ':': |
| 184 | fprintf(stderr, "-%c: Expected an accompanying value\n", |
| 185 | optopt); |
| 186 | show_usage = true; |
| 187 | break; |
| 188 | default: |
| 189 | fprintf(stderr, "-%c: Unexpected command-line switch\n", |
| 190 | optopt); |
| 191 | show_usage = true; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | if (show_usage || argc - optind != 2) { |
| 196 | usage(argv[0]); |
| 197 | return FMAPTOOL_EXIT_BAD_ARGS; |
| 198 | } |
| 199 | args.fmd_filename = argv[optind]; |
| 200 | args.fmap_filename = argv[optind + 1]; |
| 201 | |
| 202 | FILE *fmd_file = stdin; |
| 203 | if (strcmp(args.fmd_filename, STDIN_FILENAME_SENTINEL) != 0) { |
| 204 | fmd_file = fopen(args.fmd_filename, "r"); |
| 205 | if (!fmd_file) { |
| 206 | fprintf(stderr, "FATAL: Unable to open file '%s'\n", |
| 207 | args.fmd_filename); |
| 208 | return FMAPTOOL_EXIT_BAD_INPUT_PATH; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | struct flashmap_descriptor *descriptor = fmd_create(fmd_file); |
| 213 | fclose(fmd_file); |
| 214 | if (!descriptor) { |
| 215 | fputs("FATAL: Failed while processing provided descriptor\n", |
| 216 | stderr); |
| 217 | full_fmd_cleanup(&descriptor); |
| 218 | return FMAPTOOL_EXIT_FAILED_DESCRIPTOR; |
nothing calls this directly
no test coverage detected