GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
at_exit_funcs.c
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * at_exit_funcs.c
4  *
5  * Mon Apr 18 14:52:20 2005
6  * Copyright 2005 Benjamin Ducke
7  ****************************************************************************/
8 
9 /*
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #include "globals.h"
26 
27 
28 /* unset environment variables */
29 void exit_env(void)
30 {
31 
32  /*
33  NOT NECESSARY, as process cannot set env vars of caller anyway and this
34  gives trouble with MINGW compilation, too.
35  */
36 
37  /*
38  unsetenv ("GINSTALL_DST");
39  unsetenv ("GINSTALL_INC");
40  unsetenv ("GINSTALL_LIB");
41  unsetenv ("UNINSTALL_BASE");
42  unsetenv ("GEM_EXT_NAME");
43  unsetenv ("GEM_EXT_VERSION");
44  unsetenv ("GEM_EXT_DESCR");
45  unsetenv ("GEM_EXT_INFO");
46  unsetenv ("GEM_EXT_DEPS");
47  unsetenv ("GEM_EXT_BUGS");
48  unsetenv ("GEM_EXT_AUTHORS");
49  unsetenv ("GEM_GRASS_DIR");
50  unsetenv ("GEM_ACTION");
51  unsetenv ("INSTALL_BASE");
52  unsetenv ("INSTALL_TYPE");
53  unsetenv ("GEM_FORCE");
54  unsetenv ("GEM_VERBOSE");
55  unsetenv ("GEM_GUI");
56  unsetenv ("GEM_C_OPTS");
57  unsetenv ("EXT_BASE");
58  */
59 }
60 
61 /* delete temp directory */
62 void exit_tmp(void)
63 {
64  int error;
65  char tmp[MAXSTR];
66 
67  DIR *dir;
68 
69  /* if TMPDIR is not set: do not call rmdir! */
70  if (!strcmp(TMPDIR, "")) {
71  TMPCLEAN = 1;
72  return;
73  }
74 
75  if (TMPCLEAN == 0) { /* a dirty trick to make sure this only runs once */
76 
77  /* step out of temporary dir, in case this extension has been */
78  /* installed from an archived dir */
79  chdir(CWD);
80 
81  sprintf(tmp, "rm -rf %s/*", TMPDIR);
82 
83  if (VERBOSE) {
84  fprintf(stdout, "Removing temporary extension files...");
85  }
86  error = system(tmp);
87 
88  sprintf(tmp, "rmdir %s", TMPDIR);
89  error = system(tmp);
90 
91  /* check if extension dir still exists and if so: warn */
92  dir = opendir(TMPDIR);
93  if (dir != NULL) {
95  ("could not remove temporary directory %s.\nPlease remove manually.\n",
96  TMPDIR);
97  }
98  if (VERBOSE) {
99  print_done();
100  }
101  TMPCLEAN = 1;
102  }
103 }
104 
105 /* delete temp database */
106 void exit_db(void)
107 {
108  int error;
109  char tmp[MAXSTR];
110 
111  if (TMPDBCLEAN == 0) { /* a dirty trick to make sure this only runs once */
112 
113  /* step out of temporary dir, in case this extension has been */
114  /* installed from an archived dir */
115  chdir(CWD);
116 
117  if (VERBOSE) {
118  fprintf(stdout, "Removing temporary registration files...");
119  }
120 
121  if (strcmp(TMPDB, "")) {
122  sprintf(tmp, "rm -rf %s", TMPDB);
123  error = system(tmp);
124  if (error != 0) {
126  ("could not remove temporary file %s.\nPlease remove manually.\n",
127  TMPDB);
128  }
129  }
130 
131  if (strcmp(TMP_GISMAN, "")) {
132  sprintf(tmp, "rm -f %s", TMP_GISMAN);
133  error = system(tmp);
134  if (error != 0) {
136  ("could not remove temporary file %s.\nPlease remove manually.\n",
137  TMP_GISMAN);
138  }
139  }
140 
141  if (strcmp(TMP_DESCR, "")) {
142  sprintf(tmp, "rm -f %s", TMP_DESCR);
143  error = system(tmp);
144  if (error != 0) {
146  ("could not remove temporary file %s.\nPlease remove manually.\n",
147  TMP_DESCR);
148  }
149  }
150 
151  if (strcmp(TMP_INFO, "")) {
152  sprintf(tmp, "rm -f %s", TMP_INFO);
153  error = system(tmp);
154  if (error != 0) {
156  ("could not remove temporary file %s.\nPlease remove manually.\n",
157  TMP_INFO);
158  }
159  }
160 
161  if (strcmp(TMP_DEPS, "")) {
162  sprintf(tmp, "rm -f %s", TMP_DEPS);
163  error = system(tmp);
164  if (error != 0) {
166  ("could not remove temporary file %s.\nPlease remove manually.\n",
167  TMP_INFO);
168  }
169  }
170 
171  if (strcmp(TMP_BUGS, "")) {
172  sprintf(tmp, "rm -f %s", TMP_BUGS);
173  error = system(tmp);
174  if (error != 0) {
176  ("could not remove temporary file %s.\nPlease remove manually.\n",
177  TMP_INFO);
178  }
179  }
180 
181  if (strcmp(TMP_AUTHORS, "")) {
182  sprintf(tmp, "rm -f %s", TMP_AUTHORS);
183  error = system(tmp);
184  if (error != 0) {
186  ("could not remove temporary file %s.\nPlease remove manually.\n",
187  TMP_INFO);
188  }
189  }
190 
191  if (strcmp(TMP_HTML, "")) {
192  sprintf(tmp, "rm -f %s", TMP_HTML);
193  error = system(tmp);
194  if (error != 0) {
196  ("could not remove temporary file %s.\nPlease remove manually.\n",
197  TMP_HTML);
198  }
199  }
200 
201  if (!VERBOSE) {
202  if (strcmp(TMP_NULL, "")) {
203  sprintf(tmp, "rm -f %s", TMP_NULL);
204  error = system(tmp);
205  if (error != 0) {
207  ("could not remove temporary file %s.\nPlease remove manually.\n",
208  TMP_NULL);
209  }
210  }
211  }
212 
213  if (VERBOSE) {
214  print_done();
215  }
216  TMPDBCLEAN = 1;
217  }
218 }
219 
220 /* show a message at end of program */
221 void exit_msg(void)
222 {
223  if (ERROR < 0) {
224  fprintf(stdout,
225  "Program exited with an error (code %i). Operation aborted.\n",
226  ERROR);
227  }
228  else {
229  if (WARNINGS == 1) {
230  fprintf(stdout,
231  "Job done but there was one warning. Please check.\n");
232  }
233  if (WARNINGS > 1) {
234  fprintf(stdout,
235  "Job done but there were %i warnings. Please check.\n",
236  WARNINGS);
237  }
238  }
239 }
EXTERN int VERBOSE
Definition: globals.h:147
void exit_db(void)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
DIR * opendir()
void print_done(void)
Definition: gem/error.c:70
#define MAXSTR
Definition: globals.h:59
EXTERN char TMPDIR[MAXSTR]
Definition: globals.h:148
EXTERN char TMP_NULL[MAXSTR]
Definition: globals.h:156
EXTERN int WARNINGS
Definition: globals.h:179
EXTERN char TMP_HTML[MAXSTR]
Definition: globals.h:158
void exit_env(void)
Definition: at_exit_funcs.c:29
EXTERN int TMPCLEAN
Definition: globals.h:159
EXTERN char TMP_AUTHORS[MAXSTR]
Definition: globals.h:155
EXTERN char TMP_BUGS[MAXSTR]
Definition: globals.h:154
void exit_tmp(void)
Definition: at_exit_funcs.c:62
EXTERN char TMP_DESCR[MAXSTR]
Definition: globals.h:151
EXTERN char TMPDB[MAXSTR]
Definition: globals.h:149
EXTERN char CWD[MAXSTR]
Definition: globals.h:175
void print_warning(char *msg,...)
Definition: gem/error.c:52
return NULL
Definition: dbfopen.c:1394
EXTERN char TMP_INFO[MAXSTR]
Definition: globals.h:152
void exit_msg(void)
EXTERN int ERROR
Definition: globals.h:178
EXTERN char TMP_DEPS[MAXSTR]
Definition: globals.h:153
EXTERN int TMPDBCLEAN
Definition: globals.h:160
EXTERN char TMP_GISMAN[MAXSTR]
Definition: globals.h:150