[sac-dev] small fixes for sac

Brian Savage savage13 at dtm.ciw.edu
Tue Oct 4 06:22:28 PDT 2005


All,

I have developed a patch for sac. It includes the following

- removed AddHistory form main/sac.c - not needed, replaced by libedit
- removed newstn from dff/rdhdr.c - not needed, old code
- removed code from dispatch event which segfaults during unmapnotify
	destorying the window using that little [x] in the corner 	
	resulted in a sac segfault
- added catch for WM_DELETE_WINDOW for destroying the plot window
       should only close connection to X server
- changed plotw3_pixmap = NULL to = 0 for correctness in
	gd3.x11/dispatcheve3.c
- inc/proto.h -- preceeded #define MIN in a #ifdef #undef #endif #define
- added catch for WM_DELETE_WINDOW for destroying the plot window
       should only close connection to X server
- removed gets from utils/sgftops.c, now uses fgets()

The included file is a patch file was created using
% cvs diff -u > patch-bks-20051004
and can be applied to the current CVS version as
% cvs co SAC
.....
% ls
SAC
% patch -p0 < patch-bks-20051004

Please test and and get back to me if you experience any problems.

Cheers,
Brian Savage
savage13 at dtm.ciw.edu
-------------- next part --------------
Index: SAC/inc/gd3.x11.h
===================================================================
RCS file: /export/home/cvs/repository/SAC/inc/gd3.x11.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 gd3.x11.h
--- SAC/inc/gd3.x11.h	27 Jul 2005 18:55:03 -0000	1.1.1.1
+++ SAC/inc/gd3.x11.h	4 Oct 2005 13:03:38 -0000
@@ -70,6 +70,7 @@
   int height_p;
   int status;
   GC  gc;
+  Atom wm_delete_window;
 };
 
 point current_pt_p3;
Index: SAC/inc/proto.h
===================================================================
RCS file: /export/home/cvs/repository/SAC/inc/proto.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 proto.h
--- SAC/inc/proto.h	27 Jul 2005 18:55:03 -0000	1.1.1.1
+++ SAC/inc/proto.h	4 Oct 2005 13:03:38 -0000
@@ -22,6 +22,9 @@
 #define ichar(s) (int)(*(s))
 #define maxfi(f1,f2) (long) fmax(f1,f2)
 #define minfi(f1,f2) (long) fmin(f1,f2)
+#ifdef MIN
+#undef MIN
+#endif
 #define MIN(f1,f2) ((f1) < (f2) ? (f1) : (f2))
 
 void CSStoSAC () ;
Index: SAC/src/dff/rdhdr.c
===================================================================
RCS file: /export/home/cvs/repository/SAC/src/dff/rdhdr.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 rdhdr.c
--- SAC/src/dff/rdhdr.c	27 Jul 2005 18:55:04 -0000	1.1.1.1
+++ SAC/src/dff/rdhdr.c	4 Oct 2005 13:03:38 -0000
@@ -221,7 +221,7 @@
 
 	/* - Update station name if necessary. */
 
-	newstn( kstnm, kstnm,9 );
+/*	newstn( kstnm, kstnm,9 ); */
 
 	/* - Adjust reference year if necessary. */
 
Index: SAC/src/gd3.x11/createwindo3.c
===================================================================
RCS file: /export/home/cvs/repository/SAC/src/gd3.x11/createwindo3.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 createwindo3.c
--- SAC/src/gd3.x11/createwindo3.c	27 Jul 2005 18:55:05 -0000	1.1.1.1
+++ SAC/src/gd3.x11/createwindo3.c	4 Oct 2005 13:03:39 -0000
@@ -51,10 +51,13 @@
 #include <stdio.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
+#include <X11/Xatom.h>
 #include <X11/cursorfont.h>
 #include "../../inc/gd3.x11.h"
 #include "sac.bitmap"
 
+Atom deletewindow3(Display *display, Window win);
+
 Cursor cursor;
 
 
