[GRASS-SVN] r39174 - in grass/trunk: include lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Sep 13 08:51:05 EDT 2009
Author: mmetz
Date: 2009-09-13 08:51:04 -0400 (Sun, 13 Sep 2009)
New Revision: 39174
Modified:
grass/trunk/include/vector.h
grass/trunk/lib/vector/Vlib/field.c
Log:
Vector libs: check for duplicate layer names
Modified: grass/trunk/include/vector.h
===================================================================
--- grass/trunk/include/vector.h 2009-09-13 11:00:12 UTC (rev 39173)
+++ grass/trunk/include/vector.h 2009-09-13 12:51:04 UTC (rev 39174)
@@ -98,12 +98,12 @@
void Vect_reset_dblinks(struct dblinks *);
int Vect_add_dblink(struct dblinks *, int, const char *,
const char *, const char *, const char *, const char *);
-int Vect_check_dblink(const struct dblinks *, int);
+int Vect_check_dblink(const struct dblinks *, int, const char *);
int Vect_map_add_dblink(struct Map_info *, int, const char *,
const char *, const char *, const char *,
const char *);
int Vect_map_del_dblink(struct Map_info *, int);
-int Vect_map_check_dblink(const struct Map_info *, int);
+int Vect_map_check_dblink(const struct Map_info *, int, const char *);
int Vect_read_dblinks(struct Map_info *);
int Vect_write_dblinks(struct Map_info *);
struct field_info *Vect_default_field_info(struct Map_info *, int,
Modified: grass/trunk/lib/vector/Vlib/field.c
===================================================================
--- grass/trunk/lib/vector/Vlib/field.c 2009-09-13 11:00:12 UTC (rev 39173)
+++ grass/trunk/lib/vector/Vlib/field.c 2009-09-13 12:51:04 UTC (rev 39174)
@@ -160,9 +160,9 @@
\return 1 dblink for field exists
\return 0 dblink does not exist for field
*/
-int Vect_map_check_dblink(const struct Map_info *Map, int field)
+int Vect_map_check_dblink(const struct Map_info *Map, int field, const char *name)
{
- return Vect_check_dblink(Map->dblnk, field);
+ return Vect_check_dblink(Map->dblnk, field, name);
}
/*!
@@ -174,16 +174,20 @@
\return 1 dblink for field exists
\return 0 dblink does not exist for field
*/
-int Vect_check_dblink(const struct dblinks *p, int field)
+int Vect_check_dblink(const struct dblinks *p, int field, const char *name)
{
int i;
- G_debug(3, "Vect_check_dblink: field %d", field);
+ G_debug(3, "Vect_check_dblink: field %d, name %s", field, (name != NULL ? name : "not given"));
for (i = 0; i < p->n_fields; i++) {
if (p->field[i].number == field) {
return 1;
}
+ if (name != NULL && p->field[i].name != NULL) {
+ if (strcmp(p->field[i].name, name) == 0)
+ return 1;
+ }
}
return 0;
}
@@ -209,7 +213,7 @@
int ret;
G_debug(3, "Field number <%d>, name <%s>", number, name);
- ret = Vect_check_dblink(p, number);
+ ret = Vect_check_dblink(p, number, name);
if (ret == 1) {
G_warning(_("Layer number %d or name <%s> already exists"), number,
name);
@@ -225,8 +229,11 @@
p->field[p->n_fields].number = number;
- if (name != NULL)
+ if (name != NULL) {
p->field[p->n_fields].name = G_store(name);
+ /* replace all spaces with underscore, otherwise dbln can't be read */
+ G_strchg(p->field[p->n_fields].name, ' ', '_');
+ }
else
p->field[p->n_fields].name = NULL;
More information about the grass-commit
mailing list