OpenCOBOL 1.1pre-rel
Data Structures | Defines | Functions
call.h File Reference
#include <setjmp.h>
#include <libcob/common.h>
Include dependency graph for call.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cobjmp_buf

Defines

#define cobsetjmp(x)   setjmp (cobsavenv (x))

Functions

void cob_set_cancel (const char *, void *, void *)
void * cob_resolve (const char *)
void * cob_resolve_1 (const char *)
const char * cob_resolve_error (void)
void * cob_call_resolve (const cob_field *)
void * cob_call_resolve_1 (const cob_field *)
void cob_field_cancel (const cob_field *)
void cobcancel (const char *)
int cobcall (const char *, const int, void **)
int cobfunc (const char *, const int, void **)
void * cobsavenv (struct cobjmp_buf *)
void * cobsavenv2 (struct cobjmp_buf *, const int)
void coblongjmp (struct cobjmp_buf *)
void cob_call_error (void)

Define Documentation

#define cobsetjmp (   x)    setjmp (cobsavenv (x))

Definition at line 49 of file call.h.


Function Documentation

void cob_call_error ( void  )

Definition at line 286 of file call.c.

{
        const char      *s;

        s = cob_resolve_error ();
        if (!s) {
                s = "Unknown error";
        }
        cob_runtime_error ("%s", s);
        cob_stop_run (1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_call_resolve ( const cob_field )

Definition at line 454 of file call.c.

{
        char    *buff;

        buff = cob_get_buff (f->size + 1);
        cob_field_to_string (f, buff);
        return cob_resolve (buff);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_call_resolve_1 ( const cob_field )

Definition at line 464 of file call.c.

{
        void    *p;

        p = cob_call_resolve (f);
        if (unlikely(!p)) {
                cob_call_error ();
        }
        return p;
}

Here is the call graph for this function:

void cob_field_cancel ( const cob_field )

Definition at line 504 of file call.c.

{
        char    *name;

        name = cob_get_buff (f->size + 1);
        cob_field_to_string (f, name);
        cobcancel (name);
}

Here is the call graph for this function:

void* cob_resolve ( const char *  )

Definition at line 317 of file call.c.

{
        unsigned char           *p;
        const unsigned char     *s;
        void                    *func;
#if     defined (_WIN32) || !defined (RTLD_DEFAULT)
        struct struct_handle    *chkhandle;
#endif
        lt_dlhandle             handle;
        size_t                  i;
        struct stat             st;

/* Checked in generated code
        if (!cob_initialized) {
                fputs ("cob_init() must be called before cob_resolve()", stderr);
                cob_stop_run (1);
        }
*/

        /* search the cache */
        cob_exception_code = 0;
        func = lookup (name);
        if (func) {
                return func;
        }

        /* encode program name */
        p = (unsigned char *)call_entry_buff;
        s = (const unsigned char *)name;
        if (unlikely(isdigit (*s))) {
                p += sprintf ((char *)p, "_%02X", *s++);
        }
        for (; *s; ++s) {
                if (likely(isalnum (*s) || *s == '_')) {
                        *p++ = *s;
                } else if (*s == '-') {
                        *p++ = '_';
                        *p++ = '_';
                } else {
                        p += sprintf ((char *)p, "_%02X", *s);
                }
        }
        *p = 0;

        /* search the main program */
        if (mainhandle != NULL && (func = lt_dlsym (mainhandle, call_entry_buff)) != NULL) {
                insert (name, func, NULL);
                resolve_error = NULL;
                return func;
        }

        /* Search preloaded modules */
#if     defined (_WIN32) || !defined (RTLD_DEFAULT)
        for (chkhandle = pre_handle; chkhandle; chkhandle = chkhandle->next) {
                if ((func = lt_dlsym (chkhandle->preload_handle, call_entry_buff)) != NULL) {
                        insert (name, func, NULL);
                        resolve_error = NULL;
                        return func;
                }
        }
#endif
#if     defined(USE_LIBDL) && defined (RTLD_DEFAULT)
        if ((func = lt_dlsym (RTLD_DEFAULT, call_entry_buff)) != NULL) {
                insert (name, func, NULL);
                resolve_error = NULL;
                return func;
        }
#endif

        s = (const unsigned char *)name;
        if (unlikely(name_convert != 0)) {
                s = (const unsigned char *)name;
                p = call_entry2_buff;
                for (; *s; ++s) {
                        if (name_convert == 1 && isupper (*s)) {
                                *p++ = tolower (*s);
                        } else if (name_convert == 2 && islower (*s)) {
                                *p++ = toupper (*s);
                        } else {
                                *p++ = *s;
                        }
                }
                *p = 0;
                s = (const unsigned char *)call_entry2_buff;
        }

        /* search external modules */
        for (i = 0; i < resolve_size; ++i) {
                call_filename_buff[CALL_FILEBUFF_SIZE - 1] = 0;
                if (resolve_path[i] == NULL) {
                        snprintf (call_filename_buff, CALL_FILEBUFF_SIZE - 1,
                                  "%s.%s", s, COB_MODULE_EXT);
                } else {
                        snprintf (call_filename_buff, CALL_FILEBUFF_SIZE - 1,
                                  "%s/%s.%s", resolve_path[i], s, COB_MODULE_EXT);
                }
                if (stat (call_filename_buff, &st) == 0) {
                        if ((handle = lt_dlopen (call_filename_buff)) != NULL) {
#if     defined (_WIN32) || !defined (RTLD_DEFAULT)
                                /* Candidate for future calls */
                                cache_handle (handle);
#endif
                                if ((func = lt_dlsym (handle, call_entry_buff)) != NULL) {
                                        insert (name, func, NULL);
                                        resolve_error = NULL;
                                        return func;
                                }
                        }
                        resolve_error_buff[CALL_BUFF_SIZE - 1] = 0;
                        strncpy (resolve_error_buff, lt_dlerror (),
                                 CALL_BUFF_SIZE - 1);
                        resolve_error = resolve_error_buff;
                        cob_set_exception (COB_EC_PROGRAM_NOT_FOUND);
                        return NULL;
                }
        }
        resolve_error_buff[CALL_BUFF_SIZE - 1] = 0;
        snprintf (resolve_error_buff, CALL_BUFF_SIZE - 1,
                  "Cannot find module '%s'", name);
        resolve_error = resolve_error_buff;
        cob_set_exception (COB_EC_PROGRAM_NOT_FOUND);
        return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_resolve_1 ( const char *  )

Definition at line 442 of file call.c.

{
        void    *p;

        p = cob_resolve (name);
        if (unlikely(!p)) {
                cob_call_error ();
        }
        return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* cob_resolve_error ( void  )

Definition at line 277 of file call.c.

{
        const char      *p = resolve_error;

        resolve_error = NULL;
        return p;
}

Here is the caller graph for this function:

void cob_set_cancel ( const char *  ,
void *  ,
void *   
)

Definition at line 299 of file call.c.

{
        struct call_hash        *p;

#ifdef  COB_ALT_HASH
        for (p = call_table; p; p = p->next) {
#else
        for (p = call_table[hash ((const unsigned char *)name)]; p; p = p->next) {
#endif
                if (strcmp (name, p->name) == 0) {
                        p->cancel = cancel;
                        return;
                }
        }
        insert (name, entry, cancel);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cobcall ( const char *  ,
const int  ,
void **   
)

Definition at line 596 of file call.c.

{
        int     i;
        union {
                void    *(*funcptr)();
                int     (*funcint)();
                void    *func_void;
        } unifunc;
        void    *pargv[16];

        if (unlikely(!cob_initialized)) {
                cob_runtime_error ("'cobcall' - Runtime has not been initialized");
                cob_stop_run (1);
        }
        if (argc < 0 || argc > 16) {
                cob_runtime_error ("Invalid number of arguments to 'cobcall'");
                cob_stop_run (1);
        }
        if (unlikely(!name)) {
                cob_runtime_error ("NULL name parameter passed to 'cobcall'");
                cob_stop_run (1);
        }
        unifunc.func_void = cob_resolve_1 (name);
        memset (pargv, 0, sizeof(pargv));
        /* Set number of parameters */
        cob_call_params = argc;
        for (i = 0; i < argc; ++i) {
                pargv[i] = argv[i];
        }
        return unifunc.funcint (pargv[0], pargv[1], pargv[2], pargv[3],
                                pargv[4], pargv[5], pargv[6], pargv[7],
                                pargv[8], pargv[9], pargv[10], pargv[11],
                                pargv[12], pargv[13], pargv[14], pargv[15]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cobcancel ( const char *  )

Definition at line 476 of file call.c.

{
        struct call_hash        *p;
        union {
                int     (*cancel_func)(int, ...);
                void    *cancel_void;
        } unicanc;

        if (unlikely(!name)) {
                cob_runtime_error ("NULL name parameter passed to 'cobcancel'");
                cob_stop_run (1);
        }
#ifdef  COB_ALT_HASH
        for (p = call_table; p; p = p->next) {
#else
        for (p = call_table[hash ((const unsigned char *)name)]; p; p = p->next) {
#endif
                if (strcmp (name, p->name) == 0) {
                        if (p->cancel && !p->flag_is_active) {
                                unicanc.cancel_void = p->cancel;
                                unicanc.cancel_func (-1, NULL, NULL, NULL, NULL,
                                                     NULL, NULL, NULL, NULL);
                        }
                }
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cobfunc ( const char *  ,
const int  ,
void **   
)

Definition at line 632 of file call.c.

{
        int     ret;

        if (unlikely(!cob_initialized)) {
                cob_runtime_error ("'cobfunc' - Runtime has not been initialized");
                cob_stop_run (1);
        }
        ret = cobcall (name, argc, argv);
        cobcancel (name);
        return ret;
}

Here is the call graph for this function:

void coblongjmp ( struct cobjmp_buf )

Definition at line 671 of file call.c.

{
        if (unlikely(!jbuf)) {
                cob_runtime_error ("NULL name parameter passed to 'coblongjmp'");
                cob_stop_run (1);
        }
        if (!cobjmp_primed) {
                cob_runtime_error ("Call to 'coblongjmp' with no prior 'cobsetjmp'");
                cob_stop_run (1);
        }
        cobjmp_primed = 0;
        longjmp (jbuf->cbj_jmp_buf, 1);
}

Here is the call graph for this function:

void* cobsavenv ( struct cobjmp_buf )

Definition at line 646 of file call.c.

{
        if (unlikely(!jbuf)) {
                cob_runtime_error ("NULL name parameter passed to 'cobsavenv'");
                cob_stop_run (1);
        }
        if (cobjmp_primed) {
                cob_runtime_error ("Multiple call to 'cobsetjmp'");
                cob_stop_run (1);
        }
        cobjmp_primed = 1;
        return jbuf->cbj_jmp_buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* cobsavenv2 ( struct cobjmp_buf ,
const int   
)

Definition at line 661 of file call.c.

{
        int     jtemp;

        /* Shut up compiler */
        jtemp = jsize;
        return cobsavenv (jbuf);
}

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines