[GRASS-SVN] r33012 - in grass/trunk/lib: cairodriver htmldriver pngdriver psdriver

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 22 19:34:16 EDT 2008


Author: glynn
Date: 2008-08-22 19:34:16 -0400 (Fri, 22 Aug 2008)
New Revision: 33012

Modified:
   grass/trunk/lib/cairodriver/Box.c
   grass/trunk/lib/cairodriver/Draw_bitmap.c
   grass/trunk/lib/cairodriver/Draw_line.c
   grass/trunk/lib/cairodriver/Draw_point.c
   grass/trunk/lib/cairodriver/Erase.c
   grass/trunk/lib/cairodriver/Graph.c
   grass/trunk/lib/cairodriver/Poly.c
   grass/trunk/lib/cairodriver/Raster.c
   grass/trunk/lib/cairodriver/Respond.c
   grass/trunk/lib/cairodriver/Text.c
   grass/trunk/lib/cairodriver/cairodriver.h
   grass/trunk/lib/cairodriver/read.c
   grass/trunk/lib/cairodriver/read_bmp.c
   grass/trunk/lib/cairodriver/read_ppm.c
   grass/trunk/lib/cairodriver/write.c
   grass/trunk/lib/cairodriver/write_bmp.c
   grass/trunk/lib/cairodriver/write_ppm.c
   grass/trunk/lib/htmldriver/Graph_Clse.c
   grass/trunk/lib/htmldriver/Graph_Set.c
   grass/trunk/lib/htmldriver/Polygon.c
   grass/trunk/lib/htmldriver/Text.c
   grass/trunk/lib/htmldriver/htmlmap.h
   grass/trunk/lib/pngdriver/Box.c
   grass/trunk/lib/pngdriver/Color.c
   grass/trunk/lib/pngdriver/Color_table.c
   grass/trunk/lib/pngdriver/Draw_bitmap.c
   grass/trunk/lib/pngdriver/Draw_line.c
   grass/trunk/lib/pngdriver/Draw_point.c
   grass/trunk/lib/pngdriver/Erase.c
   grass/trunk/lib/pngdriver/Graph_close.c
   grass/trunk/lib/pngdriver/Graph_set.c
   grass/trunk/lib/pngdriver/Polygon.c
   grass/trunk/lib/pngdriver/Raster.c
   grass/trunk/lib/pngdriver/Respond.c
   grass/trunk/lib/pngdriver/Set_window.c
   grass/trunk/lib/pngdriver/pngdriver.h
   grass/trunk/lib/pngdriver/read.c
   grass/trunk/lib/pngdriver/read_bmp.c
   grass/trunk/lib/pngdriver/read_png.c
   grass/trunk/lib/pngdriver/read_ppm.c
   grass/trunk/lib/pngdriver/write.c
   grass/trunk/lib/pngdriver/write_bmp.c
   grass/trunk/lib/pngdriver/write_png.c
   grass/trunk/lib/pngdriver/write_ppm.c
   grass/trunk/lib/psdriver/Color.c
   grass/trunk/lib/psdriver/Color_table.c
   grass/trunk/lib/psdriver/Erase.c
   grass/trunk/lib/psdriver/Graph_close.c
   grass/trunk/lib/psdriver/Graph_set.c
   grass/trunk/lib/psdriver/Raster.c
   grass/trunk/lib/psdriver/Respond.c
   grass/trunk/lib/psdriver/Set_window.c
   grass/trunk/lib/psdriver/psdriver.h
Log:
Wrap local variables in per-driver structures to prevent name conflicts


Modified: grass/trunk/lib/cairodriver/Box.c
===================================================================
--- grass/trunk/lib/cairodriver/Box.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/Box.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -8,5 +8,5 @@
 
     cairo_rectangle(cairo, x1, y1, x2 - x1, y2 - y1);
     cairo_fill(cairo);
-    modified = 1;
+    ca.modified = 1;
 }

Modified: grass/trunk/lib/cairodriver/Draw_bitmap.c
===================================================================
--- grass/trunk/lib/cairodriver/Draw_bitmap.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/Draw_bitmap.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -43,5 +43,5 @@
     cairo_mask_surface(cairo, surf, cur_x, cur_y);
 
     cairo_surface_destroy(surf);
-    modified = 1;
+    ca.modified = 1;
 }

Modified: grass/trunk/lib/cairodriver/Draw_line.c
===================================================================
--- grass/trunk/lib/cairodriver/Draw_line.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/Draw_line.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -13,5 +13,5 @@
     cairo_move_to(cairo, x1, y1);
     cairo_line_to(cairo, x2, y2);
     cairo_stroke(cairo);
-    modified = 1;
+    ca.modified = 1;
 }

Modified: grass/trunk/lib/cairodriver/Draw_point.c
===================================================================
--- grass/trunk/lib/cairodriver/Draw_point.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/Draw_point.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -11,5 +11,5 @@
 		    x - HALFPOINTSIZE, y - HALFPOINTSIZE,
 		    POINTSIZE, POINTSIZE);
     cairo_fill(cairo);
-    modified = 1;
+    ca.modified = 1;
 }

Modified: grass/trunk/lib/cairodriver/Erase.c
===================================================================
--- grass/trunk/lib/cairodriver/Erase.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/Erase.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -5,10 +5,10 @@
     G_debug(1, "Cairo_Erase");
 
     cairo_save(cairo);
-    cairo_set_source_rgba(cairo, bgcolor_r, bgcolor_g, bgcolor_b, bgcolor_a);
+    cairo_set_source_rgba(cairo, ca.bgcolor_r, ca.bgcolor_g, ca.bgcolor_b, ca.bgcolor_a);
     cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
     cairo_paint(cairo);
     cairo_restore(cairo);
 
-    modified = 1;
+    ca.modified = 1;
 }

Modified: grass/trunk/lib/cairodriver/Graph.c
===================================================================
--- grass/trunk/lib/cairodriver/Graph.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/Graph.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -20,23 +20,11 @@
 #include <X11/Xutil.h>
 #endif
 
-/* globals */
-char *file_name;
-int file_type;
-int is_vector;
-int width, height, stride;
-unsigned char *grid;
-int modified;
-int auto_write;
-int mapped;
+struct cairo_state ca;
 
-/* background color */
-double bgcolor_r, bgcolor_g, bgcolor_b, bgcolor_a;
-
 /* cairo objects */
 cairo_surface_t *surface;
 cairo_t *cairo;
-cairo_antialias_t antialias;
 
 static void init_cairo(void);
 static int ends_with(const char *string, const char *suffix);
@@ -88,59 +76,60 @@
 
     cairo = cairo_create(surface);
 
-    file_name = "<X11>";
+    ca.file_name = "<X11>";
     file_type = FTYPE_X11;
 
