[GRASS-SVN] r40701 - in grass/trunk: general/g.proj include lib/g3d
lib/gis lib/raster raster/r.colors
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jan 27 12:10:10 EST 2010
Author: glynn
Date: 2010-01-27 12:10:07 -0500 (Wed, 27 Jan 2010)
New Revision: 40701
Modified:
grass/trunk/general/g.proj/output.c
grass/trunk/include/gisdefs.h
grass/trunk/lib/g3d/g3dkeys.c
grass/trunk/lib/g3d/g3dwindowio.c
grass/trunk/lib/g3d/header.c
grass/trunk/lib/gis/get_ellipse.c
grass/trunk/lib/gis/get_projinfo.c
grass/trunk/lib/gis/key_value1.c
grass/trunk/lib/gis/key_value2.c
grass/trunk/lib/gis/key_value3.c
grass/trunk/lib/gis/key_value4.c
grass/trunk/lib/gis/make_loc.c
grass/trunk/lib/raster/closecell.c
grass/trunk/lib/raster/opencell.c
grass/trunk/raster/r.colors/main.c
Log:
Generate fatal errors rather than returning a status, for:
G_set_key_value
G_write_key_value_file
G_read_key_value_file
G_update_key_value_file
Modified: grass/trunk/general/g.proj/output.c
===================================================================
--- grass/trunk/general/g.proj/output.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/general/g.proj/output.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -193,22 +193,17 @@
}
{
- int out_stat;
char path[GPATH_MAX];
/* Write out the PROJ_INFO, and PROJ_UNITS if available. */
if (projinfo != NULL) {
G__file_name(path, "", "PROJ_INFO", "PERMANENT");
- G_write_key_value_file(path, projinfo, &out_stat);
- if (out_stat != 0)
- G_fatal_error(_("Error writing PROJ_INFO"));
+ G_write_key_value_file(path, projinfo);
}
if (projunits != NULL) {
G__file_name(path, "", "PROJ_UNITS", "PERMANENT");
- G_write_key_value_file(path, projunits, &out_stat);
- if (out_stat != 0)
- G_fatal_error(_("Error writing PROJ_UNITS"));
+ G_write_key_value_file(path, projunits);
}
if ((old_cellhd.zone != cellhd.zone) ||
Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/include/gisdefs.h 2010-01-27 17:10:07 UTC (rev 40701)
@@ -308,7 +308,7 @@
/* key_value1.c */
struct Key_Value *G_create_key_value(void);
-int G_set_key_value(const char *, const char *, struct Key_Value *);
+void G_set_key_value(const char *, const char *, struct Key_Value *);
const char *G_find_key_value(const char *, const struct Key_Value *);
void G_free_key_value(struct Key_Value *);
@@ -317,11 +317,11 @@
struct Key_Value *G_fread_key_value(FILE *);
/* key_value3.c */
-int G_write_key_value_file(const char *, const struct Key_Value *, int *);
-struct Key_Value *G_read_key_value_file(const char *, int *);
+void G_write_key_value_file(const char *, const struct Key_Value *);
+struct Key_Value *G_read_key_value_file(const char *);
/* key_value4.c */
-int G_update_key_value_file(const char *, const char *, const char *);
+void G_update_key_value_file(const char *, const char *, const char *);
int G_lookup_key_value_from_file(const char *, const char *, char[], int);
/* legal_name.c */
Modified: grass/trunk/lib/g3d/g3dkeys.c
===================================================================
--- grass/trunk/lib/g3d/g3dkeys.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/g3d/g3dkeys.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -93,7 +93,8 @@
char keyValStr[200];
sprintf(keyValStr, "%d", *i);
- return (G_set_key_value(key, keyValStr, keys) != 0);
+ G_set_key_value(key, keyValStr, keys);
+ return 1;
}
/*---------------------------------------------------------------------------*/
@@ -103,7 +104,8 @@
char keyValStr[200];
sprintf(keyValStr, "%.50f", *d);
- return (G_set_key_value(key, keyValStr, keys) != 0);
+ G_set_key_value(key, keyValStr, keys);
+ return 1;
}
/*---------------------------------------------------------------------------*/
@@ -112,7 +114,8 @@
G3d_keySetString(struct Key_Value *keys, const char *key,
char *const *keyValStr)
{
- return (G_set_key_value(key, *keyValStr, keys) != 0);
+ G_set_key_value(key, *keyValStr, keys);
+ return 1;
}
/*---------------------------------------------------------------------------*/
@@ -122,11 +125,16 @@
const char *val2, int keyval1, int keyval2,
const int *keyvalVar)
{
- if (*keyvalVar == keyval1)
- return (G_set_key_value(key, val1, keys) != 0);
- if (*keyvalVar == keyval2)
- return (G_set_key_value(key, val2, keys) != 0);
+ if (*keyvalVar == keyval1) {
+ G_set_key_value(key, val1, keys);
+ return 1;
+ }
+ if (*keyvalVar == keyval2) {
+ G_set_key_value(key, val2, keys);
+ return 1;
+ }
+
G3d_error("G3d_keySetValue: wrong key value");
return 0;
}
Modified: grass/trunk/lib/g3d/g3dwindowio.c
===================================================================
--- grass/trunk/lib/g3d/g3dwindowio.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/g3d/g3dwindowio.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -141,7 +141,6 @@
struct Cell_head win;
struct Key_Value *windowKeys;
char path[GPATH_MAX];
- int status;
if (windowName == NULL) {
@@ -170,11 +169,7 @@
return 0;
}
- windowKeys = G_read_key_value_file(path, &status);
- if (status != 0) {
- G3d_error("G3d_readWindow: Unable to open %s", path);
- return 0;
- }
+ windowKeys = G_read_key_value_file(path);
if (!G3d_readWriteWindow(windowKeys, 1,
&(window->proj), &(window->zone),
Modified: grass/trunk/lib/g3d/header.c
===================================================================
--- grass/trunk/lib/g3d/header.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/g3d/header.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -119,7 +119,6 @@
{
struct Key_Value *headerKeys;
char path[GPATH_MAX];
- int status;
G3d_filename(path, G3D_HEADER_ELEMENT, map->fileName, map->mapset);
if (access(path, R_OK) != 0) {
@@ -127,11 +126,7 @@
return 0;
}
- headerKeys = G_read_key_value_file(path, &status);
- if (status != 0) {
- G3d_error("G3d_readHeader: Unable to open %s", path);
- return 0;
- }
+ headerKeys = G_read_key_value_file(path);
if (!G3d_readWriteHeader(headerKeys, 1,
proj, zone,
@@ -162,7 +157,6 @@
{
struct Key_Value *headerKeys;
char path[GPATH_MAX];
- int status;
headerKeys = G_create_key_value();
@@ -182,15 +176,11 @@
G3d_filename(path, G3D_HEADER_ELEMENT, map->fileName, map->mapset);
G3d_makeMapsetMapDirectory(map->fileName);
- G_write_key_value_file(path, headerKeys, &status);
+ G_write_key_value_file(path, headerKeys);
G_free_key_value(headerKeys);
- if (status == 0)
- return 1;
-
- G3d_error("G3d_writeHeader: error writing header file %s", path);
- return 0;
+ return 1;
}
/*---------------------------------------------------------------------------*/
Modified: grass/trunk/lib/gis/get_ellipse.c
===================================================================
--- grass/trunk/lib/gis/get_ellipse.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/gis/get_ellipse.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -66,7 +66,7 @@
*/
int G_get_ellipsoid_parameters(double *a, double *e2)
{
- int in_stat, stat;
+ int stat;
char ipath[GPATH_MAX];
struct Key_Value *proj_keys;
@@ -80,13 +80,8 @@
return 0;
}
- proj_keys = G_read_key_value_file(ipath, &in_stat);
+ proj_keys = G_read_key_value_file(ipath);
- if (in_stat != 0) {
- G_fatal_error(_("Unable to open file %s in <%s>"),
- PROJECTION_FILE, PERMANENT);
- }
-
stat = get_ellipsoid_parameters(proj_keys, a, e2);
G_free_key_value(proj_keys);
Modified: grass/trunk/lib/gis/get_projinfo.c
===================================================================
--- grass/trunk/lib/gis/get_projinfo.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/gis/get_projinfo.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -24,7 +24,6 @@
*/
struct Key_Value *G_get_projunits(void)
{
- int stat;
struct Key_Value *in_units_keys;
char path[GPATH_MAX];
@@ -36,12 +35,7 @@
}
return NULL;
}
- in_units_keys = G_read_key_value_file(path, &stat);
- if (stat != 0) {
- G_warning(_("ERROR in reading <%s> file for location <%s>"),
- UNIT_FILE, G_location());
- return NULL;
- }
+ in_units_keys = G_read_key_value_file(path);
return in_units_keys;
}
@@ -53,7 +47,6 @@
*/
struct Key_Value *G_get_projinfo(void)
{
- int stat;
struct Key_Value *in_proj_keys;
char path[GPATH_MAX];
@@ -65,11 +58,7 @@
}
return NULL;
}
- in_proj_keys = G_read_key_value_file(path, &stat);
- if (stat != 0) {
- G_warning(_("ERROR in reading <%s> file for location <%s>"),
- PROJECTION_FILE, G_location());
- return NULL;
- }
+ in_proj_keys = G_read_key_value_file(path);
+
return in_proj_keys;
}
Modified: grass/trunk/lib/gis/key_value1.c
===================================================================
--- grass/trunk/lib/gis/key_value1.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/gis/key_value1.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -24,16 +24,12 @@
*/
struct Key_Value *G_create_key_value(void)
{
- struct Key_Value *kv;
+ struct Key_Value *kv = G_malloc(sizeof(struct Key_Value));
- kv = (struct Key_Value *)G_malloc(sizeof(struct Key_Value));
- if (kv == NULL)
- return NULL;
-
kv->nitems = 0;
kv->nalloc = 0;
- kv->key = (char **)NULL;
- kv->value = (char **)NULL;
+ kv->key = NULL;
+ kv->value = NULL;
return kv;
}
@@ -41,24 +37,17 @@
/*!
\brief Set value for given key
- If key has spaces in it, this will break the logic
- so rule is: NO SPACES IN key.
-
\param[in] key key to be set up
\param[in] value value for given key
\param[in,out] kv Key_value structure to be modified
-
- \return 0 no memory
- \return 1 ok, but key was NULL or "" so ignored
- \return 2 ok
*/
-int G_set_key_value(const char *key, const char *value, struct Key_Value *kv)
+
+void G_set_key_value(const char *key, const char *value, struct Key_Value *kv)
{
int n;
- int size;
- if (key == NULL || key == 0)
- return 1;
+ if (!key)
+ return;
for (n = 0; n < kv->nitems; n++)
if (strcmp(key, kv->key[n]) == 0)
@@ -66,54 +55,28 @@
if (n == kv->nitems) {
if (n >= kv->nalloc) {
- if (kv->nalloc <= 0) {
+ size_t size;
+
+ if (kv->nalloc <= 0)
kv->nalloc = 8;
- size = kv->nalloc * sizeof(char *);
- kv->key = (char **)G_malloc(size);
- kv->value = (char **)G_malloc(size);
- }
- else {
+ else
kv->nalloc *= 2;
- size = kv->nalloc * sizeof(char *);
- kv->key = (char **)G_realloc(kv->key, size);
- kv->value = (char **)G_realloc(kv->value, size);
- }
- if (kv->key == NULL || kv->value == NULL) {
- if (kv->key) {
- G_free(kv->key);
- kv->key = NULL;
- }
- if (kv->value) {
- G_free(kv->value);
- kv->value = NULL;
- }
- kv->nitems = kv->nalloc = 0;
- return 0;
- }
+ size = kv->nalloc * sizeof(char *);
+ kv->key = G_realloc(kv->key, size);
+ kv->value = G_realloc(kv->value, size);
}
- kv->value[n] = NULL;
- kv->key[n] = G_malloc(strlen(key) + 1);
- if (kv->key[n] == NULL)
- return 0;
- strcpy(kv->key[n], key);
+
+ kv->key[n] = G_store(key);
+ kv->value[n] = G_store(value);
kv->nitems++;
+ return;
}
- if (value == NULL)
- size = 0;
- else
- size = strlen(value);
- if (kv->value[n] != NULL)
+
+ if (kv->value[n])
G_free(kv->value[n]);
- if (size > 0) {
- kv->value[n] = G_malloc(size + 1);
- if (kv->value[n] == NULL)
- return 0;
- strcpy(kv->value[n], value);
- }
- else
- kv->value[n] = NULL;
- return 2;
+
+ kv->value[n] = value ? G_store(value) : NULL;
}
/*!
Modified: grass/trunk/lib/gis/key_value2.c
===================================================================
--- grass/trunk/lib/gis/key_value2.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/gis/key_value2.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -66,10 +66,7 @@
*value++ = 0;
G_strip(key);
G_strip(value);
- if (!G_set_key_value(key, value, kv)) {
- G_free_key_value(kv);
- return NULL;
- }
+ G_set_key_value(key, value, kv);
}
return kv;
}
Modified: grass/trunk/lib/gis/key_value3.c
===================================================================
--- grass/trunk/lib/gis/key_value3.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/gis/key_value3.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -14,30 +14,30 @@
*/
#include <grass/gis.h>
+#include <grass/glocale.h>
/*!
\brief Write key/value pairs to file
\param[in] file filename for writing
\param[in] kv Key_Value structure
- \param[out] stat status (0 ok, -3 cannot open file, -4 error writing key/value)
\return 0 success
\return 1 error writing
*/
-int G_write_key_value_file(const char *file,
- const struct Key_Value *kv, int *stat)
+void G_write_key_value_file(const char *file,
+ const struct Key_Value *kv)
{
- FILE *fd;
+ FILE *fp = fopen(file, "w");
+ if (!fp)
+ G_fatal_error(_("Unable to open output file <%s>"), file);
- *stat = 0;
- fd = fopen(file, "w");
- if (fd == NULL)
- *stat = -3;
- else if (G_fwrite_key_value(fd, kv) != 0 || fclose(fd) == EOF)
- *stat = -4;
- return (*stat != 0);
+ if (G_fwrite_key_value(fp, kv) != 0)
+ G_fatal_error(_("Error writing file <%s>"), file);
+
+ if (fclose(fp) != 0)
+ G_fatal_error(_("Error closing output file <%s>"), file);
}
/*!
@@ -51,20 +51,21 @@
\return poiter to allocated Key_Value structure
\return NULL on error
*/
-struct Key_Value *G_read_key_value_file(const char *file, int *stat)
+struct Key_Value *G_read_key_value_file(const char *file)
{
- FILE *fd;
+ FILE *fp;
struct Key_Value *kv;
- *stat = 0;
- fd = fopen(file, "r");
- if (fd == NULL) {
- *stat = -1;
- return NULL;
- }
- kv = G_fread_key_value(fd);
- fclose(fd);
- if (kv == NULL)
- *stat = -2;
+ fp = fopen(file, "r");
+ if (!fp)
+ G_fatal_error(_("Unable to open input file <%s>"), file);
+
+ kv = G_fread_key_value(fp);
+ if (!kv)
+ G_fatal_error(_("Error reading file <%s>"), file);
+
+ if (fclose(fp) != 0)
+ G_fatal_error(_("Error closing input file <%s>"), file);
+
return kv;
}
Modified: grass/trunk/lib/gis/key_value4.c
===================================================================
--- grass/trunk/lib/gis/key_value4.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/gis/key_value4.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -22,31 +22,16 @@
\param[in] file filename to be updated
\param[in] key key value
\param[in] value value to be updated
-
- \return -1 can't open file for reading
- \return -2 no memory for key,value info, file not modified
- \return -3 can't open file for re-write
- \return -4 error writing the file (might be damaged)
*/
-int G_update_key_value_file(const char *file, const char *key,
- const char *value)
+void G_update_key_value_file(const char *file,
+ const char *key, const char *value)
{
struct Key_Value *kv;
- int stat;
- kv = G_read_key_value_file(file, &stat);
- if (stat != 0)
- return stat;
-
- if (!G_set_key_value(key, value, kv)) {
- G_free_key_value(kv);
- return -2;
- }
-
- G_write_key_value_file(file, kv, &stat);
+ kv = G_read_key_value_file(file);
+ G_set_key_value(key, value, kv);
+ G_write_key_value_file(file, kv);
G_free_key_value(kv);
-
- return stat;
}
/*!
@@ -57,7 +42,6 @@
\param[out] value value for key
\param[in] n number of characters to be copied
- \return <0 are file/memory errors
\return 0 not found
\return 1 ok
*/
@@ -65,22 +49,19 @@
const char *key, char value[], int n)
{
struct Key_Value *kv;
- int stat;
const char *v;
- *value = 0;
- kv = G_read_key_value_file(file, &stat);
- if (stat != 0)
- return stat;
+ *value = '\0';
+ kv = G_read_key_value_file(file);
v = G_find_key_value(key, kv);
+
if (v) {
strncpy(value, v, n);
- value[n - 1] = 0;
- stat = 1;
+ value[n - 1] = '\0';
}
- else
- stat = 0;
+
G_free_key_value(kv);
- return stat;
+
+ return v ? 1 : 0;
}
Modified: grass/trunk/lib/gis/make_loc.c
===================================================================
--- grass/trunk/lib/gis/make_loc.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/gis/make_loc.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -47,7 +47,6 @@
struct Key_Value *proj_units, FILE * report_file)
{
char path[GPATH_MAX];
- int out_stat;
/* Try to create the location directory, under the gisdbase. */
sprintf(path, "%s/%s", G_gisdbase(), location_name);
@@ -70,16 +69,12 @@
/* Write out the PROJ_INFO, and PROJ_UNITS if available. */
if (proj_info != NULL) {
G__file_name(path, "", "PROJ_INFO", "PERMANENT");
- G_write_key_value_file(path, proj_info, &out_stat);
- if (out_stat != 0)
- return -2;
+ G_write_key_value_file(path, proj_info);
}
if (proj_units != NULL) {
G__file_name(path, "", "PROJ_UNITS", "PERMANENT");
- G_write_key_value_file(path, proj_units, &out_stat);
- if (out_stat != 0)
- return -2;
+ G_write_key_value_file(path, proj_units);
}
return 0;
Modified: grass/trunk/lib/raster/closecell.c
===================================================================
--- grass/trunk/lib/raster/closecell.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/raster/closecell.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -36,7 +36,7 @@
static int close_old(int);
static int close_new(int, int);
-static int write_fp_format(int fd);
+static void write_fp_format(int fd);
/*!
* \brief Close a raster map
@@ -287,11 +287,7 @@
close(cell_fd);
if (fcb->map_type != CELL_TYPE) { /* floating point map */
- if (write_fp_format(fd) != 0) {
- G_warning(_("Error writing floating point format file for map %s"),
- fcb->name);
- stat = -1;
- }
+ write_fp_format(fd);
/* write 0-length fcell file */
G__make_mapset_element("fcell");
@@ -399,11 +395,7 @@
if (fcb->map_type != CELL_TYPE) { /* floating point map */
int cell_fd;
- if (write_fp_format(fd) != 0) {
- G_warning(_("Error writing floating point format file for map <%s>"),
- fcb->name);
- stat = -1;
- }
+ write_fp_format(fd);
/* now write 0-length cell file */
G__make_mapset_element("cell");
@@ -476,16 +468,15 @@
}
/* returns 0 on success, 1 on failure */
-static int write_fp_format(int fd)
+static void write_fp_format(int fd)
{
struct fileinfo *fcb = &R__.fileinfo[fd];
struct Key_Value *format_kv;
char path[GPATH_MAX];
- int stat;
if (fcb->map_type == CELL_TYPE) {
G_warning(_("unable to write f_format file for CELL maps"));
- return 0;
+ return;
}
format_kv = G_create_key_value();
if (fcb->map_type == FCELL_TYPE)
@@ -500,9 +491,7 @@
G__make_mapset_element_misc("cell_misc", fcb->name);
G__file_name_misc(path, "cell_misc", FORMAT_FILE, fcb->name, fcb->mapset);
- G_write_key_value_file(path, format_kv, &stat);
+ G_write_key_value_file(path, format_kv);
G_free_key_value(format_kv);
-
- return stat;
}
Modified: grass/trunk/lib/raster/opencell.c
===================================================================
--- grass/trunk/lib/raster/opencell.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/lib/raster/opencell.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -823,7 +823,6 @@
{
char path[GPATH_MAX];
struct Key_Value *format_keys;
- int in_stat;
const char *str, *str1;
RASTER_MAP_TYPE map_type;
const char *xmapset;
@@ -838,9 +837,7 @@
if (access(path, 0) != 0)
G_fatal_error(_("Unable to find '%s'"), path);
- format_keys = G_read_key_value_file(path, &in_stat);
- if (in_stat != 0)
- G_fatal_error(_("Unable to open '%s'"), path);
+ format_keys = G_read_key_value_file(path);
if ((str = G_find_key_value("type", format_keys)) != NULL) {
if (strcmp(str, "double") == 0)
Modified: grass/trunk/raster/r.colors/main.c
===================================================================
--- grass/trunk/raster/r.colors/main.c 2010-01-27 17:05:25 UTC (rev 40700)
+++ grass/trunk/raster/r.colors/main.c 2010-01-27 17:10:07 UTC (rev 40701)
@@ -81,12 +81,11 @@
int result_len = 0;
int result_max = 2000;
char *result = G_malloc(result_max);
- int stat;
int i;
sprintf(path, "%s/etc/colors.desc", G_gisbase());
- kv = G_read_key_value_file(path, &stat);
- if (!kv || stat < 0)
+ kv = G_read_key_value_file(path);
+ if (!kv)
return NULL;
for (i = 0; i < nrules; i++) {
More information about the grass-commit
mailing list