Import PicoSAT-913
[cl-satwrap.git] / backends / picosat / main.c
blobcb82580fa76ecc55b49316a594dacf725582ac81
1 #include <signal.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "picosat.h"
7 int picosat_main (int, char **);
9 static int catched;
11 static void (*sig_int_handler);
12 static void (*sig_segv_handler);
13 static void (*sig_abrt_handler);
14 static void (*sig_term_handler);
15 #ifndef NALLSIGNALS
16 static void (*sig_kill_handler);
17 static void (*sig_xcpu_handler);
18 static void (*sig_xfsz_handler);
19 #endif
21 static void
22 resetsighandlers (void)
24 (void) signal (SIGINT, sig_int_handler);
25 (void) signal (SIGSEGV, sig_segv_handler);
26 (void) signal (SIGABRT, sig_abrt_handler);
27 (void) signal (SIGTERM, sig_term_handler);
28 #ifndef NALLSIGNALS
29 (void) signal (SIGKILL, sig_kill_handler);
30 (void) signal (SIGXCPU, sig_xcpu_handler);
31 (void) signal (SIGXFSZ, sig_xfsz_handler);
32 #endif
35 static void
36 message (int sig)
38 picosat_message (1, "");
39 picosat_message (1, "*** CAUGHT SIGNAL %d ***", sig);
40 picosat_message (1, "");
43 static void
44 catch (int sig)
46 if (!catched)
48 message (sig);
49 catched = 1;
50 picosat_stats ();
51 message (sig);
54 resetsighandlers ();
55 raise (sig);
58 static void
59 setsighandlers (void)
61 sig_int_handler = signal (SIGINT, catch);
62 sig_segv_handler = signal (SIGSEGV, catch);
63 sig_abrt_handler = signal (SIGABRT, catch);
64 sig_term_handler = signal (SIGTERM, catch);
65 #ifndef NALLSIGNALS
66 sig_kill_handler = signal (SIGKILL, catch);
67 sig_xcpu_handler = signal (SIGXCPU, catch);
68 sig_xfsz_handler = signal (SIGXFSZ, catch);
69 #endif
72 int
73 main (int argc, char **argv)
75 int res, verbose;
77 for (verbose = argc - 1; verbose; verbose--)
78 if (!strcmp (argv[verbose], "-v"))
79 break;
81 if (verbose)
82 setsighandlers ();
84 res = picosat_main (argc, argv);
86 if (verbose)
87 resetsighandlers ();
89 return res;