-    screen_right = screen_left + width;
-    screen_bottom = screen_top + height;
+    screen_right = screen_left + ca.width;
+    screen_bottom = screen_top + ca.height;
 #endif
 }
 
 static void init_file(void)
 {
+    int is_vector;
     int do_read = 0;
     int do_map = 0;
     char *p;
 
     /* set image properties */
-    width = screen_width;
-    height = screen_height;
-    stride = width * 4;
+    ca.width = screen_width;
+    ca.height = screen_height;
+    ca.stride = ca.width * 4;
 
     /* get file name */
     p = getenv("GRASS_PNGFILE");
     if (!p || strlen(p) == 0)
 	p = DEFAULT_FILE_NAME;
 
-    file_name = p;
+    ca.file_name = p;
 
     /* get file type (from extension) */
-    if (file_type == FTYPE_X11) ;	/* skip */
-    else if (ends_with(file_name, ".ppm"))
-	file_type = FTYPE_PPM;
-    else if (ends_with(file_name, ".bmp"))
-	file_type = FTYPE_BMP;
+    if (ca.file_type == FTYPE_X11) ;	/* skip */
+    else if (ends_with(ca.file_name, ".ppm"))
+	ca.file_type = FTYPE_PPM;
+    else if (ends_with(ca.file_name, ".bmp"))
+	ca.file_type = FTYPE_BMP;
 #if CAIRO_HAS_PNG_FUNCTIONS
-    else if (ends_with(file_name, ".png"))
-	file_type = FTYPE_PNG;
+    else if (ends_with(ca.file_name, ".png"))
+	ca.file_type = FTYPE_PNG;
 #endif
 #if CAIRO_HAS_PDF_SURFACE
-    else if (ends_with(file_name, ".pdf"))
-	file_type = FTYPE_PDF;
+    else if (ends_with(ca.file_name, ".pdf"))
+	ca.file_type = FTYPE_PDF;
 #endif
 #if CAIRO_HAS_PS_SURFACE
-    else if (ends_with(file_name, ".ps"))
-	file_type = FTYPE_PS;
+    else if (ends_with(ca.file_name, ".ps"))
+	ca.file_type = FTYPE_PS;
 #endif
 #if CAIRO_HAS_SVG_SURFACE
-    else if (ends_with(file_name, ".svg"))
-	file_type = FTYPE_SVG;
+    else if (ends_with(ca.file_name, ".svg"))
+	ca.file_type = FTYPE_SVG;
 #endif
     else
 	G_fatal_error("Unknown file extension: %s", p);
-    G_debug(1, "File type: %s (%d)", file_name, file_type);
+    G_debug(1, "File type: %s (%d)", ca.file_name, ca.file_type);
 
-    switch (file_type) {
+    switch (ca.file_type) {
     case FTYPE_PDF:
     case FTYPE_PS:
     case FTYPE_SVG:
@@ -149,40 +138,40 @@
     }
 
     p = getenv("GRASS_PNG_MAPPED");
-    do_map = p && strcmp(p, "TRUE") == 0 && ends_with(file_name, ".bmp");
+    do_map = p && strcmp(p, "TRUE") == 0 && ends_with(ca.file_name, ".bmp");
 
     p = getenv("GRASS_PNG_READ");
     do_read = p && strcmp(p, "TRUE") == 0;
 
     if (is_vector) {
 	do_read = do_map = 0;
-	bgcolor_a = 1.0;
+	ca.bgcolor_a = 1.0;
     }
 
-    if (do_read && access(file_name, 0) != 0)
+    if (do_read && access(ca.file_name, 0) != 0)
 	do_read = 0;
 
     G_message
 	("cairo: collecting to file: %s,\n     GRASS_WIDTH=%d, GRASS_HEIGHT=%d",
-	 file_name, width, height);
+	 ca.file_name, ca.width, ca.height);
 
     if (do_read && do_map)
 	map_file();
 
-    if (!mapped && !is_vector)
-	grid = G_malloc(height * stride);
+    if (!ca.mapped && !is_vector)
+	ca.grid = G_malloc(ca.height * ca.stride);
 
     init_cairo();
 
     if (!do_read && !is_vector) {
 	Cairo_Erase();
-	modified = 1;
+	ca.modified = 1;
     }
 
-    if (do_read && !mapped)
+    if (do_read && !ca.mapped)
 	cairo_read_image();
 
-    if (do_map && !mapped) {
+    if (do_map && !ca.mapped) {
 	cairo_write_image();
 	map_file();
 	init_cairo();
@@ -191,6 +180,7 @@
 
 int Cairo_Graph_set(void)
 {
+    cairo_antialias_t antialias;
     char *p;
 
     G_gisinit("Cairo driver");
@@ -202,25 +192,25 @@
 	unsigned int red, green, blue;
 
 	if (sscanf(p, "%02x%02x%02x", &red, &green, &blue) == 3) {
-	    bgcolor_r = CAIROCOLOR(red);
-	    bgcolor_g = CAIROCOLOR(green);
-	    bgcolor_b = CAIROCOLOR(blue);
+	    ca.bgcolor_r = CAIROCOLOR(red);
+	    ca.bgcolor_g = CAIROCOLOR(green);
+	    ca.bgcolor_b = CAIROCOLOR(blue);
 	}
 	else
 	    G_fatal_error("Unknown background color: %s", p);
     }
     else
-	bgcolor_r = bgcolor_g = bgcolor_b = 1.0;
+	ca.bgcolor_r = ca.bgcolor_g = ca.bgcolor_b = 1.0;
 
     /* get background transparency setting */
     p = getenv("GRASS_TRANSPARENT");
     if (p && strcmp(p, "TRUE") == 0)
-	bgcolor_a = 0.0;
+	ca.bgcolor_a = 0.0;
     else
-	bgcolor_a = 1.0;
+	ca.bgcolor_a = 1.0;
 
     p = getenv("GRASS_PNG_AUTO_WRITE");
-    auto_write = p && strcmp(p, "TRUE") == 0;
+    ca.auto_write = p && strcmp(p, "TRUE") == 0;
 
     antialias = CAIRO_ANTIALIAS_DEFAULT;
     p = getenv("GRASS_ANTIALIAS");
@@ -265,33 +255,33 @@
     G_debug(1, "init_cairo");
 
     /* create cairo surface */
-    switch (file_type) {
+    switch (ca.file_type) {
     case FTYPE_PPM:
     case FTYPE_BMP:
     case FTYPE_PNG:
 	surface =
 	    (cairo_surface_t *) cairo_image_surface_create_for_data(
-		grid, CAIRO_FORMAT_ARGB32, width, height, stride);
+		ca.grid, CAIRO_FORMAT_ARGB32, ca.width, ca.height, ca.stride);
 	break;
 #if CAIRO_HAS_PDF_SURFACE
     case FTYPE_PDF:
 	surface =
 	    (cairo_surface_t *) cairo_pdf_surface_create(
-		file_name, (double) width, (double) height);
+		ca.file_name, (double) ca.width, (double) ca.height);
 	break;
 #endif
 #if CAIRO_HAS_PS_SURFACE
     case FTYPE_PS:
 	surface =
 	    (cairo_surface_t *) cairo_ps_surface_create(
-		file_name, (double) width, (double) height);
+		ca.file_name, (double) ca.width, (double) ca.height);
 	break;
 #endif
 #if CAIRO_HAS_SVG_SURFACE
     case FTYPE_SVG:
 	surface =
 	    (cairo_surface_t *) cairo_svg_surface_create(
-		file_name, (double) width, (double) height);
+		ca.file_name, (double) ca.width, (double) ca.height);
 	break;
 #endif
     default:
@@ -318,11 +308,11 @@
 static void map_file(void)
 {
 #ifndef __MINGW32__
-    size_t size = HEADER_SIZE + width * height * sizeof(unsigned int);
+    size_t size = HEADER_SIZE + ca.width * ca.height * sizeof(unsigned int);
     void *ptr;
     int fd;
 
-    fd = open(file_name, O_RDWR);
+    fd = open(ca.file_name, O_RDWR);
     if (fd < 0)
 	return;
 
@@ -330,15 +320,15 @@
     if (ptr == MAP_FAILED)
 	return;
 
-    if (grid) {
+    if (ca.grid) {
 	cairo_destroy(cairo);
 	cairo_surface_destroy(surface);
-	G_free(grid);
+	G_free(ca.grid);
     }
-    grid = (char *)ptr + HEADER_SIZE;
+    ca.grid = (char *)ptr + HEADER_SIZE;
 
     close(fd);
 
-    mapped = 1;
+    ca.mapped = 1;
 #endif
 }

Modified: grass/trunk/lib/cairodriver/Poly.c
===================================================================
--- grass/trunk/lib/cairodriver/Poly.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/Poly.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -14,7 +14,7 @@
     G_debug(3, "Cairo_Polygon (%d points)", count);
     do_polygon(xarray, yarray, count);
     cairo_fill(cairo);
-    modified = 1;
+    ca.modified = 1;
 }
 
 void Cairo_Polyline(const double *xarray, const double *yarray, int count)
@@ -22,7 +22,7 @@
     G_debug(3, "Cairo_Polyline (%d points)", count);
     do_polygon(xarray, yarray, count);
     cairo_stroke(cairo);
-    modified = 1;
+    ca.modified = 1;
 }
 
 void Cairo_Polydots(const double *xarray, const double *yarray, int count)
@@ -32,6 +32,6 @@
     G_debug(3, "Cairo_Polydots (%d points)", count);
     for (i = 1; i < count; i++)
 	Cairo_draw_point(xarray[0], yarray[0]);
-    modified = 1;
+    ca.modified = 1;
 }
 

Modified: grass/trunk/lib/cairodriver/Raster.c
===================================================================
--- grass/trunk/lib/cairodriver/Raster.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/Raster.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -85,5 +85,5 @@
 
     /* cleanup */
     cairo_surface_destroy(src_surf);
-    modified = 1;
+    ca.modified = 1;
 }

Modified: grass/trunk/lib/cairodriver/Respond.c
===================================================================
--- grass/trunk/lib/cairodriver/Respond.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/Respond.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -3,6 +3,6 @@
 
 void Cairo_Respond(void)
 {
-    if (auto_write)
+    if (ca.auto_write)
 	cairo_write_image();
 }

Modified: grass/trunk/lib/cairodriver/Text.c
===================================================================
--- grass/trunk/lib/cairodriver/Text.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/Text.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -95,7 +95,7 @@
 
     G_free(utf8);
 
-    modified = 1;
+    ca.modified = 1;
 }
 
 void Cairo_text_box(const char *str, double *t, double *b, double *l, double *r)

Modified: grass/trunk/lib/cairodriver/cairodriver.h
===================================================================
--- grass/trunk/lib/cairodriver/cairodriver.h	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/cairodriver.h	2008-08-22 23:34:16 UTC (rev 33012)
@@ -34,17 +34,19 @@
 extern cairo_surface_t *surface;
 extern cairo_t *cairo;
 
-extern char *file_name;
-extern int file_type;
-extern int width, height, stride;
-extern unsigned char *grid;
-extern double clip_left, clip_right, clip_top, clip_bottom;
-extern int auto_write;
-extern double bgcolor_r, bgcolor_g, bgcolor_b, bgcolor_a;
-extern int modified;
-extern int auto_write;
-extern int mapped;
+struct cairo_state {
+    char *file_name;
+    int file_type;
+    int width, height, stride;
+    unsigned char *grid;
+    int auto_write;
+    double bgcolor_r, bgcolor_g, bgcolor_b, bgcolor_a;
+    int modified;
+    int mapped;
+};
 
+extern struct cairo_state ca;
+
 extern const struct driver *Cairo_Driver(void);
 
 extern void Cairo_Client_Close(void);

Modified: grass/trunk/lib/cairodriver/read.c
===================================================================
--- grass/trunk/lib/cairodriver/read.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/read.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -7,21 +7,21 @@
     if (!cairo || !surface)
 	return;
 
