Index: lib/gis/error.c
===================================================================
--- lib/gis/error.c	(revision 55643)
+++ lib/gis/error.c	(working copy)
@@ -45,6 +45,7 @@
 static int (*ext_error) (const char *, int);	/* Roger Bivand 17 June 2000 */
 static int no_warn  = FALSE;
 static int no_sleep = TRUE;
+static int err_code = G_FATAL_EXIT;
 
 static int grass_info_format;
 static char *logfile;
@@ -171,7 +172,63 @@
     exit(EXIT_FAILURE);
 }
 
+void G__error(const char *msg, ...)
+{
+    static int busy;
+    va_list ap;
+    
+    if (err_code == G_FATAL_EXIT) {
+        if (busy)
+            exit(EXIT_FAILURE);
+        busy = 1;
+    }
+
+    if (G_verbose() > -1 && err_code != G_FATAL_RETURN) {
+        va_start(ap, msg);
+        vfprint_error(ERR, msg, ap);
+        va_end(ap);
+    }
+
+    if (err_code == G_FATAL_EXIT) {
+        G__call_error_handlers();
+
+        /* Raise SIGSEGV, useful for debugging only.
+         * Type "export GRASS_SIGSEGV_ON_ERROR=1"
+         * to enable this feature using bash.
+         */
+        if (getenv("GRASS_SIGSEGV_ON_ERROR"))
+            raise(SIGSEGV);
+        
+        exit(EXIT_FAILURE);
+    }
+}
+
 /*!
+  \brief Set error code
+
+  \param error_code
+
+  \return 1 on success
+  \return 0 on invalid return code
+*/
+int G__set_error_code(int error_code)
+{
+    int valid = TRUE;
+    
+    switch(error_code) {
+    case G_FATAL_EXIT:
+    case G_FATAL_PRINT:
+    case G_FATAL_RETURN:
+        err_code = error_code;
+        break;
+    defaut:
+        valid = FALSE;
+    }
+
+    return valid;
+}
+
+/*!
  * \brief Print a warning message to stderr
  * 
  * The output format depends on environment variable
Index: lib/gis/legal_name.c
===================================================================
--- lib/gis/legal_name.c	(revision 55643)
+++ lib/gis/legal_name.c	(working copy)
@@ -60,46 +60,27 @@
  *
  * \param input input map name
  * \param output output map name
- * \param error error type: G_FATAL_EXIT, G_FATAL_PRINT, G_FATAL_RETURN
  *
  * \return 0 OK
  * \return 1 error
  */
-int G_check_input_output_name(const char *input, const char *output,
-			      int error)
+int G_check_input_output_name(const char *input, const char *output)
 {
     const char *mapset;
 
     if (output == NULL)
 	return 0;		/* don't die on undefined parameters */
     if (G_legal_filename(output) == -1) {
-	if (error == G_FATAL_EXIT) {
-	    G_fatal_error(_("Output raster map name <%s> is not valid map name"),
-			  output);
-	}
-	else if (error == G_FATAL_PRINT) {
-	    G_warning(_("Output raster map name <%s> is not valid map name"),
-		      output);
-	    return 1;
-	}
-	else {			/* G_FATAL_RETURN */
-	    return 1;
-	}
+        G__error(_("Output raster map name <%s> is not valid map name"),
+                 output);
+        return 1;
     }
 
     mapset = G_find_raster2(input, "");
 
     if (mapset == NULL) {
-	if (error == G_FATAL_EXIT) {
-	    G_fatal_error(_("Raster map <%s> not found"), input);
-	}
-	else if (error == G_FATAL_PRINT) {
-	    G_warning(_("Raster map <%s> not found"), input);
-	    return 1;
-	}
-	else {			/* G_FATAL_RETURN */
-	    return 1;
-	}
+        G__error(_("Raster map <%s> not found"), input);
+        return 1;
     }
 
     if (strcmp(mapset, G_mapset()) == 0) {
@@ -114,18 +95,9 @@
 	}
 
 	if (strcmp(in, output) == 0) {
-	    if (error == G_FATAL_EXIT) {
-		G_fatal_error(_("Output raster map <%s> is used as input"),
-			      output);
-	    }
-	    else if (error == G_FATAL_PRINT) {
-		G_warning(_("Output raster map <%s> is used as input"),
-			  output);
+            G__error(_("Output raster map <%s> is used as input"),
+                     output);
 		return 1;
-	    }
-	    else {		/* G_FATAL_RETURN */
-		return 1;
-	    }
 	}
     }
 
Index: include/defs/gis.h
===================================================================
--- include/defs/gis.h	(revision 55643)
+++ include/defs/gis.h	(working copy)
@@ -224,6 +224,8 @@
     __attribute__ ((format(printf, 1, 2)));
 void G_fatal_error(const char *, ...) __attribute__ ((format(printf, 1, 2)))
     __attribute__ ((noreturn));
+int G__set_error_code(int);
+void G__error(const char *, ...) __attribute__ ((format(printf, 1, 2)));
 void G_warning(const char *, ...) __attribute__ ((format(printf, 1, 2)));
 int G_suppress_warnings(int);
 int G_sleep_on_error(int);
@@ -352,7 +354,7 @@
 
 /* legal_name.c */
 int G_legal_filename(const char *);
-int G_check_input_output_name(const char *, const char *, int);
+int G_check_input_output_name(const char *, const char *);
 
 /* line_dist.c */
 void G_set_distance_to_line_tolerance(double);
