[GRASS-SVN] r34462 - in grass/trunk: include lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Nov 23 22:41:31 EST 2008
Author: glynn
Date: 2008-11-23 22:41:31 -0500 (Sun, 23 Nov 2008)
New Revision: 34462
Modified:
grass/trunk/include/gisdefs.h
grass/trunk/lib/gis/G.h
grass/trunk/lib/gis/debug.c
grass/trunk/lib/gis/gisinit.c
grass/trunk/lib/gis/opencell.c
grass/trunk/lib/gis/progrm_nme.c
grass/trunk/lib/gis/whoami.c
Log:
Remove unnecessary static variables from opencell.c
Move remaining static variables from opencell.c to fields of G__
Remove unnecessary return values
Miscellaneous clean-up
Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h 2008-11-23 23:25:53 UTC (rev 34461)
+++ grass/trunk/include/gisdefs.h 2008-11-24 03:41:31 UTC (rev 34462)
@@ -833,8 +833,8 @@
int G__open_cell_old(const char *, const char *);
int G_open_cell_new(const char *);
int G_open_cell_new_uncompressed(const char *);
-int G_want_histogram(int);
-int G_set_cell_format(int);
+void G_want_histogram(int);
+void G_set_cell_format(int);
int G_cellvalue_format(CELL);
int G_open_fp_cell_new(const char *);
int G_open_fp_cell_new_uncompressed(const char *);
@@ -896,7 +896,7 @@
/* progrm_nme.c */
const char *G_program_name(void);
-int G_set_program_name(const char *);
+void G_set_program_name(const char *);
/* proj1.c */
int G_projection(void);
Modified: grass/trunk/lib/gis/G.h
===================================================================
--- grass/trunk/lib/gis/G.h 2008-11-23 23:25:53 UTC (rev 34461)
+++ grass/trunk/lib/gis/G.h 2008-11-24 03:41:31 UTC (rev 34462)
@@ -72,13 +72,14 @@
struct G__ /* Structure of library globals */
{
- int fp_nbytes; /* size of cell in floating maps */
RASTER_MAP_TYPE fp_type; /* type for writing floating maps */
struct Cell_head window; /* Contains the current window */
int window_set; /* Flag: window set? */
int mask_fd; /* File descriptor for automatic mask */
int auto_mask; /* Flag denoting automatic masking */
int want_histogram;
+ int nbytes;
+ int compression_type;
int fileinfo_count;
struct fileinfo *fileinfo;
Modified: grass/trunk/lib/gis/debug.c
===================================================================
--- grass/trunk/lib/gis/debug.c 2008-11-23 23:25:53 UTC (rev 34461)
+++ grass/trunk/lib/gis/debug.c 2008-11-24 03:41:31 UTC (rev 34462)
@@ -45,7 +45,6 @@
int G_debug(int level, const char *msg, ...)
{
-#ifdef GDEBUG
char *lstr, *filen;
va_list ap;
FILE *fd;
@@ -84,7 +83,6 @@
va_end(ap);
}
-#endif
return 1;
}
@@ -105,7 +103,6 @@
const struct fileinfo *fcb = &G__.fileinfo[fd];
G_message("G_dump: memory allocated to G__");
- G_message("Size of cell in fp maps = %d", G__.fp_nbytes);
G_message("type for writing floating maps = %d", G__.fp_type);
G_message("current window = %p", &G__.window);
G_message("Flag: window set? %d", G__.window_set);
Modified: grass/trunk/lib/gis/gisinit.c
===================================================================
--- grass/trunk/lib/gis/gisinit.c 2008-11-23 23:25:53 UTC (rev 34461)
+++ grass/trunk/lib/gis/gisinit.c 2008-11-24 03:41:31 UTC (rev 34462)
@@ -120,12 +120,14 @@
G__.want_histogram = 0;
/* set the write type for floating maps */
- G__.fp_type = FCELL_TYPE;
- G__.fp_nbytes = XDR_FLOAT_NBYTES;
+ G__.fp_type = -1;
/* Set masking flag unknown */
G__.auto_mask = -1;
+ G__.nbytes = sizeof(CELL);
+ G__.compression_type = 0;
+
initialized = 1;
setlocale(LC_NUMERIC, "C");
Modified: grass/trunk/lib/gis/opencell.c
===================================================================
--- grass/trunk/lib/gis/opencell.c 2008-11-23 23:25:53 UTC (rev 34461)
+++ grass/trunk/lib/gis/opencell.c 2008-11-24 03:41:31 UTC (rev 34462)
@@ -67,7 +67,8 @@
* \return int
*/
-static int G__open_raster_new(const char *name, int open_mode);
+static int G__open_raster_new(const char *name, int open_mode,
+ RASTER_MAP_TYPE map_type);
/*!
\brief Open an existing integer raster map (cell)
@@ -148,7 +149,7 @@
{
struct fileinfo *fcb;
int fd;
- char cell_dir[100];
+ char *cell_dir;
const char *r_name;
const char *r_mapset;
struct Cell_head cellhd;
@@ -237,18 +238,18 @@
/* record number of bytes per cell */
if (MAP_TYPE == FCELL_TYPE) {
- strcpy(cell_dir, "fcell");
+ cell_dir = "fcell";
INTERN_SIZE = sizeof(FCELL);
MAP_NBYTES = XDR_FLOAT_NBYTES;
}
else if (MAP_TYPE == DCELL_TYPE) {
- strcpy(cell_dir, "fcell");
+ cell_dir = "fcell";
INTERN_SIZE = sizeof(DCELL);
MAP_NBYTES = XDR_DOUBLE_NBYTES;
}
else { /* integer */
- strcpy(cell_dir, "cell");
+ cell_dir = "cell";
INTERN_SIZE = sizeof(CELL);
MAP_NBYTES = CELL_nbytes;
}
@@ -345,29 +346,6 @@
/*****************************************************************/
-static int WRITE_NBYTES = sizeof(CELL);
-
-/* bytes per cell for current map */
-
-static int NBYTES = sizeof(CELL);
-
-/* bytes per cell for writing integer maps */
-
-static RASTER_MAP_TYPE WRITE_MAP_TYPE = CELL_TYPE;
-
-/* a type of current map */
-
-static int COMPRESSION_TYPE = 0;
-
-#define FP_NBYTES G__.fp_nbytes
-/* bytes per cell for writing floating point maps */
-#define FP_TYPE G__.fp_type
-/* a type of floating maps to be open */
-static int FP_TYPE_SET = 0; /* wether or not the f.p. type was set explicitly
- by calling G_set_fp_type() */
-
-static char cell_dir[100];
-
/*!
\brief Opens a new cell file in a database (compressed)
@@ -397,11 +375,7 @@
*/
int G_open_cell_new(const char *name)
{
- WRITE_MAP_TYPE = CELL_TYPE;
- strcpy(cell_dir, "cell");
- /* bytes per cell for current map */
- WRITE_NBYTES = NBYTES;
- return G__open_raster_new(name, OPEN_NEW_COMPRESSED);
+ return G__open_raster_new(name, OPEN_NEW_COMPRESSED, CELL_TYPE);
}
/*!
@@ -416,11 +390,7 @@
*/
int G_open_cell_new_uncompressed(const char *name)
{
- WRITE_MAP_TYPE = CELL_TYPE; /* a type of current map */
- strcpy(cell_dir, "cell");
- /* bytes per cell for current map */
- WRITE_NBYTES = NBYTES;
- return G__open_raster_new(name, OPEN_NEW_UNCOMPRESSED);
+ return G__open_raster_new(name, OPEN_NEW_UNCOMPRESSED, CELL_TYPE);
}
/*!
@@ -433,11 +403,9 @@
\return 0
*/
-int G_want_histogram(int flag)
+void G_want_histogram(int flag)
{
G__.want_histogram = flag;
-
- return 0;
}
/*!
@@ -454,18 +422,14 @@
\return 0
*/
-int G_set_cell_format(int n)
+void G_set_cell_format(int n)
/* sets the format for integer raster map */
{
- if (WRITE_MAP_TYPE == CELL_TYPE) {
- NBYTES = n + 1;
- if (NBYTES <= 0)
- NBYTES = 1;
- if ((unsigned int) NBYTES > sizeof(CELL))
- NBYTES = sizeof(CELL);
- }
-
- return 0;
+ G__.nbytes = n + 1;
+ if (G__.nbytes <= 0)
+ G__.nbytes = 1;
+ if (G__.nbytes > sizeof(CELL))
+ G__.nbytes = sizeof(CELL);
}
/*!
@@ -486,6 +450,16 @@
return sizeof(CELL) - 1;
}
+static int get_fp_type(void)
+{
+ if (G__.fp_type <= 0)
+ G__.fp_type = getenv("GRASS_FP_DOUBLE")
+ ? DCELL_TYPE
+ : FCELL_TYPE;
+
+ return G__.fp_type;
+}
+
/*!
\brief Opens new fcell file in a database
@@ -505,24 +479,7 @@
*/
int G_open_fp_cell_new(const char *name)
{
- /* use current float. type for writing float point maps */
- /* if the FP type was NOT explicitly set by G_set_fp_type()
- use environment variable */
- if (!FP_TYPE_SET) {
- if (getenv("GRASS_FP_DOUBLE")) {
- FP_TYPE = DCELL_TYPE;
- FP_NBYTES = XDR_DOUBLE_NBYTES;
- }
- else {
- FP_TYPE = FCELL_TYPE;
- FP_NBYTES = XDR_FLOAT_NBYTES;
- }
- }
- WRITE_MAP_TYPE = FP_TYPE;
- WRITE_NBYTES = FP_NBYTES;
-
- strcpy(cell_dir, "fcell");
- return G__open_raster_new(name, OPEN_NEW_COMPRESSED);
+ return G__open_raster_new(name, OPEN_NEW_COMPRESSED, get_fp_type());
}
/*!
@@ -537,26 +494,11 @@
*/
int G_open_fp_cell_new_uncompressed(const char *name)
{
- /* use current float. type for writing float point maps */
- if (!FP_TYPE_SET) {
- if (getenv("GRASS_FP_DOUBLE")) {
- FP_TYPE = DCELL_TYPE;
- FP_NBYTES = XDR_DOUBLE_NBYTES;
- }
- else {
- FP_TYPE = FCELL_TYPE;
- FP_NBYTES = XDR_FLOAT_NBYTES;
- }
- }
- WRITE_MAP_TYPE = FP_TYPE;
- WRITE_NBYTES = FP_NBYTES;
-
- strcpy(cell_dir, "fcell");
- return G__open_raster_new(name, OPEN_NEW_UNCOMPRESSED);
+ return G__open_raster_new(name, OPEN_NEW_UNCOMPRESSED, get_fp_type());
}
-/* opens a f-cell or cell file depending on WRITE_MAP_TYPE */
-static int G__open_raster_new(const char *name, int open_mode)
+static int G__open_raster_new(const char *name, int open_mode,
+ RASTER_MAP_TYPE map_type)
{
char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
struct fileinfo *fcb;
@@ -564,7 +506,27 @@
char *tempname;
char *map;
char *mapset;
+ const char *cell_dir;
+ int nbytes;
+ switch (map_type) {
+ case CELL_TYPE:
+ cell_dir = "cell";
+ nbytes = G__.nbytes;
+ break;
+ case FCELL_TYPE:
+ nbytes = XDR_FLOAT_NBYTES;
+ cell_dir = "fcell";
+ break;
+ case DCELL_TYPE:
+ nbytes = XDR_DOUBLE_NBYTES;
+ cell_dir = "fcell";
+ break;
+ default:
+ G_fatal_error(_("Invalid map type <%d>"), map_type);
+ break;
+ }
+
if (G__unqualified_name(name, G_mapset(), xname, xmapset) < 0)
G_fatal_error(_("Raster map <%s> is not in the current mapset (%s)"),
name, G_mapset());
@@ -599,7 +561,7 @@
G__make_mapset_element(cell_dir);
/* mark closed */
- fcb->map_type = WRITE_MAP_TYPE;
+ fcb->map_type = map_type;
fcb->open_mode = -1;
/* for writing fcb->data is allocated to be G__.window.cols *
@@ -607,8 +569,8 @@
fcb->data = (unsigned char *)G_calloc(G__.window.cols,
G_raster_size(fcb->map_type));
- if (open_mode == OPEN_NEW_COMPRESSED && !COMPRESSION_TYPE)
- COMPRESSION_TYPE = getenv("GRASS_INT_ZLIB") ? 2 : 1;
+ if (open_mode == OPEN_NEW_COMPRESSED && !G__.compression_type)
+ G__.compression_type = getenv("GRASS_INT_ZLIB") ? 2 : 1;
/*
* copy current window into cell header
@@ -622,17 +584,17 @@
fcb->row_ptr = G_calloc(fcb->cellhd.rows + 1, sizeof(off_t));
G_zero(fcb->row_ptr, (fcb->cellhd.rows + 1) * sizeof(off_t));
G__write_row_ptrs(fd);
- fcb->cellhd.compressed = COMPRESSION_TYPE;
+ fcb->cellhd.compressed = G__.compression_type;
fcb->nbytes = 1; /* to the minimum */
}
else {
- fcb->nbytes = WRITE_NBYTES;
+ fcb->nbytes = nbytes;
if (open_mode == OPEN_NEW_COMPRESSED) {
fcb->row_ptr = G_calloc(fcb->cellhd.rows + 1, sizeof(off_t));
G_zero(fcb->row_ptr, (fcb->cellhd.rows + 1) * sizeof(off_t));
G__write_row_ptrs(fd);
- fcb->cellhd.compressed = COMPRESSION_TYPE;
+ fcb->cellhd.compressed = G__.compression_type;
}
else
fcb->cellhd.compressed = 0;
@@ -709,18 +671,15 @@
*/
int G_set_fp_type(RASTER_MAP_TYPE map_type)
{
- FP_TYPE_SET = 1;
- if (map_type != FCELL_TYPE && map_type != DCELL_TYPE) {
+ switch (map_type) {
+ case FCELL_TYPE:
+ case DCELL_TYPE:
+ G__.fp_type = map_type;
+ return 1;
+ default:
G_warning(_("G_set_fp_type(): can only be called with FCELL_TYPE or DCELL_TYPE"));
return -1;
}
- FP_TYPE = map_type;
- if (map_type == DCELL_TYPE)
- FP_NBYTES = XDR_DOUBLE_NBYTES;
- else
- FP_NBYTES = XDR_FLOAT_NBYTES;
-
- return 1;
}
@@ -899,11 +858,7 @@
*/
int G_open_raster_new(const char *name, RASTER_MAP_TYPE wr_type)
{
- if (wr_type == CELL_TYPE)
- return G_open_cell_new(name);
-
- G_set_fp_type(wr_type);
- return G_open_fp_cell_new(name);
+ return G__open_raster_new(name, OPEN_NEW_COMPRESSED, wr_type);
}
/*!
@@ -919,11 +874,7 @@
*/
int G_open_raster_new_uncompressed(const char *name, RASTER_MAP_TYPE wr_type)
{
- if (wr_type == CELL_TYPE)
- return G_open_cell_new_uncompressed(name);
-
- G_set_fp_type(wr_type);
- return G_open_fp_cell_new_uncompressed(name);
+ return G__open_raster_new(name, OPEN_NEW_UNCOMPRESSED, wr_type);
}
/*!
Modified: grass/trunk/lib/gis/progrm_nme.c
===================================================================
--- grass/trunk/lib/gis/progrm_nme.c 2008-11-23 23:25:53 UTC (rev 34461)
+++ grass/trunk/lib/gis/progrm_nme.c 2008-11-24 03:41:31 UTC (rev 34462)
@@ -35,7 +35,7 @@
return name;
}
-int G_set_program_name(const char *s)
+void G_set_program_name(const char *s)
{
int i;
char *temp;
@@ -51,6 +51,4 @@
G_basename(temp, "exe");
name = G_store(temp);
G_free(temp);
-
- return 0;
}
Modified: grass/trunk/lib/gis/whoami.c
===================================================================
--- grass/trunk/lib/gis/whoami.c 2008-11-23 23:25:53 UTC (rev 34461)
+++ grass/trunk/lib/gis/whoami.c 2008-11-24 03:41:31 UTC (rev 34462)
@@ -39,41 +39,30 @@
char *G_whoami(void)
{
-#ifdef __MINGW32__
- char *name = getenv("USERNAME");
+ static char *name;
- if (name == NULL) {
- name = "user_name";
- }
-#else
- static char *name = NULL;
+ if (name)
+ return name;
-#ifdef COMMENTED_OUT
- char *getlogin();
- char *ttyname();
+#ifdef __MINGW32__
+ name = getenv("USERNAME");
+#endif
+ if (!name || !*name)
+ name = getenv("LOGNAME");
- if (name == NULL) {
- char *x;
+ if (!name || !*name)
+ name = getenv("USER");
- x = ttyname(0);
- if (x && *x) {
- x = getlogin();
- if (x && *x)
- name = G_store(x);
- }
- }
-#endif /* COMMENTED_OUT */
-
- if (name == NULL) {
- struct passwd *p;
-
- if ((p = getpwuid(getuid())))
+#ifndef __MINGW32__
+ if (!name || !*name) {
+ struct passwd *p = getpwuid(getuid());
+ if (p && p->pw_name && *p->pw_name)
name = G_store(p->pw_name);
}
- if (name == NULL)
- name = G_store("?");
-
#endif
+ if (!name || !*name)
+ name = "anonymous";
+
return name;
}
More information about the grass-commit
mailing list