-/*
- ** va_catch_errors().
- ** General purpose function to execute a function, catching errors.
- ** If there is no error, the value returned by 'func' is returned.
- ** If there is error, then zero is returned.
- ** Note that 'func' must take a variable argument list as well.
- **
- ** Must not be called with immediate_quit in effect (bad things might
- ** happen, say we got a signal in the middle of a memcpy to quit_return).
- ** This is an OK restriction; with very few exceptions immediate_quit can
- ** be replaced by judicious use of QUIT.
- */
-Opaque
-va_catch_errors (TuiOpaqueFuncPtr func, va_list args)
-{
- Opaque ret = (Opaque) NULL;
-
- /*
- ** We could have used catch_errors(), but it doesn't handle variable args.
- ** Also, for the tui, we always want to catch all errors, so we don't
- ** need to pass a mask, or an error string.
- */
- jmp_buf saved_error;
- jmp_buf saved_quit;
- jmp_buf tmp_jmp;
- struct cleanup *saved_cleanup_chain;
- char *saved_error_pre_print;
- char *saved_quit_pre_print;
- extern jmp_buf error_return;
- extern jmp_buf quit_return;
-
- saved_cleanup_chain = save_cleanups ();
- saved_error_pre_print = error_pre_print;
- saved_quit_pre_print = quit_pre_print;
-
- memcpy ((char *) saved_error, (char *) error_return, sizeof (jmp_buf));
- error_pre_print = "";
- memcpy (saved_quit, quit_return, sizeof (jmp_buf));
- quit_pre_print = "";
-
- if (setjmp (tmp_jmp) == 0)
- {
- va_list argList = args;
- memcpy (error_return, tmp_jmp, sizeof (jmp_buf));
- memcpy (quit_return, tmp_jmp, sizeof (jmp_buf));
- ret = func (argList);
- }
- restore_cleanups (saved_cleanup_chain);
- memcpy (error_return, saved_error, sizeof (jmp_buf));
- error_pre_print = saved_error_pre_print;
- memcpy (quit_return, saved_quit, sizeof (jmp_buf));
- quit_pre_print = saved_quit_pre_print;
-
- return ret;
-}
-
-/*
- ** vcatch_errors().
- ** Catch errors occurring in tui or non tui function, handling
- ** variable param lists. Note that 'func' must take a variable
- ** argument list as well.
- */
-Opaque
-vcatch_errors (OpaqueFuncPtr func, ...)
-{
- Opaque ret = (Opaque) NULL;
- va_list args;
- va_start (args, func);
-/*
- va_arg(args, OpaqueFuncPtr);
- */
- ret = va_catch_errors (func, args);
- va_end (args);
-
- return ret;
-}
-
-