home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / app / errors.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  3.5 KB  |  169 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include <signal.h>
  22. #include <stdarg.h>
  23. #include <stdlib.h>
  24. #include <sys/types.h>
  25. #ifdef HAVE_UNISTD_H
  26. #include <unistd.h>
  27. #endif
  28.  
  29. #include <gtk/gtk.h>
  30.  
  31. #include "apptypes.h"
  32.  
  33. #include "appenv.h"
  34. #include "app_procs.h"
  35. #include "errorconsole.h"
  36. #include "errors.h"
  37. #include "gimpui.h"
  38.  
  39. #ifdef G_OS_WIN32
  40. #include <windows.h>
  41. #endif
  42.  
  43. extern gchar *prog_name;
  44.  
  45. StackTraceMode stack_trace_mode = STACK_TRACE_QUERY;
  46.  
  47. void
  48. gimp_message_func (const gchar    *log_domain,
  49.            GLogLevelFlags  log_level,
  50.            const gchar    *message,
  51.            gpointer        data)
  52. {
  53.   if (console_messages == FALSE)
  54.     {
  55.       switch (message_handler)
  56.     {
  57.     case MESSAGE_BOX:
  58.       gimp_message_box ((gchar *) message, NULL, NULL);
  59.       break;
  60.  
  61.     case ERROR_CONSOLE:
  62.       error_console_add ((gchar *) message);
  63.       break;
  64.  
  65.     default:
  66.       g_printerr ("%s: %s\n", prog_name, (gchar *) message);
  67.       break;
  68.     }
  69.     }
  70.   else
  71.     {
  72.       g_printerr ("%s: %s\n", prog_name, (gchar *) message);
  73.     }
  74. }
  75.  
  76. void
  77. gimp_fatal_error (gchar *fmt, ...)
  78. {
  79.   va_list args;
  80.  
  81. #ifndef G_OS_WIN32
  82.  
  83.   va_start (args, fmt);
  84.   g_printerr ("%s: fatal error: %s\n", prog_name, g_strdup_vprintf (fmt, args));
  85.   va_end (args);
  86.  
  87.   switch (stack_trace_mode)
  88.     {
  89.     case STACK_TRACE_NEVER:
  90.       break;
  91.  
  92.     case STACK_TRACE_QUERY:
  93.       {
  94.     sigset_t sigset;
  95.  
  96.     sigemptyset (&sigset);
  97.     sigprocmask (SIG_SETMASK, &sigset, NULL);
  98.     g_on_error_query (prog_name);
  99.       }
  100.       break;
  101.  
  102.     case STACK_TRACE_ALWAYS:
  103.       {
  104.     sigset_t sigset;
  105.  
  106.     sigemptyset (&sigset);
  107.     sigprocmask (SIG_SETMASK, &sigset, NULL);
  108.     g_on_error_stack_trace (prog_name);
  109.       }
  110.       break;
  111.  
  112.     default:
  113.       break;
  114.     }
  115.  
  116. #else
  117.  
  118.   /* g_on_error_* don't do anything reasonable on Win32. */
  119.   gchar *msg;
  120.  
  121.   va_start (args, fmt);
  122.   msg = g_strdup_vprintf (fmt, args);
  123.   va_end (args);
  124.  
  125.   MessageBox (NULL, msg, prog_name, MB_OK|MB_ICONERROR);
  126.   /* I don't dare do anything more. */
  127.   ExitProcess (1);
  128.  
  129. #endif /* ! G_OS_WIN32 */
  130.  
  131.   app_exit (TRUE);
  132. }
  133.  
  134. void
  135. gimp_terminate (gchar *fmt, ...)
  136. {
  137.   va_list args;
  138.  
  139. #ifndef G_OS_WIN32
  140.  
  141.   va_start (args, fmt);
  142.   g_printerr ("%s terminated: %s\n", prog_name, g_strdup_vprintf (fmt, args));
  143.   va_end (args);
  144.  
  145.   if (use_debug_handler)
  146.     {
  147.       sigset_t sigset;
  148.  
  149.       sigemptyset (&sigset);
  150.       sigprocmask (SIG_SETMASK, &sigset, NULL);
  151.       g_on_error_query (prog_name);
  152.     }
  153.  
  154. #else
  155.  
  156.   /* g_on_error_* don't do anything reasonable on Win32. */
  157.   gchar *msg;
  158.  
  159.   va_start (args, fmt);
  160.   msg = g_strdup_vprintf (fmt, args);
  161.   va_end (args);
  162.  
  163.   MessageBox (NULL, msg, prog_name, MB_OK|MB_ICONERROR);
  164.  
  165. #endif /* ! G_OS_WIN32 */
  166.  
  167.   gdk_exit (1);
  168. }
  169.