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
60 #ifdef HAVE_LIBDMALLOC
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
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 */
86 /* ---------------------------------------------------------------------------
87 * output of message in a dialog window or log window
90 Message (const char *Format
, ...)
93 va_start (args
, Format
);
94 gui
->logv (Format
, args
);
99 /* ---------------------------------------------------------------------------
100 * print standard 'open error'
103 OpenErrorMessage (char *Filename
)
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
] : "???");
113 Message (_("Can't open file\n"
114 " '%s'\nfopen() returned: '%s'\n"), utf8
, strerror (errno
));
119 /* ---------------------------------------------------------------------------
120 * print standard 'popen error'
123 PopenErrorMessage (char *Filename
)
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
] : "???");
133 Message (_("Can't execute command\n"
134 " '%s'\npopen() returned: '%s'\n"), utf8
, strerror (errno
));
139 /* ---------------------------------------------------------------------------
140 * print standard 'opendir'
143 OpendirErrorMessage (char *DirName
)
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
] : "???");
153 Message (_("Can't scan directory\n"
154 " '%s'\nopendir() returned: '%s'\n"), utf8
, strerror (errno
));
159 /* ---------------------------------------------------------------------------
160 * print standard 'chdir error'
163 ChdirErrorMessage (char *DirName
)
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
] : "???");
173 Message (_("Can't change working directory to\n"
174 " '%s'\nchdir() returned: '%s'\n"), utf8
, strerror (errno
));
179 /* ---------------------------------------------------------------------------
180 * output of fatal error message
183 MyFatal (char *Format
, ...)
187 va_start (args
, Format
);
189 /* try to save the layout and do some cleanup */
191 fprintf (stderr
, "%s (%i): fatal, ", Progname
, (int) getpid ());
192 vfprintf (stderr
, Format
, args
);
198 /* ---------------------------------------------------------------------------
199 * catches signals which abort the program
202 CatchSignal (int Signal
)
234 MyFatal ("aborted by %s signal\n", s
);