[GRASS-SVN] r34445 - in grass/trunk: include lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 22 20:41:04 EST 2008


Author: glynn
Date: 2008-11-22 20:41:03 -0500 (Sat, 22 Nov 2008)
New Revision: 34445

Modified:
   grass/trunk/include/gisdefs.h
   grass/trunk/lib/gis/alloc_cell.c
   grass/trunk/lib/gis/cats.c
   grass/trunk/lib/gis/cell_stats.c
   grass/trunk/lib/gis/clicker.c
   grass/trunk/lib/gis/closecell.c
   grass/trunk/lib/gis/datum.c
   grass/trunk/lib/gis/env.c
   grass/trunk/lib/gis/get_ellipse.c
   grass/trunk/lib/gis/get_row.c
   grass/trunk/lib/gis/get_row_colr.c
   grass/trunk/lib/gis/gisinit.c
   grass/trunk/lib/gis/list.c
   grass/trunk/lib/gis/mach_name.c
   grass/trunk/lib/gis/mask_info.c
   grass/trunk/lib/gis/myname.c
   grass/trunk/lib/gis/null_val.c
   grass/trunk/lib/gis/parser.c
   grass/trunk/lib/gis/percent.c
   grass/trunk/lib/gis/popen.c
   grass/trunk/lib/gis/proj3.c
   grass/trunk/lib/gis/put_row.c
   grass/trunk/lib/gis/reclass.c
   grass/trunk/lib/gis/spawn.c
   grass/trunk/lib/gis/view.c
Log:
Reduce use of static variables
Miscellaneous clean-up


Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/include/gisdefs.h	2008-11-23 01:41:03 UTC (rev 34445)
@@ -787,7 +787,6 @@
 int G__unqualified_name(const char *, const char *, char *, char *);
 
 /* null_val.c */
-void G__init_null_patterns(void);
 void G__set_null_value(void *, int, int, RASTER_MAP_TYPE);
 void G_set_null_value(void *, int, RASTER_MAP_TYPE);
 void G_set_c_null_value(CELL *, int);
@@ -869,7 +868,6 @@
 
 /* percent.c */
 int G_percent(long, long, int);
-int G_percent2(long, long, int, FILE *);
 int G_percent_reset(void);
 
 /* plot.c */
@@ -915,7 +913,6 @@
 int G_put_cellhd(const char *, struct Cell_head *);
 
 /* put_row.c */
-int G_zeros_r_nulls(int);
 int G_put_map_row(int, const CELL *);
 int G__put_null_value_row(int, const char *);
 int G_put_raster_row(int, const void *, RASTER_MAP_TYPE);

Modified: grass/trunk/lib/gis/alloc_cell.c
===================================================================
--- grass/trunk/lib/gis/alloc_cell.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/alloc_cell.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -21,7 +21,7 @@
 #define F2I(map_type) \
 	(map_type == CELL_TYPE ? 0 : (map_type == FCELL_TYPE ? 1 : 2))
 
-static int type_size[3] = { sizeof(CELL), sizeof(FCELL), sizeof(DCELL) };
+static const int type_size[3] = { sizeof(CELL), sizeof(FCELL), sizeof(DCELL) };
 
 
 /**

Modified: grass/trunk/lib/gis/cats.c
===================================================================
--- grass/trunk/lib/gis/cats.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/cats.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -563,9 +563,7 @@
 
 char *G_get_raster_cats_title(const struct Categories *pcats)
 {
-    static char *none = "";
-
-    return pcats->title ? pcats->title : none;
+    return pcats->title ? pcats->title : "";
 }
 
 

Modified: grass/trunk/lib/gis/cell_stats.c
===================================================================
--- grass/trunk/lib/gis/cell_stats.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/cell_stats.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -4,7 +4,7 @@
 #define INCR 10
 #define SHIFT 6
 
-static int NCATS = 1 << SHIFT;
+static const int NCATS = 1 << SHIFT;
 
 #define NODE struct Cell_stats_node
 

Modified: grass/trunk/lib/gis/clicker.c
===================================================================
--- grass/trunk/lib/gis/clicker.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/clicker.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -13,7 +13,7 @@
 int G_clicker(void)
 {
     int x;
-    static char clicks[] = "|/-\\";
+    static const char clicks[] = "|/-\\";
 
     if (G_clicker_prev == -1 || G_clicker_prev == 3)
 	x = 0;

Modified: grass/trunk/lib/gis/closecell.c
===================================================================
--- grass/trunk/lib/gis/closecell.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/closecell.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -41,7 +41,6 @@
 
 static int close_old(int);
 static int close_new(int, int);
-static char CELL_DIR[100];
 
 static int write_fp_format(int fd);
 
@@ -168,6 +167,7 @@
     char path[GPATH_MAX];
     CELL cell_min, cell_max;
     int row, i, open_mode;
+    const char *CELL_DIR;
 
     if (ok) {
 	switch (fcb->open_mode) {
@@ -255,7 +255,7 @@
 		creat(G__file_name(path, "cell", fcb->name, fcb->mapset),
 		      0666);
 	    close(cell_fd);
-	    strcpy(CELL_DIR, "fcell");
+	    CELL_DIR = "fcell";
 	}
 	else {
 	    /* remove fcell/name file */
@@ -265,7 +265,7 @@
 	    G__file_name_misc(path, "cell_misc", FORMAT_FILE, fcb->name,
 			      fcb->mapset);
 	    remove(path);
-	    strcpy(CELL_DIR, "cell");
+	    CELL_DIR = "cell";
 	    close(fd);
 	}
     }				/* ok */