-    if (file_type == FTYPE_PPM) {
-	G_debug(1, "Reading image from %s", file_name);
+    if (ca.file_type == FTYPE_PPM) {
+	G_debug(1, "Reading image from %s", ca.file_name);
 	cairo_read_ppm();
     }
-    else if (file_type == FTYPE_BMP) {
-	G_debug(1, "Reading image from %s", file_name);
+    else if (ca.file_type == FTYPE_BMP) {
+	G_debug(1, "Reading image from %s", ca.file_name);
 	cairo_read_bmp();
     }
 #if CAIRO_HAS_PNG_FUNCTIONS
-    else if (file_type == FTYPE_PNG) {
+    else if (ca.file_type == FTYPE_PNG) {
 	cairo_surface_t *img_surf;
 
-	G_debug(1, "Reading image from %s", file_name);
+	G_debug(1, "Reading image from %s", ca.file_name);
 
-	img_surf = cairo_image_surface_create_from_png(file_name);
+	img_surf = cairo_image_surface_create_from_png(ca.file_name);
 	if (!img_surf)
 	    return;
 
@@ -35,5 +35,5 @@
 #endif
     /* vector format files are written directly to file */
 
-    modified = 0;
+    ca.modified = 0;
 }

Modified: grass/trunk/lib/cairodriver/read_bmp.c
===================================================================
--- grass/trunk/lib/cairodriver/read_bmp.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/read_bmp.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -31,7 +31,7 @@
     if (*p++ != 'M')
 	return 0;
 
-    if (get_4(&p) != HEADER_SIZE + width * height * 4)
+    if (get_4(&p) != HEADER_SIZE + ca.width * ca.height * 4)
 	return 0;
 
     get_4(&p);
@@ -42,9 +42,9 @@
     if (get_4(&p) != 40)
 	return 0;
 
-    if (get_4(&p) != width)
+    if (get_4(&p) != ca.width)
 	return 0;
-    if (get_4(&p) != -height)
+    if (get_4(&p) != -ca.height)
 	return 0;
 
     get_2(&p);
@@ -53,7 +53,7 @@
 
     if (get_4(&p) != 0)
 	return 0;
-    if (get_4(&p) != width * height * 4)
+    if (get_4(&p) != ca.width * ca.height * 4)
 	return 0;
 
     get_4(&p);
@@ -69,17 +69,17 @@
     char header[HEADER_SIZE];
     FILE *input;
 
-    input = fopen(file_name, "rb");
+    input = fopen(ca.file_name, "rb");
     if (!input)
-	G_fatal_error("cairo:: couldn't open input file %s", file_name);
+	G_fatal_error("cairo:: couldn't open input file %s", ca.file_name);
 
     if (fread(header, sizeof(header), 1, input) != 1)
-	G_fatal_error("cairo:: invalid input file %s", file_name);
+	G_fatal_error("cairo:: invalid input file %s", ca.file_name);
 
     if (!read_bmp_header(header))
-	G_fatal_error("cairo:: invalid BMP header for %s", file_name);
+	G_fatal_error("cairo:: invalid BMP header for %s", ca.file_name);
 
-    fread(grid, stride, height, input);
+    fread(ca.grid, ca.stride, ca.height, input);
 
     fclose(input);
 }

Modified: grass/trunk/lib/cairodriver/read_ppm.c
===================================================================
--- grass/trunk/lib/cairodriver/read_ppm.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/read_ppm.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -2,24 +2,24 @@
 
 void cairo_read_ppm(void)
 {
-    char *mask_name = G_store(file_name);
+    char *mask_name = G_store(ca.file_name);
     FILE *input, *mask;
     int x, y;
     int i_width, i_height, maxval;
 
-    input = fopen(file_name, "rb");
+    input = fopen(ca.file_name, "rb");
     if (!input)
-	G_fatal_error("cairo: couldn't open input file %s", file_name);
+	G_fatal_error("cairo: couldn't open input file %s", ca.file_name);
 
     if (fscanf(input, "P6 %d %d %d", &i_width, &i_height, &maxval) != 3)
-	G_fatal_error("cairo: invalid input file %s", file_name);
+	G_fatal_error("cairo: invalid input file %s", ca.file_name);
 
     fgetc(input);
 
-    if (i_width != width || i_height != height)
+    if (i_width != ca.width || i_height != ca.height)
 	G_fatal_error
 	    ("cairo: input file has incorrect dimensions: expected: %dx%d got: %dx%d",
-	     width, height, i_width, i_height);
+	     ca.width, ca.height, i_width, i_height);
 
     mask_name[strlen(mask_name) - 2] = 'g';
 
@@ -32,17 +32,17 @@
 
     fgetc(input);
 
-    if (i_width != width || i_height != height)
+    if (i_width != ca.width || i_height != ca.height)
 	G_fatal_error
 	    ("cairo: input mask file has incorrect dimensions: expected: %dx%d got: %dx%d",
-	     width, height, i_width, i_height);
+	     ca.width, ca.height, i_width, i_height);
 
     G_free(mask_name);
 
-    for (y = 0; y < height; y++) {
-	unsigned int *row = (unsigned int *)(grid + y * stride);
+    for (y = 0; y < ca.height; y++) {
+	unsigned int *row = (unsigned int *)(ca.grid + y * ca.stride);
 
-	for (x = 0; x < width; x++) {
+	for (x = 0; x < ca.width; x++) {
 	    int r = fgetc(input);
 	    int g = fgetc(input);
 	    int b = fgetc(input);

Modified: grass/trunk/lib/cairodriver/write.c
===================================================================
--- grass/trunk/lib/cairodriver/write.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/write.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -9,35 +9,35 @@
 {
     G_debug(1, "write_image");
 
-    if (!modified)
+    if (!ca.modified)
 	return;
 
-    if (mapped)
+    if (ca.mapped)
 	return;
 
     if (!cairo || !surface)
 	return;
 
-    if (file_type == FTYPE_PPM) {
-	G_debug(1, "Writing image to %s", file_name);
+    if (ca.file_type == FTYPE_PPM) {
+	G_debug(1, "Writing image to %s", ca.file_name);
 	cairo_write_ppm();
     }
-    else if (file_type == FTYPE_BMP) {
-	G_debug(1, "Writing image to %s", file_name);
+    else if (ca.file_type == FTYPE_BMP) {
+	G_debug(1, "Writing image to %s", ca.file_name);
 	cairo_write_bmp();
     }
 #if CAIRO_HAS_PNG_FUNCTIONS
-    else if (file_type == FTYPE_PNG) {
-	G_debug(1, "Writing image to %s", file_name);
-	cairo_surface_write_to_png(surface, file_name);
+    else if (ca.file_type == FTYPE_PNG) {
+	G_debug(1, "Writing image to %s", ca.file_name);
+	cairo_surface_write_to_png(surface, ca.file_name);
     }
 #endif
 #if CAIRO_HAS_XLIB_SURFACE
-    else if (file_type == FTYPE_X11) {
+    else if (ca.file_type == FTYPE_X11) {
 	XFlush(cairo_xlib_surface_get_display(surface));
     }
 #endif
     /* vector format files are written directly to file */
 
-    modified = 0;
+    ca.modified = 0;
 }

Modified: grass/trunk/lib/cairodriver/write_bmp.c
===================================================================
--- grass/trunk/lib/cairodriver/write_bmp.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/write_bmp.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -31,17 +31,17 @@
     *p++ = 'B';
     *p++ = 'M';
 
-    p = put_4(p, HEADER_SIZE + width * height * 4);
+    p = put_4(p, HEADER_SIZE + ca.width * ca.height * 4);
     p = put_4(p, 0);
     p = put_4(p, HEADER_SIZE);
 
     p = put_4(p, 40);
-    p = put_4(p, width);
-    p = put_4(p, -height);
+    p = put_4(p, ca.width);
+    p = put_4(p, -ca.height);
     p = put_2(p, 1);
     p = put_2(p, 32);
     p = put_4(p, 0);
-    p = put_4(p, width * height * 4);
+    p = put_4(p, ca.width * ca.height * 4);
     p = put_4(p, 0);
     p = put_4(p, 0);
     p = put_4(p, 0);
@@ -53,14 +53,14 @@
     char header[HEADER_SIZE];
     FILE *output;
 
-    output = fopen(file_name, "wb");
+    output = fopen(ca.file_name, "wb");
     if (!output)
-	G_fatal_error("cairo: couldn't open output file %s", file_name);
+	G_fatal_error("cairo: couldn't open output file %s", ca.file_name);
 
     make_bmp_header(header);
     fwrite(header, sizeof(header), 1, output);
 
-    fwrite(grid, stride, height, output);
+    fwrite(ca.grid, ca.stride, ca.height, output);
 
     fclose(output);
 }

Modified: grass/trunk/lib/cairodriver/write_ppm.c
===================================================================
--- grass/trunk/lib/cairodriver/write_ppm.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/cairodriver/write_ppm.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -2,13 +2,13 @@
 
 void cairo_write_ppm(void)
 {
-    char *mask_name = G_store(file_name);
+    char *mask_name = G_store(ca.file_name);
     FILE *output, *mask;
     int x, y;
 
-    output = fopen(file_name, "wb");
+    output = fopen(ca.file_name, "wb");
     if (!output)
-	G_fatal_error("cairo: couldn't open output file %s", file_name);
+	G_fatal_error("cairo: couldn't open output file %s", ca.file_name);
 
     mask_name[strlen(mask_name) - 2] = 'g';
 
@@ -18,13 +18,13 @@
 
     G_free(mask_name);
 
-    fprintf(output, "P6\n%d %d\n255\n", width, height);
-    fprintf(mask, "P5\n%d %d\n255\n", width, height);
+    fprintf(output, "P6\n%d %d\n255\n", ca.width, ca.height);
+    fprintf(mask, "P5\n%d %d\n255\n", ca.width, ca.height);
 
-    for (y = 0; y < height; y++) {
-	const unsigned int *row = (const unsigned int *)(grid + y * stride);
+    for (y = 0; y < ca.height; y++) {
+	const unsigned int *row = (const unsigned int *)(ca.grid + y * ca.stride);
 
-	for (x = 0; x < width; x++) {
+	for (x = 0; x < ca.width; x++) {
 	    unsigned int c = row[x];
 	    int a = (c >> 24) & 0xFF;
 	    int r = (c >> 16) & 0xFF;

Modified: grass/trunk/lib/htmldriver/Graph_Clse.c
===================================================================
--- grass/trunk/lib/htmldriver/Graph_Clse.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/htmldriver/Graph_Clse.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -42,9 +42,9 @@
      *
      */
 
-    for (poly = head; poly != NULL; poly = poly->next_poly) {
+    for (poly = html.head; poly != NULL; poly = poly->next_poly) {
 
-	for (test_poly = head; test_poly != NULL;
+	for (test_poly = html.head; test_poly != NULL;
 	     test_poly = test_poly->next_poly) {
 	    if (poly == test_poly) {
 		continue;	/* don't check ourselves */
@@ -69,17 +69,17 @@
      * write any beginning prologue appropriate for the map type
      */
 
-    switch (html_type) {
+    switch (html.type) {
 
     case APACHE:
-	fprintf(output, "#base _base_\n#default _default_\n");
+	fprintf(html.output, "#base _base_\n#default _default_\n");
 	break;
 
     case RAW:
 	break;
 
     case CLIENT:
-	fprintf(output, "<MAP NAME=\"map\">\n");
+	fprintf(html.output, "<MAP NAME=\"map\">\n");
 	break;
     }
 
@@ -87,45 +87,45 @@
      * write the polygons in a specific format
      */
 
-    for (poly = head; poly != NULL; poly = poly->next_poly) {
+    for (poly = html.head; poly != NULL; poly = poly->next_poly) {
 	if (poly->num_pts >= 3) {
 
-	    switch (html_type) {
+	    switch (html.type) {
 
 	    case APACHE:
-		fprintf(output, "poly %s", poly->url);
+		fprintf(html.output, "poly %s", poly->url);
 		for (i = 0; i < poly->num_pts; i++) {
-		    fprintf(output, " %d,%d", poly->x_pts[i], poly->y_pts[i]);
+		    fprintf(html.output, " %d,%d", poly->x_pts[i], poly->y_pts[i]);
 		}
-		fprintf(output, " %d,%d", poly->x_pts[0], poly->y_pts[0]);
-		fprintf(output, "\n");
+		fprintf(html.output, " %d,%d", poly->x_pts[0], poly->y_pts[0]);
+		fprintf(html.output, "\n");
 		break;
 
 	    case RAW:
-		fprintf(output, "%s", poly->url);
+		fprintf(html.output, "%s", poly->url);
 		for (i = 0; i < poly->num_pts; i++) {
-		    fprintf(output, " %d %d", poly->x_pts[i], poly->y_pts[i]);
+		    fprintf(html.output, " %d %d", poly->x_pts[i], poly->y_pts[i]);
 		}
-		fprintf(output, " %d %d", poly->x_pts[0], poly->y_pts[0]);
-		fprintf(output, "\n");
+		fprintf(html.output, " %d %d", poly->x_pts[0], poly->y_pts[0]);
+		fprintf(html.output, "\n");
 		break;
 
 	    case CLIENT:
-		fprintf(output,
+		fprintf(html.output,
 			"<AREA SHAPE=\"POLY\"\n HREF=\"%s\"\n  ALT=\"%s\"\n  COORDS=\"",
 			poly->url, poly->url);
 		for (i = 0; i < poly->num_pts; i++) {
 		    if (i > 0)
-			fprintf(output, ", ");
+			fprintf(html.output, ", ");
 		    /* 
 		     * don't add newlines, which confuses the weak-minded
 		     * i.e., ms internet exploder :-(
-		     * was: if (i % 8 == 0 && i != 0) fprintf(output,"\n  ");
+		     * was: if (i % 8 == 0 && i != 0) fprintf(html.output,"\n  ");
 		     */
-		    fprintf(output, "%d,%d", poly->x_pts[i], poly->y_pts[i]);
+		    fprintf(html.output, "%d,%d", poly->x_pts[i], poly->y_pts[i]);
 		}
-		fprintf(output, ", %d,%d", poly->x_pts[0], poly->y_pts[0]);
-		fprintf(output, "\">\n");
+		fprintf(html.output, ", %d,%d", poly->x_pts[0], poly->y_pts[0]);
+		fprintf(html.output, "\">\n");
 		break;
 
 	    }
@@ -136,7 +136,7 @@
 
     /* final stuff, if needed */
 
-    switch (html_type) {
+    switch (html.type) {
 
     case APACHE:
 	break;
@@ -145,10 +145,10 @@
 	break;
 
     case CLIENT:
-	fprintf(output,
+	fprintf(html.output,
 		"<AREA SHAPE=\"RECT\" NOHREF COORDS=\"%d,%d %d,%d\">\n",
 		0, 0, screen_width, screen_height);
-	fprintf(output, "</MAP>\n");
+	fprintf(html.output, "</MAP>\n");
 	break;
 
     }
@@ -157,5 +157,5 @@
      * close file 
      */
 
-    fclose(output);
+    fclose(html.output);
 }

Modified: grass/trunk/lib/htmldriver/Graph_Set.c
===================================================================
--- grass/trunk/lib/htmldriver/Graph_Set.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/htmldriver/Graph_Set.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -19,21 +19,11 @@
 #include "driver.h"
 #include "htmlmap.h"
 
-char *last_text;
-int last_text_len;
-char *file_name;
-int html_type;
-FILE *output;
+struct html_state html;
 
-struct MapPoly *head;
-struct MapPoly **tail;
-
-int BBOX_MINIMUM;
-int MAX_POINTS;
-int MINIMUM_DIST;
-
 int HTML_Graph_set(void)
 {
+    char *file_name;
     char *p;
 
     G_gisinit("HTMLMAP driver");
@@ -45,13 +35,13 @@
      */
 
     if (NULL != (p = getenv("GRASS_HTMLMINBBOX"))) {
-	BBOX_MINIMUM = atoi(p);
-	if (BBOX_MINIMUM <= 0) {
-	    BBOX_MINIMUM = DEF_MINBBOX;
+	html.BBOX_MINIMUM = atoi(p);
+	if (html.BBOX_MINIMUM <= 0) {
+	    html.BBOX_MINIMUM = DEF_MINBBOX;
 	}
     }
     else {
-	BBOX_MINIMUM = DEF_MINBBOX;
+	html.BBOX_MINIMUM = DEF_MINBBOX;
     }
 
     /*
@@ -59,13 +49,13 @@
      */
 
     if (NULL != (p = getenv("GRASS_HTMLMAXPOINTS"))) {
-	MAX_POINTS = atoi(p);
-	if (MAX_POINTS <= 0) {
-	    MAX_POINTS = DEF_MAXPTS;
+	html.MAX_POINTS = atoi(p);
+	if (html.MAX_POINTS <= 0) {
+	    html.MAX_POINTS = DEF_MAXPTS;
 	}
     }
     else {
-	MAX_POINTS = DEF_MAXPTS;
+	html.MAX_POINTS = DEF_MAXPTS;
     }
 
     /*
@@ -73,13 +63,13 @@
      */
 
     if (NULL != (p = getenv("GRASS_HTMLMINDIST"))) {
-	MINIMUM_DIST = atoi(p);
-	if (MINIMUM_DIST <= 0) {
-	    MINIMUM_DIST = DEF_MINDIST;
+	html.MINIMUM_DIST = atoi(p);
+	if (html.MINIMUM_DIST <= 0) {
+	    html.MINIMUM_DIST = DEF_MINDIST;
 	}
     }
     else {
-	MINIMUM_DIST = DEF_MINDIST;
+	html.MINIMUM_DIST = DEF_MINDIST;
     }
 
 
@@ -97,8 +87,8 @@
     }
     file_name = p;
 
-    output = fopen(file_name, "w");
-    if (output == NULL) {
+    html.output = fopen(file_name, "w");
+    if (html.output == NULL) {
 	G_fatal_error("HTMLMAP: couldn't open output file %s", file_name);
 	exit(EXIT_FAILURE);
     }
@@ -116,17 +106,17 @@
     }
 
     if (strcmp(p, "APACHE") == 0) {
-	html_type = APACHE;
+	html.type = APACHE;
 	fprintf(stdout, "type = APACHE\n");
 
     }
     else if (strcmp(p, "RAW") == 0) {
-	html_type = RAW;
+	html.type = RAW;
 	fprintf(stdout, "type = RAW\n");
 
     }
     else {
-	html_type = CLIENT;
+	html.type = CLIENT;
 	fprintf(stdout, "type = CLIENT\n");
     }
 
@@ -135,12 +125,12 @@
      * initialize text memory and list pointers
      */
 
-    last_text = (char *)G_malloc(INITIAL_TEXT + 1);
-    last_text[0] = '\0';
-    last_text_len = INITIAL_TEXT;
+    html.last_text = (char *)G_malloc(INITIAL_TEXT + 1);
+    html.last_text[0] = '\0';
+    html.last_text_len = INITIAL_TEXT;
 
-    head = NULL;
-    tail = &head;
+    html.head = NULL;
+    html.tail = &html.head;
 
     return 0;
 }

Modified: grass/trunk/lib/htmldriver/Polygon.c
===================================================================
--- grass/trunk/lib/htmldriver/Polygon.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/htmldriver/Polygon.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -8,12 +8,6 @@
 
 #define RAD_DEG 57.29578
 
-/* max points & bbox minimum dimension defined in Graph_Set.c */
-extern int MAX_POINTS;
-extern int BBOX_MINIMUM;
-extern int MINIMUM_DIST;
-
-
 static void delete_point(int *x, int *y, int count)
 {
     int i;
@@ -91,7 +85,7 @@
 	    delta_y = -delta_y;
 
 	if ((x[i] == x[i + 1] && y[i] == y[i + 1]) ||
-	    (delta_x <= MINIMUM_DIST && delta_y <= MINIMUM_DIST)) {
+	    (delta_x <= html.MINIMUM_DIST && delta_y <= html.MINIMUM_DIST)) {
 	    delete_point(&x[i + 1], &y[i + 1], n - i - 1);
 	    --n;
 	}
@@ -110,7 +104,7 @@
 	    delta_y = -delta_y;
 
 	if ((x[0] == x[n - 1] && y[0] == y[n - 1]) ||
-	    (delta_x <= MINIMUM_DIST && delta_y <= MINIMUM_DIST)) {
+	    (delta_x <= html.MINIMUM_DIST && delta_y <= html.MINIMUM_DIST)) {
 	    --n;
 	}
 	else {
@@ -140,7 +134,7 @@
     }
     delta_x = max_x - min_x;
     delta_y = max_y - min_y;
-    if (delta_x < BBOX_MINIMUM || delta_y < BBOX_MINIMUM) {
+    if (delta_x < html.BBOX_MINIMUM || delta_y < html.BBOX_MINIMUM) {
 	n = 0;
     }
 
@@ -149,7 +143,7 @@
      * remove points in excess of MAX_POINTS vertices
      */
 
-    while (n > MAX_POINTS) {
+    while (n > html.MAX_POINTS) {
 
 	for (i = 0; i < (n - 2); i++) {
 
@@ -195,12 +189,12 @@
 	new = (struct MapPoly *)G_malloc(sizeof(struct MapPoly));
 
 	/* grab the last text string written as url */
-	new->url = G_store(last_text);
+	new->url = G_store(html.last_text);
 
 	/* hook up new MapPoly into list */
 	new->next_poly = NULL;
-	*tail = new;
-	tail = &(new->next_poly);
+	*html.tail = new;
+	html.tail = &(new->next_poly);
 
 	new->num_pts = n;
 	new->x_pts = x;

Modified: grass/trunk/lib/htmldriver/Text.c
===================================================================
--- grass/trunk/lib/htmldriver/Text.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/htmldriver/Text.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -13,14 +13,14 @@
     const char *s;
     char *d;
 
-    if (len > last_text_len) {
-	G_free(last_text);
-	last_text = (char *)G_malloc(len + 1);
-	last_text_len = len;
+    if (len > html.last_text_len) {
+	G_free(html.last_text);
+	html.last_text = (char *)G_malloc(len + 1);
+	html.last_text_len = len;
     }
 
     /* copy string to last_text area, make sure we don't copy \n */
-    for (d = last_text, s = text; *s != '\0'; s++) {
+    for (d = html.last_text, s = text; *s != '\0'; s++) {
 	if (*s != '\n') {
 	    *d = *s;
 	    d++;

Modified: grass/trunk/lib/htmldriver/htmlmap.h
===================================================================
--- grass/trunk/lib/htmldriver/htmlmap.h	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/htmldriver/htmlmap.h	2008-08-22 23:34:16 UTC (rev 33012)
@@ -14,12 +14,6 @@
 #define CLIENT 1		/* write output in netscape client side image map format */
 #define RAW    2		/* write output in raw format */
 
-extern char *last_text;
-extern int last_text_len;
-extern char *file_name;
-extern int html_type;
-extern FILE *output;
-
 struct MapPoly
 {
     char *url;
@@ -29,9 +23,21 @@
     struct MapPoly *next_poly;
 };
 
-extern struct MapPoly *head;
-extern struct MapPoly **tail;
+struct html_state
+{
+    char *last_text;
+    int last_text_len;
+    int type;
+    FILE *output;
+    struct MapPoly *head;
+    struct MapPoly **tail;
+    int MAX_POINTS;
+    int BBOX_MINIMUM;
+    int MINIMUM_DIST;
+};
 
+extern struct html_state html;
+
 /* Driver.c */
 extern const struct driver *HTML_Driver(void);
 

Modified: grass/trunk/lib/pngdriver/Box.c
===================================================================
--- grass/trunk/lib/pngdriver/Box.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Box.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -17,30 +17,30 @@
     if (y1 > y2)
 	tmp = y1, y1 = y2, y2 = tmp;
 
-    if (x2 < 0 || x1 > width)
+    if (x2 < 0 || x1 > png.width)
 	return;
 
-    if (y2 < 0 || y1 > height)
+    if (y2 < 0 || y1 > png.height)
 	return;
 
-    if (x1 < clip_left)
-	x1 = clip_left;
+    if (x1 < png.clip_left)
+	x1 = png.clip_left;
 
-    if (x2 > clip_rite)
-	x2 = clip_rite;
+    if (x2 > png.clip_rite)
+	x2 = png.clip_rite;
 
-    if (y1 < clip_top)
-	y1 = clip_top;
+    if (y1 < png.clip_top)
+	y1 = png.clip_top;
 
-    if (y2 > clip_bot)
-	y2 = clip_bot;
+    if (y2 > png.clip_bot)
+	y2 = png.clip_bot;
 
     for (y = y1; y < y2; y++) {
-	unsigned int *p = &grid[y * width + x1];
+	unsigned int *p = &png.grid[y * png.width + x1];
 
 	for (x = x1; x < x2; x++)
-	    *p++ = currentColor;
+	    *p++ = png.current_color;
     }
 
-    modified = 1;
+    png.modified = 1;
 }

Modified: grass/trunk/lib/pngdriver/Color.c
===================================================================
--- grass/trunk/lib/pngdriver/Color.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Color.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -16,13 +16,13 @@
 	return;
     }
 
-    if (true_color) {
+    if (png.true_color) {
 	int r = (number >> 16) & 0xFF;
 	int g = (number >> 8) & 0xFF;
 	int b = (number >> 0) & 0xFF;
 
-	currentColor = get_color(r, g, b, 0);
+	png.current_color = get_color(r, g, b, 0);
     }
     else
-	currentColor = number;
+	png.current_color = number;
 }

Modified: grass/trunk/lib/pngdriver/Color_table.c
===================================================================
--- grass/trunk/lib/pngdriver/Color_table.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Color_table.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -11,10 +11,10 @@
 
 static void set_color(int i, int red, int grn, int blu)
 {
-    png_palette[i][0] = red;
-    png_palette[i][1] = grn;
-    png_palette[i][2] = blu;
-    png_palette[i][3] = 0;
+    png.palette[i][0] = red;
+    png.palette[i][1] = grn;
+    png.palette[i][2] = blu;
+    png.palette[i][3] = 0;
 }
 
 static void init_colors_rgb(void)
@@ -45,7 +45,7 @@
 
     n_pixels = 0;
 
-    if (has_alpha)
+    if (png.has_alpha)
 	/* transparent color should be the first!
 	 * Its RGB value doesn't matter since we fake RGB-to-index. */
 	set_color(n_pixels++, 0, 0, 0);
@@ -76,7 +76,7 @@
 
 void init_color_table(void)
 {
-    if (true_color)
+    if (png.true_color)
 	init_colors_rgb();
     else
 	init_colors_indexed();
@@ -89,10 +89,10 @@
 
 static int get_color_indexed(int r, int g, int b, int a)
 {
-    if (has_alpha && a >= 128)
+    if (png.has_alpha && a >= 128)
 	return 0;
 
-    return Red[r] + Grn[g] + Blu[b] + has_alpha;
+    return Red[r] + Grn[g] + Blu[b] + png.has_alpha;
 }
 
 static void get_pixel_rgb(unsigned int pixel, int *r, int *g, int *b, int *a)
@@ -106,16 +106,16 @@
 static void get_pixel_indexed(unsigned int pixel, int *r, int *g, int *b,
 			      int *a)
 {
-    *r = png_palette[pixel][0];
-    *g = png_palette[pixel][1];
-    *b = png_palette[pixel][2];
-    *a = png_palette[pixel][3];
+    *r = png.palette[pixel][0];
+    *g = png.palette[pixel][1];
+    *b = png.palette[pixel][2];
+    *a = png.palette[pixel][3];
 }
 
 
 void get_pixel(unsigned int pixel, int *r, int *g, int *b, int *a)
 {
-    if (true_color)
+    if (png.true_color)
 	get_pixel_rgb(pixel, r, g, b, a);
     else
 	get_pixel_indexed(pixel, r, g, b, a);
@@ -123,12 +123,12 @@
 
 unsigned int get_color(int r, int g, int b, int a)
 {
-    return true_color ? get_color_rgb(r, g, b, a)
+    return png.true_color ? get_color_rgb(r, g, b, a)
 	: get_color_indexed(r, g, b, a);
 }
 
 int PNG_lookup_color(int r, int g, int b)
 {
-    return true_color ? ((r << 16) | (g << 8) | (b << 0))
-	: Red[r] + Grn[g] + Blu[b] + has_alpha;
+    return png.true_color ? ((r << 16) | (g << 8) | (b << 0))
+	: Red[r] + Grn[g] + Blu[b] + png.has_alpha;
 }

Modified: grass/trunk/lib/pngdriver/Draw_bitmap.c
===================================================================
--- grass/trunk/lib/pngdriver/Draw_bitmap.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Draw_bitmap.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -20,12 +20,12 @@
 void PNG_draw_bitmap(int ncols, int nrows, int threshold,
 		     const unsigned char *buf)
 {
-    int i0 = max(clip_left - cur_x, 0);
-    int i1 = min(clip_rite - cur_x, ncols);
-    int j0 = max(clip_top - cur_y, 0);
-    int j1 = min(clip_bot - cur_y, nrows);
+    int i0 = max(png.clip_left - cur_x, 0);
+    int i1 = min(png.clip_rite - cur_x, ncols);
+    int j0 = max(png.clip_top - cur_y, 0);
+    int j1 = min(png.clip_bot - cur_y, nrows);
 
-    if (!true_color) {
+    if (!png.true_color) {
 	int i, j;
 
 	for (j = j0; j < j1; j++) {
@@ -34,10 +34,10 @@
 	    for (i = i0; i < i1; i++) {
 		int x = cur_x + i;
 		unsigned int k = buf[j * ncols + i];
-		unsigned int *p = &grid[y * width + x];
+		unsigned int *p = &png.grid[y * png.width + x];
 
 		if (k > threshold)
-		    *p = currentColor;
+		    *p = png.current_color;
 	    }
 	}
     }
@@ -45,7 +45,7 @@
 	int r1, g1, b1, a1;
 	int i, j;
 
-	get_pixel(currentColor, &r1, &g1, &b1, &a1);
+	get_pixel(png.current_color, &r1, &g1, &b1, &a1);
 
 	for (j = j0; j < j1; j++) {
 	    int y = cur_y + j;
@@ -53,7 +53,7 @@
 	    for (i = i0; i < i1; i++) {
 		int x = cur_x + i;
 		unsigned int k = buf[j * ncols + i];
-		unsigned int *p = &grid[y * width + x];
+		unsigned int *p = &png.grid[y * png.width + x];
 		unsigned int a0, r0, g0, b0;
 		unsigned int a, r, g, b;
 
@@ -69,5 +69,5 @@
 	}
     }
 
-    modified = 1;
+    png.modified = 1;
 }

Modified: grass/trunk/lib/pngdriver/Draw_line.c
===================================================================
--- grass/trunk/lib/pngdriver/Draw_line.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Draw_line.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -13,10 +13,10 @@
 
 static void store_xy(int x, int y)
 {
-    if (x < clip_left || x >= clip_rite || y < clip_top || y >= clip_bot)
+    if (x < png.clip_left || x >= png.clip_rite || y < png.clip_top || y >= png.clip_bot)
 	return;
 
-    grid[y * width + x] = currentColor;
+    png.grid[y * png.width + x] = png.current_color;
 }
 
 static void draw_line(int x1, int y1, int x2, int y2)
@@ -108,17 +108,17 @@
     int dx, dy;
     int i;
 
-    if (linewidth <= 1) {
+    if (png.linewidth <= 1) {
 	draw_line(x1, y1, x2, y2);
-	modified = 1;
+	png.modified = 1;
 	return;
     }
 
     dx = abs(x2 - x1);
     dy = abs(y2 - y1);
 
-    for (i = 0; i < linewidth; i++) {
-	int k = i - linewidth / 2;
+    for (i = 0; i < png.linewidth; i++) {
+	int k = i - png.linewidth / 2;
 
 	if (dy > dx)
 	    draw_line(x1 + k, y1, x2 + k, y2);
@@ -126,5 +126,5 @@
 	    draw_line(x1, y1 + k, x2, y2 + k);
     }
 
-    modified = 1;
+    png.modified = 1;
 }

Modified: grass/trunk/lib/pngdriver/Draw_point.c
===================================================================
--- grass/trunk/lib/pngdriver/Draw_point.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Draw_point.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -6,10 +6,10 @@
     int x = (int) floor(fx + 0.5);
     int y = (int) floor(fy + 0.5);
 
-    if (x < clip_left || x >= clip_rite || y < clip_top || y >= clip_bot)
+    if (x < png.clip_left || x >= png.clip_rite || y < png.clip_top || y >= png.clip_bot)
 	return;
 
-    grid[y * width + x] = currentColor;
+    png.grid[y * png.width + x] = png.current_color;
 
-    modified = 1;
+    png.modified = 1;
 }

Modified: grass/trunk/lib/pngdriver/Erase.c
===================================================================
--- grass/trunk/lib/pngdriver/Erase.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Erase.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -2,11 +2,11 @@
 
 void PNG_Erase(void)
 {
-    int n = width * height;
+    int n = png.width * png.height;
     int i;
 
     for (i = 0; i < n; i++)
-	grid[i] = background;
+	png.grid[i] = png.background;
 
-    modified = 1;
+    png.modified = 1;
 }

Modified: grass/trunk/lib/pngdriver/Graph_close.c
===================================================================
--- grass/trunk/lib/pngdriver/Graph_close.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Graph_close.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -17,15 +17,15 @@
 static void unmap_file(void)
 {
 #ifndef __MINGW32__
-    size_t size = HEADER_SIZE + width * height * sizeof(unsigned int);
-    void *ptr = (char *)grid - HEADER_SIZE;
+    size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
+    void *ptr = (char *)png.grid - HEADER_SIZE;
 
-    if (!mapped)
+    if (!png.mapped)
 	return;
 
     munmap(ptr, size);
 
-    mapped = 0;
+    png.mapped = 0;
 #endif
 }
 
@@ -33,8 +33,8 @@
 {
     write_image();
 
-    if (mapped)
+    if (png.mapped)
 	unmap_file();
     else
-	G_free(grid);
+	G_free(png.grid);
 }

Modified: grass/trunk/lib/pngdriver/Graph_set.c
===================================================================
--- grass/trunk/lib/pngdriver/Graph_set.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Graph_set.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -23,29 +23,16 @@
 #include <grass/gis.h>
 #include "pngdriver.h"
 
-char *file_name;
-int currentColor;
-int true_color;
-int auto_write;
-int has_alpha;
-int mapped;
+struct png_state png;
 
-double clip_top, clip_bot, clip_left, clip_rite;
-int width, height;
-void *image;
-unsigned int *grid;
-unsigned char png_palette[256][4];
-unsigned int background;
-int modified;
-
 static void map_file(void)
 {
 #ifndef __MINGW32__
-    size_t size = HEADER_SIZE + width * height * sizeof(unsigned int);
+    size_t size = HEADER_SIZE + png.width * png.height * sizeof(unsigned int);
     void *ptr;
     int fd;
 
-    fd = open(file_name, O_RDWR);
+    fd = open(png.file_name, O_RDWR);
     if (fd < 0)
 	return;
 
@@ -53,13 +40,13 @@
     if (ptr == MAP_FAILED)
 	return;
 
-    if (grid)
-	G_free(grid);
-    grid = (int *)((char *)ptr + HEADER_SIZE);
+    if (png.grid)
+	G_free(png.grid);
+    png.grid = (int *)((char *)ptr + HEADER_SIZE);
 
     close(fd);
 
-    mapped = 1;
+    png.mapped = 1;
 #endif
 }
 
@@ -76,22 +63,22 @@
     if (!p || strlen(p) == 0)
 	p = FILE_NAME;
 
-    file_name = p;
+    png.file_name = p;
 
     p = getenv("GRASS_TRUECOLOR");
-    true_color = p && strcmp(p, "TRUE") == 0;
+    png.true_color = p && strcmp(p, "TRUE") == 0;
 
     G_message("PNG: GRASS_TRUECOLOR status: %s",
-	      true_color ? "TRUE" : "FALSE");
+	      png.true_color ? "TRUE" : "FALSE");
 
     p = getenv("GRASS_PNG_AUTO_WRITE");
-    auto_write = p && strcmp(p, "TRUE") == 0;
+    png.auto_write = p && strcmp(p, "TRUE") == 0;
 
     p = getenv("GRASS_PNG_MAPPED");
     do_map = p && strcmp(p, "TRUE") == 0;
 
     if (do_map) {
-	char *ext = file_name + strlen(file_name) - 4;
+	char *ext = png.file_name + strlen(png.file_name) - 4;
 
 	if (G_strcasecmp(ext, ".bmp") != 0)
 	    do_map = 0;
@@ -100,54 +87,54 @@
     p = getenv("GRASS_PNG_READ");
     do_read = p && strcmp(p, "TRUE") == 0;
 
-    if (do_read && access(file_name, 0) != 0)
+    if (do_read && access(png.file_name, 0) != 0)
 	do_read = 0;
 
-    width = screen_width;
-    height = screen_height;
+    png.width = screen_width;
+    png.height = screen_height;
 
-    clip_top = 0;
-    clip_bot = height;
-    clip_left = 0;
-    clip_rite = width;
+    png.clip_top = 0;
+    png.clip_bot = png.height;
+    png.clip_left = 0;
+    png.clip_rite = png.width;
 
     p = getenv("GRASS_TRANSPARENT");
-    has_alpha = p && strcmp(p, "TRUE") == 0;
+    png.has_alpha = p && strcmp(p, "TRUE") == 0;
 
     init_color_table();
 
     p = getenv("GRASS_BACKGROUNDCOLOR");
     if (p && *p && sscanf(p, "%02x%02x%02x", &red, &grn, &blu) == 3)
-	background = get_color(red, grn, blu, has_alpha ? 255 : 0);
+	png.background = get_color(red, grn, blu, png.has_alpha ? 255 : 0);
     else {
 	/* 0xffffff = white, 0x000000 = black */
 	if (strcmp(DEFAULT_FG_COLOR, "white") == 0)
 	    /* foreground: white, background: black */
-	    background = get_color(0, 0, 0, has_alpha ? 255 : 0);
+	    png.background = get_color(0, 0, 0, png.has_alpha ? 255 : 0);
 	else
 	    /* foreground: black, background: white */
-	    background = get_color(255, 255, 255, has_alpha ? 255 : 0);
+	    png.background = get_color(255, 255, 255, png.has_alpha ? 255 : 0);
     }
 
     G_message
 	("PNG: collecting to file: %s,\n     GRASS_WIDTH=%d, GRASS_HEIGHT=%d",
-	 file_name, width, height);
+	 png.file_name, png.width, png.height);
 
     if (do_read && do_map)
 	map_file();
 
-    if (!mapped)
-	grid = G_malloc(width * height * sizeof(unsigned int));
+    if (!png.mapped)
+	png.grid = G_malloc(png.width * png.height * sizeof(unsigned int));
 
     if (!do_read) {
 	PNG_Erase();
-	modified = 1;
+	png.modified = 1;
     }
 
-    if (do_read && !mapped)
+    if (do_read && !png.mapped)
 	read_image();
 
-    if (do_map && !mapped) {
+    if (do_map && !png.mapped) {
 	write_image();
 	map_file();
     }

Modified: grass/trunk/lib/pngdriver/Polygon.c
===================================================================
--- grass/trunk/lib/pngdriver/Polygon.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Polygon.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -29,25 +29,25 @@
     unsigned int *p;
     int x;
 
-    if (yi >= clip_bot || yi < clip_top)
+    if (yi >= png.clip_bot || yi < png.clip_top)
 	return;
 
-    if (xi0 > clip_rite)
+    if (xi0 > png.clip_rite)
 	return;
 
-    if (xi1 < clip_left)
+    if (xi1 < png.clip_left)
 	return;
 
-    if (xi0 < clip_left)
-	xi0 = clip_left;
+    if (xi0 < png.clip_left)
+	xi0 = png.clip_left;
 
-    if (xi1 > clip_rite)
-	xi1 = clip_rite;
+    if (xi1 > png.clip_rite)
+	xi1 = png.clip_rite;
 
-    p = &grid[yi * width + xi0];
+    p = &png.grid[yi * png.width + xi0];
 
     for (x = xi0; x < xi1; x++)
-	*p++ = currentColor;
+	*p++ = png.current_color;
 }
 
 static void line(const struct point *p, int n, double y)
@@ -110,14 +110,14 @@
 	    y1 = p[i].y;
     }
 
-    if (y0 > clip_bot || y1 < clip_top)
+    if (y0 > png.clip_bot || y1 < png.clip_top)
 	return;
 
-    if (y0 < clip_top)
-	y0 = clip_top;
+    if (y0 < png.clip_top)
+	y0 = png.clip_top;
 
-    if (y1 > clip_bot)
-	y1 = clip_bot;
+    if (y1 > png.clip_bot)
+	y1 = png.clip_bot;
 
     y0 = floor(y0 + 0.5) + 0.5;
 

Modified: grass/trunk/lib/pngdriver/Raster.c
===================================================================
--- grass/trunk/lib/pngdriver/Raster.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Raster.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -86,10 +86,10 @@
     int d_y0 = scale_fwd_y(row + 0);
     int d_y1 = scale_fwd_y(row + 1);
     int d_rows = d_y1 - d_y0;
-    int x0 = max(clip_left - dst[0][0], 0);
-    int x1 = min(clip_rite - dst[0][0], ncols);
-    int y0 = max(clip_top - d_y0, 0);
-    int y1 = min(clip_bot - d_y0, d_rows);
+    int x0 = max(png.clip_left - dst[0][0], 0);
+    int x1 = min(png.clip_rite - dst[0][0], ncols);
+    int y0 = max(png.clip_top - d_y0, 0);
+    int y1 = min(png.clip_bot - d_y0, d_rows);
     int x, y;
 
     if (y1 <= y0)
@@ -108,11 +108,11 @@
 	for (y = y0; y < y1; y++) {
 	    int yy = d_y0 + y;
 
-	    grid[yy * width + xx] = c;
+	    png.grid[yy * png.width + xx] = c;
 	}
     }
 
-    modified = 1;
+    png.modified = 1;
 
     return next_row(row, d_y1);
 }

Modified: grass/trunk/lib/pngdriver/Respond.c
===================================================================
--- grass/trunk/lib/pngdriver/Respond.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Respond.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -3,6 +3,6 @@
 
 void PNG_Respond(void)
 {
-    if (auto_write)
+    if (png.auto_write)
 	write_image();
 }

Modified: grass/trunk/lib/pngdriver/Set_window.c
===================================================================
--- grass/trunk/lib/pngdriver/Set_window.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/Set_window.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -22,9 +22,9 @@
 
 void PNG_Set_window(double t, double b, double l, double r)
 {
-    clip_top  = t > 0      ? t : 0;
-    clip_bot  = b < height ? b : height;
-    clip_left = l > 0      ? l : 0;
-    clip_rite = r < width  ? r : width;
+    png.clip_top  = t > 0          ? t : 0;
+    png.clip_bot  = b < png.height ? b : png.height;
+    png.clip_left = l > 0          ? l : 0;
+    png.clip_rite = r < png.width  ? r : png.width;
 }
 

Modified: grass/trunk/lib/pngdriver/pngdriver.h
===================================================================
--- grass/trunk/lib/pngdriver/pngdriver.h	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/pngdriver.h	2008-08-22 23:34:16 UTC (rev 33012)
@@ -10,22 +10,27 @@
 
 #define HEADER_SIZE 54
 
-extern char *file_name;
-extern int currentColor;
-extern int true_color;
-extern int auto_write;
-extern int has_alpha;
-extern int mapped;
+struct png_state
+{
+    char *file_name;
+    int current_color;
+    int true_color;
+    int auto_write;
+    int has_alpha;
+    int mapped;
 
-extern double clip_top, clip_bot, clip_left, clip_rite;
-extern int width, height;
-extern unsigned int *grid;
-extern unsigned char png_palette[256][4];
-extern unsigned int background;
-extern int modified;
+    double clip_top, clip_bot, clip_left, clip_rite;
+    int width, height;
+    unsigned int *grid;
+    unsigned char palette[256][4];
+    unsigned int background;
+    int modified;
 
-extern int linewidth;
+    int linewidth;
+};
 
+extern struct png_state png;
+
 extern void read_image(void);
 extern void read_ppm(void);
 extern void read_pgm(void);

Modified: grass/trunk/lib/pngdriver/read.c
===================================================================
--- grass/trunk/lib/pngdriver/read.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/read.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -9,11 +9,11 @@
 
 void read_image(void)
 {
-    char *p = file_name + strlen(file_name) - 4;
+    char *p = png.file_name + strlen(png.file_name) - 4;
 
     if (G_strcasecmp(p, ".ppm") == 0) {
 	read_ppm();
-	if (has_alpha)
+	if (png.has_alpha)
 	    read_pgm();
     }
     else if (G_strcasecmp(p, ".bmp") == 0)
@@ -25,5 +25,5 @@
     else
 	G_fatal_error("read_image: unknown file type: %s", p);
 
-    modified = 0;
+    png.modified = 0;
 }

Modified: grass/trunk/lib/pngdriver/read_bmp.c
===================================================================
--- grass/trunk/lib/pngdriver/read_bmp.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/read_bmp.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -31,7 +31,7 @@
     if (*p++ != 'M')
 	return 0;
 
-    if (get_4(&p) != HEADER_SIZE + width * height * 4)
+    if (get_4(&p) != HEADER_SIZE + png.width * png.height * 4)
 	return 0;
 
     get_4(&p);
@@ -42,9 +42,9 @@
     if (get_4(&p) != 40)
 	return 0;
 
-    if (get_4(&p) != width)
+    if (get_4(&p) != png.width)
 	return 0;
-    if (get_4(&p) != -height)
+    if (get_4(&p) != -png.height)
 	return 0;
 
     get_2(&p);
@@ -53,7 +53,7 @@
 
     if (get_4(&p) != 0)
 	return 0;
-    if (get_4(&p) != width * height * 4)
+    if (get_4(&p) != png.width * png.height * 4)
 	return 0;
 
     get_4(&p);
@@ -71,21 +71,21 @@
     int x, y;
     unsigned int *p;
 
-    if (!true_color)
+    if (!png.true_color)
 	G_fatal_error("PNG: cannot use BMP with indexed color");
 
-    input = fopen(file_name, "rb");
+    input = fopen(png.file_name, "rb");
     if (!input)
-	G_fatal_error("PNG: couldn't open input file %s", file_name);
+	G_fatal_error("PNG: couldn't open input file %s", png.file_name);
 
     if (fread(header, sizeof(header), 1, input) != 1)
-	G_fatal_error("PNG: invalid input file %s", file_name);
+	G_fatal_error("PNG: invalid input file %s", png.file_name);
 
     if (!read_bmp_header(header))
-	G_fatal_error("PNG: invalid BMP header for %s", file_name);
+	G_fatal_error("PNG: invalid BMP header for %s", png.file_name);
 
-    for (y = 0, p = grid; y < height; y++) {
-	for (x = 0; x < width; x++, p++) {
+    for (y = 0, p = png.grid; y < png.height; y++) {
+	for (x = 0; x < png.width; x++, p++) {
 	    int b = fgetc(input);
 	    int g = fgetc(input);
 	    int r = fgetc(input);

Modified: grass/trunk/lib/pngdriver/read_png.c
===================================================================
--- grass/trunk/lib/pngdriver/read_png.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/read_png.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -30,9 +30,9 @@
     if (setjmp(png_jmpbuf(png_ptr)))
 	G_fatal_error("error reading PNG file");
 
-    input = fopen(file_name, "rb");
+    input = fopen(png.file_name, "rb");
     if (!input)
-	G_fatal_error("PNG: couldn't open output file %s", file_name);
+	G_fatal_error("PNG: couldn't open output file %s", png.file_name);
 
     png_init_io(png_ptr, input);
 
@@ -44,12 +44,12 @@
     if (depth != 8)
 	G_fatal_error("PNG: input file is not 8-bit");
 
-    if (i_width != width || i_height != height)
+    if (i_width != png.width || i_height != png.height)
 	G_fatal_error
 	    ("PNG: input file has incorrect dimensions: expected: %dx%d got: %lux%lu",
-	     width, height, i_width, i_height);
+	     png.width, png.height, i_width, i_height);
 
-    if (true_color) {
+    if (png.true_color) {
 	if (color_type != PNG_COLOR_TYPE_RGB_ALPHA)
 	    G_fatal_error("PNG: input file is not RGBA");
     }
@@ -58,7 +58,7 @@
 	    G_fatal_error("PNG: input file is not indexed color");
     }
 
-    if (!true_color && has_alpha) {
+    if (!png.true_color && png.has_alpha) {
 	png_bytep trans;
 	int num_trans;
 
@@ -68,7 +68,7 @@
 	    G_fatal_error("PNG: input file has invalid palette");
     }
 
-    if (true_color)
+    if (png.true_color)
 	png_set_invert_alpha(png_ptr);
     else {
 	png_colorp png_pal;
@@ -81,21 +81,21 @@
 	    num_palette = 256;
 
 	for (i = 0; i < num_palette; i++) {
-	    png_palette[i][0] = png_pal[i].red;
-	    png_palette[i][1] = png_pal[i].green;
-	    png_palette[i][2] = png_pal[i].blue;
+	    png.palette[i][0] = png_pal[i].red;
+	    png.palette[i][1] = png_pal[i].green;
+	    png.palette[i][2] = png_pal[i].blue;
 	}
     }
 
-    line = G_malloc(width * 4);
+    line = G_malloc(png.width * 4);
 
-    for (y = 0, p = grid; y < height; y++) {
+    for (y = 0, p = png.grid; y < png.height; y++) {
 	png_bytep q = line;
 
 	png_read_row(png_ptr, q, NULL);
 
-	if (true_color)
-	    for (x = 0; x < width; x++, p++) {
+	if (png.true_color)
+	    for (x = 0; x < png.width; x++, p++) {
 		int r = *q++;
 		int g = *q++;
 		int b = *q++;
@@ -105,7 +105,7 @@
 		*p = c;
 	    }
 	else
-	    for (x = 0; x < width; x++, p++, q++)
+	    for (x = 0; x < png.width; x++, p++, q++)
 		*p = (png_byte) * q;
     }
 

Modified: grass/trunk/lib/pngdriver/read_ppm.c
===================================================================
--- grass/trunk/lib/pngdriver/read_ppm.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/read_ppm.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -14,25 +14,25 @@
     unsigned int rgb_mask = get_color(255, 255, 255, 0);
     unsigned int *p;
 
-    if (!true_color)
+    if (!png.true_color)
 	G_fatal_error("PNG: cannot use PPM/PGM with indexed color");
 
-    input = fopen(file_name, "rb");
+    input = fopen(png.file_name, "rb");
     if (!input)
-	G_fatal_error("PNG: couldn't open input file %s", file_name);
+	G_fatal_error("PNG: couldn't open input file %s", png.file_name);
 
     if (fscanf(input, "P6 %d %d %d", &i_width, &i_height, &maxval) != 3)
-	G_fatal_error("PNG: invalid input file %s", file_name);
+	G_fatal_error("PNG: invalid input file %s", png.file_name);
 
     fgetc(input);
 
-    if (i_width != width || i_height != height)
+    if (i_width != png.width || i_height != png.height)
 	G_fatal_error
 	    ("PNG: input file has incorrect dimensions: expected: %dx%d got: %dx%d",
-	     width, height, i_width, i_height);
+	     png.width, png.height, i_width, i_height);
 
-    for (y = 0, p = grid; y < height; y++) {
-	for (x = 0; x < width; x++, p++) {
+    for (y = 0, p = png.grid; y < png.height; y++) {
+	for (x = 0; x < png.width; x++, p++) {
 	    unsigned int c = *p;
 
 	    int r = fgetc(input);
@@ -55,14 +55,14 @@
 
 void read_pgm(void)
 {
-    char *mask_name = G_store(file_name);
+    char *mask_name = G_store(png.file_name);
     FILE *input;
     int x, y;
     int i_width, i_height, maxval;
     unsigned int rgb_mask = get_color(255, 255, 255, 0);
     unsigned int *p;
 
-    if (!true_color)
+    if (!png.true_color)
 	G_fatal_error("PNG: cannot use PPM/PGM with indexed color");
 
     mask_name[strlen(mask_name) - 2] = 'g';
@@ -76,15 +76,15 @@
 
     fgetc(input);
 
-    if (i_width != width || i_height != height)
+    if (i_width != png.width || i_height != png.height)
 	G_fatal_error
 	    ("PNG: input mask file has incorrect dimensions: expected: %dx%d got: %dx%d",
-	     width, height, i_width, i_height);
+	     png.width, png.height, i_width, i_height);
 
     G_free(mask_name);
 
-    for (y = 0, p = grid; y < height; y++) {
-	for (x = 0; x < width; x++, p++) {
+    for (y = 0, p = png.grid; y < png.height; y++) {
+	for (x = 0; x < png.width; x++, p++) {
 	    unsigned int c = *p;
 
 	    int k = fgetc(input);

Modified: grass/trunk/lib/pngdriver/write.c
===================================================================
--- grass/trunk/lib/pngdriver/write.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/write.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -9,17 +9,17 @@
 
 void write_image(void)
 {
-    char *p = file_name + strlen(file_name) - 4;
+    char *p = png.file_name + strlen(png.file_name) - 4;
 
-    if (!modified)
+    if (!png.modified)
 	return;
 
-    if (mapped)
+    if (png.mapped)
 	return;
 
     if (G_strcasecmp(p, ".ppm") == 0) {
 	write_ppm();
-	if (has_alpha)
+	if (png.has_alpha)
 	    write_pgm();
     }
     else if (G_strcasecmp(p, ".bmp") == 0)
@@ -31,5 +31,5 @@
     else
 	G_fatal_error("write_image: unknown file type: %s", p);
 
-    modified = 0;
+    png.modified = 0;
 }

Modified: grass/trunk/lib/pngdriver/write_bmp.c
===================================================================
--- grass/trunk/lib/pngdriver/write_bmp.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/write_bmp.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -31,17 +31,17 @@
     *p++ = 'B';
     *p++ = 'M';
 
-    p = put_4(p, HEADER_SIZE + width * height * 4);
+    p = put_4(p, HEADER_SIZE + png.width * png.height * 4);
     p = put_4(p, 0);
     p = put_4(p, HEADER_SIZE);
 
     p = put_4(p, 40);
-    p = put_4(p, width);
-    p = put_4(p, -height);
+    p = put_4(p, png.width);
+    p = put_4(p, -png.height);
     p = put_2(p, 1);
     p = put_2(p, 32);
     p = put_4(p, 0);
-    p = put_4(p, width * height * 4);
+    p = put_4(p, png.width * png.height * 4);
     p = put_4(p, 0);
     p = put_4(p, 0);
     p = put_4(p, 0);
@@ -55,15 +55,15 @@
     int x, y;
     unsigned int *p;
 
-    output = fopen(file_name, "wb");
+    output = fopen(png.file_name, "wb");
     if (!output)
-	G_fatal_error("PNG: couldn't open output file %s", file_name);
+	G_fatal_error("PNG: couldn't open output file %s", png.file_name);
 
     make_bmp_header(header);
     fwrite(header, sizeof(header), 1, output);
 
-    for (y = 0, p = grid; y < height; y++) {
-	for (x = 0; x < width; x++, p++) {
+    for (y = 0, p = png.grid; y < png.height; y++) {
+	for (x = 0; x < png.width; x++, p++) {
 	    unsigned int c = *p;
 	    int r, g, b, a;
 

Modified: grass/trunk/lib/pngdriver/write_png.c
===================================================================
--- grass/trunk/lib/pngdriver/write_png.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/write_png.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -30,33 +30,33 @@
     if (setjmp(png_jmpbuf(png_ptr)))
 	G_fatal_error("error writing PNG file");
 
-    output = fopen(file_name, "wb");
+    output = fopen(png.file_name, "wb");
     if (!output)
-	G_fatal_error("PNG: couldn't open output file %s", file_name);
+	G_fatal_error("PNG: couldn't open output file %s", png.file_name);
 
     png_init_io(png_ptr, output);
 
     png_set_IHDR(png_ptr, info_ptr,
-		 width, height, 8,
-		 true_color ? PNG_COLOR_TYPE_RGB_ALPHA :
+		 png.width, png.height, 8,
+		 png.true_color ? PNG_COLOR_TYPE_RGB_ALPHA :
 		 PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
 		 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
 
-    if (true_color)
+    if (png.true_color)
 	png_set_invert_alpha(png_ptr);
     else {
 	png_color png_pal[256];
 	int i;
 
 	for (i = 0; i < 256; i++) {
-	    png_pal[i].red = png_palette[i][0];
-	    png_pal[i].green = png_palette[i][1];
-	    png_pal[i].blue = png_palette[i][2];
+	    png_pal[i].red   = png.palette[i][0];
+	    png_pal[i].green = png.palette[i][1];
+	    png_pal[i].blue  = png.palette[i][2];
 	}
 
 	png_set_PLTE(png_ptr, info_ptr, png_pal, 256);
 
-	if (has_alpha) {
+	if (png.has_alpha) {
 	    png_byte trans = (png_byte) 0;
 
 	    png_set_tRNS(png_ptr, info_ptr, &trans, 1, NULL);
@@ -69,13 +69,13 @@
 
     png_write_info(png_ptr, info_ptr);
 
-    line = G_malloc(width * 4);
+    line = G_malloc(png.width * 4);
 
-    for (y = 0, p = grid; y < height; y++) {
+    for (y = 0, p = png.grid; y < png.height; y++) {
 	png_bytep q = line;
 
-	if (true_color)
-	    for (x = 0; x < width; x++, p++) {
+	if (png.true_color)
+	    for (x = 0; x < png.width; x++, p++) {
 		unsigned int c = *p;
 		int r, g, b, a;
 
@@ -86,7 +86,7 @@
 		*q++ = (png_byte) a;
 	    }
 	else
-	    for (x = 0; x < width; x++, p++, q++)
+	    for (x = 0; x < png.width; x++, p++, q++)
 		*q = (png_byte) * p;
 
 	png_write_row(png_ptr, line);

Modified: grass/trunk/lib/pngdriver/write_ppm.c
===================================================================
--- grass/trunk/lib/pngdriver/write_ppm.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/pngdriver/write_ppm.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -12,14 +12,14 @@
     int x, y;
     unsigned int *p;
 
-    output = fopen(file_name, "wb");
+    output = fopen(png.file_name, "wb");
     if (!output)
-	G_fatal_error("PNG: couldn't open output file %s", file_name);
+	G_fatal_error("PNG: couldn't open output file %s", png.file_name);
 
-    fprintf(output, "P6\n%d %d\n255\n", width, height);
+    fprintf(output, "P6\n%d %d\n255\n", png.width, png.height);
 
-    for (y = 0, p = grid; y < height; y++) {
-	for (x = 0; x < width; x++, p++) {
+    for (y = 0, p = png.grid; y < png.height; y++) {
+	for (x = 0; x < png.width; x++, p++) {
 	    unsigned int c = *p;
 	    int r, g, b, a;
 
@@ -36,7 +36,7 @@
 
 void write_pgm(void)
 {
-    char *mask_name = G_store(file_name);
+    char *mask_name = G_store(png.file_name);
     FILE *output;
     int x, y;
     unsigned int *p;
@@ -49,10 +49,10 @@
 
     G_free(mask_name);
 
-    fprintf(output, "P5\n%d %d\n255\n", width, height);
+    fprintf(output, "P5\n%d %d\n255\n", png.width, png.height);
 
-    for (y = 0, p = grid; y < height; y++) {
-	for (x = 0; x < width; x++, p++) {
+    for (y = 0, p = png.grid; y < png.height; y++) {
+	for (x = 0; x < png.width; x++, p++) {
 	    unsigned int c = *p;
 	    int r, g, b, a;
 

Modified: grass/trunk/lib/psdriver/Color.c
===================================================================
--- grass/trunk/lib/psdriver/Color.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/psdriver/Color.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -9,7 +9,7 @@
 	return;
     }
 
-    if (true_color) {
+    if (ps.true_color) {
 	int r = (number >> 16) & 0xFF;
 	int g = (number >> 8) & 0xFF;
 	int b = (number >> 0) & 0xFF;

Modified: grass/trunk/lib/psdriver/Color_table.c
===================================================================
--- grass/trunk/lib/psdriver/Color_table.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/psdriver/Color_table.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -8,7 +8,7 @@
 
 void init_color_table(void)
 {
-    NCOLORS = true_color ? (1 << 24) : (1 << 8);
+    NCOLORS = ps.true_color ? (1 << 24) : (1 << 8);
 }
 
 static int get_color_rgb(int r, int g, int b)
@@ -23,6 +23,6 @@
 
 int PS_lookup_color(int r, int g, int b)
 {
-    return true_color ? get_color_rgb(r, g, b)
+    return ps.true_color ? get_color_rgb(r, g, b)
 	: get_color_gray(r, g, b);
 }

Modified: grass/trunk/lib/psdriver/Erase.c
===================================================================
--- grass/trunk/lib/psdriver/Erase.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/psdriver/Erase.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -2,8 +2,8 @@
 
 void PS_Erase(void)
 {
-    if (encapsulated)
-	output("%d %d %d %d BOX\n", left, top, right, bot);
+    if (ps.encapsulated)
+	output("%d %d %d %d BOX\n", ps.left, ps.top, ps.right, ps.bot);
     else
 	output("ERASE\n");
 }

Modified: grass/trunk/lib/psdriver/Graph_close.c
===================================================================
--- grass/trunk/lib/psdriver/Graph_close.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/psdriver/Graph_close.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -7,11 +7,11 @@
 
 void PS_Graph_close(void)
 {
-    if (!no_trailer) {
+    if (!ps.no_trailer) {
 	output("%%%%BeginTrailer\n");
 	output("END\n");
 	output("%%%%EndTrailer\n");
     }
 
-    fclose(outfp);
+    fclose(ps.outfp);
 }

Modified: grass/trunk/lib/psdriver/Graph_set.c
===================================================================
--- grass/trunk/lib/psdriver/Graph_set.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/psdriver/Graph_set.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -21,13 +21,10 @@
 
 #define DATE_FORMAT "%c"
 
-const char *file_name;
-FILE *outfp;
-int true_color;
-int encapsulated;
-int no_header, no_trailer;
-double left, right, bot, top;
+struct ps_state ps;
 
+static const char *file_name;
+
 static double width, height;
 static int landscape;
 
@@ -67,7 +64,7 @@
     if (!prolog_fp)
 	G_fatal_error("Unable to open prolog file");
 
-    if (encapsulated)
+    if (ps.encapsulated)
 	output("%%!PS-Adobe-3.0 EPSF-3.0\n");
     else
 	output("%%!PS-Adobe-3.0\n");
@@ -78,8 +75,8 @@
     output("%%%%For: %s\n", G_whoami());
     output("%%%%Orientation: %s\n", landscape ? "Landscape" : "Portrait");
     output("%%%%BoundingBox: %d %d %d %d\n",
-	   (int)floor(left), (int)floor(bot),
-	   (int)ceil(right), (int)ceil(top));
+	   (int)floor(ps.left), (int)floor(ps.bot),
+	   (int)ceil(ps.right), (int)ceil(ps.top));
     output("%%%%CreationDate: %s\n", date_str);
     output("%%%%EndComments\n");
 
@@ -90,7 +87,7 @@
 	if (!fgets(buf, sizeof(buf), prolog_fp))
 	    break;
 
-	fputs(buf, outfp);
+	fputs(buf, ps.outfp);
     }
     output("%%%%EndProlog\n");
 
@@ -101,7 +98,7 @@
 {
     output("%%%%BeginSetup\n");
 
-    output("%.1f %.1f translate\n", left, bot);
+    output("%.1f %.1f translate\n", ps.left, ps.bot);
 
     if (landscape)
 	output("90 rotate 0 1 -1 scale\n");
@@ -136,13 +133,13 @@
     width = screen_width;
     height = screen_height;
 
-    left = 0;
-    right = width;
-    bot = 0;
-    top = height;
+    ps.left = 0;
+    ps.right = width;
+    ps.bot = 0;
+    ps.top = height;
 
     if (landscape)
-	swap(&right, &top);
+	swap(&ps.right, &ps.top);
 
     if (!name)
 	return;
@@ -157,19 +154,19 @@
 	    break;
     }
 
-    left = in2pt(paper->left);
-    right = in2pt(paper->width) - in2pt(paper->right);
-    bot = in2pt(paper->bot);
-    top = in2pt(paper->height) - in2pt(paper->top);
+    ps.left = in2pt(paper->left);
+    ps.right = in2pt(paper->width) - in2pt(paper->right);
+    ps.bot = in2pt(paper->bot);
+    ps.top = in2pt(paper->height) - in2pt(paper->top);
 
-    width = right - left;
+    width = ps.right - ps.left;
     height = in2pt(paper->height) - in2pt(paper->top) - in2pt(paper->bot);
 
     if (landscape)
 	swap(&width, &height);
 
-    right = left + width;
-    bot = top + height;
+    ps.right = ps.left + width;
+    ps.bot = ps.top + height;
 }
 
 int PS_Graph_set(void)
@@ -184,33 +181,33 @@
 
     file_name = p;
     p = file_name + strlen(file_name) - 4;
-    encapsulated = (G_strcasecmp(p, ".eps") == 0);
+    ps.encapsulated = (G_strcasecmp(p, ".eps") == 0);
 
     p = getenv("GRASS_TRUECOLOR");
-    true_color = p && strcmp(p, "TRUE") == 0;
+    ps.true_color = p && strcmp(p, "TRUE") == 0;
 
     p = getenv("GRASS_LANDSCAPE");
     landscape = p && strcmp(p, "TRUE") == 0;
 
     p = getenv("GRASS_PS_HEADER");
-    no_header = p && strcmp(p, "FALSE") == 0;
+    ps.no_header = p && strcmp(p, "FALSE") == 0;
 
     p = getenv("GRASS_PS_TRAILER");
-    no_trailer = p && strcmp(p, "FALSE") == 0;
+    ps.no_trailer = p && strcmp(p, "FALSE") == 0;
 
     G_message("PS: GRASS_TRUECOLOR status: %s",
-	      true_color ? "TRUE" : "FALSE");
+	      ps.true_color ? "TRUE" : "FALSE");
 
     get_paper();
 
     init_color_table();
 
-    outfp = fopen(file_name, no_header ? "a" : "w");
+    ps.outfp = fopen(file_name, ps.no_header ? "a" : "w");
 
-    if (!outfp)
+    if (!ps.outfp)
 	G_fatal_error("Unable to open output file: %s", file_name);
 
-    if (!no_header) {
+    if (!ps.no_header) {
 	write_prolog();
 	write_setup();
     }
@@ -219,7 +216,7 @@
 	"PS: collecting to file: %s,\nGRASS_WIDTH=%.1f, GRASS_HEIGHT=%.1f",
 	 file_name, width, height);
 
-    fflush(outfp);
+    fflush(ps.outfp);
 
     return 0;
 }
@@ -229,6 +226,6 @@
     va_list va;
 
     va_start(va, fmt);
-    vfprintf(outfp, fmt, va);
+    vfprintf(ps.outfp, fmt, va);
     va_end(va);
 }

Modified: grass/trunk/lib/psdriver/Raster.c
===================================================================
--- grass/trunk/lib/psdriver/Raster.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/psdriver/Raster.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -7,7 +7,7 @@
 
 void PS_begin_scaled_raster(int mask, int src[2][2], double dst[2][2])
 {
-    const char *type = true_color ? (mask ? "RASTERRGBMASK" : "RASTERRGB")
+    const char *type = ps.true_color ? (mask ? "RASTERRGBMASK" : "RASTERRGB")
 	: (mask ? "RASTERGRAYMASK" : "RASTERGRAY");
 
     int ssx = src[0][1] - src[0][0];
@@ -35,7 +35,7 @@
     int i;
 
     for (i = 0; i < n; i++) {
-	if (true_color) {
+	if (ps.true_color) {
 	    if (masked)
 		output("%02X%02X%02X%02X", (nul && nul[i]) ? 0xFF : 0x00,
 		       red[i], grn[i], blu[i]);

Modified: grass/trunk/lib/psdriver/Respond.c
===================================================================
--- grass/trunk/lib/psdriver/Respond.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/psdriver/Respond.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -3,5 +3,5 @@
 
 void PS_Respond(void)
 {
-    fflush(outfp);
+    fflush(ps.outfp);
 }

Modified: grass/trunk/lib/psdriver/Set_window.c
===================================================================
--- grass/trunk/lib/psdriver/Set_window.c	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/psdriver/Set_window.c	2008-08-22 23:34:16 UTC (rev 33012)
@@ -22,5 +22,5 @@
 void PS_Set_window(double t, double b, double l, double r)
 {
     output("%.1f %.1f %.1f %.1f %s\n", t, b, l, r,
-	   encapsulated ? "EPSWINDOW" : "WINDOW");
+	   ps.encapsulated ? "EPSWINDOW" : "WINDOW");
 }

Modified: grass/trunk/lib/psdriver/psdriver.h
===================================================================
--- grass/trunk/lib/psdriver/psdriver.h	2008-08-22 21:59:09 UTC (rev 33011)
+++ grass/trunk/lib/psdriver/psdriver.h	2008-08-22 23:34:16 UTC (rev 33012)
@@ -8,13 +8,17 @@
 
 #define FILE_NAME  "map.ps"
 
-extern const char *file_name;
-extern FILE *outfp;
-extern int true_color;
-extern int encapsulated;
-extern int no_header, no_trailer;
-extern double left, right, bot, top;
+struct ps_state
+{
+    FILE *outfp;
+    int true_color;
+    int encapsulated;
+    int no_header, no_trailer;
+    double left, right, bot, top;
+};
 
+extern struct ps_state ps;
+
 extern void output(const char *, ...);
 
 extern void init_color_table(void);



More information about the grass-commit mailing list