From cf287d1c098111ad5bee0720f6929b7e7f8837c9 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 23 Sep 2023 11:01:38 +0300 Subject: [PATCH 31/31] Clients: Shut down cleanly after "-- --help" See osdn #47186 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/gui_main.c | 283 +++++++++++++++++---------------- client/gui-gtk-4.0/gui_main.c | 85 +++++----- client/gui-sdl2/gui_main.c | 218 ++++++++++++------------- client/gui-stub/gui_main.c | 21 +-- 4 files changed, 310 insertions(+), 297 deletions(-) diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index e88d25b793..d15e8b8ab7 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -202,7 +202,7 @@ static void set_wait_for_writable_socket(struct connection *pc, bool socket_writable); static void print_usage(void); -static void parse_options(int argc, char **argv); +static bool parse_options(int argc, char **argv); static gboolean toplevel_key_press_handler(GtkWidget *w, GdkEventKey *ev, gpointer data); static gboolean toplevel_key_release_handler(GtkWidget *w, GdkEventKey *ev, gpointer data); static gboolean mouse_scroll_mapcanvas(GtkWidget *w, GdkEventScroll *ev); @@ -292,7 +292,7 @@ static void print_usage(void) /**********************************************************************//** Search for gui-specific command-line options. **************************************************************************/ -static void parse_options(int argc, char **argv) +static bool parse_options(int argc, char **argv) { int i = 1; @@ -301,7 +301,8 @@ static void parse_options(int argc, char **argv) if (is_option("--help", argv[i])) { print_usage(); - exit(EXIT_SUCCESS); + + return FALSE; #ifdef EXP_ZOOM_LEVELS } else if ((option = get_option_malloc("--zoom", argv, &i, argc, FALSE))) { @@ -327,6 +328,8 @@ static void parse_options(int argc, char **argv) i++; } + + return TRUE; } /**********************************************************************//** @@ -1908,162 +1911,162 @@ int ui_main(int argc, char **argv) PangoFontDescription *toplevel_font_name; guint sig; - parse_options(argc, argv); + if (parse_options(argc, argv)) { + /* The locale has already been set in init_nls() and the windows-specific + * locale logic in gtk_init() causes problems with zh_CN (see PR#39475) */ + gtk_disable_setlocale(); - /* the locale has already been set in init_nls() and the windows-specific - * locale logic in gtk_init() causes problems with zh_CN (see PR#39475) */ - gtk_disable_setlocale(); - - /* GTK withdraw gtk options. Process GTK arguments */ - if (!gtk_init_check(&argc, &argv)) { - log_fatal(_("Failed to open graphical mode.")); - exit(EXIT_FAILURE); - } + /* GTK withdraw gtk options. Process GTK arguments */ + if (!gtk_init_check(&argc, &argv)) { + log_fatal(_("Failed to open graphical mode.")); + return EXIT_FAILURE; + } - help_system_init(); + help_system_init(); - dlg_tab_provider_prepare(); + dlg_tab_provider_prepare(); - toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_position(GTK_WINDOW(toplevel), GTK_WIN_POS_CENTER); - if (vmode.width > 0 && vmode.height > 0) { - gtk_window_resize(GTK_WINDOW(toplevel), vmode.width, vmode.height); - } - g_signal_connect(toplevel, "key_press_event", - G_CALLBACK(toplevel_handler), NULL); - - g_signal_connect(toplevel, "focus_out_event", - G_CALLBACK(fc_lost_focus), NULL); - g_signal_connect(toplevel, "focus_in_event", - G_CALLBACK(fc_gained_focus), NULL); - - gtk_window_set_role(GTK_WINDOW(toplevel), "toplevel"); - gtk_widget_realize(toplevel); - gtk_widget_set_name(toplevel, "Freeciv"); - root_window = gtk_widget_get_window(toplevel); - - if (gui_options.first_boot) { - adjust_default_options(); - /* We're using fresh defaults for this version of this client, - * so prevent any future migrations from other clients / versions */ - GUI_GTK_OPTION(migrated_from_gtk3) = TRUE; - /* Avoid also marking gtk3 as migrated, so that it can have its own - * run of its adjust_default_options() if it is ever run (as a - * side effect of Gtk2->Gtk3 migration). */ - } else { - if (!GUI_GTK_OPTION(migrated_from_gtk3)) { - if (!gui_options.gui_gtk3_migrated_from_gtk2) { - migrate_options_from_gtk2(); - /* We want a fresh look at screen-size-related options after Gtk2 */ - adjust_default_options(); - /* We don't ever want to consider pre-2.6 fullscreen option again - * (even for gui-gtk3) */ - gui_options.gui_gtk3_migrated_from_2_5 = TRUE; + toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_position(GTK_WINDOW(toplevel), GTK_WIN_POS_CENTER); + if (vmode.width > 0 && vmode.height > 0) { + gtk_window_resize(GTK_WINDOW(toplevel), vmode.width, vmode.height); + } + g_signal_connect(toplevel, "key_press_event", + G_CALLBACK(toplevel_handler), NULL); + + g_signal_connect(toplevel, "focus_out_event", + G_CALLBACK(fc_lost_focus), NULL); + g_signal_connect(toplevel, "focus_in_event", + G_CALLBACK(fc_gained_focus), NULL); + + gtk_window_set_role(GTK_WINDOW(toplevel), "toplevel"); + gtk_widget_realize(toplevel); + gtk_widget_set_name(toplevel, "Freeciv"); + root_window = gtk_widget_get_window(toplevel); + + if (gui_options.first_boot) { + adjust_default_options(); + /* We're using fresh defaults for this version of this client, + * so prevent any future migrations from other clients / versions */ + GUI_GTK_OPTION(migrated_from_gtk3) = TRUE; + /* Avoid also marking gtk3 as migrated, so that it can have its own + * run of its adjust_default_options() if it is ever run (as a + * side effect of Gtk2->Gtk3 migration). */ + } else { + if (!GUI_GTK_OPTION(migrated_from_gtk3)) { + if (!gui_options.gui_gtk3_migrated_from_gtk2) { + migrate_options_from_gtk2(); + /* We want a fresh look at screen-size-related options after Gtk2 */ + adjust_default_options(); + /* We don't ever want to consider pre-2.6 fullscreen option again + * (even for gui-gtk3) */ + gui_options.gui_gtk3_migrated_from_2_5 = TRUE; + } + migrate_options_from_gtk3(); } - migrate_options_from_gtk3(); } - } - if (GUI_GTK_OPTION(fullscreen)) { - gtk_window_fullscreen(GTK_WINDOW(toplevel)); - } + if (GUI_GTK_OPTION(fullscreen)) { + gtk_window_fullscreen(GTK_WINDOW(toplevel)); + } - gtk_window_set_title(GTK_WINDOW (toplevel), _("Freeciv")); + gtk_window_set_title(GTK_WINDOW (toplevel), _("Freeciv")); - g_signal_connect(toplevel, "delete_event", - G_CALLBACK(quit_dialog_callback), NULL); + g_signal_connect(toplevel, "delete_event", + G_CALLBACK(quit_dialog_callback), NULL); - /* Disable GTK+ cursor key focus movement */ - sig = g_signal_lookup("focus", GTK_TYPE_WIDGET); - g_signal_handlers_disconnect_matched(toplevel, G_SIGNAL_MATCH_ID, sig, - 0, 0, 0, 0); - g_signal_connect(toplevel, "focus", G_CALLBACK(toplevel_focus), NULL); + /* Disable GTK+ cursor key focus movement */ + sig = g_signal_lookup("focus", GTK_TYPE_WIDGET); + g_signal_handlers_disconnect_matched(toplevel, G_SIGNAL_MATCH_ID, sig, + 0, 0, 0, 0); + g_signal_connect(toplevel, "focus", G_CALLBACK(toplevel_focus), NULL); - options_iterate(client_optset, poption) { - if (OT_FONT == option_type(poption)) { - /* Force to call the appropriate callback. */ - option_changed(poption); - } - } options_iterate_end; + options_iterate(client_optset, poption) { + if (OT_FONT == option_type(poption)) { + /* Force to call the appropriate callback. */ + option_changed(poption); + } + } options_iterate_end; - toplevel_font_name = pango_context_get_font_description( - gtk_widget_get_pango_context(toplevel)); + toplevel_font_name = pango_context_get_font_description( + gtk_widget_get_pango_context(toplevel)); - if (NULL == city_names_style) { - city_names_style = pango_font_description_copy(toplevel_font_name); - log_error("city_names_style should have been set by options."); - } - if (NULL == city_productions_style) { - city_productions_style = pango_font_description_copy(toplevel_font_name); - log_error("city_productions_style should have been set by options."); - } - if (NULL == reqtree_text_style) { - reqtree_text_style = pango_font_description_copy(toplevel_font_name); - log_error("reqtree_text_style should have been set by options."); - } + if (NULL == city_names_style) { + city_names_style = pango_font_description_copy(toplevel_font_name); + log_error("city_names_style should have been set by options."); + } + if (NULL == city_productions_style) { + city_productions_style = pango_font_description_copy(toplevel_font_name); + log_error("city_productions_style should have been set by options."); + } + if (NULL == reqtree_text_style) { + reqtree_text_style = pango_font_description_copy(toplevel_font_name); + log_error("reqtree_text_style should have been set by options."); + } - tileset_init(tileset); - tileset_load_tiles(tileset); + tileset_init(tileset); + tileset_load_tiles(tileset); - /* keep the icon of the executable on Windows (see PR#36491) */ + /* Keep the icon of the executable on Windows (see PR#36491) */ #ifndef FREECIV_MSWINDOWS - { - GdkPixbuf *pixbuf = sprite_get_pixbuf(get_icon_sprite(tileset, ICON_FREECIV)); + { + GdkPixbuf *pixbuf = sprite_get_pixbuf(get_icon_sprite(tileset, ICON_FREECIV)); - /* Only call this after tileset_load_tiles is called. */ - gtk_window_set_icon(GTK_WINDOW(toplevel), pixbuf); - g_object_unref(pixbuf); - } + /* Only call this after tileset_load_tiles is called. */ + gtk_window_set_icon(GTK_WINDOW(toplevel), pixbuf); + g_object_unref(pixbuf); + } #endif /* FREECIV_MSWINDOWS */ - setup_widgets(); - load_cursors(); - cma_fe_init(); - diplomacy_dialog_init(); - luaconsole_dialog_init(); - happiness_dialog_init(); - citizens_dialog_init(); - intel_dialog_init(); - spaceship_dialog_init(); - chatline_init(); - init_mapcanvas_and_overview(); - - tileset_use_preferred_theme(tileset); - - gtk_widget_show(toplevel); - - /* assumes toplevel showing */ - set_client_state(C_S_DISCONNECTED); - - /* assumes client_state is set */ - timer_id = g_timeout_add(TIMER_INTERVAL, timer_callback, NULL); - - gui_up = TRUE; - gtk_main(); - gui_up = FALSE; - - destroy_server_scans(); - free_mapcanvas_and_overview(); - spaceship_dialog_done(); - intel_dialog_done(); - citizens_dialog_done(); - luaconsole_dialog_done(); - happiness_dialog_done(); - diplomacy_dialog_done(); - cma_fe_done(); - free_unit_table(); - - /* We have extra ref for unit_info_box that has protected - * it from getting destroyed when editinfobox_refresh() - * moves widgets around. Free that extra ref here. */ - g_object_unref(unit_info_box); - - editgui_free(); - gtk_widget_destroy(toplevel_tabs); - gtk_widget_destroy(toplevel); - menus_free(); - message_buffer = NULL; /* Result of destruction of everything */ - tileset_free_tiles(tileset); + setup_widgets(); + load_cursors(); + cma_fe_init(); + diplomacy_dialog_init(); + luaconsole_dialog_init(); + happiness_dialog_init(); + citizens_dialog_init(); + intel_dialog_init(); + spaceship_dialog_init(); + chatline_init(); + init_mapcanvas_and_overview(); + + tileset_use_preferred_theme(tileset); + + gtk_widget_show(toplevel); + + /* Assumes toplevel showing */ + set_client_state(C_S_DISCONNECTED); + + /* Assumes client_state is set */ + timer_id = g_timeout_add(TIMER_INTERVAL, timer_callback, NULL); + + gui_up = TRUE; + gtk_main(); + gui_up = FALSE; + + destroy_server_scans(); + free_mapcanvas_and_overview(); + spaceship_dialog_done(); + intel_dialog_done(); + citizens_dialog_done(); + luaconsole_dialog_done(); + happiness_dialog_done(); + diplomacy_dialog_done(); + cma_fe_done(); + free_unit_table(); + + /* We have extra ref for unit_info_box that has protected + * it from getting destroyed when editinfobox_refresh() + * moves widgets around. Free that extra ref here. */ + g_object_unref(unit_info_box); + + editgui_free(); + gtk_widget_destroy(toplevel_tabs); + gtk_widget_destroy(toplevel); + menus_free(); + message_buffer = NULL; /* Result of destruction of everything */ + tileset_free_tiles(tileset); + } return EXIT_SUCCESS; } diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 6f80308c95..da36af435f 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -197,7 +197,7 @@ static void set_wait_for_writable_socket(struct connection *pc, static void print_usage(void); static void activate_gui(GtkApplication *app, gpointer data); -static void parse_options(int argc, char **argv); +static bool parse_options(int argc, char **argv); static gboolean toplevel_key_press_handler(GtkEventControllerKey *controller, guint keyval, guint keycode, @@ -288,7 +288,7 @@ static void print_usage(void) /**********************************************************************//** Search for gui-specific command line options. **************************************************************************/ -static void parse_options(int argc, char **argv) +static bool parse_options(int argc, char **argv) { int i = 1; @@ -297,7 +297,8 @@ static void parse_options(int argc, char **argv) if (is_option("--help", argv[i])) { print_usage(); - exit(EXIT_SUCCESS); + + return FALSE; #ifdef EXP_ZOOM_LEVELS } else if ((option = get_option_malloc("--zoom", argv, &i, argc, FALSE))) { @@ -326,6 +327,8 @@ static void parse_options(int argc, char **argv) i++; } + + return TRUE; } /**********************************************************************//** @@ -1896,49 +1899,49 @@ static void migrate_options_from_gtk3_22(void) **************************************************************************/ int ui_main(int argc, char **argv) { - parse_options(argc, argv); - - /* The locale has already been set in init_nls() and the windows-specific - * locale logic in gtk_init() causes problems with zh_CN (see PR#39475) */ - gtk_disable_setlocale(); - - if (!gtk_init_check()) { - log_fatal(_("Failed to open graphical mode.")); - exit(EXIT_FAILURE); - } + if (parse_options(argc, argv)) { + /* The locale has already been set in init_nls() and the windows-specific + * locale logic in gtk_init() causes problems with zh_CN (see PR#39475) */ + gtk_disable_setlocale(); - menus_set_initial_toggle_values(); - - gui_up = TRUE; - fc_app = gtk_application_new(NULL, 0); - g_signal_connect(fc_app, "activate", G_CALLBACK(activate_gui), NULL); - g_application_run(G_APPLICATION(fc_app), 0, NULL); - gui_up = FALSE; + if (!gtk_init_check()) { + log_fatal(_("Failed to open graphical mode.")); + return EXIT_FAILURE; + } - destroy_server_scans(); - free_mapcanvas_and_overview(); - spaceship_dialog_done(); - intel_dialog_done(); - citizens_dialog_done(); - luaconsole_dialog_done(); - happiness_dialog_done(); - diplomacy_dialog_done(); - cma_fe_done(); - free_unit_table(); + menus_set_initial_toggle_values(); + + gui_up = TRUE; + fc_app = gtk_application_new(NULL, 0); + g_signal_connect(fc_app, "activate", G_CALLBACK(activate_gui), NULL); + g_application_run(G_APPLICATION(fc_app), 0, NULL); + gui_up = FALSE; + + destroy_server_scans(); + free_mapcanvas_and_overview(); + spaceship_dialog_done(); + intel_dialog_done(); + citizens_dialog_done(); + luaconsole_dialog_done(); + happiness_dialog_done(); + diplomacy_dialog_done(); + cma_fe_done(); + free_unit_table(); + + /* We have extra ref for unit_info_box that has protected + * it from getting destroyed when editinfobox_refresh() + * moves widgets around. Free that extra ref here. */ + g_object_unref(unit_info_box); + if (empty_unit_paintable != NULL) { + g_object_unref(empty_unit_paintable); + } - /* We have extra ref for unit_info_box that has protected - * it from getting destroyed when editinfobox_refresh() - * moves widgets around. Free that extra ref here. */ - g_object_unref(unit_info_box); - if (empty_unit_paintable != NULL) { - g_object_unref(empty_unit_paintable); + editgui_free(); + gtk_window_destroy(GTK_WINDOW(toplevel)); + message_buffer = NULL; /* Result of destruction of everything */ + tileset_free_tiles(tileset); } - editgui_free(); - gtk_window_destroy(GTK_WINDOW(toplevel)); - message_buffer = NULL; /* Result of destruction of everything */ - tileset_free_tiles(tileset); - return EXIT_SUCCESS; } diff --git a/client/gui-sdl2/gui_main.c b/client/gui-sdl2/gui_main.c index 2888d5362a..78770b99e0 100644 --- a/client/gui-sdl2/gui_main.c +++ b/client/gui-sdl2/gui_main.c @@ -137,7 +137,7 @@ static SDL_Event *flush_user_event = NULL; static SDL_Event *map_scroll_user_event = NULL; static void print_usage(void); -static void parse_options(int argc, char **argv); +static bool parse_options(int argc, char **argv); static bool check_scroll_area(int x, int y); int user_event_type; @@ -187,7 +187,7 @@ static void print_usage(void) /**********************************************************************//** Search for gui-specific command-line options. **************************************************************************/ -static void parse_options(int argc, char **argv) +static bool parse_options(int argc, char **argv) { int i = 1; char *option = NULL; @@ -195,7 +195,8 @@ static void parse_options(int argc, char **argv) while (i < argc) { if (is_option("--help", argv[i])) { print_usage(); - exit(EXIT_SUCCESS); + + return FALSE; } else if (is_option("--fullscreen", argv[i])) { GUI_SDL_OPTION(fullscreen) = TRUE; } else if (is_option("--swrenderer", argv[i])) { @@ -217,6 +218,8 @@ static void parse_options(int argc, char **argv) i++; } + + return TRUE; } /**********************************************************************//** @@ -1014,151 +1017,152 @@ static void migrate_options_from_sdl(void) } /**********************************************************************//** - The main loop for the UI. This is called from main(), and when it + The main loop for the UI. This is called from main(), and when it exits the client will exit. **************************************************************************/ int ui_main(int argc, char *argv[]) { Uint32 flags = 0; - parse_options(argc, argv); - - if (!gui_options.gui_sdl2_migrated_from_sdl) { - migrate_options_from_sdl(); - } - if (!GUI_SDL_OPTION(default_screen_size_set)) { - if (font_size_parameter > 10) { - GUI_SDL_OPTION(screen) = VIDEO_MODE(640 * font_size_parameter / 10, - 480 * font_size_parameter / 10); + if (parse_options(argc, argv)) { + if (!gui_options.gui_sdl2_migrated_from_sdl) { + migrate_options_from_sdl(); } + if (!GUI_SDL_OPTION(default_screen_size_set)) { + if (font_size_parameter > 10) { + GUI_SDL_OPTION(screen) = VIDEO_MODE(640 * font_size_parameter / 10, + 480 * font_size_parameter / 10); + } - GUI_SDL_OPTION(default_screen_size_set) = TRUE; - } - - if (GUI_SDL_OPTION(fullscreen)) { - flags |= SDL_WINDOW_FULLSCREEN; - } else { - flags &= ~SDL_WINDOW_FULLSCREEN; - } + GUI_SDL_OPTION(default_screen_size_set) = TRUE; + } - log_normal(_("Using Video Output: %s"), SDL_GetCurrentVideoDriver()); - if (!set_video_mode(GUI_SDL_OPTION(screen.width), - GUI_SDL_OPTION(screen.height), - flags)) { - return EXIT_FAILURE; - } + if (GUI_SDL_OPTION(fullscreen)) { + flags |= SDL_WINDOW_FULLSCREEN; + } else { + flags &= ~SDL_WINDOW_FULLSCREEN; + } - user_event_type = SDL_RegisterEvents(1); + log_normal(_("Using Video Output: %s"), SDL_GetCurrentVideoDriver()); + if (!set_video_mode(GUI_SDL_OPTION(screen.width), + GUI_SDL_OPTION(screen.height), + flags)) { + return EXIT_FAILURE; + } - SDL_zero(__net_user_event); - __net_user_event.type = user_event_type; - __net_user_event.user.code = NET; - __net_user_event.user.data1 = NULL; - __net_user_event.user.data2 = NULL; - net_user_event = &__net_user_event; + user_event_type = SDL_RegisterEvents(1); - SDL_zero(__anim_user_event); - __anim_user_event.type = user_event_type; - __anim_user_event.user.code = EVENT_ERROR; - __anim_user_event.user.data1 = NULL; - __anim_user_event.user.data2 = NULL; - anim_user_event = &__anim_user_event; + SDL_zero(__net_user_event); + __net_user_event.type = user_event_type; + __net_user_event.user.code = NET; + __net_user_event.user.data1 = NULL; + __net_user_event.user.data2 = NULL; + net_user_event = &__net_user_event; - SDL_zero(__info_user_event); - __info_user_event.type = user_event_type; - __info_user_event.user.code = SHOW_WIDGET_INFO_LABEL; - __info_user_event.user.data1 = NULL; - __info_user_event.user.data2 = NULL; - info_user_event = &__info_user_event; + SDL_zero(__anim_user_event); + __anim_user_event.type = user_event_type; + __anim_user_event.user.code = EVENT_ERROR; + __anim_user_event.user.data1 = NULL; + __anim_user_event.user.data2 = NULL; + anim_user_event = &__anim_user_event; - SDL_zero(__flush_user_event); - __flush_user_event.type = user_event_type; - __flush_user_event.user.code = FLUSH; - __flush_user_event.user.data1 = NULL; - __flush_user_event.user.data2 = NULL; - flush_user_event = &__flush_user_event; + SDL_zero(__info_user_event); + __info_user_event.type = user_event_type; + __info_user_event.user.code = SHOW_WIDGET_INFO_LABEL; + __info_user_event.user.data1 = NULL; + __info_user_event.user.data2 = NULL; + info_user_event = &__info_user_event; - SDL_zero(__map_scroll_user_event); - __map_scroll_user_event.type = user_event_type; - __map_scroll_user_event.user.code = MAP_SCROLL; - __map_scroll_user_event.user.data1 = NULL; - __map_scroll_user_event.user.data2 = NULL; - map_scroll_user_event = &__map_scroll_user_event; + SDL_zero(__flush_user_event); + __flush_user_event.type = user_event_type; + __flush_user_event.user.code = FLUSH; + __flush_user_event.user.data1 = NULL; + __flush_user_event.user.data2 = NULL; + flush_user_event = &__flush_user_event; - is_unit_move_blocked = FALSE; + SDL_zero(__map_scroll_user_event); + __map_scroll_user_event.type = user_event_type; + __map_scroll_user_event.user.code = MAP_SCROLL; + __map_scroll_user_event.user.data1 = NULL; + __map_scroll_user_event.user.data2 = NULL; + map_scroll_user_event = &__map_scroll_user_event; - sdl2_client_flags |= (CF_DRAW_PLAYERS_NEUTRAL_STATUS - |CF_DRAW_PLAYERS_WAR_STATUS - |CF_DRAW_PLAYERS_CEASEFIRE_STATUS - |CF_DRAW_PLAYERS_PEACE_STATUS - |CF_DRAW_PLAYERS_ALLIANCE_STATUS); + is_unit_move_blocked = FALSE; - tileset_init(tileset); - tileset_load_tiles(tileset); - tileset_use_preferred_theme(tileset); + sdl2_client_flags |= (CF_DRAW_PLAYERS_NEUTRAL_STATUS + |CF_DRAW_PLAYERS_WAR_STATUS + |CF_DRAW_PLAYERS_CEASEFIRE_STATUS + |CF_DRAW_PLAYERS_PEACE_STATUS + |CF_DRAW_PLAYERS_ALLIANCE_STATUS); - load_cursors(); + tileset_init(tileset); + tileset_load_tiles(tileset); + tileset_use_preferred_theme(tileset); - callbacks = callback_list_new(); + load_cursors(); - diplomacy_dialog_init(); - intel_dialog_init(); + callbacks = callback_list_new(); - clear_double_messages_call(); + diplomacy_dialog_init(); + intel_dialog_init(); - setup_auxiliary_tech_icons(); + clear_double_messages_call(); - /* This needs correct main_data.screen size */ - init_mapcanvas_and_overview(); + setup_auxiliary_tech_icons(); - set_client_state(C_S_DISCONNECTED); + /* This needs correct main_data.screen size */ + init_mapcanvas_and_overview(); - /* Main game loop */ - gui_event_loop(NULL, NULL, main_key_down_handler, main_key_up_handler, NULL, - main_finger_down_handler, main_finger_up_handler, NULL, - main_mouse_button_down_handler, main_mouse_button_up_handler, - main_mouse_motion_handler); - start_quitting(); + set_client_state(C_S_DISCONNECTED); - return EXIT_SUCCESS; -} - -/**********************************************************************//** - Do any necessary UI-specific cleanup -**************************************************************************/ -void ui_exit(void) -{ + /* Main game loop */ + gui_event_loop(NULL, NULL, main_key_down_handler, main_key_up_handler, NULL, + main_finger_down_handler, main_finger_up_handler, NULL, + main_mouse_button_down_handler, main_mouse_button_up_handler, + main_mouse_motion_handler); + start_quitting(); #if defined UNDER_CE && defined GUI_SDL2_SMALL_SCREEN - /* Change back to window mode to restore the title bar */ - set_video_mode(320, 240, SDL_SWSURFACE | SDL_ANYFORMAT); + /* Change back to window mode to restore the title bar */ + set_video_mode(320, 240, SDL_SWSURFACE | SDL_ANYFORMAT); #endif - city_map_canvas_free(); + city_map_canvas_free(); + + free_mapcanvas_and_overview(); + + free_auxiliary_tech_icons(); - free_mapcanvas_and_overview(); + diplomacy_dialog_done(); + intel_dialog_done(); - free_auxiliary_tech_icons(); + callback_list_destroy(callbacks); + callbacks = NULL; - diplomacy_dialog_done(); - intel_dialog_done(); + unload_cursors(); - callback_list_destroy(callbacks); - callbacks = NULL; + free(button_behavior.event); + button_behavior.event = NULL; - unload_cursors(); + meswin_dialog_popdown(); - FC_FREE(button_behavior.event); + del_main_list(); - meswin_dialog_popdown(); + free_font_system(); + theme_free(active_theme); + active_theme = NULL; - del_main_list(); + quit_sdl(); + } - free_font_system(); - theme_free(active_theme); - active_theme = NULL; + return EXIT_SUCCESS; +} - quit_sdl(); +/**********************************************************************//** + Do any necessary UI-specific cleanup +**************************************************************************/ +void ui_exit(void) +{ } /**********************************************************************//** diff --git a/client/gui-stub/gui_main.c b/client/gui-stub/gui_main.c index 26c286f743..456d942e53 100644 --- a/client/gui-stub/gui_main.c +++ b/client/gui-stub/gui_main.c @@ -73,14 +73,15 @@ static void print_usage(const char *argv0) /**********************************************************************//** Parse and enact any gui-specific command-line options. **************************************************************************/ -static void parse_options(int argc, char **argv) +static bool parse_options(int argc, char **argv) { int i = 1; while (i < argc) { if (is_option("--help", argv[i])) { print_usage(argv[0]); - exit(EXIT_SUCCESS); + + return FALSE; } else { fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[i]); exit(EXIT_FAILURE); @@ -88,22 +89,24 @@ static void parse_options(int argc, char **argv) i++; } + + return TRUE; } /**********************************************************************//** - The main loop for the UI. This is called from main(), and when it + The main loop for the UI. This is called from main(), and when it exits the client will exit. **************************************************************************/ int gui_ui_main(int argc, char *argv[]) { - parse_options(argc, argv); + if (parse_options(argc, argv)) { + /* PORTME */ + fc_fprintf(stderr, "Freeciv rules!\n"); - /* PORTME */ - fc_fprintf(stderr, "Freeciv rules!\n"); + /* Main loop here */ - /* Main loop here */ - - start_quitting(); + start_quitting(); + } return EXIT_SUCCESS; } -- 2.40.1