src/hid/lesstif/menu.c: Added doxygen comments for GetXY().
[geda-pcb/pcjc2.git] / src / error.c
blob7a622cb697cb9f9eeb3bcd3b1baa04d314181b12
1 /*!
2 * \file src/error.c
4 * \brief Error and debug functions.
6 * <hr>
8 * <h1><b>Copyright.</b></h1>\n
10 * PCB, interactive printed circuit board design
12 * Copyright (C) 1994,1995,1996, 2005 Thomas Nau
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Contact addresses for paper mail and Email:
29 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
30 * Thomas.Nau@rz.uni-ulm.de
35 * getpid() needs a cast to (int) to get rid of compiler warnings
36 * on several architectures
39 #ifdef HAVE_CONFIG_H
40 #include "config.h"
41 #endif
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <errno.h>
46 #include <stdarg.h>
47 #include <signal.h>
48 #ifdef HAVE_STRING_H
49 #include <string.h>
50 #endif
51 #ifdef HAVE_UNISTD_H
52 #include <unistd.h>
53 #endif
54 #include <fcntl.h>
56 #include "global.h"
58 #include "data.h"
59 #include "error.h"
60 #include "file.h"
62 #include "misc.h"
64 #ifdef HAVE_LIBDMALLOC
65 #include <dmalloc.h>
66 #endif
68 #define utf8_dup_string(a,b) *(a) = strdup(b)
70 /* ----------------------------------------------------------------------
71 * some external identifiers
74 #if !defined(HAVE_STRERROR)
75 extern int sys_nerr; /*!< Number of messages available from array. */
76 #define USE_SYS_ERRLIST
77 #endif
79 /* the list is already defined for some OS */
80 #if !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__linux__) && !defined(__DragonFly__)
81 #ifdef USE_SYS_ERRLIST
82 extern char *sys_errlist[]; /*!< Array of error messages. */
83 #endif
84 #endif
87 /*!
88 * \brief Output of message in a dialog window or log window.
90 void
91 Message (const char *Format, ...)
93 va_list args;
94 va_start (args, Format);
95 gui->logv (Format, args);
96 va_end (args);
101 * \brief Print standard 'open error'.
103 void
104 OpenErrorMessage (char *Filename)
106 char *utf8 = NULL;
108 utf8_dup_string (&utf8, Filename);
109 #ifdef USE_SYS_ERRLIST
110 Message (_("Can't open file\n"
111 " '%s'\nfopen() returned: '%s'\n"),
112 utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
113 #else
114 Message (_("Can't open file\n"
115 " '%s'\nfopen() returned: '%s'\n"), utf8, strerror (errno));
116 #endif
117 free (utf8);
121 * \brief Print standard 'popen error'.
123 void
124 PopenErrorMessage (char *Filename)
126 char *utf8 = NULL;
128 utf8_dup_string (&utf8, Filename);
129 #ifdef USE_SYS_ERRLIST
130 Message (_("Can't execute command\n"
131 " '%s'\npopen() returned: '%s'\n"),
132 utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
133 #else
134 Message (_("Can't execute command\n"
135 " '%s'\npopen() returned: '%s'\n"), utf8, strerror (errno));
136 #endif
137 free (utf8);
141 * \brief Print standard 'opendir'.
143 void
144 OpendirErrorMessage (char *DirName)
146 char *utf8 = NULL;
148 utf8_dup_string (&utf8, DirName);
149 #ifdef USE_SYS_ERRLIST
150 Message (_("Can't scan directory\n"
151 " '%s'\nopendir() returned: '%s'\n"),
152 utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
153 #else
154 Message (_("Can't scan directory\n"
155 " '%s'\nopendir() returned: '%s'\n"), utf8, strerror (errno));
156 #endif
157 free (utf8);
161 * \brief Print standard 'chdir error'.
163 void
164 ChdirErrorMessage (char *DirName)
166 char *utf8 = NULL;
168 utf8_dup_string (&utf8, DirName);
169 #ifdef USE_SYS_ERRLIST
170 Message (_("Can't change working directory to\n"
171 " '%s'\nchdir() returned: '%s'\n"),
172 utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
173 #else
174 Message (_("Can't change working directory to\n"
175 " '%s'\nchdir() returned: '%s'\n"), utf8, strerror (errno));
176 #endif
177 free (utf8);
181 * \brief Output of fatal error message.
183 void
184 MyFatal (char *Format, ...)
186 va_list args;
188 va_start (args, Format);
190 /* try to save the layout and do some cleanup */
191 EmergencySave ();
192 fprintf (stderr, "%s (%i): fatal, ", Progname, (int) getpid ());
193 vfprintf (stderr, Format, args);
194 fflush (stderr);
195 va_end (args);
196 exit (1);
200 * \brief Catches signals which abort the program.
202 void
203 CatchSignal (int Signal)
205 char *s;
207 switch (Signal)
209 #ifdef SIGHUP
210 case SIGHUP:
211 s = "SIGHUP";
212 break;
213 #endif
214 case SIGINT:
215 s = "SIGINT";
216 break;
217 #ifdef SIGQUIT
218 case SIGQUIT:
219 s = "SIGQUIT";
220 break;
221 #endif
222 case SIGABRT:
223 s = "SIGABRT";
224 break;
225 case SIGTERM:
226 s = "SIGTERM";
227 break;
228 case SIGSEGV:
229 s = "SIGSEGV";
230 break;
231 default:
232 s = "unknown";
233 break;
235 MyFatal ("aborted by %s signal\n", s);