From 01dc3d813f1f5edc6ca3f4f32f01d1a9a8624008 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 23 Sep 2023 11:25:25 +0300 Subject: [PATCH 9/9] Clients: Shut down cleanly after "-- --help" See osdn #47186 Signed-off-by: Marko Lindqvist --- client/gui-gtk-2.0/gui_main.c | 332 +++++++++++++++++---------------- client/gui-gtk-3.0/gui_main.c | 266 +++++++++++++------------- client/gui-gtk-3.22/gui_main.c | 274 +++++++++++++-------------- client/gui-sdl2/gui_main.c | 206 ++++++++++---------- client/gui-stub/gui_main.c | 21 ++- 5 files changed, 556 insertions(+), 543 deletions(-) diff --git a/client/gui-gtk-2.0/gui_main.c b/client/gui-gtk-2.0/gui_main.c index 5ed44a6917..129328b147 100644 --- a/client/gui-gtk-2.0/gui_main.c +++ b/client/gui-gtk-2.0/gui_main.c @@ -212,7 +212,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); @@ -274,19 +274,22 @@ static void print_usage(void) /************************************************************************** Search for command line options. Right now, it's just help. **************************************************************************/ -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(); - exit(EXIT_SUCCESS); + + return FALSE; } /* Can't check against unknown options, as those might be gtk options */ i++; } + + return TRUE; } /************************************************************************** @@ -1547,196 +1550,195 @@ int ui_main(int argc, char **argv) const gchar *home; guint sig; - 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 (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(); - /* 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.")); + exit(EXIT_FAILURE); + } - /* Load resources */ - gtk_rc_parse_string(fallback_resources); + /* Load resources */ + gtk_rc_parse_string(fallback_resources); - home = g_get_home_dir(); - if (home) { - gchar *str; + home = g_get_home_dir(); + if (home) { + gchar *str; - str = g_build_filename(home, ".freeciv.rc-2.0", NULL); - gtk_rc_parse(str); - g_free(str); - } + str = g_build_filename(home, ".freeciv.rc-2.0", NULL); + gtk_rc_parse(str); + g_free(str); + } - toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); - g_signal_connect(toplevel, "key_press_event", - G_CALLBACK(toplevel_handler), NULL); + toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); + g_signal_connect(toplevel, "key_press_event", + G_CALLBACK(toplevel_handler), NULL); - gtk_window_set_role(GTK_WINDOW(toplevel), "toplevel"); - gtk_widget_realize(toplevel); - gtk_widget_set_name(toplevel, "Freeciv"); - root_window = toplevel->window; + gtk_window_set_role(GTK_WINDOW(toplevel), "toplevel"); + gtk_widget_realize(toplevel); + gtk_widget_set_name(toplevel, "Freeciv"); + root_window = toplevel->window; - if (gui_options.first_boot) { - /* We're using fresh defaults for this version of this client, - * so prevent any future migrations from other versions */ - gui_options.gui_gtk2_migrated_from_2_5 = TRUE; - } else { - if (!gui_options.gui_gtk2_migrated_from_2_5) { - migrate_options_from_2_5(); + if (gui_options.first_boot) { + /* We're using fresh defaults for this version of this client, + * so prevent any future migrations from other versions */ + gui_options.gui_gtk2_migrated_from_2_5 = TRUE; + } else { + if (!gui_options.gui_gtk2_migrated_from_2_5) { + migrate_options_from_2_5(); + } } - } - if (gui_options.gui_gtk2_fullscreen) { - gtk_window_fullscreen(GTK_WINDOW(toplevel)); - } + if (gui_options.gui_gtk2_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); + display_color_type = get_visual(); - display_color_type = get_visual(); + civ_gc = gdk_gc_new(root_window); - civ_gc = gdk_gc_new(root_window); + options_iterate(client_optset, poption) { + if (OT_FONT == option_type(poption)) { + /* Force to call the appropriated callback. */ + option_changed(poption); + } + } options_iterate_end; - options_iterate(client_optset, poption) { - if (OT_FONT == option_type(poption)) { - /* Force to call the appropriated callback. */ - option_changed(poption); + if (NULL == city_names_style) { + city_names_style = gtk_style_new(); + log_error("city_names_style should have been set by options."); + } + if (NULL == city_productions_style) { + city_productions_style = gtk_style_new(); + log_error("city_productions_style should have been set by options."); + } + if (NULL == reqtree_text_style) { + reqtree_text_style = gtk_style_new(); + log_error("reqtree_text_style should have been set by options."); } - } options_iterate_end; - - if (NULL == city_names_style) { - city_names_style = gtk_style_new(); - log_error("city_names_style should have been set by options."); - } - if (NULL == city_productions_style) { - city_productions_style = gtk_style_new(); - log_error("city_productions_style should have been set by options."); - } - if (NULL == reqtree_text_style) { - reqtree_text_style = gtk_style_new(); - log_error("reqtree_text_style should have been set by options."); - } - - fill_bg_gc = gdk_gc_new(root_window); - - /* for isometric view. always create. the tileset can change at run time. */ - thin_line_gc = gdk_gc_new(root_window); - thick_line_gc = gdk_gc_new(root_window); - border_line_gc = gdk_gc_new(root_window); - gdk_gc_set_line_attributes(thin_line_gc, 1, - GDK_LINE_SOLID, - GDK_CAP_NOT_LAST, - GDK_JOIN_MITER); - gdk_gc_set_line_attributes(thick_line_gc, 2, - GDK_LINE_SOLID, - GDK_CAP_NOT_LAST, - GDK_JOIN_MITER); - gdk_gc_set_line_attributes(border_line_gc, BORDER_WIDTH, - GDK_LINE_ON_OFF_DASH, - GDK_CAP_NOT_LAST, - GDK_JOIN_MITER); - - fill_tile_gc = gdk_gc_new(root_window); - gdk_gc_set_fill(fill_tile_gc, GDK_STIPPLED); - - { - char d1[] = {0x03, 0x0c, 0x03, 0x0c}; - char d2[] = {0x08, 0x02, 0x08, 0x02}; - char d3[] = {0xAA, 0x55, 0xAA, 0x55}; - gray50 = gdk_bitmap_create_from_data(root_window, d1, 4, 4); - gray25 = gdk_bitmap_create_from_data(root_window, d2, 4, 4); - black50 = gdk_bitmap_create_from_data(root_window, d3, 4, 4); - } + fill_bg_gc = gdk_gc_new(root_window); + + /* For isometric view. always create. the tileset can change at run time. */ + thin_line_gc = gdk_gc_new(root_window); + thick_line_gc = gdk_gc_new(root_window); + border_line_gc = gdk_gc_new(root_window); + gdk_gc_set_line_attributes(thin_line_gc, 1, + GDK_LINE_SOLID, + GDK_CAP_NOT_LAST, + GDK_JOIN_MITER); + gdk_gc_set_line_attributes(thick_line_gc, 2, + GDK_LINE_SOLID, + GDK_CAP_NOT_LAST, + GDK_JOIN_MITER); + gdk_gc_set_line_attributes(border_line_gc, BORDER_WIDTH, + GDK_LINE_ON_OFF_DASH, + GDK_CAP_NOT_LAST, + GDK_JOIN_MITER); + + fill_tile_gc = gdk_gc_new(root_window); + gdk_gc_set_fill(fill_tile_gc, GDK_STIPPLED); + + { + char d1[] = {0x03, 0x0c, 0x03, 0x0c}; + char d2[] = {0x08, 0x02, 0x08, 0x02}; + char d3[] = {0xAA, 0x55, 0xAA, 0x55}; + + gray50 = gdk_bitmap_create_from_data(root_window, d1, 4, 4); + gray25 = gdk_bitmap_create_from_data(root_window, d2, 4, 4); + black50 = gdk_bitmap_create_from_data(root_window, d3, 4, 4); + } - { - GdkColor pixel; + { + GdkColor pixel; - mask_bitmap = gdk_pixmap_new(root_window, 1, 1, 1); + mask_bitmap = gdk_pixmap_new(root_window, 1, 1, 1); - mask_fg_gc = gdk_gc_new(mask_bitmap); - pixel.pixel = 1; - gdk_gc_set_foreground(mask_fg_gc, &pixel); - gdk_gc_set_function(mask_fg_gc, GDK_OR); + mask_fg_gc = gdk_gc_new(mask_bitmap); + pixel.pixel = 1; + gdk_gc_set_foreground(mask_fg_gc, &pixel); + gdk_gc_set_function(mask_fg_gc, GDK_OR); - mask_bg_gc = gdk_gc_new(mask_bitmap); - pixel.pixel = 0; - gdk_gc_set_foreground(mask_bg_gc, &pixel); - } + mask_bg_gc = gdk_gc_new(mask_bitmap); + pixel.pixel = 0; + gdk_gc_set_foreground(mask_bg_gc, &pixel); + } - selection_gc = gdk_gc_new(root_window); - gdk_gc_set_function(selection_gc, GDK_XOR); + selection_gc = gdk_gc_new(root_window); + gdk_gc_set_function(selection_gc, GDK_XOR); - 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 - /* Only call this after tileset_load_tiles is called. */ - gtk_window_set_icon(GTK_WINDOW(toplevel), - 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), + sprite_get_pixbuf(get_icon_sprite(tileset, ICON_FREECIV))); #endif - 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); - 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); + message_buffer = NULL; /* Result of destruction of everything */ + tileset_free_tiles(tileset); + } return EXIT_SUCCESS; } diff --git a/client/gui-gtk-3.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index 4e4117390e..492280b9c1 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -201,7 +201,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); @@ -288,7 +288,7 @@ static void log_gtk_warns(const gchar *log_domain, GLogLevelFlags log_level, /************************************************************************** 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; bool gtk_warns_enabled = FALSE; @@ -298,7 +298,8 @@ static void parse_options(int argc, char **argv) if (is_option("--help", argv[i])) { print_usage(); - exit(EXIT_SUCCESS); + + return FALSE; } else if (is_option("--gtk-warnings", argv[i])) { gtk_warns_enabled = TRUE; } else if ((option = get_option_malloc("--resolution", argv, &i, argc, FALSE))) { @@ -316,6 +317,8 @@ static void parse_options(int argc, char **argv) if (!gtk_warns_enabled) { g_log_set_handler("Gtk", G_LOG_LEVEL_WARNING, log_gtk_warns, NULL); } + + return TRUE; } /************************************************************************** @@ -1683,156 +1686,155 @@ 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.")); - exit(EXIT_FAILURE); - } + help_system_init(); - help_system_init(); + 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); - 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); - - 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_gtk2) = TRUE; - GUI_GTK_OPTION(migrated_from_2_5) = TRUE; - } else { - if (!GUI_GTK_OPTION(migrated_from_gtk2)) { - migrate_options_from_gtk2(); - /* We want a fresh look at screen-size-related defaults */ + 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 don't ever want to consider pre-2.6 fullscreen option again */ + /* 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_gtk2) = TRUE; GUI_GTK_OPTION(migrated_from_2_5) = TRUE; - } else if (!GUI_GTK_OPTION(migrated_from_2_5)) { - /* This only affects the fullscreen option, which we don't want - * to touch if adjust_default_options() just adjusted it. */ - migrate_options_from_2_5(); + } else { + if (!GUI_GTK_OPTION(migrated_from_gtk2)) { + migrate_options_from_gtk2(); + /* We want a fresh look at screen-size-related defaults */ + adjust_default_options(); + /* We don't ever want to consider pre-2.6 fullscreen option again */ + GUI_GTK_OPTION(migrated_from_2_5) = TRUE; + } else if (!GUI_GTK_OPTION(migrated_from_2_5)) { + /* This only affects the fullscreen option, which we don't want + * to touch if adjust_default_options() just adjusted it. */ + migrate_options_from_2_5(); + } } - } - if (GUI_GTK_OPTION(fullscreen)) { - gtk_window_fullscreen(GTK_WINDOW(toplevel)); - } - - gtk_window_set_title(GTK_WINDOW (toplevel), _("Freeciv")); + if (GUI_GTK_OPTION(fullscreen)) { + gtk_window_fullscreen(GTK_WINDOW(toplevel)); + } - g_signal_connect(toplevel, "delete_event", - G_CALLBACK(quit_dialog_callback), NULL); + gtk_window_set_title(GTK_WINDOW (toplevel), _("Freeciv")); - /* 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); + 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); - display_color_type = get_visual(); + display_color_type = get_visual(); - options_iterate(client_optset, poption) { - if (OT_FONT == option_type(poption)) { - /* Force to call the appropriated callback. */ - option_changed(poption); - } - } options_iterate_end; + options_iterate(client_optset, poption) { + if (OT_FONT == option_type(poption)) { + /* Force to call the appropriated 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-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index d6913640fd..ca5f0d4d37 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -201,7 +201,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); @@ -274,7 +274,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; @@ -283,7 +283,8 @@ static void parse_options(int argc, char **argv) if (is_option("--help", argv[i])) { print_usage(); - exit(EXIT_SUCCESS); + + return FALSE; } else if ((option = get_option_malloc("--resolution", argv, &i, argc, FALSE))) { if (!string_to_video_mode(option, &vmode)) { fc_fprintf(stderr, _("Illegal video mode '%s'\n"), option); @@ -295,6 +296,8 @@ static void parse_options(int argc, char **argv) i++; } + + return TRUE; } /************************************************************************** @@ -1762,160 +1765,159 @@ 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.")); + exit(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); - - 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); + + 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)); - } - gtk_window_set_title(GTK_WINDOW (toplevel), _("Freeciv")); + if (GUI_GTK_OPTION(fullscreen)) { + gtk_window_fullscreen(GTK_WINDOW(toplevel)); + } - g_signal_connect(toplevel, "delete_event", - G_CALLBACK(quit_dialog_callback), NULL); + gtk_window_set_title(GTK_WINDOW (toplevel), _("Freeciv")); - /* 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); + 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); - display_color_type = get_visual(); + display_color_type = get_visual(); - options_iterate(client_optset, poption) { - if (OT_FONT == option_type(poption)) { - /* Force to call the appropriated callback. */ - option_changed(poption); - } - } options_iterate_end; + options_iterate(client_optset, poption) { + if (OT_FONT == option_type(poption)) { + /* Force to call the appropriated 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-sdl2/gui_main.c b/client/gui-sdl2/gui_main.c index 0474ed3d80..a2877e0129 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 *pMap_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 int 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_options.gui_sdl2_fullscreen = TRUE; } else if (is_option("--swrenderer", argv[i])) { @@ -216,6 +217,8 @@ static void parse_options(int argc, char **argv) i++; } + + return TRUE; } /************************************************************************** @@ -985,136 +988,137 @@ 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_options.gui_sdl2_fullscreen) { - flags |= SDL_WINDOW_FULLSCREEN; - } else { - flags &= ~SDL_WINDOW_FULLSCREEN; - } - log_normal(_("Using Video Output: %s"), SDL_GetCurrentVideoDriver()); - if (!set_video_mode(gui_options.gui_sdl2_screen.width, - gui_options.gui_sdl2_screen.height, - flags)) { - return EXIT_FAILURE; - } + if (parse_options(argc, argv)) { + if (!gui_options.gui_sdl2_migrated_from_sdl) { + migrate_options_from_sdl(); + } - user_event_type = SDL_RegisterEvents(1); + if (gui_options.gui_sdl2_fullscreen) { + flags |= SDL_WINDOW_FULLSCREEN; + } else { + flags &= ~SDL_WINDOW_FULLSCREEN; + } + log_normal(_("Using Video Output: %s"), SDL_GetCurrentVideoDriver()); + if (!set_video_mode(gui_options.gui_sdl2_screen.width, + gui_options.gui_sdl2_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; - pNet_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; - pAnim_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; + pNet_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; - pInfo_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; + pAnim_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; + pInfo_User_Event = &__Info_User_Event; - SDL_zero(__pMap_Scroll_User_Event); - __pMap_Scroll_User_Event.type = user_event_type; - __pMap_Scroll_User_Event.user.code = MAP_SCROLL; - __pMap_Scroll_User_Event.user.data1 = NULL; - __pMap_Scroll_User_Event.user.data2 = NULL; - pMap_Scroll_User_Event = &__pMap_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(__pMap_Scroll_User_Event); + __pMap_Scroll_User_Event.type = user_event_type; + __pMap_Scroll_User_Event.user.code = MAP_SCROLL; + __pMap_Scroll_User_Event.user.data1 = NULL; + __pMap_Scroll_User_Event.user.data2 = NULL; + pMap_Scroll_User_Event = &__pMap_Scroll_User_Event; - SDL_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); + SDL_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 need correct Main.screen size */ - init_mapcanvas_and_overview(); + setup_auxiliary_tech_icons(); - set_client_state(C_S_DISCONNECTED); + /* This need correct Main.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 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_mapcanvas_and_overview(); + free_auxiliary_tech_icons(); + free_intro_radar_sprites(); - free_auxiliary_tech_icons(); - free_intro_radar_sprites(); + diplomacy_dialog_done(); + intel_dialog_done(); - diplomacy_dialog_done(); - intel_dialog_done(); + callback_list_destroy(callbacks); + callbacks = NULL; - callback_list_destroy(callbacks); - callbacks = NULL; + unload_cursors(); - unload_cursors(); + free(button_behavior.event); + button_behavior.event = NULL; - FC_FREE(button_behavior.event); + meswin_dialog_popdown(); - meswin_dialog_popdown(); + del_main_list(); - del_main_list(); + free_font_system(); + theme_free(theme); + theme = NULL; - free_font_system(); - theme_free(theme); - theme = NULL; + quit_sdl(); + } - quit_sdl(); + return EXIT_SUCCESS; +} + +/************************************************************************** + 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 d5838b1a7d..a956ee2eba 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