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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 25 12:14:57 EST 2008


Author: glynn
Date: 2008-11-25 12:14:57 -0500 (Tue, 25 Nov 2008)
New Revision: 34485

Added:
   grass/trunk/lib/gis/counter.c
Modified:
   grass/trunk/include/gis.h
   grass/trunk/include/gisdefs.h
   grass/trunk/lib/gis/error.c
   grass/trunk/lib/gis/gisinit.c
   grass/trunk/lib/gis/tempfile.c
Log:
Add, use "struct Counter" and supporting functions
Add G_init_all()


Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h	2008-11-25 06:26:49 UTC (rev 34484)
+++ grass/trunk/include/gis.h	2008-11-25 17:14:57 UTC (rev 34485)
@@ -636,6 +636,10 @@
 
 struct GDAL_link;
 
+struct Counter {
+    int value;
+};
+
 /*============================== Prototypes ================================*/
 
 /* Since there are so many prototypes for the gis library they are stored */

Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h	2008-11-25 06:26:49 UTC (rev 34484)
+++ grass/trunk/include/gisdefs.h	2008-11-25 17:14:57 UTC (rev 34485)
@@ -387,6 +387,10 @@
 /* copy_file.c */
 int G_copy_file(const char *, const char *);
 
+/* counter.c */
+void G_init_counter(struct Counter *, int);
+int G_counter_next(struct Counter *);
+
 /* dalloc.c */
 double *G_alloc_vector(size_t);
 double **G_alloc_matrix(int, int);
@@ -609,6 +613,7 @@
 void G__gisinit(const char *, const char *);
 void G__no_gisinit(const char *);
 void G__check_gisinit(void);
+void G_init_all(void);
 
 /* histo_eq.c */
 void G_histogram_eq(const struct Histogram *, unsigned char **,
@@ -1100,6 +1105,7 @@
 int G_system(const char *);
 
 /* tempfile.c */
+void G_init_tempfile(void);
 char *G_tempfile(void);
 char *G__tempfile(int);
 void G__temp_element(char *);

Added: grass/trunk/lib/gis/counter.c
===================================================================
--- grass/trunk/lib/gis/counter.c	                        (rev 0)
+++ grass/trunk/lib/gis/counter.c	2008-11-25 17:14:57 UTC (rev 34485)
@@ -0,0 +1,12 @@
+#include <grass/gis.h>
+
+void G_init_counter(struct Counter *c, int v)
+{
+    c->value = v;
+}
+
+int G_counter_next(struct Counter *c)
+{
+    return c->value++;
+}
+

Modified: grass/trunk/lib/gis/error.c
===================================================================
--- grass/trunk/lib/gis/error.c	2008-11-25 06:26:49 UTC (rev 34484)
+++ grass/trunk/lib/gis/error.c	2008-11-25 17:14:57 UTC (rev 34485)
@@ -46,12 +46,11 @@
 static int no_warn = 0;
 static int no_sleep = 1;
 
-static int grass_info_format = -1;
+static int grass_info_format;
 static char *logfile;
 static char *prefix_std[3];
+static struct Counter message_id;
 
-static int message_id = 1;
-
 static int print_word(FILE *, char **, int *, const int);
 static void print_sentence(FILE *, const int, const char *);
 static void print_error(const char *, const int);
@@ -312,6 +311,8 @@
     if (initialized)
 	return;
 
+    G_init_counter(&message_id, 1);
+
     prefix_std[0] = "";
     prefix_std[1] = _("WARNING: ");
     prefix_std[2] = _("ERROR: ");
@@ -446,16 +447,17 @@
 {
     char prefix[100];
     const char *start;
+    int id = G_counter_next(&message_id);
 
     switch (type) {
     case MSG:
-	sprintf(prefix, "GRASS_INFO_MESSAGE(%d,%d): ", getpid(), message_id);
+	sprintf(prefix, "GRASS_INFO_MESSAGE(%d,%d): ", getpid(), id);
 	break;
     case WARN:
-	sprintf(prefix, "GRASS_INFO_WARNING(%d,%d): ", getpid(), message_id);
+	sprintf(prefix, "GRASS_INFO_WARNING(%d,%d): ", getpid(), id);
 	break;
     case ERR:
-	sprintf(prefix, "GRASS_INFO_ERROR(%d,%d): ", getpid(), message_id);
+	sprintf(prefix, "GRASS_INFO_ERROR(%d,%d): ", getpid(), id);
 	break;
     }
 
@@ -480,8 +482,7 @@
 	fprintf(fd, "\n");
 	start = next;
     }
-    fprintf(stderr, "GRASS_INFO_END(%d,%d)\n", getpid(), message_id);
-    message_id++;
+    fprintf(stderr, "GRASS_INFO_END(%d,%d)\n", getpid(), id);
 }
 
 /*!

Modified: grass/trunk/lib/gis/gisinit.c
===================================================================
--- grass/trunk/lib/gis/gisinit.c	2008-11-25 06:26:49 UTC (rev 34484)
+++ grass/trunk/lib/gis/gisinit.c	2008-11-25 17:14:57 UTC (rev 34485)
@@ -129,3 +129,26 @@
 
     return 0;
 }
+
+void G_init_all(void)
+{
+    G__check_gisinit();
+    G_init_env();
+    G_init_logging();
+    G__init_window();
+    G_get_fp_type();
+    G_get_compression_type();
+    G__check_for_auto_masking();
+    G_init_locale();
+    G_init_debug();
+    G_verbose();
+    G_init_tempfile();
+    G_init_gdal();
+    G_get_list_of_mapsets();
+    G__home();
+    G__machine_name();
+    G_whoami();
+    G_read_datum_table();
+    G_read_ellipsoid_table(0);
+}
+

Modified: grass/trunk/lib/gis/tempfile.c
===================================================================
--- grass/trunk/lib/gis/tempfile.c	2008-11-25 06:26:49 UTC (rev 34484)
+++ grass/trunk/lib/gis/tempfile.c	2008-11-25 17:14:57 UTC (rev 34485)
@@ -19,7 +19,19 @@
 #include <sys/stat.h>
 #include <grass/gis.h>
 
+static struct Counter unique;
+static int initialized;
 
+void G_init_tempfile(void)
+{
+    if (initialized)
+	return;
+
+    G_init_counter(&unique, 0);
+
+    initialized = 1;
+}
+
 /**
  * \brief Returns a temporary file name.
  *
@@ -49,7 +61,6 @@
     return G__tempfile(getpid());
 }
 
-
 /**
  * \brief Create tempfile from process id.
  *
@@ -64,14 +75,15 @@
     char path[GPATH_MAX];
     char name[GNAME_MAX];
     char element[100];
-    static int uniq = 0;
     struct stat st;
 
     if (pid <= 0)
 	pid = getpid();
     G__temp_element(element);
+    G_init_tempfile();
     do {
-	sprintf(name, "%d.%d", pid, uniq++);
+	int uniq = G_counter_next(&unique);
+	sprintf(name, "%d.%d", pid, uniq);
 	G__file_name(path, element, name, G_mapset());
     }
     while (stat(path, &st) == 0);



More information about the grass-commit mailing list