@@ -89,7 +92,7 @@
   width_p = (unsigned int) ((float) (scr_width_p3-1) * (*xmax_vp - *xmin_vp));
   height_p = (unsigned int) ((float) (scr_height_p3-1) * (*ymax_vp - *ymin_vp));
 
-
+  
 /* Create title label */
 
   make_label3("Graphics Window:  ", win_num, title_label);
@@ -206,12 +209,17 @@
   XSelectInput(display3,plotw3[*win_num].win,
 	       ( ExposureMask | StructureNotifyMask ));
 
+  plotw3[*win_num].wm_delete_window = 
+    deletewindow3(display3, plotw3[*win_num].win);
+  
 #endif /* USE_X11_DOUBLE_BUFFER */
 
 /* Select events will be accepted by each window */
 
   XSelectInput(display3,basew3[*win_num].win,
 	       (ExposureMask | StructureNotifyMask));
+  basew3[*win_num].wm_delete_window = 
+    deletewindow3(display3, basew3[*win_num].win);
 
 /* Map the windows */
 
@@ -247,3 +255,10 @@
 #endif /* USE_X11_DOUBLE_BUFFER */
 }
 
+Atom
+deletewindow3(Display *display, Window win) {
+  Atom wm_delete_window;
+  wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
+  XSetWMProtocols(display, win, &wm_delete_window, 1);
+  return(wm_delete_window);
+}
Index: SAC/src/gd3.x11/dispatcheve3.c
===================================================================
RCS file: /export/home/cvs/repository/SAC/src/gd3.x11/dispatcheve3.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 dispatcheve3.c
--- SAC/src/gd3.x11/dispatcheve3.c	27 Jul 2005 18:55:05 -0000	1.1.1.1
+++ SAC/src/gd3.x11/dispatcheve3.c	4 Oct 2005 13:03:39 -0000
@@ -98,8 +98,9 @@
 
 /* Find out which window event occurred in and set index */
 
