4 * PCB, interactive printed circuit board design
5 * Copyright (C) 1994,1995,1996, 2005 Thomas Nau
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Contact addresses for paper mail and Email:
22 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
23 * Thomas.Nau@rz.uni-ulm.de
28 /* error and debug functions
29 * getpid() needs a cast to (int) to get rid of compiler warnings
30 * on several architectures
58 #ifdef HAVE_LIBDMALLOC
62 #define utf8_dup_string(a,b) *(a) = strdup(b)
64 /* ----------------------------------------------------------------------
65 * some external identifiers
68 #if !defined(HAVE_STRERROR)
69 extern int sys_nerr
; /* number of messages available from array */
70 #define USE_SYS_ERRLIST
73 /* the list is already defined for some OS */
74 #if !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__linux__) && !defined(__DragonFly__)
75 #ifdef USE_SYS_ERRLIST
76 extern char *sys_errlist
[]; /* array of error messages */
81 /* ---------------------------------------------------------------------------
82 * output of message in a dialog window or log window
85 Message (const char *Format
, ...)
88 va_start (args
, Format
);
89 gui
->logv (Format
, args
);
94 /* ---------------------------------------------------------------------------
95 * print standard 'open error'
98 OpenErrorMessage (char *Filename
)
102 utf8_dup_string (&utf8
, Filename
);
103 #ifdef USE_SYS_ERRLIST
104 Message (_("Can't open file\n"
105 " '%s'\nfopen() returned: '%s'\n"),
106 utf8
, errno
<= sys_nerr
? sys_errlist
[errno
] : "???");
108 Message (_("Can't open file\n"
109 " '%s'\nfopen() returned: '%s'\n"), utf8
, strerror (errno
));
114 /* ---------------------------------------------------------------------------
115 * print standard 'popen error'
118 PopenErrorMessage (char *Filename
)
122 utf8_dup_string (&utf8
, Filename
);
123 #ifdef USE_SYS_ERRLIST
124 Message (_("Can't execute command\n"
125 " '%s'\npopen() returned: '%s'\n"),
126 utf8
, errno
<= sys_nerr
? sys_errlist
[errno
] : "???");
128 Message (_("Can't execute command\n"
129 " '%s'\npopen() returned: '%s'\n"), utf8
, strerror (errno
));
134 /* ---------------------------------------------------------------------------
135 * print standard 'opendir'
138 OpendirErrorMessage (char *DirName
)
142 utf8_dup_string (&utf8
, DirName
);
143 #ifdef USE_SYS_ERRLIST
144 Message (_("Can't scan directory\n"
145 " '%s'\nopendir() returned: '%s'\n"),
146 utf8
, errno
<= sys_nerr
? sys_errlist
[errno
] : "???");
148 Message (_("Can't scan directory\n"
149 " '%s'\nopendir() returned: '%s'\n"), utf8
, strerror (errno
));
154 /* ---------------------------------------------------------------------------
155 * print standard 'chdir error'
158 ChdirErrorMessage (char *DirName
)
162 utf8_dup_string (&utf8
, DirName
);
163 #ifdef USE_SYS_ERRLIST
164 Message (_("Can't change working directory to\n"
165 " '%s'\nchdir() returned: '%s'\n"),
166 utf8
, errno
<= sys_nerr
? sys_errlist
[errno
] : "???");
168 Message (_("Can't change working directory to\n"
169 " '%s'\nchdir() returned: '%s'\n"), utf8
, strerror (errno
));
174 /* ---------------------------------------------------------------------------
175 * output of fatal error message
178 MyFatal (char *Format
, ...)
182 va_start (args
, Format
);
184 /* try to save the layout and do some cleanup */
186 fprintf (stderr
, "%s (%i): fatal, ", Progname
, (int) getpid ());
187 vfprintf (stderr
, Format
, args
);
193 /* ---------------------------------------------------------------------------
194 * catches signals which abort the program
197 CatchSignal (int Signal
)
229 MyFatal ("aborted by %s signal\n", s
);