1 #include <setjmp.h>
2 #include <stdio.h>
3 #include <stdarg.h>
4 #include "tpl.h"
5 
6 jmp_buf env;
7 extern tpl_hook_t tpl_hook;
8 
catch_oops(const char * fmt,...)9 int catch_oops(const char *fmt, ...) {
10   va_list ap;
11 
12   va_start(ap, fmt);
13   vfprintf(stderr, fmt, ap);
14   va_end(ap);
15   longjmp(env,-1);                /* return to setjmp point */
16   return 0; /* not reached */
17 }
18 
main()19 int main() {
20   int err;
21   tpl_node *tn;
22   tpl_hook.oops = catch_oops;    /* install fatal handler */
23 
24   err = setjmp(env); /* on error, control will return here  */
25   if (err) {
26     printf("caught error!\n");
27     return -1;
28   }
29 
30   tn = tpl_map("@");              /* generate a fatal error */
31   printf("program ending, without error\n");
32   return 0;
33 }
34