/** * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; const char *mstr = NULL; const char *soundstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef UNIX /* Default permissions on files */ (void)umask(022); /* Get the user id */ player_uid = getuid(); #endif /* UNIX */ #ifdef SETGID /* Save the effective GID for later recall */ player_egid = getegid(); #endif /* UNIX */ /* Drop permissions */ safe_setuid_drop(); /* Get the file paths * Paths may be overriden by -d options, so this has to occur *before* * processing command line args */ init_stuff(); /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { const char *arg = argv[i]; /* Require proper options */ if (*arg++ != '-') goto usage; /* Analyze option */ switch (*arg++) { case 'l': list_saves(); exit(0); case 'n': new_game = TRUE; break; case 'w': arg_wizard = TRUE; break; case 'p': arg_power = TRUE; break; case 'r': arg_rebalance = TRUE; break; case 'g': /* Default graphics tile */ /* in graphics.txt, 2 corresponds to adam bolt's tiles */ arg_graphics = 2; if (*arg) arg_graphics = atoi(arg); break; case 'u': { if (!*arg) goto usage; my_strcpy(op_ptr->full_name, arg, sizeof op_ptr->full_name); /* The difference here is because on setgid we have to be * careful to only let the player have savefiles stored in * the central save directory. Sanitising input using * player_safe_name() removes anything like that. * * But if the player is running with per-user saves, they * can do whatever the hell they want. */ #ifdef SETGID savefile_set_name(player_safe_name(player, FALSE)); #else savefile_set_name(arg); #endif /* SETGID */ continue; } case 'm': if (!*arg) goto usage; mstr = arg; continue; case 's': if (!*arg) goto usage; soundstr = arg; continue; case 'd': change_path(arg); continue; case 'x': debug_opt(arg); continue; case '-': argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; default: usage: puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character (WARNING: overwrites default savefile without -u)"); puts(" -l Lists all savefiles you can play"); puts(" -w Resurrect dead character (marks savefile)"); puts(" -r Rebalance monsters"); puts(" -g Request graphics mode"); puts(" -x<opt> Debug options; see -xhelp"); puts(" -u<who> Use your <who> savefile"); puts(" -d<dir>=<path> Override a specific directory with <path>. <path> can be:"); for (i = 0; i < (int)N_ELEMENTS(change_path_values); i++) { #ifdef SETGID if (!change_path_values[i].setgid_ok) continue; #endif printf(" %s (default is %s)\n", change_path_values[i].name, *change_path_values[i].path); } puts(" Multiple -d options are allowed."); puts(" -s<mod> Use sound module <sys>:"); for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++) printf(" %s %s\n", sound_modules[i].name, sound_modules[i].help); puts(" -m<sys> Use module <sys>, where <sys> can be:"); /* Print the name and help for each available module */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) printf(" %s %s\n", modules[i].name, modules[i].help); /* Actually abort the process */ quit(NULL); } if (*arg) goto usage; } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Install "quit" hook */ quit_aux = quit_hook; /* If we were told which mode to use, then use it */ if (mstr) ANGBAND_SYS = mstr; if (setlocale(LC_CTYPE, "")) { /* Require UTF-8 */ if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0) quit("Angband requires UTF-8 support"); } /* Try the modules in the order specified by modules[] */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) { /* User requested a specific module? */ if (!mstr || (streq(mstr, modules[i].name))) { ANGBAND_SYS = modules[i].name; if (0 == modules[i].init(argc, argv)) { done = TRUE; break; } } } /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); #ifdef UNIX /* Get the "user name" as default player name, unless set with -u switch */ if (!op_ptr->full_name[0]) { user_name(op_ptr->full_name, sizeof(op_ptr->full_name), player_uid); /* Set the savefile to load */ savefile_set_name(player_safe_name(player, FALSE)); } /* Create any missing directories */ create_needed_dirs(); #endif /* UNIX */ /* Try the modules in the order specified by sound_modules[] */ for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++) if (!soundstr || streq(soundstr, sound_modules[i].name)) if (0 == sound_modules[i].init(argc, argv)) break; /* Catch nasty signals */ signals_init(); /* Set up the command hook */ cmd_get_hook = textui_get_cmd; /* Set up the display handlers and things. */ init_display(); init_angband(); textui_init(); /* Wait for response */ pause_line(Term); /* Play the game */ play_game(new_game); /* Free resources */ textui_cleanup(); cleanup_angband(); /* Quit */ quit(NULL); /* Exit */ return (0); }
int teardown_tests(void **state) { file_delete("Test1"); cleanup_angband(); return 0; }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; const char *mstr = NULL; const char *soundstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef SET_UID /* Default permissions on files */ (void)umask(022); #endif /* SET_UID */ #ifdef SET_UID /* Get the user id */ player_uid = getuid(); /* Save the effective GID for later recall */ player_egid = getegid(); #endif /* SET_UID */ /* Drop permissions */ safe_setuid_drop(); /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { const char *arg = argv[i]; /* Require proper options */ if (*arg++ != '-') goto usage; /* Analyze option */ switch (*arg++) { case 'n': new_game = TRUE; break; case 'w': arg_wizard = TRUE; break; case 'r': arg_rebalance = TRUE; break; case 'g': /* Default graphics tile */ /* in graphics.txt, 2 corresponds to adam bolt's tiles */ arg_graphics = 2; if (*arg) arg_graphics = atoi(arg); break; case 'u': if (!*arg) goto usage; /* Get the savefile name */ my_strcpy(op_ptr->full_name, arg, sizeof(op_ptr->full_name)); continue; case 'm': if (!*arg) goto usage; mstr = arg; continue; case 's': if (!*arg) goto usage; soundstr = arg; continue; case 'd': change_path(arg); continue; case 'x': debug_opt(arg); continue; case '-': argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; default: usage: puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character (WARNING: overwrites default savefile without -u)"); puts(" -w Resurrect dead character (marks savefile)"); puts(" -r Rebalance monsters"); puts(" -g Request graphics mode"); puts(" -x<opt> Debug options; see -xhelp"); puts(" -u<who> Use your <who> savefile"); puts(" -d<path> Store pref files and screendumps in <path>"); puts(" -s<mod> Use sound module <sys>:"); for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++) printf(" %s %s\n", sound_modules[i].name, sound_modules[i].help); puts(" -m<sys> Use module <sys>, where <sys> can be:"); /* Print the name and help for each available module */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) printf(" %s %s\n", modules[i].name, modules[i].help); /* Actually abort the process */ quit(NULL); } if (*arg) goto usage; } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Install "quit" hook */ quit_aux = quit_hook; /* If we were told which mode to use, then use it */ if (mstr) ANGBAND_SYS = mstr; if (setlocale(LC_CTYPE, "")) { /* Require UTF-8 */ if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0) quit("Angband requires UTF-8 support"); } /* Get the file paths */ init_stuff(); /* Try the modules in the order specified by modules[] */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) { /* User requested a specific module? */ if (!mstr || (streq(mstr, modules[i].name))) { ANGBAND_SYS = modules[i].name; if (0 == modules[i].init(argc, argv)) { done = TRUE; break; } } } /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); #ifdef SET_UID /* Get the "user name" as a default player name, unless set with -u switch */ if (!op_ptr->full_name[0]) { user_name(op_ptr->full_name, sizeof(op_ptr->full_name), player_uid); } /* Create any missing directories */ create_needed_dirs(); #endif /* SET_UID */ /* Process the player name */ process_player_name(TRUE); /* Try the modules in the order specified by sound_modules[] */ for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++) if (!soundstr || streq(soundstr, sound_modules[i].name)) if (0 == sound_modules[i].init(argc, argv)) break; /* Catch nasty signals */ signals_init(); /* Set up the command hook */ cmd_get_hook = default_get_cmd; /* Set up the display handlers and things. */ init_display(); /* Play the game */ play_game(); /* Free resources */ cleanup_angband(); /* Quit */ quit(NULL); /* Exit */ return (0); }
/* * Simple "main" function for multiple platforms. * * Note the special "--" option which terminates the processing of * standard options. All non-standard options (if any) are passed * directly to the "init_xxx()" function. */ int main(int argc, char *argv[]) { int i; bool done = FALSE; const char *mstr = NULL; bool args = TRUE; /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; #ifdef SET_UID /* Default permissions on files */ (void)umask(022); #endif /* SET_UID */ /* Get the file paths */ init_stuff(); #ifdef SET_UID /* Get the user id */ player_uid = getuid(); /* Save the effective GID for later recall */ player_egid = getegid(); #endif /* SET_UID */ /* Drop permissions */ safe_setuid_drop(); #ifdef SET_UID /* Get the "user name" as a default player name */ user_name(op_ptr->full_name, sizeof(op_ptr->full_name), player_uid); /* Create any missing directories */ create_needed_dirs(); #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { cptr arg = argv[i]; /* Require proper options */ if (*arg++ != '-') goto usage; /* Analyze option */ switch (*arg++) { case 'N': case 'n': { new_game = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'R': case 'r': { arg_rebalance = TRUE; break; } case 'G': case 'g': { /* Default graphics tile */ arg_graphics = GRAPHICS_ADAM_BOLT; break; } case 'u': case 'U': { if (!*arg) goto usage; /* Get the savefile name */ my_strcpy(op_ptr->full_name, arg, sizeof(op_ptr->full_name)); continue; } case 'm': case 'M': { if (!*arg) goto usage; mstr = arg; continue; } case 'd': case 'D': { change_path(arg); continue; } case '-': { argv[i] = argv[0]; argc = argc - i; argv = argv + i; args = FALSE; break; } default: usage: { /* Dump usage information */ puts("Usage: angband [options] [-- subopts]"); puts(" -n Start a new character"); puts(" -L Load a new-format save file"); puts(" -w Resurrect dead character (marks savefile)"); puts(" -r Rebalance monsters if monster.raw is absent"); puts(" -g Request graphics mode"); puts(" -u<who> Use your <who> savefile"); puts(" -d<path> Store pref files and screendumps in <path>"); puts(" -m<sys> Use module <sys>, where <sys> can be:"); /* Print the name and help for each available module */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) { printf(" %s %s\n", modules[i].name, modules[i].help); } /* Actually abort the process */ quit(NULL); } } if (*arg) goto usage; } /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Try the modules in the order specified by modules[] */ for (i = 0; i < (int)N_ELEMENTS(modules); i++) { /* User requested a specific module? */ if (!mstr || (streq(mstr, modules[i].name))) { if (0 == modules[i].init(argc, argv)) { ANGBAND_SYS = modules[i].name; done = TRUE; break; } } } /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Process the player name */ process_player_name(TRUE); /* Install "quit" hook */ quit_aux = quit_hook; #ifdef USE_SOUND /* Try the modules in the order specified by sound_modules[] */ for (i = 0; i < (int)N_ELEMENTS(sound_modules) - 1; i++) { if (0 == sound_modules[i].init(argc, argv)) break; } #endif /* Catch nasty signals */ signals_init(); /* Set up the command hook */ cmd_get_hook = default_get_cmd; /* Set up the display handlers and things. */ init_display(); /* Play the game */ play_game(); /* Free resources */ cleanup_angband(); /* Quit */ quit(NULL); /* Exit */ return (0); }