home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part02 / u_error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-27  |  2.7 KB  |  108 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1985 by Supoj Sutanthavibul
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "mode.h"
  15. #include "resources.h"
  16.  
  17. #define MAXERRORS 6
  18. #define MAXERRMSGLEN 512
  19.  
  20. static int    error_cnt = 0;
  21.  
  22. /* VARARGS1 */
  23. put_err(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
  24.     char       *format, *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7,
  25.            *arg8;
  26. {
  27.     fprintf(stderr, format, arg1, arg2, arg3, arg4, arg5,
  28.         arg6, arg7, arg8);
  29.     put_msg(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
  30. }
  31.  
  32. error_handler(err_sig)
  33.     int            err_sig;
  34. {
  35.     switch (err_sig) {
  36.     case SIGHUP:
  37.     fprintf(stderr, "\nxfig: SIGHUP signal trapped\n");
  38.     break;
  39.     case SIGFPE:
  40.     fprintf(stderr, "\nxfig: SIGFPE signal trapped\n");
  41.     break;
  42. #ifndef NO_SIBGUS
  43.     case SIGBUS:
  44.     fprintf(stderr, "\nxfig: SIGBUS signal trapped\n");
  45.     break;
  46. #endif
  47.     case SIGSEGV:
  48.     fprintf(stderr, "\nxfig: SIGSEGV signal trapped\n");
  49.     break;
  50.     }
  51.     emergency_quit();
  52. }
  53.  
  54. X_error_handler(d, err_ev)
  55.     Display       *d;
  56.     XErrorEvent       *err_ev;
  57. {
  58.     char        err_msg[MAXERRMSGLEN];
  59.  
  60.     XGetErrorText(tool_d, (int) (err_ev->error_code), err_msg, MAXERRMSGLEN - 1);
  61.     (void) fprintf(stderr,
  62.        "xfig: X error trapped - error message follows:\n%s\n", err_msg);
  63.     emergency_quit();
  64. }
  65.  
  66. emergency_quit()
  67. {
  68.     if (++error_cnt > MAXERRORS) {
  69.     fprintf(stderr, "xfig: too many errors - giving up.\n");
  70.     exit(-1);
  71.     }
  72.     signal(SIGHUP, SIG_DFL);
  73.     signal(SIGFPE, SIG_DFL);
  74. #ifndef NO_SIBGUS
  75.     signal(SIGBUS, SIG_DFL);
  76. #endif
  77.     signal(SIGSEGV, SIG_DFL);
  78.  
  79.     aborting = 1;
  80.     if (figure_modified && !emptyfigure()) {
  81.     fprintf(stderr, "xfig: attempting to save figure\n");
  82.     if (emergency_save("xfig.SAVE") == -1)
  83.         if (emergency_save(strcat(TMPDIR,"/xfig.SAVE")) == -1)
  84.         fprintf(stderr, "xfig: unable to save figure\n");
  85.     } else
  86.     fprintf(stderr, "xfig: figure empty or not modified - exiting\n");
  87.  
  88.     quit();
  89. }
  90.  
  91. /* ARGSUSED */
  92. void my_quit(w, event, params, num_params)
  93. Widget w;
  94. XEvent *event;
  95. String *params;
  96. Cardinal *num_params;
  97. {
  98.     extern Atom wm_delete_window;
  99.     if (event && event->type == ClientMessage &&
  100.     event->xclient.data.l[0] != wm_delete_window)
  101.     {
  102.     return;
  103.     }
  104.     /* free all the GC's */
  105.     free_GCs();
  106.     emergency_quit();
  107. }
  108.