libicl.h

Go to the documentation of this file.
00001 /****************************************************************************
00002  *   File    : libicl.h
00003  *   Author  : Adam Cheyer
00004  *   Updated : 5/21/97
00005  *
00006  *****************************************************************************/
00007 /*
00008  * Copyright (C) 2006  SRI International
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  * SRI International: 333 Ravenswood Ave, Menlo Park, CA 94025
00025  */
00026 #ifndef _ICLLIB_H_INCLUDED
00027 #define _ICLLIB_H_INCLUDED
00028 
00029 #include <stdlib.h>
00030 #include "glib.h"
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 #ifdef IS_DLL
00037 #define EXTERN __declspec(dllexport)
00038 #else
00039 #define EXTERN extern
00040 #endif
00041 
00042 #ifndef FALSE
00043 #define FALSE 0
00044 #define TRUE  1
00045 #endif
00046 
00047 #ifdef NORMAL_GC
00048 #undef CHECK_LEAKS
00049 #include <gc/leak_detector.h>
00050 #undef strdup
00051   EXTERN char* gc_strdup(char*s);
00052 #define strdup(s) gc_strdup(s)
00053 #else
00054 #define CHECK_LEAKS()
00055 #endif
00056 
00057   enum ICLType
00058     {icl_no_type, icl_int_type, icl_float_type, icl_str_type, icl_struct_type,
00059      icl_list_type, icl_group_type, icl_var_type, icl_callback_type, icl_dataq_type};
00060 
00061   struct iclTerm;
00062   struct iclListType;
00063   struct iclGroupType;
00064   struct iclStructType;
00065   struct dyn_array;
00066   typedef struct iclTerm ICLTerm;
00067   typedef struct iclListType ICLListType;
00068   typedef struct iclGroupType ICLGroupType;
00069   typedef struct iclStructType ICLStructType;
00070 
00071   /* Structure construction & testing routines */
00072   EXTERN ICLTerm *  icl_NewTermFromString(char* s);
00073   EXTERN ICLTerm *  icl_NewTermFromData(char* data, size_t len);
00074   EXTERN char *   icl_NewStringFromTerm(ICLTerm const*t);
00075   EXTERN char *           icl_NewStringStructFromTerm(ICLTerm *t);
00082   EXTERN char*      icl_UnquotedStringFromStr(ICLTerm* t);
00090   EXTERN char*      icl_ForcedQuotedStringFromStr(ICLTerm* t);
00099   EXTERN char*      icl_MinimallyQuotedStringFromStr(ICLTerm* t);
00100   EXTERN int    icl_WriteTerm(ICLTerm *t);
00101   EXTERN ICLTerm *  icl_CopyTerm(ICLTerm const*t);
00102   EXTERN ICLListType *    icl_CopyListType(ICLListType *list);
00103   EXTERN ICLTerm *  icl_NewInt(gint64 i);
00104   EXTERN ICLTerm *  icl_NewFloat(double f);
00105   EXTERN ICLTerm *  icl_NewStr(char const* s);
00106   EXTERN ICLTerm *  icl_NewVar(char *name);
00107   EXTERN ICLTerm *  icl_NewStruct(char const* functor, int arity, ...);
00108   EXTERN ICLTerm *  icl_NewStructFromList(char const* functor, ICLTerm *args);
00109   EXTERN ICLListType *  icl_NewCons(ICLTerm *elt, ICLListType *tail);
00110   EXTERN ICLTerm *  icl_NewList(ICLListType *list);
00111   EXTERN ICLTerm *  icl_NewGroup(char sChar, char *sep, ICLListType *list);
00112   EXTERN ICLTerm *      icl_NewDataQ(void const* data, size_t dataLen);
00113   EXTERN void   icl_FreeTerm(ICLTerm *elt);
00114   EXTERN void   icl_FreeTermSingle(ICLTerm *elt);
00115   EXTERN int    icl_IsList(ICLTerm const*elt);
00116   EXTERN int    icl_IsGroup(ICLTerm const*elt);
00117   EXTERN int    icl_IsStruct(ICLTerm const*elt);
00118   EXTERN int    icl_IsStr(ICLTerm const*elt);
00119   EXTERN int    icl_IsVar(ICLTerm const*elt);
00120   EXTERN int    icl_IsInt(ICLTerm const*elt);
00121   EXTERN int    icl_IsFloat(ICLTerm const*elt);
00122   EXTERN int            icl_IsDataQ(ICLTerm const*elt);
00123   EXTERN int    icl_IsValid(ICLTerm const*elt);
00124   EXTERN int    icl_IsGround(ICLTerm const*elt);
00125   EXTERN void*          icl_DataQ(ICLTerm const* elt);
00126   EXTERN size_t         icl_DataQLen(ICLTerm const* elt);
00127   EXTERN size_t         icl_Len(ICLTerm const* elt);
00128   EXTERN gint64   icl_Int(ICLTerm const*elt);
00129   EXTERN double   icl_Float(ICLTerm const*elt);
00130   EXTERN char *   icl_Str(ICLTerm const*elt);
00131   EXTERN char *     icl_Functor(ICLTerm const*elt);
00132   EXTERN ICLListType *  icl_Arguments(ICLTerm const*elt);
00133   EXTERN int    icl_GetGroupChars(ICLTerm const*group, char *startC,
00134                                           char **sep);
00135   EXTERN int              icl_Arity(ICLTerm const* inTerm);
00136   EXTERN int            icl_ReplaceElement(ICLTerm* term, int index, ICLTerm* replacement, int freeReplaced);
00137   EXTERN int            icl_ReplaceUnifying(ICLTerm* term, ICLTerm const* selector, ICLTerm const* replacement, int freeReplaced);
00138 
00139   /* List manipulations */
00140   EXTERN ICLListType *  icl_List(ICLTerm const*elt);
00141   EXTERN ICLListType *  icl_ListNext(ICLListType const* t);
00142   EXTERN ICLTerm *  icl_ListElt(ICLListType const* t);
00143   EXTERN ICLListType *  icl_ListCopy(ICLTerm const*elt);
00144   EXTERN ICLTerm *  icl_NthTerm(ICLTerm const*elt, int n);
00145   EXTERN int          icl_NthTermAsInt(ICLTerm const*elt, int n, int *Value);
00146   EXTERN int    icl_NumTerms(ICLTerm const*elt);
00147   EXTERN int    icl_ListLen(ICLTerm const*elt);
00148   EXTERN int              icl_AddToList(ICLTerm *list, ICLTerm *elt, int atEnd);
00149   EXTERN int              icl_ClearList(ICLTerm *list);
00150   EXTERN int              icl_SortList(
00151    ICLTerm *list,
00152    int (*user_function)(ICLTerm *Elt1, ICLTerm *Elt2));
00153   EXTERN int      icl_Append(ICLTerm *list1, ICLTerm *list2);
00154   EXTERN int      icl_AppendCopy(ICLTerm *list1, ICLTerm const*list2);
00155   EXTERN int              icl_Union(ICLTerm *list1, ICLTerm *list2,
00156                                     ICLTerm **dest);
00157   EXTERN int              icl_ListHasMoreElements(ICLListType const*l);
00158   EXTERN ICLListType*            icl_ListNextElement(ICLListType const*l);
00159   EXTERN ICLTerm*                icl_ListElement(ICLListType const*list);
00160   EXTERN int                     icl_ListDelete(ICLTerm *list,
00161                                                 ICLTerm *elem,
00162                                                 ICLTerm **residue);
00163   EXTERN ICLTerm*            icl_GenerateSimpleUnifyingTerm(ICLTerm const*term);
00164 
00165   EXTERN int    icl_Unify(ICLTerm const*t1, ICLTerm const*t2, ICLTerm **answer);
00166   EXTERN int    icl_ParamValue(char *func, ICLTerm *match,
00167                ICLTerm *params, ICLTerm **answer);
00168   EXTERN gint64           icl_ParamValueAsInt(char *func, ICLTerm *params,
00169                                             gint64 *Value);
00170 
00171   EXTERN int         icl_Member(ICLTerm const *elt, ICLTerm const *list, ICLTerm **res);
00172 #if 0
00173   EXTERN ICLTerm *  icl_ReuseMem(ICLTerm *elt);
00174 #endif
00175 
00176   EXTERN char * icl_stFixQuotes(char *s);
00180   EXTERN int icl_stIsProperlyQuoted(char* s);
00181 
00182   /* List management utility functions */
00183   EXTERN int    icl_list_has_more_elements(ICLListType *l);
00184   EXTERN ICLListType     *icl_list_next_element(ICLListType *l);
00185   EXTERN ICLTerm         *icl_list_element(ICLListType *list);
00186   EXTERN int    icl_list_delete(ICLTerm *list, ICLTerm *elem,
00187           ICLTerm **residue);
00188   EXTERN int    icl_append_to_list(ICLTerm *list1, ICLTerm *list2,
00189              ICLTerm **list3);
00190 
00191   /* Convenience functions for representing often-used terms */
00192   EXTERN ICLTerm *  icl_True();
00193   EXTERN ICLTerm *  icl_False();
00194   EXTERN ICLTerm *  icl_Empty();
00195   EXTERN ICLTerm *  icl_Var();
00196 
00197   /****************************************************************************
00198    * Macros
00199    ****************************************************************************/
00200 #define ICL_TRUE icl_True()
00201 #define ICL_FALSE icl_False()
00202 #define ICL_EMPTY icl_Empty()
00203 #define ICL_VAR   icl_Var()
00204 
00205 
00206   EXTERN void icl_stFree(void *p);
00207 
00208   /*#define icl_Free(A) if (A) { void* vp = current_text_addr();icl_FreeTerm(A,n,vp); A = 0;}*/
00209   /*
00210     #ifdef LINUX
00211     #include <asm/processor.h>
00212     #define icl_Free(A,n) if (A) { void* vp = current_text_addr();icl_FreeTerm(A,n,vp); A = 0; }
00213     #else
00214     #define icl_Free(A,n) if (A) { icl_FreeTerm(A,n,0); A = 0; }
00215     #endif
00216   */
00217 #define icl_Free(A) if (A) {icl_FreeTerm(A); A = 0;}
00218 
00219   EXTERN int icl_match_terms(ICLTerm *t1, ICLTerm *t2, struct dyn_array *vars);
00220   /*EXTERN ICLTerm *icl_copy_term(ICLTerm *t, struct dyn_array *vars);*/
00221   EXTERN ICLTerm *icl_copy_term_nonrec(ICLTerm const*t, struct dyn_array *vars);
00222 #define icl_copy_term(T,V) icl_copy_term_nonrec(T,V)
00223   EXTERN void icl_init_dyn_array(struct dyn_array *da);
00224   /* static void icl_deref(ICLTerm **var, struct dyn_array var_bindings); */
00225 
00226 #ifdef __cplusplus
00227 }
00228 #endif
00229 
00230 #endif
00231 

Generated on Wed May 23 17:20:11 2007 using doxygen 1.5.2