4 * \brief Error and debug functions.
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
64 #ifdef HAVE_LIBDMALLOC
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
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. */
88 * \brief Output of message in a dialog window or log window.
91 Message (const char *Format
, ...)
94 va_start (args
, Format
);
95 gui
->logv (Format
, args
);
101 * \brief Print standard 'open error'.
104 OpenErrorMessage (char *Filename
)
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
] : "???");
114 Message (_("Can't open file\n"
115 " '%s'\nfopen() returned: '%s'\n"), utf8
, strerror (errno
));
121 * \brief Print standard 'popen error'.
124 PopenErrorMessage (char *Filename
)
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
] : "???");
134 Message (_("Can't execute command\n"
135 " '%s'\npopen() returned: '%s'\n"), utf8
, strerror (errno
));
141 * \brief Print standard 'opendir'.
144 OpendirErrorMessage (char *DirName
)
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
] : "???");
154 Message (_("Can't scan directory\n"
155 " '%s'\nopendir() returned: '%s'\n"), utf8
, strerror (errno
));
161 * \brief Print standard 'chdir error'.
164 ChdirErrorMessage (char *DirName
)
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
] : "???");
174 Message (_("Can't change working directory to\n"
175 " '%s'\nchdir() returned: '%s'\n"), utf8
, strerror (errno
));
181 * \brief Output of fatal error message.
184 MyFatal (char *Format
, ...)
188 va_start (args
, Format
);
190 /* try to save the layout and do some cleanup */
192 fprintf (stderr
, "%s (%i): fatal, ", Progname
, (int) getpid ());
193 vfprintf (stderr
, Format
, args
);
200 * \brief Catches signals which abort the program.
203 CatchSignal (int Signal
)
235 MyFatal ("aborted by %s signal\n", s
);