/* Main.c - standard application frame * * Copyright (C) 2001 Patrice St-Gelais * patrstg@users.sourceforge.net * www.oricom.ca/patrice.st-gelais * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include "./main.h" #include "./globals.h" // Gtkglext - 2005-11 #include /* Returns a char * that contains the path to the geomorph data dir NOTE: This is a pointer to a statically allocated block of memory and should not be modified or freed */ gchar *get_data_dir() { #ifdef GEOMORPHDATADIR return GEOMORPHDATADIR; #else return "/usr/local/share/geomorph/" ## VERSION; #endif } gint create_config_file(gchar *rc_file) { gchar *buf, *command; buf = malloc(strlen(rc_file)+1+strlen(_("Creation of the option file %s"))); sprintf(buf,_("Creation of the option file %s"),rc_file); my_msg(buf,INFO); free(buf); command = concat_dname_fname(get_data_dir(),"install-step2-rcfile"); if (system(command)) my_msg(_("Fatal error during the creation of the option file"),ABORT); if (command) free(command); } char *get_current_dir_name() { char *buf = malloc(MAXPATHLEN); getwd(buf); return buf; } gchar *find_config_file() { // Returns the config file name (name OPTIONS_FILE, defined in globals.h), // with its full path gchar *default_dir, *path_n_file, *buf, *command; gboolean shortcuts; // Config file is located under $HOME/.geomorph/geomorphrc default_dir = getenv("HOME"); default_dir = concat_dname_fname(default_dir,DEFAULT_DIR); path_n_file = concat_dname_fname(default_dir, OPTIONS_FILE); if (directory_exists(default_dir)) { if (!filexists(path_n_file)) { // Big problem, create a default rc file create_config_file(path_n_file); } } else { // Geomorph directory ("default_dir") doesn't exist // Create one with default scenes and rc file buf = malloc(strlen(_("Creation of the default working directory?"))+1+strlen(default_dir)); sprintf(buf,_("Creation of the default working directory?"),default_dir); if (!yes_no(buf,TRUE)) exit(0); if (buf) free(buf); shortcuts = yes_no(_("Add shortcuts on the KDE and GNOME desktops?"), TRUE); command = concat_dname_fname(get_data_dir(),"install-step1-dir"); if (system(command)) my_msg(_("Fatal error during the creation of the default working directory"),ABORT); if (command) free(command); create_config_file(path_n_file); if (shortcuts) { command = concat_dname_fname(get_data_dir(),"install-step3-desktop"); if (system(command)) my_msg(_("Error during the creation of one shortcut or both"),WARNING); if (buf) free(buf); if (command) free(command); } if (path_n_file) free(path_n_file); } return add_filesep(default_dir); } int main( int argc, char *argv[] ) { app_struct *main_app; gint i; option_file_type *opt=NULL, *allowed_opt=NULL; gboolean file_on_cmd = FALSE; gchar *msg = NULL,*options_file = NULL, *buf, *dir, *default_dir=NULL; bindtextdomain("geomorph",LOCALEDIR); bind_textdomain_codeset("geomorph", "UTF-8"); textdomain("geomorph"); gtk_set_locale(); gtk_init(&argc, &argv); gdk_rgb_init(); if (!gtk_gl_init_check (&argc, &argv)) { my_msg(_("Not able to display the Open GL preview"),WARNING); } // printf("\nLOCALEDIR: %s; LANGUAGE: %s\n",LOCALEDIR, getenv("LANGUAGE")); allowed_opt = init_allowed_options(); if (argc > 1) { for (i=1; ifile_on_cmdline = buf; } else main_app->file_on_cmdline = argv[i]; open_callb(NULL,(gpointer) main_app); } gtk_main(); app_free(main_app); gtk_exit(0) ; }