[GRASS-SVN] r34483 - in grass/trunk: include lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 24 20:05:48 EST 2008
Author: glynn
Date: 2008-11-24 20:05:48 -0500 (Mon, 24 Nov 2008)
New Revision: 34483
Modified:
grass/trunk/include/gisdefs.h
grass/trunk/lib/gis/debug.c
grass/trunk/lib/gis/error.c
grass/trunk/lib/gis/opencell.c
Log:
Add various functions to force initialisation:
G_init_debug, G_init_logging, G_get_fp_type, G_get_compression_type
Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h 2008-11-24 23:58:48 UTC (rev 34482)
+++ grass/trunk/include/gisdefs.h 2008-11-25 01:05:48 UTC (rev 34483)
@@ -406,6 +406,7 @@
/* debug.c */
+void G_init_debug(void);
int G_debug(int, const char *, ...) __attribute__ ((format(printf, 2, 3)));
/* distance.c */
@@ -460,6 +461,7 @@
int G_sleep_on_error(int);
int G_set_error_routine(int (*)(const char *, int));
int G_unset_error_routine(void);
+void G_init_logging(void);
/* file_name.c */
char *G__file_name(char *, const char *, const char *, const char *);
@@ -837,6 +839,8 @@
void G_want_histogram(int);
void G_set_cell_format(int);
int G_cellvalue_format(CELL);
+int G_get_fp_type(void);
+int G_get_compression_type(void);
int G_open_fp_cell_new(const char *);
int G_open_fp_cell_new_uncompressed(const char *);
int G_set_fp_type(RASTER_MAP_TYPE);
Modified: grass/trunk/lib/gis/debug.c
===================================================================
--- grass/trunk/lib/gis/debug.c 2008-11-24 23:58:48 UTC (rev 34482)
+++ grass/trunk/lib/gis/debug.c 2008-11-25 01:05:48 UTC (rev 34483)
@@ -43,21 +43,29 @@
* \return 1 on success
*/
+void G_init_debug(void)
+{
+ const char *lstr;
+
+ if (grass_debug_level >= 0)
+ return;
+
+ lstr = G__getenv("DEBUG");
+
+ if (lstr != NULL)
+ grass_debug_level = atoi(lstr);
+ else
+ grass_debug_level = 0;
+}
+
int G_debug(int level, const char *msg, ...)
{
- char *lstr, *filen;
+ char *filen;
va_list ap;
FILE *fd;
- if (grass_debug_level < 0) {
- lstr = G__getenv("DEBUG");
+ G_init_debug();
- if (lstr != NULL)
- grass_debug_level = atoi(lstr);
- else
- grass_debug_level = 0;
- }
-
if (grass_debug_level >= level) {
va_start(ap, msg);
Modified: grass/trunk/lib/gis/error.c
===================================================================
--- grass/trunk/lib/gis/error.c 2008-11-24 23:58:48 UTC (rev 34482)
+++ grass/trunk/lib/gis/error.c 2008-11-25 01:05:48 UTC (rev 34483)
@@ -45,6 +45,11 @@
static int (*ext_error) (const char *, int); /* Roger Bivand 17 June 2000 */
static int no_warn = 0;
static int no_sleep = 1;
+
+static int grass_info_format = -1;
+static char *logfile;
+static char *prefix_std[3];
+
static int message_id = 1;
static int print_word(FILE *, char **, int *, const int);
@@ -249,15 +254,8 @@
/* Print info to stderr and optionally to log file and optionally send mail */
static int print_error(const char *msg, const int type)
{
- static char *prefix_std[3];
int fatal, format;
- if (!prefix_std[0]) { /* First time: set prefixes */
- prefix_std[0] = "";
- prefix_std[1] = _("WARNING: ");
- prefix_std[2] = _("ERROR: ");
- }
-
if (type == ERR)
fatal = TRUE;
else /* WARN */
@@ -270,6 +268,7 @@
char *w;
int len, lead;
+ G_init_logging();
format = G_info_format();
if (format != G_INFO_FORMAT_GUI) {
@@ -321,23 +320,47 @@
return 0;
}
+void G_init_logging(void)
+{
+ static int initialized;
+ char *fstr;
+
+ if (initialized)
+ return;
+
+ prefix_std[0] = "";
+ prefix_std[1] = _("WARNING: ");
+ prefix_std[2] = _("ERROR: ");
+
+ logfile = getenv("GIS_ERROR_LOG");
+ if (!logfile) {
+ char buf[GPATH_MAX];
+ sprintf(buf, "%s/GIS_ERROR_LOG", G__home());
+ logfile = G_store(buf);
+ }
+
+ fstr = getenv("GRASS_MESSAGE_FORMAT");
+
+ if (fstr && G_strcasecmp(fstr, "gui") == 0)
+ grass_info_format = G_INFO_FORMAT_GUI;
+ else if (fstr && G_strcasecmp(fstr, "silent") == 0)
+ grass_info_format = G_INFO_FORMAT_SILENT;
+ else if (fstr && G_strcasecmp(fstr, "plain") == 0)
+ grass_info_format = G_INFO_FORMAT_PLAIN;
+ else
+ grass_info_format = G_INFO_FORMAT_STANDARD;
+
+ initialized = 1;
+}
+
/* Write a message to the log file */
static int write_error(const char *msg, int fatal,
time_t clock, const char *cwd)
{
- static char *logfile;
FILE *log;
- if (!logfile) {
- logfile = getenv("GIS_ERROR_LOG");
- if (!logfile) {
- char buf[GPATH_MAX];
+ G_init_logging();
- sprintf(buf, "%s/GIS_ERROR_LOG", G__home());
- logfile = G_store(buf);
- }
- }
-
log = fopen(logfile, "r");
if (!log)
/* GIS_ERROR_LOG file is not readable or does not exist */
@@ -486,21 +509,7 @@
*/
int G_info_format(void)
{
- static int grass_info_format = -1;
- char *fstr;
+ G_init_logging();
- if (grass_info_format < 0) {
- fstr = getenv("GRASS_MESSAGE_FORMAT");
-
- if (fstr && G_strcasecmp(fstr, "gui") == 0)
- grass_info_format = G_INFO_FORMAT_GUI;
- else if (fstr && G_strcasecmp(fstr, "silent") == 0)
- grass_info_format = G_INFO_FORMAT_SILENT;
- else if (fstr && G_strcasecmp(fstr, "plain") == 0)
- grass_info_format = G_INFO_FORMAT_PLAIN;
- else
- grass_info_format = G_INFO_FORMAT_STANDARD;
- }
-
return grass_info_format;
}
Modified: grass/trunk/lib/gis/opencell.c
===================================================================
--- grass/trunk/lib/gis/opencell.c 2008-11-24 23:58:48 UTC (rev 34482)
+++ grass/trunk/lib/gis/opencell.c 2008-11-25 01:05:48 UTC (rev 34483)
@@ -450,7 +450,7 @@
return sizeof(CELL) - 1;
}
-static int get_fp_type(void)
+int G_get_fp_type(void)
{
if (G__.fp_type <= 0)
G__.fp_type = getenv("GRASS_FP_DOUBLE")
@@ -460,6 +460,14 @@
return G__.fp_type;
}
+int G_get_compression_type(void)
+{
+ if (!G__.compression_type)
+ G__.compression_type = getenv("GRASS_INT_ZLIB") ? 2 : 1;
+ return G__.compression_type;
+}
+
+
/*!
\brief Opens new fcell file in a database
@@ -479,7 +487,7 @@
*/
int G_open_fp_cell_new(const char *name)
{
- return G__open_raster_new(name, OPEN_NEW_COMPRESSED, get_fp_type());
+ return G__open_raster_new(name, OPEN_NEW_COMPRESSED, G_get_fp_type());
}
/*!
@@ -494,7 +502,7 @@
*/
int G_open_fp_cell_new_uncompressed(const char *name)
{
- return G__open_raster_new(name, OPEN_NEW_UNCOMPRESSED, get_fp_type());
+ return G__open_raster_new(name, OPEN_NEW_UNCOMPRESSED, G_get_fp_type());
}
static int G__open_raster_new(const char *name, int open_mode,
@@ -569,9 +577,6 @@
fcb->data = (unsigned char *)G_calloc(G__.window.cols,
G_raster_size(fcb->map_type));
- if (open_mode == OPEN_NEW_COMPRESSED && !G__.compression_type)
- G__.compression_type = getenv("GRASS_INT_ZLIB") ? 2 : 1;
-
/*
* copy current window into cell header
* set format to cell/supercell
@@ -584,7 +589,7 @@
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 = G__.compression_type;
+ fcb->cellhd.compressed = G_get_compression_type();
fcb->nbytes = 1; /* to the minimum */
}
@@ -594,7 +599,7 @@
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 = G__.compression_type;
+ fcb->cellhd.compressed = G_get_compression_type();
}
else
fcb->cellhd.compressed = 0;
More information about the grass-commit
mailing list