pcb 4.1.1
An interactive printed circuit board layout editor.

error.c

Go to the documentation of this file.
00001 
00034 /*
00035  * getpid() needs a cast to (int) to get rid of compiler warnings
00036  * on several architectures
00037  */
00038 
00039 #ifdef HAVE_CONFIG_H
00040 #include "config.h"
00041 #endif
00042 
00043 #include <stdio.h>
00044 #include <stdlib.h>
00045 #include <errno.h>
00046 #include <stdarg.h>
00047 #include <signal.h>
00048 #ifdef HAVE_STRING_H
00049 #include <string.h>
00050 #endif
00051 #ifdef HAVE_UNISTD_H
00052 #include <unistd.h>
00053 #endif
00054 #include <fcntl.h>
00055 
00056 #include "global.h"
00057 
00058 #include "data.h"
00059 #include "error.h"
00060 #include "file.h"
00061 
00062 #include "misc.h"
00063 
00064 #ifdef HAVE_LIBDMALLOC
00065 #include <dmalloc.h>
00066 #endif
00067 
00068 #define utf8_dup_string(a,b) *(a) = strdup(b)
00069 
00070 /* ----------------------------------------------------------------------
00071  * some external identifiers
00072  */
00073 
00074 #if !defined(HAVE_STRERROR)
00075 extern int sys_nerr;            
00076 #define USE_SYS_ERRLIST
00077 #endif
00078 
00079 /* the list is already defined for some OS */
00080 #if !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__linux__) && !defined(__DragonFly__)
00081 #ifdef USE_SYS_ERRLIST
00082 extern char *sys_errlist[];     
00083 #endif
00084 #endif
00085 
00086 
00090 void
00091 Message (const char *Format, ...)
00092 {
00093   va_list args;
00094   va_start (args, Format);
00095   gui->logv (Format, args);
00096   va_end (args);
00097 }
00098 
00099 
00103 void
00104 OpenErrorMessage (char *Filename)
00105 {
00106   char *utf8 = NULL;
00107 
00108   utf8_dup_string (&utf8, Filename);
00109 #ifdef USE_SYS_ERRLIST
00110   Message (_("Can't open file\n"
00111              "   '%s'\nfopen() returned: '%s'\n"),
00112            utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
00113 #else
00114   Message (_("Can't open file\n"
00115              "   '%s'\nfopen() returned: '%s'\n"), utf8, strerror (errno));
00116 #endif
00117   free (utf8);
00118 }
00119 
00123 void
00124 PopenErrorMessage (char *Filename)
00125 {
00126   char *utf8 = NULL;
00127 
00128   utf8_dup_string (&utf8, Filename);
00129 #ifdef USE_SYS_ERRLIST
00130   Message (_("Can't execute command\n"
00131              "   '%s'\npopen() returned: '%s'\n"),
00132            utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
00133 #else
00134   Message (_("Can't execute command\n"
00135              "   '%s'\npopen() returned: '%s'\n"), utf8, strerror (errno));
00136 #endif
00137   free (utf8);
00138 }
00139 
00143 void
00144 OpendirErrorMessage (char *DirName)
00145 {
00146   char *utf8 = NULL;
00147 
00148   utf8_dup_string (&utf8, DirName);
00149 #ifdef USE_SYS_ERRLIST
00150   Message (_("Can't scan directory\n"
00151              "   '%s'\nopendir() returned: '%s'\n"),
00152            utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
00153 #else
00154   Message (_("Can't scan directory\n"
00155              "   '%s'\nopendir() returned: '%s'\n"), utf8, strerror (errno));
00156 #endif
00157   free (utf8);
00158 }
00159 
00163 void
00164 ChdirErrorMessage (char *DirName)
00165 {
00166   char *utf8 = NULL;
00167 
00168   utf8_dup_string (&utf8, DirName);
00169 #ifdef USE_SYS_ERRLIST
00170   Message (_("Can't change working directory to\n"
00171              "   '%s'\nchdir() returned: '%s'\n"),
00172            utf8, errno <= sys_nerr ? sys_errlist[errno] : "???");
00173 #else
00174   Message (_("Can't change working directory to\n"
00175              "   '%s'\nchdir() returned: '%s'\n"), utf8, strerror (errno));
00176 #endif
00177   free (utf8);
00178 }
00179 
00183 void
00184 MyFatal (char *Format, ...)
00185 {
00186   va_list args;
00187 
00188   va_start (args, Format);
00189 
00190   /* try to save the layout and do some cleanup */
00191   EmergencySave ();
00192   fprintf (stderr, "%s (%i): fatal, ", Progname, (int) getpid ());
00193   vfprintf (stderr, Format, args);
00194   fflush (stderr);
00195   va_end (args);
00196   exit (1);
00197 }
00198 
00202 void
00203 CatchSignal (int Signal)
00204 {
00205   char *s;
00206 
00207   switch (Signal)
00208     {
00209 #ifdef SIGHUP
00210     case SIGHUP:
00211       s = "SIGHUP";
00212       break;
00213 #endif
00214     case SIGINT:
00215       s = "SIGINT";
00216       break;
00217 #ifdef SIGQUIT
00218     case SIGQUIT:
00219       s = "SIGQUIT";
00220       break;
00221 #endif
00222     case SIGABRT:
00223       s = "SIGABRT";
00224       break;
00225     case SIGTERM:
00226       s = "SIGTERM";
00227       break;
00228     case SIGSEGV:
00229       s = "SIGSEGV";
00230       break;
00231     default:
00232       s = "unknown";
00233       break;
00234     }
00235   MyFatal ("aborted by %s signal\n", s);
00236 }