This aculongjmp() routine cuts the C and COBOL call stacks to the point recorded in passed "acujmp_buf". This point must have been recorded by a prior call to both acusavenv() and setjmp(). Once a state has been recorded, you can only jump to it one time using aculongjmp(). After that, it must be recorded again.
Usage
void aculongjmp(acujmp_buf *buffer)
Like acusavenv(), aculongjmp() is intended for use with batch programs or programs written for a transaction processing system and therefore is not recommended for programs that use the ACUCOBOL-GT graphical user interface.
Return Values
This routine does not return; instead, it internally calls the C library longjmp() routine which transfers control to the point of the prior setjmp() call and causes setjmp() to return a value of "1".
Example
#include "acusetjmp.h" acujmp_buf mark1; /* A COBOL or 'C' subroutine can CALL "myexception" to transfer /* control back to the point where "mark1" was recorded. */ void myexception() { aculongjmp( &mark1 ); } /* Prototypical 'C' service routine to run a COBOL program with /* the ability to exit out of the COBOL code via call to /* 'myexception' */ void myservice() { /* Record our position in the 'C' and COBOL call stacks. /* 'Setjmp' will return "0" when executed first. We /* call it in a "while" loop so that the location /* recording re-executes in case we end /* up jumping here via 'aculongjmp' */ while( setjmp( *acusavenv(&mark1) ) ) { /* If we get here, it's because 'aculongjmp' jumped /* here. Put recovery/cleanup code here. /* If you do not want to re-execute the COBOL routine, /* add a "return" here. Otherwise, just fall out of the /* while loop to re-execute the COBOL routine */ } /* Setup to call COBOL here and call a COBOL routine */ /* The COBOL program can jump back to the top of this /* routine by calling "myexception" at some point. This /* will transfer control to the point of the 'setjmp' /* call above and cause 'setjmp' to return "1". */ struct a_cobol_info cblinfo; memset(&cblinfo, 0, sizeof(cblinfo)); cblinfo.a_cobol_info_size = sizeof(cblinfo); cblinfo.pgm_name = "cblprog"; cblinfo.num_params = 0; cblinfo.params = NULL; acu_cobol(&cblinfo); }
Restrictions
if ( setjmp(mybuf) == 1 ) { /* longjmp lands here */ } becomes: while ( setjmp(*acusavenv(&myacubuf)) == 1 ) { /* aculongjmp lands here */ }