gerber.c: Tidy up use_gc() routine to avoid a static anlysis warning
[geda-pcb/pcjc2.git] / src / error.c
blobf01420e46d8d76a3dbecddce570d0b1e95f36fb2
1 /* $Id$ */
3 /*
4 * COPYRIGHT
6 * PCB, interactive printed circuit board design
7 * Copyright (C) 1994,1995,1996, 2005 Thomas Nau
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Contact addresses for paper mail and Email:
24 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
25 * Thomas.Nau@rz.uni-ulm.de
30 /* error and debug functions
31 * getpid() needs a cast to (int) to get rid of compiler warnings
32 * on several architectures
35 #ifdef HAVE_CONFIG_H
36 #include "config.h"
37 #endif
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <errno.h>
42 #include <stdarg.h>
43 #include <signal.h>
44 #ifdef HAVE_STRING_H
45 #include <string.h>
46 #endif
47 #ifdef HAVE_UNISTD_H
48 #include <unistd.h>
49 #endif
50 #include <fcntl.h>
52 #include "global.h"
54 #include "data.h"
55 #include "error.h"
56 #include "file.h"
58 #include "misc.h"
60 #ifdef HAVE_LIBDMALLOC
61 #include <dmalloc.h>
62 #endif
64 RCSID ("$Id$");
67 #define utf8_dup_string(a,b) *(a) = strdup(b)
69 /* ----------------------------------------------------------------------
70 * some external identifiers
73 #if !defined(HAVE_STRERROR)
74 extern int sys_nerr; /* number of messages available from array */
75 #define USE_SYS_ERRLIST
76 #endif
78 /* the list is already defined for some OS */
79 #if !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__linux__) && !defined(__DragonFly__)
80 #ifdef USE_SYS_ERRLIST
81 extern char *sys_errlist[]; /* array of error messages */
82 #endif
83 #endif
86 /* ---------------------------------------------------------------------------
87 * output of message in a dialog window or log window
89 void
90 Message (const char *Format, ...)
92 va_list args;
93 va_start (args, Format);
94 gui->logv (Format, args);
95 va_end (args);
99 /* ---------------------------------------------------------------------------
100 * print standard 'open error'
102 void
103 OpenErrorMessage (char *Filename)
105 char *utf8 = NULL;
107 utf8_dup_string (&utf8, Filename);
108 #ifdef USE_SYS_ERRLIST
109 Message (_("Can't open file\n"
110 " '%s'\nfopen() returned: '%s'\n"),
111 utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
112 #else
113 Message (_("Can't open file\n"
114 " '%s'\nfopen() returned: '%s'\n"), utf8, strerror (errno));
115 #endif
116 free (utf8);
119 /* ---------------------------------------------------------------------------
120 * print standard 'popen error'
122 void
123 PopenErrorMessage (char *Filename)
125 char *utf8 = NULL;
127 utf8_dup_string (&utf8, Filename);
128 #ifdef USE_SYS_ERRLIST
129 Message (_("Can't execute command\n"
130 " '%s'\npopen() returned: '%s'\n"),
131 utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
132 #else
133 Message (_("Can't execute command\n"
134 " '%s'\npopen() returned: '%s'\n"), utf8, strerror (errno));
135 #endif
136 free (utf8);
139 /* ---------------------------------------------------------------------------
140 * print standard 'opendir'
142 void
143 OpendirErrorMessage (char *DirName)
145 char *utf8 = NULL;
147 utf8_dup_string (&utf8, DirName);
148 #ifdef USE_SYS_ERRLIST
149 Message (_("Can't scan directory\n"
150 " '%s'\nopendir() returned: '%s'\n"),
151 utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
152 #else
153 Message (_("Can't scan directory\n"
154 " '%s'\nopendir() returned: '%s'\n"), utf8, strerror (errno));
155 #endif
156 free (utf8);
159 /* ---------------------------------------------------------------------------
160 * print standard 'chdir error'
162 void
163 ChdirErrorMessage (char *DirName)
165 char *utf8 = NULL;
167 utf8_dup_string (&utf8, DirName);
168 #ifdef USE_SYS_ERRLIST
169 Message (_("Can't change working directory to\n"
170 " '%s'\nchdir() returned: '%s'\n"),
171 utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
172 #else
173 Message (_("Can't change working directory to\n"
174 " '%s'\nchdir() returned: '%s'\n"), utf8, strerror (errno));
175 #endif
176 free (utf8);
179 /* ---------------------------------------------------------------------------
180 * output of fatal error message
182 void
183 MyFatal (char *Format, ...)
185 va_list args;
187 va_start (args, Format);
189 /* try to save the layout and do some cleanup */
190 EmergencySave ();
191 fprintf (stderr, "%s (%i): fatal, ", Progname, (int) getpid ());
192 vfprintf (stderr, Format, args);
193 fflush (stderr);
194 va_end (args);
195 exit (1);
198 /* ---------------------------------------------------------------------------
199 * catches signals which abort the program
201 void
202 CatchSignal (int Signal)
204 char *s;
206 switch (Signal)
208 #ifdef SIGHUP
209 case SIGHUP:
210 s = "SIGHUP";
211 break;
212 #endif
213 case SIGINT:
214 s = "SIGINT";
215 break;
216 #ifdef SIGQUIT
217 case SIGQUIT:
218 s = "SIGQUIT";
219 break;
220 #endif
221 case SIGABRT:
222 s = "SIGABRT";
223 break;
224 case SIGTERM:
225 s = "SIGTERM";
226 break;
227 case SIGSEGV:
228 s = "SIGSEGV";
229 break;
230 default:
231 s = "unknown";
232 break;
234 MyFatal ("aborted by %s signal\n", s);