Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor how we exit to workaround emscripten bug
See kripen/emscripten#2968
  • Loading branch information
ddevault committed Nov 4, 2014
1 parent 5aba134 commit c4eefa8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions main.c
Expand Up @@ -38,18 +38,18 @@ void show_help() {
);
}

void parse_context(int argc, char **argv) {
int parse_context(int argc, char **argv) {
context.rom_file = context.model_dir = NULL;
const char *errorMessage = "Invalid usage - see `genkfs --help`\n";
int i;
for (i = 1; i < argc; i++) {
if (*argv[i] == '-') {
if (strcasecmp(argv[i], "--help") == 0) {
show_help();
exit(0);
return 0;
} else {
fprintf(stderr, errorMessage);
exit(1);
return 1;
}
} else {
if (context.rom_file == NULL) {
Expand All @@ -58,25 +58,26 @@ void parse_context(int argc, char **argv) {
context.model_dir = argv[i];
} else {
fprintf(stderr, errorMessage);
exit(1);
return 1;
}
}
}
if (context.rom_file == NULL || context.model_dir == NULL) {
fprintf(stderr, errorMessage);
exit(1);
return 1;
}
context.rom = fopen(context.rom_file, "r+");
if (context.rom == NULL) {
fprintf(stderr, "Unable to open %s.\n", context.rom_file);
exit(1);
return 1;
}
fseek(context.rom, 0L, SEEK_END);
uint32_t length = ftell(context.rom);
fseek(context.rom, 0L, SEEK_SET);

context.dat_start = 0x04;
context.fat_start = length / PAGE_LENGTH - 0x9;
return -1;
}

char *concat_path(char* parent, char* child) {
Expand Down Expand Up @@ -263,12 +264,15 @@ void write_filesystem(char *model, FILE *rom, uint8_t fat_start, uint8_t dat_sta
}

int main(int argc, char **argv) {
parse_context(argc, argv);
int ret = parse_context(argc, argv);
if (ret != -1) {
return ret;
}
DIR *model = opendir(context.model_dir);
if (model == NULL) {
fprintf(stderr, "Unable to open %s.\n", context.model_dir);
fclose(context.rom);
exit(1);
return 1;
}
closedir(model); // Re-opened later

Expand Down

0 comments on commit c4eefa8

Please sign in to comment.