Modified: grass/trunk/lib/gis/datum.c
===================================================================
--- grass/trunk/lib/gis/datum.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/datum.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -144,7 +144,7 @@
 static void read_datum_table(void)
 {
     FILE *fd;
-    char file[1024];
+    char file[GPATH_MAX];
     char buf[1024];
     int line;
 

Modified: grass/trunk/lib/gis/env.c
===================================================================
--- grass/trunk/lib/gis/env.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/env.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -197,11 +197,10 @@
     FILE *fd;
     int n;
     char dummy[2];
-    void (*sigint) ()
+    RETSIGTYPE (*sigint)(int);
 #ifdef SIGQUIT
-     , (*sigquit) ()
+    RETSIGTYPE (*sigquit)(int);
 #endif
-     ;
 
     if (loc == G_VAR_GISRC && varmode == G_GISRC_MODE_MEMORY)
 	return 0;		/* don't use file for GISRC */

Modified: grass/trunk/lib/gis/get_ellipse.c
===================================================================
--- grass/trunk/lib/gis/get_ellipse.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/get_ellipse.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -38,7 +38,7 @@
 } *table = NULL;
 
 static int count = -1;
-static char *PERMANENT = "PERMANENT";
+static const char PERMANENT[] = "PERMANENT";
 
 /* static int get_a_e2 (char *, char *, double *,double *); */
 static int get_a_e2_f(const char *, const char *, double *, double *,

Modified: grass/trunk/lib/gis/get_row.c
===================================================================
--- grass/trunk/lib/gis/get_row.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/get_row.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -615,10 +615,11 @@
 static int get_map_row_nomask(int fd, void *rast, int row,
 			      RASTER_MAP_TYPE data_type)
 {
-    static void (*transfer_to_cell_FtypeOtype[3][3]) () = { {
-    transfer_to_cell_XX, transfer_to_cell_if, transfer_to_cell_id}, {
-    transfer_to_cell_fi, transfer_to_cell_XX, transfer_to_cell_fd}, {
-    transfer_to_cell_di, transfer_to_cell_df, transfer_to_cell_XX}};
+    static void (*transfer_to_cell_FtypeOtype[3][3])() = {
+	{transfer_to_cell_XX, transfer_to_cell_if, transfer_to_cell_id},
+	{transfer_to_cell_fi, transfer_to_cell_XX, transfer_to_cell_fd},
+	{transfer_to_cell_di, transfer_to_cell_df, transfer_to_cell_XX}
+    };
     struct fileinfo *fcb = &G__.fileinfo[fd];
     int r;
     int rowStatus;

Modified: grass/trunk/lib/gis/get_row_colr.c
===================================================================
--- grass/trunk/lib/gis/get_row_colr.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/get_row_colr.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -25,35 +25,31 @@
 			unsigned char *red, unsigned char *grn,
 			unsigned char *blu, unsigned char *nul)
 {
-    static void *array;
-    static int array_size;
-    static unsigned char *set;
-    static int set_size;
-
-    int cols = G__.window.cols;
-    int type = G__.fileinfo[fd].map_type;
+    int cols = G_window_cols();
+    int type = G_get_raster_map_type(fd);
     int size = G_raster_size(type);
+    void *array;
+    unsigned char *set;
     void *p;
     int i;
 
-    if (array_size < cols * size) {
-	array_size = cols * size;
-	array = (DCELL *) G_realloc(array, array_size);
-    }
+    array = G__alloca(cols * size);
 
-    if (set_size < cols) {
-	set_size = cols;
-	set = G_realloc(set, set_size);
+    if (G_get_raster_row(fd, array, row, type) < 0) {
+	G__freea(array);
+	return -1;
     }
 
-    if (G_get_raster_row(fd, array, row, type) < 0)
-	return -1;
-
     if (nul)
 	for (i = 0, p = array; i < cols; i++, p = G_incr_void_ptr(p, size))
 	    nul[i] = G_is_null_value(p, type);
 
+    set = G__alloca(cols);
+
     G_lookup_raster_colors(array, red, grn, blu, set, cols, colors, type);
 
+    G__freea(array);
+    G__freea(set);
+
     return 0;
 }

Modified: grass/trunk/lib/gis/gisinit.c
===================================================================
--- grass/trunk/lib/gis/gisinit.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/gisinit.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -126,9 +126,6 @@
     /* Set masking flag unknown */
     G__.auto_mask = -1;
 
-    /* set architecture dependent bit patterns for embeded null vals */
-    G__init_null_patterns();
-
     initialized = 1;
 
     setlocale(LC_NUMERIC, "C");

Modified: grass/trunk/lib/gis/list.c
===================================================================
--- grass/trunk/lib/gis/list.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/list.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -23,7 +23,7 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
-static int broken_pipe;
+static volatile int broken_pipe;
 static int list_element(FILE *, const char *, const char *, const char *,
 			int (*)(const char *, const char *, const char *));
 static void sigpipe_catch(int);
@@ -60,7 +60,7 @@
     int count;
 
 #ifdef SIGPIPE
-    void (*sigpipe) ();
+    RETSIGTYPE (*sigpipe)(int);
 #endif
 
     /* must catch broken pipe in case "more" quits */
@@ -133,11 +133,9 @@
     signal(n, sigpipe_catch);
 }
 
-static int list_element(FILE * out,
-			const char *element, const char *desc,
-			const char *mapset, int (*lister) (const char *,
-							   const char *,
-							   const char *))
+static int list_element(
+    FILE *out, const char *element, const char *desc, const char *mapset,
+    int (*lister)(const char *, const char *, const char *))
 {
     char path[GPATH_MAX];
     int count = 0;

Modified: grass/trunk/lib/gis/mach_name.c
===================================================================
--- grass/trunk/lib/gis/mach_name.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/mach_name.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -1,5 +1,10 @@
 #include <unistd.h>
 #include <grass/gis.h>
+#include <grass/config.h>
+#ifdef HAVE_SYS_UTSNAME_H
+#include <sys/utsname.h>
+#endif
+
 /* this routine returns a name for the machine
  * it returns the empty string, if this info
  * not available (it never returns a NULL pointer)
@@ -7,34 +12,27 @@
  * the name is stored in a static array and the pointer to this
  * array is returned.
  *
- * the contents of this array are reset upon each call
- *
  */
 
-#include <grass/config.h>
-
-#ifndef HAVE_GETHOSTNAME
-#ifdef HAVE_SYS_UTSNAME_H
-#include <sys/utsname.h>
-static struct utsname attname;
-#endif
-#endif
-
 char *G__machine_name(void)
 {
     static char name[128];
 
-    *name = 0;
+    if (*name)
+	return name;
 
-#ifdef HAVE_GETHOSTNAME
+#if defined(HAVE_GETHOSTNAME)
     gethostname(name, sizeof(name));
-    name[sizeof(name) - 1] = 0;	/* make sure null terminated */
-#else
-#ifdef HAVE_SYS_UTSNAME_H
-    uname(&attname);
-    strcpy(name, attname.nodename);
+    name[sizeof(name) - 1] = 0;	/* make sure NUL terminated */
+#elif defined(HAVE_SYS_UTSNAME_H)
+    {
+	struct utsname attname;
+	uname(&attname);
+	strcpy(name, attname.nodename);
+    }
+#elif
+    strcpy(name, "unknown");
 #endif
-#endif
 
-    return (name);
+    return name;
 }

Modified: grass/trunk/lib/gis/mask_info.c
===================================================================
--- grass/trunk/lib/gis/mask_info.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/mask_info.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -29,9 +29,10 @@
 #include <string.h>
 #include <grass/gis.h>
 #include <grass/glocale.h>
+
 char *G_mask_info(void)
 {
-    static char text[200];
+    char text[GNAME_MAX + GMAPSET_MAX + 16];
     char name[GNAME_MAX];
     char mapset[GMAPSET_MAX];
 
@@ -47,7 +48,7 @@
 	break;
     }
 
-    return text;
+    return G_store(text);
 }
 
 int G__mask_info(char *name, char *mapset)

Modified: grass/trunk/lib/gis/myname.c
===================================================================
--- grass/trunk/lib/gis/myname.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/myname.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -34,7 +34,7 @@
 
 char *G_myname(void)
 {
-    static char name[GNAME_MAX];
+    char name[GNAME_MAX];
     char path[GPATH_MAX];
     FILE *fd;
     int ok;
@@ -49,5 +49,5 @@
     if (!ok)
 	strcpy(name, _("Unknown Location"));
 
-    return name;
+    return G_store(name);
 }

Modified: grass/trunk/lib/gis/null_val.c
===================================================================
--- grass/trunk/lib/gis/null_val.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/null_val.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -24,31 +24,12 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
-/*======================= Internal Constants/Defines =======================*/
-
-/* none */
-
-/*========================== Internal Typedefs =============================*/
-
-/* none */
-
-/*====================== Static Variable Declaration =======================*/
-
-/* Null pattern variables */
-static CELL cellNullPattern;
-static FCELL fcellNullPattern;
-static DCELL dcellNullPattern;
-
 /* Flag to indicate null patterns are initialized */
 static int initialized = FALSE;
 
-/*============================== Prototypes ================================*/
-
 static int EmbedGivenNulls(void *, char *, RASTER_MAP_TYPE, int);
 static void InitError(void);
 
-/*======================= Internal Static Functions ========================*/
-
 /****************************************************************************
 * int EmbedGivenNulls (void *cell, char *nulls, RASTER_MAP_TYPE map_type,
 *   int ncols)
@@ -120,57 +101,6 @@
 /*========================== Library Functions =============================*/
 
 /****************************************************************************
-* void G__init_null_patterns (void)
-*
-* PURPOSE: 	To initialize the three null patterns for CELL, FCELL, and
-*   	    	DCELL data types. It also sets the initialized flag to TRUE.
-*   	    	This function is called by G_gisinit()
-* INPUT VARS:	none
-* RETURN VAL:	none
-*****************************************************************************/
-void G__init_null_patterns(void)
-{
-    unsigned char *bytePtr;	/* pointer to traverse FCELL and DCELL */
-    int numBits;		/* number of bits for CELL type */
-    int i;			/* counter */
-
-    if (!initialized) {
-	/* Create the null pattern for the CELL data type - set the left */
-	/* most bit to 1 and the rest to 0, basically INT_MIN. Since CELL is */
-	/* some type of integer the bytes are not split into exponent and */
-	/* mantissa. Thus a simple left shift can be used */
-	numBits = sizeof(CELL) * 8;
-
-	cellNullPattern = 1 << (numBits - 1);
-
-	/* Create the null pattern for the FCELL data type - set all bits */
-	/* to 1, basically NaN. Need to use a byte pointer since bytes */
-	/* represent the exponent and mantissa */
-	bytePtr = (unsigned char *)&fcellNullPattern;
-
-	for (i = 0; i < sizeof(FCELL); i++) {
-	    *bytePtr = (unsigned char)255;
-	    bytePtr++;
-	}
-
-	/* Create the null pattern for the DCELL data type - set all bits */
-	/* to 1, basically NaN. Need to use a byte pointer since bytes */
-	/* represent the exponent and mantissa */
-	bytePtr = (unsigned char *)&dcellNullPattern;
-
-	for (i = 0; i < sizeof(DCELL); i++) {
-	    *bytePtr = (unsigned char)255;
-	    bytePtr++;
-	}
-
-	/* Set the initialized flag to TRUE */
-	initialized = TRUE;
-    }
-
-    return;
-}
-
-/****************************************************************************
 * void G__set_null_value (void *rast, int numVals, int null_is_zero,
 *   RASTER_MAP_TYPE data_type)
 *
@@ -234,25 +164,12 @@
 *   	    	numVals     =>	number of values to set to null
 * RETURN VAL:	none
 *****************************************************************************/
-void G_set_c_null_value(CELL * cellVals, int numVals)
+void G_set_c_null_value(CELL *cellVals, int numVals)
 {
-    CELL *cellPtr;		/* pointer to CELL array to set to null */
     int i;			/* counter */
 
-    /* Check if the null patterns have been initialized */
-    if (!initialized) {
-	InitError();
-    }
-
-    /* Set numVals consecutive CELL values to null */
-    cellPtr = cellVals;
-
-    for (i = 0; i < numVals; i++) {
-	*cellPtr = cellNullPattern;
-	cellPtr++;
-    }
-
-    return;
+    for (i = 0; i < numVals; i++)
+	cellVals[i] = (int) 0x80000000;
 }
 
 /****************************************************************************
@@ -263,25 +180,14 @@
 *   	    	numVals     =>	number of values to set to null
 * RETURN VAL:	none
 *****************************************************************************/
-void G_set_f_null_value(FCELL * fcellVals, int numVals)
+void G_set_f_null_value(FCELL *fcellVals, int numVals)
 {
-    FCELL *fcellPtr;		/* pointer to FCELL array to set to null */
-    int i;			/* counter */
+    static const unsigned char null_bits[4] = {
+	0xFF, 0xFF, 0xFF, 0xFF};
+    int i;
 
-    /* Check if the null patterns have been initialized */
-    if (!initialized) {
-	InitError();
-    }
-
-    /* Set numVals consecutive FCELL values to null */
-    fcellPtr = fcellVals;
-
-    for (i = 0; i < numVals; i++) {
-	*fcellPtr = fcellNullPattern;
-	fcellPtr++;
-    }
-
-    return;
+    for (i = 0; i < numVals; i++)
+	memcpy(&fcellVals[i], null_bits, sizeof(null_bits));
 }
 
 /****************************************************************************
@@ -292,25 +198,14 @@
 *   	    	numVals     =>	number of values to set to null
 * RETURN VAL:	none
 *****************************************************************************/
-void G_set_d_null_value(DCELL * dcellVals, int numVals)
+void G_set_d_null_value(DCELL *dcellVals, int numVals)
 {
-    DCELL *dcellPtr;		/* pointer to DCELL array to set to null */
-    int i;			/* counter */
+    static const unsigned char null_bits[8] = {
+	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+    int i;
 
-    /* Check if the null patterns have been initialized */
-    if (!initialized) {
-	InitError();
-    }
-
-    /* Set numVals consecutive DCELL values to null */
-    dcellPtr = dcellVals;
-
-    for (i = 0; i < numVals; i++) {
-	*dcellPtr = dcellNullPattern;
-	dcellPtr++;
-    }
-
-    return;
+    for (i = 0; i < numVals; i++)
+	memcpy(&dcellVals[i], null_bits, sizeof(null_bits));
 }
 
 /****************************************************************************
@@ -384,12 +279,9 @@
     }
 
     /* Check if the CELL value matches the null pattern */
-    for (i = 0; i < sizeof(CELL); i++) {
-	if (((unsigned char *)cellVal)[i] !=
-	    ((unsigned char *)&cellNullPattern)[i]) {
+    for (i = 0; i < sizeof(CELL); i++)
+	if (cellVal[i] != (CELL) 0x80000000)
 	    return FALSE;
-	}
-    }
 
     return TRUE;
 }

Modified: grass/trunk/lib/gis/parser.c
===================================================================
--- grass/trunk/lib/gis/parser.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/parser.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -2616,7 +2616,7 @@
  */
 char *G_recreate_command(void)
 {
-    static char *buff;
+    char *buff;
     char flg[4];
     char *cur;
     const char *tmp;

Modified: grass/trunk/lib/gis/percent.c
===================================================================
--- grass/trunk/lib/gis/percent.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/percent.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -22,76 +22,8 @@
 static int first = 1;
 
 
-/**
- * \brief Print percent complete messages.
- *
- * This routine prints a percentage complete message to stderr. The
- * percentage complete is <i>(<b>n</b>/<b>d</b>)*100</i>, and these are 
- * printed only for each <b>s</b> percentage. This is perhaps best 
- * explained by example:
-\code
-  #include <stdio.h>
-  #include <grass/gis.h>
-  int row;
-  int nrows;
-  nrows = 1352; // 1352 is not a special value - example only
-
-  fprintf (stderr, "Percent complete: ");
-  for (row = 0; row < nrows; row++)
-  {
-      G_percent (row, nrows, 10);
-  }
-  G_percent (row, nrows, 10);
-\endcode
- * This will print completion messages at 10% increments; i.e., 10%, 20%, 30%,
- * etc., up to 100%. Each message does not appear on a new line, but rather erases
- * the previous message. After 100%, a new line is printed.
- *
- * \param[in] n current element
- * \param[in] d total number of elements
- * \param[in] s increment size
- * \return always returns 0
- */
-
 int G_percent(long n, long d, int s)
 {
-    return (G_percent2(n, d, s, stderr));
-}
-
-
-/**
- * \brief Print percent complete messages.
- *
- * This routine prints a percentage complete message to stderr. The
- * percentage complete is <i>(<b>n</b>/<b>d</b>)*100</i>, and these are 
- * printed only for each <b>s</b> percentage. This is perhaps best 
- * explained by example:
-\code
-  #include <stdio.h>
-  #include <grass/gis.h>
-  int row;
-  int nrows;
-  nrows = 1352; // 1352 is not a special value - example only
-  fprintf (stderr, "Percent complete: ");
-  for (row = 0; row < nrows; row++)
-  {
-      G_percent (row, nrows, 10);
-  }
-  G_percent (row, nrows, 10);
-\endcode
- * This will print completion messages at 10% increments; i.e., 10%, 20%, 30%,
- * etc., up to 100%. Each message does not appear on a new line, but rather erases
- * the previous message. After 100%, a new line is printed.
- *
- * \param[in] n current element
- * \param[in] d total number of elements
- * \param[in] s increment size
- * \param[in,out] out file to print to
- * \return always returns 0
- */
-
-int G_percent2(long n, long d, int s, FILE * out)
-{
     int x, format;
 
     format = G_info_format();
@@ -107,27 +39,21 @@
 	prev = x;
 
 	if (format == G_INFO_FORMAT_STANDARD) {
-	    if (out != NULL) {
-		fprintf(out, "%4d%%\b\b\b\b\b", x);
-	    }
+	    fprintf(stderr, "%4d%%\b\b\b\b\b", x);
 	}
 	else {
 	    if (format == G_INFO_FORMAT_PLAIN) {
-		if (out != NULL) {
-		    if (x == 100)
-			fprintf(out, "%d\n", x);
-		    else
-			fprintf(out, "%d..", x);
-		}
+		if (x == 100)
+		    fprintf(stderr, "%d\n", x);
+		else
+		    fprintf(stderr, "%d..", x);
 	    }
 	    else {		/* GUI */
-		if (out != NULL) {
-		    if (first) {
-			fprintf(out, "\n");
-		    }
-		    fprintf(out, "GRASS_INFO_PERCENT: %d\n", x);
-		    fflush(out);
+		if (first) {
+		    fprintf(stderr, "\n");
 		}
+		fprintf(stderr, "GRASS_INFO_PERCENT: %d\n", x);
+		fflush(stderr);
 		first = 0;
 	    }
 	}
@@ -135,9 +61,7 @@
 
     if (x >= 100) {
 	if (format == G_INFO_FORMAT_STANDARD) {
-	    if (out != NULL) {
-		fprintf(out, "\n");
-	    }
+	    fprintf(stderr, "\n");
 	}
 	prev = -1;
 	first = 1;

Modified: grass/trunk/lib/gis/popen.c
===================================================================
--- grass/trunk/lib/gis/popen.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/popen.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -4,30 +4,22 @@
 #include <stdlib.h>
 #include <sys/types.h>
 
-
 #ifdef __MINGW32__
 #  include <io.h>
 #  include <fcntl.h>
 #  include <process.h>
-#else
-#  include <sys/wait.h>
-#  define tst(a,b)        (*mode == 'r'? (b) : (a))
 #endif
 
 #include <grass/gis.h>
 
-
 #define READ      0
 #define WRITE     1
 
-static int popen_pid[50];
-
-
 FILE *G_popen(const char *cmd, const char *mode)
 {
-
-#ifdef __MINGW32__
-
+#ifndef __MINGW32__
+    return popen(cmd, mode);
+#else
     int thepipes[2];
     FILE *rv = NULL;
 
@@ -42,88 +34,31 @@
 	rv = fdopen(thepipes[READ], mode);
     }
 
-    return (rv);
-
-#else /* __MINGW32__ */
-
-    int p[2];
-    int me, you, pid;
-
-    fflush(stdout);
-    fflush(stderr);
-
-    if (pipe(p) < 0)
-	return NULL;
-    me = tst(p[WRITE], p[READ]);
-    you = tst(p[READ], p[WRITE]);
-    if ((pid = fork()) == 0) {
-	/* me and you reverse roles in child */
-	close(me);
-	close(tst(0, 1));
-	dup(you);
-	close(you);
-	execl("/bin/sh", "sh", "-c", cmd, (char *)NULL);
-	_exit(1);
-    }
-
-    if (pid == -1)
-	return NULL;
-    popen_pid[me] = pid;
-    close(you);
-
-    return (fdopen(me, mode));
-
-#endif /* __MINGW32__ */
-
+    return rv;
+#endif
 }
 
-int G_pclose(FILE * ptr)
+int G_pclose(FILE *ptr)
 {
-    RETSIGTYPE(*sigint) ();
-#ifdef SIGHUP
-    RETSIGTYPE(*sighup) ();
-#endif
-#ifdef SIGQUIT
-    RETSIGTYPE(*sigquit) ();
-#endif
-    int f;
-
 #ifndef __MINGW32__
-    int r;
-#endif
+    return pclose(ptr);
+#else
+    RETSIGTYPE(*sigint)(int);
     int status;
+    int f;
 
     f = fileno(ptr);
     fclose(ptr);
 
     sigint = signal(SIGINT, SIG_IGN);
-#ifdef __MINGW32__
+
     _cwait(&status, popen_pid[f], WAIT_CHILD);
     if (0 & status) {
 	status = -1;
     }
-#else
 
-#ifdef SIGQUIT
-    sigquit = signal(SIGQUIT, SIG_IGN);
-#endif
-#ifdef SIGHUP
-    sighup = signal(SIGHUP, SIG_IGN);
-#endif
-    while ((r = wait(&status)) != popen_pid[f] && r != -1) ;
-    if (r == -1)
-	status = -1;
-
-#endif /* __MINGW32__ */
-
     signal(SIGINT, sigint);
 
-#ifdef SIGQUIT
-    signal(SIGQUIT, sigquit);
+    return status;
 #endif
-#ifdef SIGHUP
-    signal(SIGHUP, sighup);
-#endif
-
-    return (status);
 }

Modified: grass/trunk/lib/gis/proj3.c
===================================================================
--- grass/trunk/lib/gis/proj3.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/proj3.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -84,7 +84,7 @@
     char buf[256];
     int n;
 
-    static struct
+    static const struct
     {
 	char *unit;
 	double factor;

Modified: grass/trunk/lib/gis/put_row.c
===================================================================
--- grass/trunk/lib/gis/put_row.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/put_row.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -1,25 +1,6 @@
 
 /**********************************************************************
  *
- *   G_zeros_r_nulls(zeros_r_nulls)
- *      int zeros_r_nulls	the last argument of put_data()
- *
- *   zeros_r_nulls > 0		zero values of buf to be written into files
- *   				are null values by default.
- *
- *   zeros_r_nulls == 0		zero values are just zero itself.
- *
- *   zeros_r_nulls < 0		do not set. return current setting.
- *   				1: set
- *   				0: not set
- *
- *   Return setting values in all cases.
- *
- *   *** NOTE *** 
- *   Use only to change a default behavior for zero of G_put_map_row
- *
- ********************************************************************** 
- *
  *   G_put_[c/f/d]_raster_row(fd, buf)
  *      int fd           file descriptor of the opened map
  *      [F/D]CELL *buf   buffer holding row info to be written
@@ -104,8 +85,6 @@
 #include "G.h"
 #include <grass/glocale.h>
 
-static int _zeros_r_nulls = 1;
-
 static int put_raster_data(int, char *, const void *, int, int, int,
 			   RASTER_MAP_TYPE);
 static int put_data(int, char *, const CELL *, int, int, int);
@@ -128,14 +107,6 @@
 
 /*--------------------------------------------------------------------------*/
 
-int G_zeros_r_nulls(int zeros_r_nulls)
-{
-    if (zeros_r_nulls >= 0)
-	_zeros_r_nulls = zeros_r_nulls > 0;
-
-    return _zeros_r_nulls;
-}
-
 int G__put_null_value_row(int fd, const char *buf)
 {
     struct fileinfo *fcb = &G__.fileinfo[fd];
@@ -162,7 +133,7 @@
 	return -1;
     }
 
-    return put_raster_row(fd, buf, CELL_TYPE, _zeros_r_nulls);
+    return put_raster_row(fd, buf, CELL_TYPE, 1);
 }
 
 int G_put_raster_row(int fd, const void *buf, RASTER_MAP_TYPE data_type)
@@ -795,11 +766,10 @@
 static int put_raster_row(int fd, const void *buf, RASTER_MAP_TYPE data_type,
 			  int zeros_r_nulls)
 {
-    static int (*convert_and_write_FtypeOtype[3][3]) () = {
-	{
-	NULL, convert_and_write_if, convert_and_write_id}, {
-	convert_and_write_fi, NULL, convert_and_write_fd}, {
-	convert_and_write_di, convert_and_write_df, NULL}
+    static int (*convert_and_write_FtypeOtype[3][3])() = {
+	{NULL, convert_and_write_if, convert_and_write_id},
+	{convert_and_write_fi, NULL, convert_and_write_fd},
+	{convert_and_write_di, convert_and_write_df, NULL}
     };
     struct fileinfo *fcb = &G__.fileinfo[fd];
     char *null_buf;

Modified: grass/trunk/lib/gis/reclass.c
===================================================================
--- grass/trunk/lib/gis/reclass.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/reclass.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -2,7 +2,7 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
-static char *NULL_STRING = "null";
+static const char NULL_STRING[] = "null";
 static int reclass_type(FILE *, char **, char **);
 static FILE *fopen_cellhd_old(const char *, const char *);
 static FILE *fopen_cellhd_new(const char *);

Modified: grass/trunk/lib/gis/spawn.c
===================================================================
--- grass/trunk/lib/gis/spawn.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/spawn.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -191,16 +191,19 @@
     const char *val;
 };
 
-static const char *args[MAX_ARGS];
-static int num_args;
-static struct redirect redirects[MAX_REDIRECTS];
-static int num_redirects;
-static struct signal signals[MAX_SIGNALS];
-static int num_signals;
-static struct binding bindings[MAX_BINDINGS];
-static int num_bindings;
-static int background;
-static const char *directory;
+struct spawn
+{
+    const char *args[MAX_ARGS];
+    int num_args;
+    struct redirect redirects[MAX_REDIRECTS];
+    int num_redirects;
+    struct signal signals[MAX_SIGNALS];
+    int num_signals;
+    struct binding bindings[MAX_BINDINGS];
+    int num_bindings;
+    int background;
+    const char *directory;
+};
 
 #ifdef __MINGW32__
 
@@ -380,54 +383,53 @@
 
     for (i = 0; i < num_bindings; i++) {
 	struct binding *b = &bindings[i];
-	static char *str = NULL;
+	char *str = G_malloc(strlen(b->var) + strlen(b->val) + 2);
 
-	str = G_realloc(str, strlen(b->var) + strlen(b->val) + 2);
 	sprintf(str, "%s=%s", b->var, b->val);
 	putenv(str);
     }
 }
 
-static int do_spawn(const char *command)
+static int do_spawn(struct spawn *sp, const char *command)
 {
     int status = -1;
     pid_t pid;
 
-    if (!do_signals(signals, num_signals, SST_PRE))
+    if (!do_signals(sp->signals, sp->num_signals, SST_PRE))
 	return status;
 
     pid = fork();
     if (pid < 0) {
 	G_warning(_("Unable to create a new process"));
-	undo_signals(signals, num_signals, SST_PRE);
+	undo_signals(sp->signals, sp->num_signals, SST_PRE);
 
 	return status;
     }
 
     if (pid == 0) {
-	if (!undo_signals(signals, num_signals, SST_PRE))
+	if (!undo_signals(sp->signals, sp->num_signals, SST_PRE))
 	    _exit(127);
 
-	if (!do_signals(signals, num_signals, SST_CHILD))
+	if (!do_signals(sp->signals, sp->num_signals, SST_CHILD))
 	    _exit(127);
 
-	if (directory)
-	    if (chdir(directory) < 0) {
-		G_warning(_("Unable to change directory to %s"), directory);
+	if (sp->directory)
+	    if (chdir(sp->directory) < 0) {
+		G_warning(_("Unable to change directory to %s"), sp->directory);
 		_exit(127);
 	    }
 
-	do_redirects(redirects, num_redirects);
-	do_bindings(bindings, num_bindings);
+	do_redirects(sp->redirects, sp->num_redirects);
+	do_bindings(sp->bindings, sp->num_bindings);
 
-	execvp(command, (char **)args);
+	execvp(command, (char **)sp->args);
 	G_warning(_("Unable to execute command"));
 	_exit(127);
     }
 
-    do_signals(signals, num_signals, SST_POST);
+    do_signals(sp->signals, sp->num_signals, SST_POST);
 
-    if (background)
+    if (sp->background)
 	status = (int)pid;
     else {
 	pid_t n;
@@ -440,27 +442,27 @@
 	    status = -1;
     }
 
-    undo_signals(signals, num_signals, SST_POST);
-    undo_signals(signals, num_signals, SST_PRE);
+    undo_signals(sp->signals, sp->num_signals, SST_POST);
+    undo_signals(sp->signals, sp->num_signals, SST_PRE);
 
     return status;
 }
 
 #endif /* __MINGW32__ */
 
-static void begin_spawn(void)
+static void begin_spawn(struct spawn *sp)
 {
-    num_args = 0;
-    num_redirects = 0;
-    num_signals = 0;
-    num_bindings = 0;
-    background = 0;
-    directory = NULL;
+    sp->num_args = 0;
+    sp->num_redirects = 0;
+    sp->num_signals = 0;
+    sp->num_bindings = 0;
+    sp->background = 0;
+    sp->directory = NULL;
 }
 
 #define NEXT_ARG(var, type) ((type) *(var)++)
 
-static void parse_argvec(const char **va)
+static void parse_argvec(struct spawn *sp, const char **va)
 {
     for (;;) {
 	const char *arg = NEXT_ARG(va, const char *);
@@ -468,64 +470,64 @@
 
 	switch ((int)arg) {
 	case 0:
-	    args[num_args++] = NULL;
+	    sp->args[sp->num_args++] = NULL;
 	    break;
 	case ((int)SF_REDIRECT_FILE):
-	    redirects[num_redirects].dst_fd = NEXT_ARG(va, int);
+	    sp->redirects[sp->num_redirects].dst_fd = NEXT_ARG(va, int);
 
-	    redirects[num_redirects].src_fd = -1;
-	    redirects[num_redirects].mode = NEXT_ARG(va, int);
-	    redirects[num_redirects].file = NEXT_ARG(va, const char *);
+	    sp->redirects[sp->num_redirects].src_fd = -1;
+	    sp->redirects[sp->num_redirects].mode = NEXT_ARG(va, int);
+	    sp->redirects[sp->num_redirects].file = NEXT_ARG(va, const char *);
 
-	    num_redirects++;
+	    sp->num_redirects++;
 	    break;
 	case ((int)SF_REDIRECT_DESCRIPTOR):
-	    redirects[num_redirects].dst_fd = NEXT_ARG(va, int);
-	    redirects[num_redirects].src_fd = NEXT_ARG(va, int);
+	    sp->redirects[sp->num_redirects].dst_fd = NEXT_ARG(va, int);
+	    sp->redirects[sp->num_redirects].src_fd = NEXT_ARG(va, int);
 
-	    redirects[num_redirects].file = NULL;
-	    num_redirects++;
+	    sp->redirects[sp->num_redirects].file = NULL;
+	    sp->num_redirects++;
 	    break;
 	case ((int)SF_CLOSE_DESCRIPTOR):
-	    redirects[num_redirects].dst_fd = NEXT_ARG(va, int);
+	    sp->redirects[sp->num_redirects].dst_fd = NEXT_ARG(va, int);
 
-	    redirects[num_redirects].src_fd = -1;
-	    redirects[num_redirects].file = NULL;
-	    num_redirects++;
+	    sp->redirects[sp->num_redirects].src_fd = -1;
+	    sp->redirects[sp->num_redirects].file = NULL;
+	    sp->num_redirects++;
 	    break;
 	case ((int)SF_SIGNAL):
-	    signals[num_signals].which = NEXT_ARG(va, int);
-	    signals[num_signals].action = NEXT_ARG(va, int);
-	    signals[num_signals].signum = NEXT_ARG(va, int);
+	    sp->signals[sp->num_signals].which = NEXT_ARG(va, int);
+	    sp->signals[sp->num_signals].action = NEXT_ARG(va, int);
+	    sp->signals[sp->num_signals].signum = NEXT_ARG(va, int);
 
-	    signals[num_signals].valid = 0;
-	    num_signals++;
+	    sp->signals[sp->num_signals].valid = 0;
+	    sp->num_signals++;
 	    break;
 	case ((int)SF_VARIABLE):
 	    var = NEXT_ARG(va, const char *);
 
 	    val = getenv(var);
-	    args[num_args++] = val ? val : "";
+	    sp->args[sp->num_args++] = val ? val : "";
 	    break;
 	case ((int)SF_BINDING):
-	    bindings[num_bindings].var = NEXT_ARG(va, const char *);
-	    bindings[num_bindings].val = NEXT_ARG(va, const char *);
+	    sp->bindings[sp->num_bindings].var = NEXT_ARG(va, const char *);
+	    sp->bindings[sp->num_bindings].val = NEXT_ARG(va, const char *);
 
-	    num_bindings++;
+	    sp->num_bindings++;
 	    break;
 	case ((int)SF_BACKGROUND):
-	    background = 1;
+	    sp->background = 1;
 	    break;
 	case ((int)SF_DIRECTORY):
-	    directory = NEXT_ARG(va, const char *);
+	    sp->directory = NEXT_ARG(va, const char *);
 
 	    break;
 	case ((int)SF_ARGVEC):
-	    parse_argvec(NEXT_ARG(va, const char **));
+	    parse_argvec(sp, NEXT_ARG(va, const char **));
 
 	    break;
 	default:
-	    args[num_args++] = arg;
+	    sp->args[sp->num_args++] = arg;
 	    break;
 	}
 
@@ -534,7 +536,7 @@
     }
 }
 
-static void parse_arglist(va_list va)
+static void parse_arglist(struct spawn *sp, va_list va)
 {
     for (;;) {
 	const char *arg = va_arg(va, const char *);
@@ -542,64 +544,64 @@
 
 	switch ((int)arg) {
 	case 0:
-	    args[num_args++] = NULL;
+	    sp->args[sp->num_args++] = NULL;
 	    break;
 	case ((int)SF_REDIRECT_FILE):
-	    redirects[num_redirects].dst_fd = va_arg(va, int);
+	    sp->redirects[sp->num_redirects].dst_fd = va_arg(va, int);
 
-	    redirects[num_redirects].src_fd = -1;
-	    redirects[num_redirects].mode = va_arg(va, int);
-	    redirects[num_redirects].file = va_arg(va, const char *);
+	    sp->redirects[sp->num_redirects].src_fd = -1;
+	    sp->redirects[sp->num_redirects].mode = va_arg(va, int);
+	    sp->redirects[sp->num_redirects].file = va_arg(va, const char *);
 
-	    num_redirects++;
+	    sp->num_redirects++;
 	    break;
 	case ((int)SF_REDIRECT_DESCRIPTOR):
-	    redirects[num_redirects].dst_fd = va_arg(va, int);
-	    redirects[num_redirects].src_fd = va_arg(va, int);
+	    sp->redirects[sp->num_redirects].dst_fd = va_arg(va, int);
+	    sp->redirects[sp->num_redirects].src_fd = va_arg(va, int);
 
-	    redirects[num_redirects].file = NULL;
-	    num_redirects++;
+	    sp->redirects[sp->num_redirects].file = NULL;
+	    sp->num_redirects++;
 	    break;
 	case ((int)SF_CLOSE_DESCRIPTOR):
-	    redirects[num_redirects].dst_fd = va_arg(va, int);
+	    sp->redirects[sp->num_redirects].dst_fd = va_arg(va, int);
 
-	    redirects[num_redirects].src_fd = -1;
-	    redirects[num_redirects].file = NULL;
-	    num_redirects++;
+	    sp->redirects[sp->num_redirects].src_fd = -1;
+	    sp->redirects[sp->num_redirects].file = NULL;
+	    sp->num_redirects++;
 	    break;
 	case ((int)SF_SIGNAL):
-	    signals[num_signals].which = va_arg(va, int);
-	    signals[num_signals].action = va_arg(va, int);
-	    signals[num_signals].signum = va_arg(va, int);
+	    sp->signals[sp->num_signals].which = va_arg(va, int);
+	    sp->signals[sp->num_signals].action = va_arg(va, int);
+	    sp->signals[sp->num_signals].signum = va_arg(va, int);
 
-	    signals[num_signals].valid = 0;
-	    num_signals++;
+	    sp->signals[sp->num_signals].valid = 0;
+	    sp->num_signals++;
 	    break;
 	case ((int)SF_VARIABLE):
 	    var = va_arg(va, char *);
 
 	    val = getenv(var);
-	    args[num_args++] = val ? val : "";
+	    sp->args[sp->num_args++] = val ? val : "";
 	    break;
 	case ((int)SF_BINDING):
-	    bindings[num_bindings].var = va_arg(va, const char *);
-	    bindings[num_bindings].val = va_arg(va, const char *);
+	    sp->bindings[sp->num_bindings].var = va_arg(va, const char *);
+	    sp->bindings[sp->num_bindings].val = va_arg(va, const char *);
 
-	    num_bindings++;
+	    sp->num_bindings++;
 	    break;
 	case ((int)SF_BACKGROUND):
-	    background = 1;
+	    sp->background = 1;
 	    break;
 	case ((int)SF_DIRECTORY):
-	    directory = va_arg(va, const char *);
+	    sp->directory = va_arg(va, const char *);
 
 	    break;
 	case ((int)SF_ARGVEC):
-	    parse_argvec(va_arg(va, const char **));
+	    parse_argvec(sp, va_arg(va, const char **));
 
 	    break;
 	default:
-	    args[num_args++] = arg;
+	    sp->args[sp->num_args++] = arg;
 	    break;
 	}
 
@@ -620,11 +622,13 @@
  */
 int G_vspawn_ex(const char *command, const char **args)
 {
-    begin_spawn();
+    struct spawn sp;
 
-    parse_argvec(args);
+    begin_spawn(&sp);
 
-    return do_spawn(command);
+    parse_argvec(&sp, args);
+
+    return do_spawn(&sp, command);
 }
 
 /**
@@ -639,13 +643,14 @@
 
 int G_spawn_ex(const char *command, ...)
 {
+    struct spawn sp;
     va_list va;
 
-    begin_spawn();
+    begin_spawn(&sp);
 
     va_start(va, command);
-    parse_arglist(va);
+    parse_arglist(&sp, va);
     va_end(va);
 
-    return do_spawn(command);
+    return do_spawn(&sp, command);
 }

Modified: grass/trunk/lib/gis/view.c
===================================================================
--- grass/trunk/lib/gis/view.c	2008-11-22 21:52:25 UTC (rev 34444)
+++ grass/trunk/lib/gis/view.c	2008-11-23 01:41:03 UTC (rev 34445)
@@ -29,8 +29,9 @@
 static void edge_sort(float sides[4]);
 static int read_old_format(struct G_3dview *, FILE *);
 
-static int vers_major = 4;
-static int vers_minor = 1;
+static const int vers_major = 4;
+static const int vers_minor = 1;
+
 static int Suppress_warn = 0;
 
 



More information about the grass-commit mailing list