GRASS Programmer's Manual
6.4.2(2012)
|
00001 00002 /*************************************************************************** 00003 * at_exit_funcs.c 00004 * 00005 * Mon Apr 18 14:52:20 2005 00006 * Copyright 2005 Benjamin Ducke 00007 ****************************************************************************/ 00008 00009 /* 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00023 */ 00024 00025 #include "globals.h" 00026 00027 00028 /* unset environment variables */ 00029 void exit_env(void) 00030 { 00031 00032 /* 00033 NOT NECESSARY, as process cannot set env vars of caller anyway and this 00034 gives trouble with MINGW compilation, too. 00035 */ 00036 00037 /* 00038 unsetenv ("GINSTALL_DST"); 00039 unsetenv ("GINSTALL_INC"); 00040 unsetenv ("GINSTALL_LIB"); 00041 unsetenv ("UNINSTALL_BASE"); 00042 unsetenv ("GEM_EXT_NAME"); 00043 unsetenv ("GEM_EXT_VERSION"); 00044 unsetenv ("GEM_EXT_DESCR"); 00045 unsetenv ("GEM_EXT_INFO"); 00046 unsetenv ("GEM_EXT_DEPS"); 00047 unsetenv ("GEM_EXT_BUGS"); 00048 unsetenv ("GEM_EXT_AUTHORS"); 00049 unsetenv ("GEM_GRASS_DIR"); 00050 unsetenv ("GEM_ACTION"); 00051 unsetenv ("INSTALL_BASE"); 00052 unsetenv ("INSTALL_TYPE"); 00053 unsetenv ("GEM_FORCE"); 00054 unsetenv ("GEM_VERBOSE"); 00055 unsetenv ("GEM_GUI"); 00056 unsetenv ("GEM_C_OPTS"); 00057 unsetenv ("EXT_BASE"); 00058 */ 00059 } 00060 00061 /* delete temp directory */ 00062 void exit_tmp(void) 00063 { 00064 int error; 00065 char tmp[MAXSTR]; 00066 00067 DIR *dir; 00068 00069 /* if TMPDIR is not set: do not call rmdir! */ 00070 if (!strcmp(TMPDIR, "")) { 00071 TMPCLEAN = 1; 00072 return; 00073 } 00074 00075 if (TMPCLEAN == 0) { /* a dirty trick to make sure this only runs once */ 00076 00077 /* step out of temporary dir, in case this extension has been */ 00078 /* installed from an archived dir */ 00079 chdir(CWD); 00080 00081 sprintf(tmp, "rm -rf %s/*", TMPDIR); 00082 00083 if (VERBOSE) { 00084 fprintf(stdout, "Removing temporary extension files..."); 00085 } 00086 error = system(tmp); 00087 00088 sprintf(tmp, "rmdir %s", TMPDIR); 00089 error = system(tmp); 00090 00091 /* check if extension dir still exists and if so: warn */ 00092 dir = opendir(TMPDIR); 00093 if (dir != NULL) { 00094 print_warning 00095 ("could not remove temporary directory %s.\nPlease remove manually.\n", 00096 TMPDIR); 00097 } 00098 if (VERBOSE) { 00099 print_done(); 00100 } 00101 TMPCLEAN = 1; 00102 } 00103 } 00104 00105 /* delete temp database */ 00106 void exit_db(void) 00107 { 00108 int error; 00109 char tmp[MAXSTR]; 00110 00111 if (TMPDBCLEAN == 0) { /* a dirty trick to make sure this only runs once */ 00112 00113 /* step out of temporary dir, in case this extension has been */ 00114 /* installed from an archived dir */ 00115 chdir(CWD); 00116 00117 if (VERBOSE) { 00118 fprintf(stdout, "Removing temporary registration files..."); 00119 } 00120 00121 if (strcmp(TMPDB, "")) { 00122 sprintf(tmp, "rm -rf %s", TMPDB); 00123 error = system(tmp); 00124 if (error != 0) { 00125 print_warning 00126 ("could not remove temporary file %s.\nPlease remove manually.\n", 00127 TMPDB); 00128 } 00129 } 00130 00131 if (strcmp(TMP_GISMAN, "")) { 00132 sprintf(tmp, "rm -f %s", TMP_GISMAN); 00133 error = system(tmp); 00134 if (error != 0) { 00135 print_warning 00136 ("could not remove temporary file %s.\nPlease remove manually.\n", 00137 TMP_GISMAN); 00138 } 00139 } 00140 00141 if (strcmp(TMP_DESCR, "")) { 00142 sprintf(tmp, "rm -f %s", TMP_DESCR); 00143 error = system(tmp); 00144 if (error != 0) { 00145 print_warning 00146 ("could not remove temporary file %s.\nPlease remove manually.\n", 00147 TMP_DESCR); 00148 } 00149 } 00150 00151 if (strcmp(TMP_INFO, "")) { 00152 sprintf(tmp, "rm -f %s", TMP_INFO); 00153 error = system(tmp); 00154 if (error != 0) { 00155 print_warning 00156 ("could not remove temporary file %s.\nPlease remove manually.\n", 00157 TMP_INFO); 00158 } 00159 } 00160 00161 if (strcmp(TMP_DEPS, "")) { 00162 sprintf(tmp, "rm -f %s", TMP_DEPS); 00163 error = system(tmp); 00164 if (error != 0) { 00165 print_warning 00166 ("could not remove temporary file %s.\nPlease remove manually.\n", 00167 TMP_INFO); 00168 } 00169 } 00170 00171 if (strcmp(TMP_BUGS, "")) { 00172 sprintf(tmp, "rm -f %s", TMP_BUGS); 00173 error = system(tmp); 00174 if (error != 0) { 00175 print_warning 00176 ("could not remove temporary file %s.\nPlease remove manually.\n", 00177 TMP_INFO); 00178 } 00179 } 00180 00181 if (strcmp(TMP_AUTHORS, "")) { 00182 sprintf(tmp, "rm -f %s", TMP_AUTHORS); 00183 error = system(tmp); 00184 if (error != 0) { 00185 print_warning 00186 ("could not remove temporary file %s.\nPlease remove manually.\n", 00187 TMP_INFO); 00188 } 00189 } 00190 00191 if (strcmp(TMP_HTML, "")) { 00192 sprintf(tmp, "rm -f %s", TMP_HTML); 00193 error = system(tmp); 00194 if (error != 0) { 00195 print_warning 00196 ("could not remove temporary file %s.\nPlease remove manually.\n", 00197 TMP_HTML); 00198 } 00199 } 00200 00201 if (!VERBOSE) { 00202 if (strcmp(TMP_NULL, "")) { 00203 sprintf(tmp, "rm -f %s", TMP_NULL); 00204 error = system(tmp); 00205 if (error != 0) { 00206 print_warning 00207 ("could not remove temporary file %s.\nPlease remove manually.\n", 00208 TMP_NULL); 00209 } 00210 } 00211 } 00212 00213 if (VERBOSE) { 00214 print_done(); 00215 } 00216 TMPDBCLEAN = 1; 00217 } 00218 } 00219 00220 /* show a message at end of program */ 00221 void exit_msg(void) 00222 { 00223 if (ERROR < 0) { 00224 fprintf(stdout, 00225 "Program exited with an error (code %i). Operation aborted.\n", 00226 ERROR); 00227 } 00228 else { 00229 if (WARNINGS == 1) { 00230 fprintf(stdout, 00231 "Job done but there was one warning. Please check.\n"); 00232 } 00233 if (WARNINGS > 1) { 00234 fprintf(stdout, 00235 "Job done but there were %i warnings. Please check.\n", 00236 WARNINGS); 00237 } 00238 } 00239 }