/*********************************************************** * register_c_module * ************************************************************ * Description: includes the routines for registering a C module, and registering the functions in the module. * * * * Created by: kave eshghi * * At: Sun Aug 23 13:45:04 1992 * ***********************************************************/ /* INCLUDES */ # include "structures.h" /* DECLARATIONS */ /* ============================================================ | register_module() | |----------------------------------------------------------| | Params : 1)the name of the module to be registered | | Desc : registers the module, creates the right data structures Returns: The agent functor for the module. If the name already belongs to an agent or module, returns -1 (as error indicator) | | |==========================================================| */ int register_module(char *module_name) { int module_functor= lookup_term(module_name); module_ptr m; if (sym_table[module_functor]->agent_ref!=NULL) return -1; else { m=(module_ptr)my_alloc(sizeof(struct module_str)); strcpy(m->name,module_name); printf("receiving agent is %s\n",m->name); m->type=C_MOD; m->clause_counter=0; m->clause_array=NULL; m->prop_table=NULL; m->clause_head_table=NULL; m->clause_body_table=NULL; m->encountered=NULL; m->function_count=0; m->f_table=(module_function_descriptor *)malloc(0); m->generic=NULL; } sym_table[module_functor]->agent_ref=m; return module_functor; } /* ============================================================ | register_function() | |----------------------------------------------------------| | Params : 1) module number | 2) pointer to a function | 3) function name 4) some data which is always passed back when that function is called | Desc : registers the function in that module's function table, so when a message to that module specifies this function name, the appropriate function is called. Returns: the functor assigned to function if OK, -1 if the function is already registered. |==========================================================| */ int register_function(int module_number, char *function_name, function_type function, void *data) { int i; module_ptr mod=sym_table[module_number]->agent_ref; module_function_descriptor *f_table=mod->f_table; int functor=lookup_term(function_name); for(i=0; ifunction_count&&f_table[i].functor!=functor; i++); if (i!=mod->function_count) return -1; else { void *temp; temp=realloc(f_table,sizeof(module_function_descriptor)* (mod->function_count+1)); if (temp==NULL) { printf("no memory for registering function\n"); exit(1); } else { mod->f_table=(module_function_descriptor *)temp; mod->f_table[mod->function_count].functor=functor; mod->f_table[mod->function_count].funct=function; mod->f_table[mod->function_count].data=data; mod->function_count++; return functor; } } } void register_generic(int module_number, generic_function function) { module_ptr mod=sym_table[module_number]->agent_ref; mod->generic=function; }