From: John Darrington Date: Sun, 13 Sep 2020 11:46:20 +0000 (+0200) Subject: Psppire: Move Mac OS specific code to its own file X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb54e9b8ccc43a3febfbe374ac02c88ba751f2c9;p=pspp Psppire: Move Mac OS specific code to its own file --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index d3036d887d..0fa4afb1bf 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -169,6 +169,7 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/missing-val-dialog.h \ src/ui/gui/options-dialog.c \ src/ui/gui/options-dialog.h \ + src/ui/gui/pre-initialisation.h \ src/ui/gui/psppire.c \ src/ui/gui/psppire-data-editor.c \ src/ui/gui/psppire-data-editor.h \ diff --git a/src/ui/gui/main.c b/src/ui/gui/main.c index a7e09af806..a0c6c313cd 100644 --- a/src/ui/gui/main.c +++ b/src/ui/gui/main.c @@ -16,13 +16,12 @@ #include +#include "pre-initialisation.h" + #include "ui/gui/psppire.h" #include #include -#if ENABLE_RELOCATABLE && defined(__APPLE__) -#include -#endif #include "language/lexer/include-path.h" #include "libpspp/argv-parser.h" @@ -304,7 +303,7 @@ process_pre_start_arguments (int *argc, char ***argv) GOptionEntry oe[] = { {"version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_and_exit, N_("Show version information and exit"), 0}, - {NULL} + {NULL, 0, 0, 0, NULL, "", 0} }; GOptionContext *oc = g_option_context_new (""); @@ -315,87 +314,11 @@ process_pre_start_arguments (int *argc, char ***argv) g_option_context_free (oc); } -#if ENABLE_RELOCATABLE && defined(__APPLE__) -static void -pspp_macos_setenv (const char * progname) -{ - /* helper to set environment variables for pspp to be relocatable. - * Due to the latest changes it is not recommended to set it in the shell - * wrapper anymore. - */ - gchar resolved_path[PATH_MAX]; - /* on some OSX installations open file limit is 256 and GIMP needs more */ - struct rlimit limit; - limit.rlim_cur = 10000; - limit.rlim_max = 10000; - setrlimit (RLIMIT_NOFILE, &limit); - if (realpath (progname, resolved_path)) - { - gchar tmp[PATH_MAX]; - gchar *app_dir; - gchar res_dir[PATH_MAX]; - struct stat sb; - - app_dir = g_path_get_dirname (resolved_path); - g_snprintf (tmp, sizeof(tmp), "%s/../../Resources", app_dir); - if (realpath (tmp, res_dir) && !stat (res_dir,&sb) && S_ISDIR (sb.st_mode)) - g_print ("pspp is started as MacOS application\n"); - else - return; - g_free (app_dir); - - g_snprintf (tmp, sizeof(tmp), "%s/lib/gtk-3.0/3.0.0", res_dir); - g_setenv ("GTK_PATH", tmp, TRUE); - g_snprintf (tmp, sizeof(tmp), "%s/etc/gtk-3.0/gtk.immodules", res_dir); - g_setenv ("GTK_IM_MODULE_FILE", tmp, TRUE); - g_snprintf (tmp, sizeof(tmp), "%s/lib/gegl-0.4", res_dir); - g_setenv ("GEGL_PATH", tmp, TRUE); - g_snprintf (tmp, sizeof(tmp), "%s/lib/babl-0.1", res_dir); - g_setenv ("BABL_PATH", tmp, TRUE); - g_snprintf (tmp, sizeof(tmp), "%s/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache", res_dir); - g_setenv ("GDK_PIXBUF_MODULE_FILE", tmp, TRUE); - g_snprintf (tmp, sizeof(tmp), "%s/etc/fonts", res_dir); - g_setenv ("FONTCONFIG_PATH", tmp, TRUE); - g_snprintf (tmp, sizeof(tmp), "%s/lib/gio/modules", res_dir); - g_setenv ("GIO_MODULE_DIR", tmp, TRUE); - g_snprintf (tmp, sizeof(tmp), "%s/etc/xdg", res_dir); - g_setenv ("XDG_CONFIG_DIRS", tmp, TRUE); - g_snprintf (tmp, sizeof(tmp), "%s/share", res_dir); - g_setenv ("XDG_DATA_DIRS", tmp, TRUE); - - if (g_getenv ("HOME")!=NULL) - { - g_snprintf (tmp, sizeof(tmp), - "%s/Library/Application Support/pspp/1.3/cache", - g_getenv("HOME")); - g_setenv ("XDG_CACHE_HOME", tmp, TRUE); - } - } -} -#endif - int main (int argc, char *argv[]) { - -#if ENABLE_RELOCATABLE && defined(__APPLE__) - /* remove MacOS session identifier from the command line args */ - gint newargc = 0; - for (gint i = 0; i < argc; i++) - { - if (!g_str_has_prefix (argv[i], "-psn_")) - { - argv[newargc] = argv[i]; - newargc++; - } - } - if (argc > newargc) - { - argv[newargc] = NULL; /* glib expects NULL terminated array */ - argc = newargc; - } - pspp_macos_setenv (argv[0]); -#endif + /* Some operating systems need to munge the arguments. */ + pre_initialisation (&argc, argv); set_program_name (argv[0]); diff --git a/src/ui/gui/pre-initialisation.h b/src/ui/gui/pre-initialisation.h new file mode 100644 index 0000000000..de5014147f --- /dev/null +++ b/src/ui/gui/pre-initialisation.h @@ -0,0 +1,105 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2020 Free Software Foundation + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#if !ENABLE_RELOCATABLE || !defined(__APPLE__) + +static inline void +pre_initialisation (int *argc, char **argv) +{ +} + +#else + +#include +#include + +static inline void +pre_initialisation (int *argc, char **argv) +{ + /* remove MacOS session identifier from the command line args */ + gint newargc = 0; + for (gint i = 0; i < *argc; i++) + { + if (!g_str_has_prefix (argv[i], "-psn_")) + { + argv[newargc] = argv[i]; + newargc++; + } + } + if (*argc > newargc) + { + argv[newargc] = NULL; /* glib expects NULL terminated array */ + *argc = newargc; + } + + const char * progname = argv[0]; + + /* helper to set environment variables for pspp to be relocatable. + * Due to the latest changes it is not recommended to set it in the shell + * wrapper anymore. + */ + gchar resolved_path[PATH_MAX]; + /* on some OSX installations open file limit is 256 and GIMP needs more */ + struct rlimit limit; + limit.rlim_cur = 10000; + limit.rlim_max = 10000; + setrlimit (RLIMIT_NOFILE, &limit); + if (realpath (progname, resolved_path)) + { + gchar tmp[PATH_MAX]; + gchar *app_dir; + gchar res_dir[PATH_MAX]; + struct stat sb; + + app_dir = g_path_get_dirname (resolved_path); + g_snprintf (tmp, sizeof(tmp), "%s/../../Resources", app_dir); + if (realpath (tmp, res_dir) && !stat (res_dir,&sb) && S_ISDIR (sb.st_mode)) + g_print ("pspp is started as MacOS application\n"); + else + return; + g_free (app_dir); + + g_snprintf (tmp, sizeof(tmp), "%s/lib/gtk-3.0/3.0.0", res_dir); + g_setenv ("GTK_PATH", tmp, TRUE); + g_snprintf (tmp, sizeof(tmp), "%s/etc/gtk-3.0/gtk.immodules", res_dir); + g_setenv ("GTK_IM_MODULE_FILE", tmp, TRUE); + g_snprintf (tmp, sizeof(tmp), "%s/lib/gegl-0.4", res_dir); + g_setenv ("GEGL_PATH", tmp, TRUE); + g_snprintf (tmp, sizeof(tmp), "%s/lib/babl-0.1", res_dir); + g_setenv ("BABL_PATH", tmp, TRUE); + g_snprintf (tmp, sizeof(tmp), "%s/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache", res_dir); + g_setenv ("GDK_PIXBUF_MODULE_FILE", tmp, TRUE); + g_snprintf (tmp, sizeof(tmp), "%s/etc/fonts", res_dir); + g_setenv ("FONTCONFIG_PATH", tmp, TRUE); + g_snprintf (tmp, sizeof(tmp), "%s/lib/gio/modules", res_dir); + g_setenv ("GIO_MODULE_DIR", tmp, TRUE); + g_snprintf (tmp, sizeof(tmp), "%s/etc/xdg", res_dir); + g_setenv ("XDG_CONFIG_DIRS", tmp, TRUE); + g_snprintf (tmp, sizeof(tmp), "%s/share", res_dir); + g_setenv ("XDG_DATA_DIRS", tmp, TRUE); + + if (g_getenv ("HOME")!=NULL) + { + g_snprintf (tmp, sizeof(tmp), + "%s/Library/Application Support/pspp/1.3/cache", + g_getenv("HOME")); + g_setenv ("XDG_CACHE_HOME", tmp, TRUE); + } + } +} +#endif