/*********************************************************** * Term accses methods * ************************************************************ * Description: * * * * Created by: avrami tzur * * At: Fri Jul 24 08:59:53 1992 * ***********************************************************/ /* INCLUDES */ #include "structures.h" #include "library.h" /* DECLARATIONS */ char *GetFunctorName(module_ptr agent1, term_pointer term); int GetFunctorRefNum(module_ptr agent1, term_pointer term); char *GetTermString(module_ptr agent1, term_pointer term); int *GetTermValue(module_ptr agent1, term_pointer term); term_pointer GetTermArgument(module_ptr agent, term_pointer term, int arg_num); /* ============================================================ | GetFunctorName() | |----------------------------------------------------------| | Params : 1) | | 2) | | 3) | | Desc : | | | | Returns: | |==========================================================| */ char *GetFunctorName(module_ptr agent, term_pointer term) { char *functor = NULL; char *name; if(term->term_type == NONVAR) { /* The term is a functor. */ name = sym_table[term->functor]->name; functor = (char *)my_alloc(strlen(name)+1); strcpy(functor, name); } return(functor); } /* ============================================================ | GetFunctorRefNum() | |----------------------------------------------------------| | Params : 1) | | 2) | | 3) | | Desc : | | | | Returns: | |==========================================================| */ int GetFunctorRefNum(module_ptr agent, term_pointer term) { return(term->ref_num); } /* ============================================================ | GetTermString() | |----------------------------------------------------------| | Params : 1) | | 2) | | 3) | | Desc : | | | | Returns: | |==========================================================| */ char *GetTermString(module_ptr agent, term_pointer term) { char *str = NULL; int len; if(term->term_type == STRING) { /* The term is a string. */ len = strlen(term->const_string)+1; str = (char *)my_alloc((len = strlen(term->const_string)+1)); strncpy(str, term->const_string, len); } return(str); } /* ============================================================ | GetTermValue() | |----------------------------------------------------------| | Params : 1) | | 2) | | 3) | | Desc : | | | | Returns: | |==========================================================| */ int *GetTermValue(module_ptr agent, term_pointer term) { int *value = NULL; if(term->term_type == INTEGER) { /* The term is an integer. */ value = (int *)my_alloc(sizeof(int)); *value = term->functor; } return(value); } /* ============================================================ | GetTermArgument() | |----------------------------------------------------------| | Params : 1) | | 2) | | 3) | | Desc : | | | | Returns: | |==========================================================| */ term_pointer GetTermArgument(module_ptr agent, term_pointer term, int arg_num) { /* term must be of type NONVAR or TUPLE. */ if((term->term_type != NONVAR) && (term->term_type != TUPLE)) return(NULL); else { if(term->arity <= arg_num) return(NULL); else return(term->argument_array[arg_num]); } }