static void init_stuff(void) { char path[1024]; cptr tail; /* Get the environment variable */ tail = getenv("ANGBAND_PATH"); /* Use the angband_path, or a default */ strcpy(path, tail ? tail : DEFAULT_PATH); /* Hack -- Add a path separator (only if needed) */ if (!suffix(path, PATH_SEP)) strcat(path, PATH_SEP); /* Initialize */ #ifdef PRIVATE_USER_PATH init_file_paths(path,path,PRIVATE_USER_PATH,NULL); create_user_dirs(); #else /* PRIVATE_USER_PATH */ init_file_paths(path,path,path,path); #endif /* PRIVATE_USER_PATH */ }
void app_init (int argc, char **argv) { static gboolean nosplash = FALSE; static gboolean nonew = FALSE; static gboolean use_integrated_ui = TRUE; static gboolean credits = FALSE; static gboolean version = FALSE; static gboolean verbose = FALSE; static gboolean log_to_stderr = FALSE; #ifdef HAVE_GNOME GnomeClient *client; #endif static char *export_file_name = NULL; static char *export_file_format = NULL; static char *size = NULL; static char *show_layers = NULL; gboolean made_conversions = FALSE; GSList *files = NULL; static const gchar **filenames = NULL; int i = 0; gchar *export_format_string = /* Translators: The argument is a list of options, not to be translated */ g_strdup_printf(_("Select the filter/format out of: %s"), "cgm, dia, dxf, eps, eps-builtin, " EPS_PANGO "fig, mp, plt, hpgl, png (" # if defined(HAVE_LIBPNG) && defined(HAVE_LIBART) "png-libart, " # endif # ifdef HAVE_CAIRO "cairo-png, cairo-alpha-png, " # endif /* we always have pixbuf but don't know exactly all it's *few* save formats */ "pixbuf-png), jpg, " "shape, svg, tex (pgf-tex, pstricks-tex), " WMF "wpg"); GOptionContext *context = NULL; static GOptionEntry options[] = { {"export", 'e', 0, G_OPTION_ARG_FILENAME, NULL /* &export_file_name */, N_("Export loaded file and exit"), N_("OUTPUT")}, {"filter",'t', 0, G_OPTION_ARG_STRING, NULL /* &export_file_format */, NULL /* &export_format_string */, N_("TYPE") }, {"size", 's', 0, G_OPTION_ARG_STRING, NULL, N_("Export graphics size"), N_("WxH")}, {"show-layers", 'L', 0, G_OPTION_ARG_STRING, NULL, N_("Show only specified layers (e.g. when exporting). Can be either the layer name or a range of layer numbers (X-Y)"), N_("LAYER,LAYER,...")}, {"nosplash", 'n', 0, G_OPTION_ARG_NONE, &nosplash, N_("Don't show the splash screen"), NULL }, {"nonew", 'n', 0, G_OPTION_ARG_NONE, &nonew, N_("Don't create an empty diagram"), NULL }, {"classic", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &use_integrated_ui, N_("Start classic user interface (no diagrams in tabs)"), NULL }, {"log-to-stderr", 'l', 0, G_OPTION_ARG_NONE, &log_to_stderr, N_("Send error messages to stderr instead of showing dialogs."), NULL }, {"input-directory", 'I', 0, G_OPTION_ARG_CALLBACK, _check_option_input_directory, N_("Directory containing input files"), N_("DIRECTORY")}, {"output-directory", 'O', 0, G_OPTION_ARG_CALLBACK, _check_option_output_directory, N_("Directory containing output files"), N_("DIRECTORY")}, {"credits", 'c', 0, G_OPTION_ARG_NONE, &credits, N_("Display credits list and exit"), NULL }, {"verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, N_("Generate verbose output"), NULL }, {"version", 'v', 0, G_OPTION_ARG_NONE, &version, N_("Display version and exit"), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, NULL /* &filenames */, NULL, NULL }, { NULL } }; /* for users of app_init() the default is interactive */ dia_is_interactive = TRUE; options[0].arg_data = &export_file_name; options[1].arg_data = &export_file_format; options[1].description = export_format_string; options[2].arg_data = &size; options[3].arg_data = &show_layers; g_assert (strcmp (options[13].long_name, G_OPTION_REMAINING) == 0); options[13].arg_data = (void*)&filenames; argv0 = (argc > 0) ? argv[0] : "(none)"; #if GTK_CHECK_VERSION(2,24,0) /* ... use setlocale directly? */ #else gtk_set_locale(); #endif setlocale(LC_NUMERIC, "C"); _setup_textdomains (); context = g_option_context_new(_("[FILE...]")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); #ifndef HAVE_GNOME /* avoid to add it a second time */ g_option_context_add_group (context, gtk_get_option_group (FALSE)); #endif if (argv) { GError *error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { if (error) { /* IMO !error here is a bug upstream, triggered e.g. with --gdk-debug=updates */ g_print ("%s", error->message); g_error_free (error); } else { g_print (_("Invalid option?")); } g_option_context_free(context); exit(1); } /* second level check of command line options, existance of input files etc. */ if (filenames) { while (filenames[i] != NULL) { gchar *filename; gchar *testpath; if (g_str_has_prefix (filenames[i], "file://")) { filename = g_filename_from_uri (filenames[i], NULL, NULL); if (!g_utf8_validate(filename, -1, NULL)) { gchar *tfn = filename; filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); g_free(tfn); } } else filename = g_filename_to_utf8 (filenames[i], -1, NULL, NULL, NULL); if (!filename) { g_print (_("Filename conversion failed: %s\n"), filenames[i]); continue; } if (g_path_is_absolute(filename)) testpath = filename; else testpath = g_build_filename(input_directory ? input_directory : ".", filename, NULL); /* we still have a problem here, if GLib's file name encoding would not be utf-8 */ if (g_file_test (testpath, G_FILE_TEST_IS_REGULAR)) files = g_slist_append(files, filename); else { g_print (_("Missing input: %s\n"), filename); g_free (filename); } if (filename != testpath) g_free (testpath); ++i; } } /* given some files to output, we are not starting up the UI */ if (export_file_name || export_file_format || size) dia_is_interactive = FALSE; } if (argv && dia_is_interactive && !version) { #ifdef HAVE_GNOME GnomeProgram *program = gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv, /* haven't found a quick way to pass GOption here */ GNOME_PARAM_GOPTION_CONTEXT, context, GNOME_PROGRAM_STANDARD_PROPERTIES, GNOME_PARAM_NONE); client = gnome_master_client(); if(client == NULL) { g_warning(_("Can't connect to session manager!\n")); } else { g_signal_connect(G_OBJECT (client), "save_yourself", G_CALLBACK (save_state), NULL); g_signal_connect(G_OBJECT (client), "die", G_CALLBACK (session_die), NULL); } /* This smaller icon is 48x48, standard Gnome size */ /* gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/dia_gnome_icon.png");*/ #else # ifdef G_THREADS_ENABLED g_thread_init (NULL); # endif gtk_init(&argc, &argv); #endif } else { #ifdef G_THREADS_ENABLED g_thread_init (NULL); #endif g_type_init(); /* * On Windows there is no command line without display so that gtk_init is harmless. * On X11 we need gtk_init_check() to avoid exit() just because there is no display * running outside of X11. */ if (!gtk_init_check(&argc, &argv)) dia_log_message ("Running without display"); } /* done with option parsing, don't leak */ g_free(export_format_string); if (version) { gchar *ver_utf8; gchar *ver_locale; #if (defined __TIME__) && (defined __DATE__) /* TRANSLATOR: 2nd and 3rd %s are time and date respectively. */ ver_utf8 = g_strdup_printf(_("Dia version %s, compiled %s %s\n"), VERSION, __TIME__, __DATE__); #else ver_utf8 = g_strdup_printf(_("Dia version %s\n"), VERSION); #endif ver_locale = g_locale_from_utf8(ver_utf8, -1, NULL, NULL, NULL); printf("%s\n", ver_locale); g_free(ver_locale); g_free(ver_utf8); if (verbose) dump_dependencies(); exit(0); } if (!dia_is_interactive) log_to_stderr = TRUE; libdia_init ( (dia_is_interactive ? DIA_INTERACTIVE : 0) | (log_to_stderr ? DIA_MESSAGE_STDERR : 0) | (verbose ? DIA_VERBOSE : 0) ); print_credits(credits); if (dia_is_interactive) { create_user_dirs(); if (!nosplash) app_splash_init(""); /* Init cursors: */ default_cursor = gdk_cursor_new(GDK_LEFT_PTR); ddisplay_set_all_cursor(default_cursor); } dia_register_plugins(); dia_register_builtin_plugin(internal_plugin_init); load_all_sheets(); /* new mechanism */ dia_log_message ("object defaults"); { DiaContext *ctx = dia_context_new (_("Object Defaults")); dia_object_defaults_load (NULL, TRUE /* prefs.object_defaults_create_lazy */, ctx); dia_context_release (ctx); } debug_break(); if (object_get_type("Standard - Box") == NULL) { message_error(_("Couldn't find standard objects when looking for " "object-libs; exiting...\n")); g_critical( _("Couldn't find standard objects when looking for " "object-libs in '%s'; exiting...\n"), dia_get_lib_directory("dia")); exit(1); } persistence_load(); /** Must load prefs after persistence */ prefs_init(); if (dia_is_interactive) { /* further initialization *before* reading files */ active_tool = create_modify_tool(); dia_log_message ("ui creation"); if (use_integrated_ui) { create_integrated_ui(); } else { create_toolbox(); /* for the integrated ui case it is integrated */ persistence_register_window_create("layer_window", (NullaryFunc*)&layer_dialog_create); } /*fill recent file menu */ recent_file_history_init(); /* Set up autosave to check every 5 minutes */ g_timeout_add_seconds(5*60, autosave_check_autosave, NULL); #if 0 /* do we really open these automatically in the next session? */ persistence_register_window_create("diagram_tree", &diagram_tree_show); #endif persistence_register_window_create("sheets_main_dialog", (NullaryFunc*)&sheets_dialog_create); /* In current setup, we can't find the autosaved files. */ /*autosave_restore_documents();*/ } dia_log_message ("diagrams"); made_conversions = handle_all_diagrams(files, export_file_name, export_file_format, size, show_layers, input_directory, output_directory); if (dia_is_interactive && files == NULL && !nonew) { if (use_integrated_ui) { GList * list; file_new_callback(NULL); list = dia_open_diagrams(); if (list) { Diagram * diagram = list->data; diagram_update_extents(diagram); diagram->is_default = TRUE; } } else { gchar *filename = g_filename_from_utf8(_("Diagram1.dia"), -1, NULL, NULL, NULL); Diagram *diagram = new_diagram (filename); g_free(filename); if (diagram != NULL) { diagram_update_extents(diagram); diagram->is_default = TRUE; /* I think this is done in diagram_init() with a call to * layer_dialog_update_diagram_list() */ layer_dialog_set_diagram(diagram); new_display(diagram); } } } g_slist_free(files); if (made_conversions) exit(0); dynobj_refresh_init(); dia_log_message ("initialized"); }
/* * 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; bool new_game = FALSE; int show_score = 0; 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 /* 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(); # if 0 /* XXX XXX XXX */ /* Redundant setting necessary in case root is running the game */ /* If not root or game not setuid the following two calls do nothing */ if (setgid(getegid()) != 0) { quit("setgid(): cannot set permissions correctly!"); } if (setuid(geteuid()) != 0) { quit("setuid(): cannot set permissions correctly!"); } # endif #endif /* SET_UID */ #ifdef SET_UID #ifdef PRIVATE_USER_PATH /* Create directories for the users files */ create_user_dirs(); #endif /* PRIVATE_USER_PATH */ /* Acquire the "user name" as a default player name */ user_name(op_ptr->full_name, player_uid); #endif /* SET_UID */ /* Process the command line arguments */ for (i = 1; args && (i < argc); i++) { /* Require proper options */ if (argv[i][0] != '-') goto usage; /* Analyze option */ switch (argv[i][1]) { case 'N': case 'n': { new_game = TRUE; break; } case 'F': case 'f': { arg_fiddle = TRUE; break; } case 'W': case 'w': { arg_wizard = TRUE; break; } case 'V': case 'v': { arg_sound = TRUE; break; } case 'R': case 'r': { arg_force_roguelike = TRUE; break; } case 'O': case 'o': { arg_force_original = TRUE; break; } case 'S': case 's': { show_score = atoi(&argv[i][2]); if (show_score <= 0) show_score = 10; break; } case 'u': case 'U': { if (!argv[i][2]) goto usage; strncpy(op_ptr->base_name, &argv[i][2], 32); op_ptr->base_name[31] = '\0'; break; } case 'm': { if (!argv[i][2]) goto usage; mstr = &argv[i][2]; break; } case 'M': { arg_monochrome = TRUE; break; } case 'd': case 'D': { change_path(&argv[i][2]); break; } 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(" -f Request fiddle mode"); puts(" -w Request wizard mode"); puts(" -v Request sound mode"); puts(" -g Request graphics mode"); puts(" -o Request original keyset"); puts(" -r Request rogue-like keyset"); puts(" -M Request monochrome mode"); puts(" -s<num> Show <num> high scores"); puts(" -u<who> Use your <who> savefile"); puts(" -d<path> Store pref files and screendumps in <path>"); #ifdef USE_X11 puts(" -mx11 To use X11"); puts(" -- Sub options"); puts(" -- -d Set display name"); puts(" -- -s Turn off smoothscaling graphics"); puts(" -- -n# Number of terms to use"); #endif /* USE_X11 */ #ifdef USE_GCU puts(" -mgcu To use GCU (GNU Curses)"); puts(" -- Sub options"); puts(" -- -x No extra sub-windows"); #endif /* USE_GCU */ #ifdef USE_SLA puts(" -msla To use SLA (SLANG)"); #endif /* USE_SLA */ /* Actually abort the process */ quit(NULL); } } } /* Process the player name (but only if one is specified) */ if (strlen(op_ptr->base_name)) process_player_name(FALSE); /* Hack -- Forget standard args */ if (args) { argc = 1; argv[1] = NULL; } /* Install "quit" hook */ quit_aux = quit_hook; /* Drop privs (so X11 will work correctly) */ safe_setuid_drop(); #ifdef USE_X11 /* Attempt to use the "main-x11.c" support */ if (!done && (!mstr || (streq(mstr, "x11")))) { extern errr init_x11(int, char**); if (0 == init_x11(argc, argv)) { ANGBAND_SYS = "x11"; done = TRUE; } } #endif #ifdef USE_GCU /* Attempt to use the "main-gcu.c" support */ if (!done && (!mstr || (streq(mstr, "gcu")))) { extern errr init_gcu(int, char**); if (0 == init_gcu(argc, argv)) { ANGBAND_SYS = "gcu"; done = TRUE; } } #endif #ifdef USE_SLA /* Attempt to use the "main-sla.c" support */ if (!done && (!mstr || (streq(mstr, "sla")))) { extern errr init_sla(void); if (0 == init_sla()) { ANGBAND_SYS = "sla"; done = TRUE; } } #endif /* Grab privs (dropped above for X11) */ safe_setuid_grab(); /* Make sure we have a display! */ if (!done) quit("Unable to prepare any 'display module'!"); /* Catch nasty signals */ signals_init(); /* Initialize */ init_angband(); /* Hack -- If requested, display scores and quit */ if (show_score > 0) { show_scores(); quit(NULL); } /* Wait for response */ pause_line(23); /* Play the game */ play_game(new_game); /* Quit */ quit(NULL); /* Exit */ return (0); }