Ver código fonte

v.to.3d: cleanup if fails, see trac https://trac.osgeo.org/grass/ticket/550

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@38297 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 16 anos atrás
pai
commit
ace138cf93
3 arquivos alterados com 48 adições e 23 exclusões
  1. 12 3
      vector/v.to.3d/main.c
  2. 18 10
      vector/v.to.3d/trans2.c
  3. 18 10
      vector/v.to.3d/trans3.c

+ 12 - 3
vector/v.to.3d/main.c

@@ -29,7 +29,8 @@ int main(int argc, char **argv)
     struct Map_info In, Out;
     BOUND_BOX box;
     int field, type;
-
+    int ret;
+    
     G_gisinit(argv[0]);
 
     module = G_define_module();
@@ -102,9 +103,10 @@ int main(int argc, char **argv)
     }
 
     G_message(_("Transforming features..."));
+    ret = 0;
     if (opt.reverse->answer) {
 	/* 3d -> 2d */
-	trans3d(&In, &Out, type, field, opt.column->answer);
+	ret = trans3d(&In, &Out, type, field, opt.column->answer);
     }
     else {
 	/* 2d -> 3d */
@@ -113,7 +115,14 @@ int main(int argc, char **argv)
 	if (opt.height->answer) {
 	    height = atof(opt.height->answer);
 	}
-	trans2d(&In, &Out, type, height, field, opt.column->answer);
+	ret = trans2d(&In, &Out, type, height, field, opt.column->answer);
+    }
+
+    if (ret < 0) {
+	Vect_close(&In);
+	Vect_close(&Out);
+	Vect_delete(opt.output->answer);
+	G_fatal_error(_("%s failed"), G_program_name());
     }
 
     if (!opt.reverse->answer && !opt.table->answer) {

+ 18 - 10
vector/v.to.3d/trans2.c

@@ -16,6 +16,7 @@
    \param column attribute column used for height
 
    \return number of writen features
+   \return -1 on error
  */
 int trans2d(struct Map_info *In, struct Map_info *Out, int type,
 	    double height, int field, const char *column)
@@ -40,23 +41,29 @@ int trans2d(struct Map_info *In, struct Map_info *Out, int type,
 	dbDriver *driver;
 
 	Fi = Vect_get_field(In, field);
-	if (!Fi)
-	    G_fatal_error(_("Database connection not defined for layer %d"),
-			  field);
+	if (!Fi) {
+	    G_warning(_("Database connection not defined for layer %d"),
+		      field);
+	    return -1;
+	}
 
 	driver = db_start_driver_open_database(Fi->driver, Fi->database);
 	if (!driver) {
-	    G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
-			  Fi->database, Fi->driver);
+	    G_warning(_("Unable to open database <%s> by driver <%s>"),
+		      Fi->database, Fi->driver);
+	    return -1;
 	}
 
 	/* column type must numeric */
 	ctype = db_column_Ctype(driver, Fi->table, column);
-	if (ctype == -1)
-	    G_fatal_error(_("Column <%s> not found in table <%s>"),
-			  column, Fi->table);
+	if (ctype == -1) {
+	    G_warning(_("Column <%s> not found in table <%s>"),
+		      column, Fi->table);
+	    return -1;
+	}
 	if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE) {
-	    G_fatal_error(_("Column must be numeric"));
+	    G_warning(_("Column must be numeric"));
+	    return -1;
 	}
 
 	db_select_CatValArray(driver, Fi->table, Fi->key,
@@ -71,7 +78,8 @@ int trans2d(struct Map_info *In, struct Map_info *Out, int type,
     while (1) {
 	ltype = Vect_read_next_line(In, Points, Cats);
 	if (ltype == -1) {
-	    G_fatal_error(_("Unable to read vector map"));
+	    G_warning(_("Unable to read vector map"));
+	    return -1;
 	}
 	if (ltype == -2) {	/* EOF */
 	    break;

+ 18 - 10
vector/v.to.3d/trans3.c

@@ -17,6 +17,7 @@ static int srch(const void *, const void *);
    \param zcolumn attribute column where to store height
 
    \return number of writen features
+   \return -1 on error
  */
 int trans3d(struct Map_info *In, struct Map_info *Out, int type,
 	    int field, const char *zcolumn)
@@ -41,23 +42,29 @@ int trans3d(struct Map_info *In, struct Map_info *Out, int type,
 
     if (zcolumn) {
 	Fi = Vect_get_field(Out, field);
-	if (!Fi)
-	    G_fatal_error(_("Database connection not defined for layer %d"),
-			  field);
+	if (!Fi) {
+	    G_warning(_("Database connection not defined for layer %d"),
+		      field);
+	    return -1;
+	}
 
 	driver = db_start_driver_open_database(Fi->driver, Fi->database);
 	if (!driver) {
-	    G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
-			  Fi->database, Fi->driver);
+	    G_warning(_("Unable to open database <%s> by driver <%s>"),
+		      Fi->database, Fi->driver);
+	    return -1;
 	}
 
 	/* column type must numeric */
 	ctype = db_column_Ctype(driver, Fi->table, zcolumn);
-	if (ctype == -1)
-	    G_fatal_error(_("Column <%s> not found in table <%s>"),
-			  zcolumn, Fi->table);
+	if (ctype == -1) {
+	    G_warning(_("Column <%s> not found in table <%s>"),
+		      zcolumn, Fi->table);
+	    return -1;
+	}
 	if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE) {
-	    G_fatal_error(_("Column must be numeric"));
+	    G_warning(_("Column must be numeric"));
+	    return -1;
 	}
 
 	db_begin_transaction(driver);
@@ -71,7 +78,8 @@ int trans3d(struct Map_info *In, struct Map_info *Out, int type,
     while (1) {
 	ltype = Vect_read_next_line(In, Points, Cats);
 	if (ltype == -1) {
-	    G_fatal_error(_("Unable to read vector map"));
+	    G_warning(_("Unable to read vector map"));
+	    return -1;
 	}
 	if (ltype == -2) {	/* EOF */
 	    break;