errors.c 2.79 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
17
 */
18
19
#include "config.h"

Elliot Lee's avatar
Elliot Lee committed
20
21
22
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
23
24
#include <stdlib.h>
#ifdef HAVE_SYS_TIME_H
Elliot Lee's avatar
Elliot Lee committed
25
#include <sys/time.h>
26
27
#endif
#ifdef HAVE_SYS_TIMES_H
Elliot Lee's avatar
Elliot Lee committed
28
#include <sys/times.h>
29
#endif
Elliot Lee's avatar
Elliot Lee committed
30
31
#include <sys/types.h>
#include <time.h>
32
#ifdef HAVE_UNISTD_H
Elliot Lee's avatar
Elliot Lee committed
33
#include <unistd.h>
34
#endif
Elliot Lee's avatar
Elliot Lee committed
35

36
#include <gtk/gtk.h>
Manish Singh's avatar
Manish Singh committed
37
#include "appenv.h"
Elliot Lee's avatar
Elliot Lee committed
38
#include "app_procs.h"
39
#include "errorconsole.h"
Elliot Lee's avatar
Elliot Lee committed
40
#include "errors.h"
41
42
#include "gimpui.h"

43
#include "libgimp/gimpintl.h"
Elliot Lee's avatar
Elliot Lee committed
44

45
#ifdef G_OS_WIN32
46
47
48
#include <windows.h>
#endif

49
extern gchar *prog_name;
Elliot Lee's avatar
Elliot Lee committed
50
51

void
52
gimp_message_func (gchar *str)
Elliot Lee's avatar
Elliot Lee committed
53
{
54
55
56
57
  if (console_messages == FALSE)
    switch (message_handler)
      {
        case MESSAGE_BOX:
58
          gimp_message_box (str, NULL, NULL);
59
60
61
62
63
64
65
66
67
68
          break;

        case ERROR_CONSOLE:
          error_console_add (str);
          break;

        default:
          fprintf (stderr, "%s: %s\n", prog_name, str);
	  break;
    }
69
  else
70
    fprintf (stderr, "%s: %s\n", prog_name, str);
Elliot Lee's avatar
Elliot Lee committed
71
72
73
}

void
74
gimp_fatal_error (gchar *fmt, ...)
Elliot Lee's avatar
Elliot Lee committed
75
{
76
#ifndef G_OS_WIN32
Elliot Lee's avatar
Elliot Lee committed
77
78
79
  va_list args;

  va_start (args, fmt);
80
  g_print ("%s: fatal error: %s\n", prog_name, g_strdup_vprintf (fmt, args));
Elliot Lee's avatar
Elliot Lee committed
81
  va_end (args);
82
  g_on_error_query (prog_name);
Tor Lillqvist's avatar
Tor Lillqvist committed
83
#else
84
85
86
87
88
89
90
91
92
93
94
  /* g_on_error_query doesn't do anything reasonable on Win32. */
  va_list args;
  gchar *msg;

  va_start (args, fmt);
  msg = g_strdup_vprintf (fmt, args);
  va_end (args);

  MessageBox (NULL, msg, prog_name, MB_OK|MB_ICONERROR);
  /* I don't dare do anything more. */
  ExitProcess (1);
Tor Lillqvist's avatar
Tor Lillqvist committed
95
#endif
96
  app_exit (TRUE);
Elliot Lee's avatar
Elliot Lee committed
97
}
98
99

void
100
gimp_terminate (gchar *fmt, ...)
101
{
102
#ifndef G_OS_WIN32
103
104
105
  va_list args;

  va_start (args, fmt);
106
  g_print ("%s terminated: ", prog_name);
107
  vprintf (fmt, args);
108
  g_print ("\n");
109
110
  va_end (args);

111
  if (use_debug_handler)
112
    g_on_error_query (prog_name);
113
114
115
116
117
118
119
120
121
122
#else
  /* g_on_error_query doesn't do anything reasonable on Win32. */
  va_list args;
  gchar *msg;

  va_start (args, fmt);
  msg = g_strdup_vprintf (fmt, args);
  va_end (args);

  MessageBox (NULL, msg, prog_name, MB_OK|MB_ICONERROR);
Tor Lillqvist's avatar
Tor Lillqvist committed
123
#endif
124
125
  gdk_exit (1);
}