--- main.c.~1.10.~	Wed Dec  8 10:34:53 2004
+++ main.c	Wed Dec  8 10:32:30 2004
@@ -6,6 +6,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <math.h>
 #include "gis.h"
 #include "display.h"
 #include "raster.h"
@@ -21,13 +22,14 @@
 #ifdef QUIET
     struct Flag *quiet;
 #endif
-    struct Flag *just, *full, *hand, *pan;
+    struct Flag *just, *full, *hand, *pan, *last;
     struct Option *rmap, *vmap, *zoom;
     struct GModule *module;
     double magnify;
     int i, first=1;
-    char *mapset;
-    struct Cell_head window;
+    char *mapset, *map;
+    double ux1, uy1, ux2, uy2;
+    struct Cell_head window, defwin, currwin, tmpwin;
 
     /* Initialize globals */
     rast = vect = NULL;
@@ -114,7 +116,9 @@
     just->key = 'j';
     just->description = "Just redraw given maps using default colors";
 
-
+    last = G_define_flag();
+    last->key = 'l';
+    last->description = "Return to last zoom";
 
     if(!rast && !vect )
     {
@@ -190,6 +194,7 @@
 	}
     }
 
+
 /* Make sure map is available */
     if (rmap->required == YES && rmap->answers == NULL)
     {
@@ -322,8 +327,34 @@
 		    nvects, (nvects > 1 ? "s":""));
     }
 
+   if (last->answer)
+   {
+      map = G_find_file ("windows", "zoom_temp", "");
+      
+      if (!map) {
+	fprintf(stderr,_("this is the first d.zoom run; no previous zoom availible\n"));
+	return(0);
+      }
+
+      G__get_window (&tmpwin, "windows", "zoom_temp", map);
+ 
+      fprintf(stderr, "returning to previous zoom\n") ;
+ 
+      ux1 = tmpwin.east;
+      ux2 = tmpwin.west;
+      uy1 = tmpwin.north;
+      uy2 = tmpwin.south;
+
+      set_win(&tmpwin, ux1, uy1, ux2, uy2, 1);
+      
+      exit(0);
+    }
+
     /* Do the zoom */
     G_get_window(&window);
+    G__put_window(&window, "windows", "zoom_temp");
+    G_get_window(&currwin);
+    G_get_default_window(&defwin);
     if ( full->answer == 1 )
 	stat = zoomwindow(&window, 1, magnify);
     else if(pan->answer == 1)
@@ -334,6 +365,8 @@
 	else
 	    make_window_box (&window, magnify, 0, 1);
     }
+    
+    quit(&defwin,&currwin);
 
     R_close_driver();
 
