at_exit_funcs.c 5.7 KB

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