-  while ((nevents = XPending(display3)) > 0) {  /* While there is an event */
-    for (n=1; n<=nevents; n++) { 
+  while (display3 && 
+	 (nevents = XPending(display3)) > 0){  /* While there is an event */
+    for (n=1; display3 && n<=nevents; n++) { 
       XNextEvent(display3,&event);                 /* Get next event */
       index = 0;
       i = 1;
@@ -125,28 +126,13 @@
       while (i <= num_wins3);
 
 /*  Process each event */
-
       switch (event.type) {
-
-#ifdef USE_X11_DOUBLE_BUFFER
-      case DestroyNotify:
-	fprintf(stderr, "DestroyNotify - Untested Code\n");
-      case UnmapNotify:
-	fprintf(stderr, "UnmapNotify - Untested Code\n");
-	XDestroyWindow(display3, basew3[index].win);
-	XDestroyWindow(display3, titlew3[index].win);
-	XDestroyWindow(display3, plotw3[index].win);
-	XFreeGC(display3, basew3[index].gc);
-	XFreeGC(display3, titlew3[index].gc);
-	XFreeGC(display3, plotw3[index].gc);
-	XFreeGC(display3, cursorgc3[index]);
-	XFreePixmap(display3, plotw3_pixmap);
-
-	num_wins3--;
-	enddevice3(nerr);
+      case ClientMessage:
+	if(event.xclient.data.l[0] == plotw3[index].wm_delete_window &&
+	  is_basew == 1) {
+	  enddevice(device_name3, 13, nerr);
+	}
 	break;
-#endif
-
 
       case ConfigureNotify:
 	if (is_basew) {
@@ -160,10 +146,11 @@
 	    
 #ifdef USE_X11_DOUBLE_BUFFER
 	    XFreePixmap(display3, plotw3_pixmap);
-	    plotw3_pixmap = NULL;
+	    plotw3_pixmap = 0;
 	    plotw3_pixmap = XCreatePixmap(display3, basew3[index].win,
 					  basew_info.width, basew_info.height,
-					  DefaultDepth(display3, DefaultScreen(display3)));
+					  DefaultDepth(display3, 
+						       DefaultScreen(display3)));
 	    XFillRectangle(display3, plotw3_pixmap, plotw3[index].gc,
 			   0, 0,
 			   basew_info.width,
@@ -420,16 +407,13 @@
 	       break;
 
       }
-
+      
 /* Reset window flags */
-
       is_basew = 0;
       is_plotw = 0;
       is_titlew = 0;
 
     }
-
   }
-
 }
 
Index: SAC/src/gd3.x11/enddevice3.c
===================================================================
RCS file: /export/home/cvs/repository/SAC/src/gd3.x11/enddevice3.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 enddevice3.c
--- SAC/src/gd3.x11/enddevice3.c	27 Jul 2005 18:55:05 -0000	1.1.1.1
+++ SAC/src/gd3.x11/enddevice3.c	4 Oct 2005 13:03:39 -0000
@@ -19,6 +19,7 @@
 *
 *******************************************************************************/
 
+#include <stdio.h>
 #include <X11/Xlib.h>
 #include "../../inc/gd3.x11.h"
 
@@ -31,21 +32,20 @@
   *nerr = 0;
 
 /* Destroy window activity and set status flag */
-
   c_win3 = 0;
   for (i=1; i <= num_wins3; i++) {
-/*  XDestroyWindow(display3,basew3[i].win);*/
+//    XDestroyWindow(display3,basew3[i].win);
     basew3[i].status = UNAVAILABLE;
+    plotw3[i].status = UNAVAILABLE;
   }
-
+  
 /*  Free title font */
-
+  
 /* XUnloadFont(display3,title_font3); */
-
+  
 /*  Close window display */
-
   XCloseDisplay(display3);
-  
+  display3 = NULL;
 }
 
 /*******************************************************************************
Index: SAC/src/main/sac.c
===================================================================
RCS file: /export/home/cvs/repository/SAC/src/main/sac.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 sac.c
--- SAC/src/main/sac.c	27 Jul 2005 18:55:05 -0000	1.1.1.1
+++ SAC/src/main/sac.c	4 Oct 2005 13:03:39 -0000
@@ -122,7 +122,7 @@
 	/* the main loop of the program */
 	while( TRUE ){
 	    zgpmsg( kmexm.kprmt,13, kmsg,MCMSG+1 );
-	    strcpy(kmsg,AddToHistory(kmsg)) ;
+//	    strcpy(kmsg,AddToHistory(kmsg)) ;
 	    ncmsg = indexb( kmsg,MCMSG+1 );
 	    if( ncmsg >= MCMSG ){
 		setmsg( "ERROR", 99 );
Index: SAC/utils/sgftops.c
===================================================================
RCS file: /export/home/cvs/repository/SAC/utils/sgftops.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 sgftops.c
--- SAC/utils/sgftops.c	27 Jul 2005 18:55:06 -0000	1.1.1.1
+++ SAC/utils/sgftops.c	4 Oct 2005 13:03:39 -0000
@@ -270,13 +270,13 @@
         printf("   Sample portrait:  0.5 0.5 0 0.75\n");
         printf(" \n");
         printf("\nx translation : ");
-        gets(xshif);
+	fgets(xshif, 6, stdin);
         printf("y translation : ");
-        gets(yshif);
+	fgets(yshif, 6, stdin);
         printf("rotation angle: ");
-        gets(angle);
+	fgets(angle, 6, stdin);
         printf("scale........ : ");
-        gets(sfact);
+	fgets(sfact, 6, stdin);
         fprintf(ofp, "gsave");
         fprintf(ofp, "\n72 %s mul 72 %s mul translate", xshif, yshif);
         fprintf(ofp, "\n%s rotate", angle);
@@ -527,7 +527,7 @@
                     if (buffer[i] == 32000 && scale_flag) {
                         printf("Scale size 32000 encountered.\n");
                         printf("Possible Old SGF - Scale anyway (y/n): ");
-                        gets(scale);
+                        fgets(scale, 4, stdin);
                     }
                     if (!strncmp(scale, "n", 1) || !scale_flag)  {
                         i++; /* don't scale */


More information about the sac-dev mailing list