4 * Copyright (c) 1997 Ben Harrison, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies.
15 * Some machines have a "main()" function in their "main-xxx.c" file,
16 * all the others use this file for their "main()" function.
20 #if defined(WIN32_CONSOLE_MODE) \
21 || (!defined(WINDOWS) && !defined(RISCOS)) \
28 * List of the available modules in the order they are tried.
30 static const struct module modules
[] =
33 { "gtk", help_gtk
, init_gtk
},
37 { "xaw", help_xaw
, init_xaw
},
41 { "x11", help_x11
, init_x11
},
45 { "sdl", help_sdl
, init_sdl
},
49 { "gcu", help_gcu
, init_gcu
},
57 * List of sound modules in the order they should be tried.
59 static const struct module sound_modules
[] =
62 { "sdl", "SDL_mixer sound module", init_sound_sdl
},
63 #endif /* SOUND_SDL */
65 { "dummy", "Dummy module", NULL
},
72 * A hook for "quit()".
74 * Close down, then fall back into "quit()".
76 static void quit_hook(cptr s
)
80 /* Unused parameter */
84 for (j
= ANGBAND_TERM_MAX
- 1; j
>= 0; j
--)
87 if (!angband_term
[j
]) continue;
90 term_nuke(angband_term
[j
]);
105 * Initialize and verify the file paths, and the score file.
107 * Use the ANGBAND_PATH environment var if possible, else use
108 * DEFAULT_PATH, and in either case, branch off appropriately.
110 * First, we'll look for the ANGBAND_PATH environment variable,
111 * and then look for the files in there. If that doesn't work,
112 * we'll try the DEFAULT_PATH constant. So be sure that one of
113 * these two things works...
115 * We must ensure that the path ends with "PATH_SEP" if needed,
116 * since the "init_file_paths()" function will simply append the
117 * relevant "sub-directory names" to the given path.
119 * Make sure that the path doesn't overflow the buffer. We have
120 * to leave enough space for the path separator, directory, and
123 static void init_stuff(void)
131 /* Get the environment variable */
132 tail
= getenv("ANGBAND_PATH");
134 #endif /* FIXED_PATHS */
136 /* Use the angband_path, or a default */
137 my_strcpy(path
, tail
? tail
: DEFAULT_PATH
, sizeof(path
));
139 /* Make sure it's terminated */
142 /* Hack -- Add a path separator (only if needed) */
143 if (!suffix(path
, PATH_SEP
)) my_strcat(path
, PATH_SEP
, sizeof(path
));
146 init_file_paths(path
);
152 * Handle a "-d<what>=<path>" option
154 * The "<what>" can be any string starting with the same letter as the
155 * name of a subdirectory of the "lib" folder (i.e. "i" or "info").
157 * The "<path>" can be any legal path for the given system, and should
158 * not end in any special path separator (i.e. "/tmp" or "~/.ang-info").
160 static void change_path(cptr info
)
164 /* Find equal sign */
165 s
= strchr(info
, '=');
167 /* Verify equal sign */
168 if (!s
) quit_fmt("Try '-d<what>=<path>' not '-d%s'", info
);
171 switch (tolower((unsigned char)info
[0]))
176 string_free(ANGBAND_DIR_APEX
);
177 ANGBAND_DIR_APEX
= string_make(s
+1);
183 string_free(ANGBAND_DIR_FILE
);
184 ANGBAND_DIR_FILE
= string_make(s
+1);
190 string_free(ANGBAND_DIR_HELP
);
191 ANGBAND_DIR_HELP
= string_make(s
+1);
197 string_free(ANGBAND_DIR_INFO
);
198 ANGBAND_DIR_INFO
= string_make(s
+1);
204 string_free(ANGBAND_DIR_XTRA
);
205 ANGBAND_DIR_XTRA
= string_make(s
+1);
211 string_free(ANGBAND_DIR_BONE
);
212 ANGBAND_DIR_BONE
= string_make(s
+1);
218 string_free(ANGBAND_DIR_DATA
);
219 ANGBAND_DIR_DATA
= string_make(s
+1);
225 string_free(ANGBAND_DIR_EDIT
);
226 ANGBAND_DIR_EDIT
= string_make(s
+1);
232 string_free(ANGBAND_DIR_SAVE
);
233 ANGBAND_DIR_SAVE
= string_make(s
+1);
237 #endif /* FIXED_PATHS */
241 string_free(ANGBAND_DIR_USER
);
242 ANGBAND_DIR_USER
= string_make(s
+1);
248 quit_fmt("Bad semantics in '-d%s'", info
);
255 * Simple "main" function for multiple platforms.
257 * Note the special "--" option which terminates the processing of
258 * standard options. All non-standard options (if any) are passed
259 * directly to the "init_xxx()" function.
261 int main(int argc
, char *argv
[])
266 bool new_game
= FALSE
;
270 const char *mstr
= NULL
;
275 /* Save the "program name" XXX XXX XXX */
281 /* Default permissions on files */
287 /* Get the file paths */
293 /* Get the user id */
294 player_uid
= getuid();
296 /* Save the effective GID for later recall */
297 player_egid
= getegid();
302 /* Drop permissions */
308 /* Get the "user name" as a default player name */
309 user_name(op_ptr
->full_name
, sizeof(op_ptr
->full_name
), player_uid
);
311 #ifdef PRIVATE_USER_PATH
313 /* Create directories for the users files */
316 #endif /* PRIVATE_USER_PATH */
321 /* Process the command line arguments */
322 for (i
= 1; args
&& (i
< argc
); i
++)
326 /* Require proper options */
327 if (*arg
++ != '-') goto usage
;
363 /* Default graphics tile */
364 arg_graphics
= GRAPHICS_ADAM_BOLT
;
371 show_score
= atoi(arg
);
372 if (show_score
<= 0) show_score
= 10;
379 if (!*arg
) goto usage
;
381 /* Get the savefile name */
382 my_strcpy(op_ptr
->full_name
, arg
, sizeof(op_ptr
->full_name
));
389 if (!*arg
) goto usage
;
413 /* Dump usage information */
414 puts("Usage: angband [options] [-- subopts]");
415 puts(" -n Start a new character");
416 puts(" -w Resurrect dead character (marks savefile)");
417 puts(" -f Request fiddle (verbose) mode");
418 puts(" -v Request sound mode");
419 puts(" -g Request graphics mode");
420 puts(" -s<num> Show <num> high scores (default: 10)");
421 puts(" -u<who> Use your <who> savefile");
422 puts(" -d<def>=<path> Instead of lib/<def>, use <path>");
423 puts(" -m<sys> Use module <sys>, where <sys> can be:");
425 /* Print the name and help for each available module */
426 for (i
= 0; i
< (int)N_ELEMENTS(modules
); i
++)
429 modules
[i
].name
, modules
[i
].help
);
432 /* Actually abort the process */
436 if (*arg
) goto usage
;
439 /* Hack -- Forget standard args */
447 /* Process the player name */
448 process_player_name(TRUE
);
451 /* Install "quit" hook */
452 quit_aux
= quit_hook
;
454 /* Try the modules in the order specified by modules[] */
455 for (i
= 0; i
< (int)N_ELEMENTS(modules
); i
++)
457 /* User requested a specific module? */
458 if (!mstr
|| (streq(mstr
, modules
[i
].name
)))
460 if (0 == modules
[i
].init(argc
, argv
))
462 ANGBAND_SYS
= modules
[i
].name
;
469 /* Make sure we have a display! */
470 if (!done
) quit("Unable to prepare any 'display module'!");
475 /* Try the modules in the order specified by sound_modules[] */
476 for (i
= 0; i
< (int)N_ELEMENTS(sound_modules
) - 1; i
++)
478 if (0 == sound_modules
[i
].init(argc
, argv
))
485 /* Catch nasty signals */
491 /* Hack -- If requested, display scores and quit */
492 if (show_score
> 0) display_scores(0, show_score
);
494 /* Wait for response */
495 pause_line(Term
->hgt
- 1);
510 #endif /* !defined(MACINTOSH) && !defined(WINDOWS) && !defined(RISCOS) */