1    /*******************************************************/
2    /*      "C" Language Integrated Production System      */
3    /*                                                     */
4    /*             CLIPS Version 6.30  08/16/14            */
5    /*                                                     */
6    /*            EXTERNAL FUNCTIONS HEADER FILE           */
7    /*******************************************************/
8 
9 /*************************************************************/
10 /* Purpose: Routines for adding new user or system defined   */
11 /*   functions.                                              */
12 /*                                                           */
13 /* Principal Programmer(s):                                  */
14 /*      Gary D. Riley                                        */
15 /*                                                           */
16 /* Contributing Programmer(s):                               */
17 /*                                                           */
18 /* Revision History:                                         */
19 /*                                                           */
20 /*      6.24: Renamed BOOLEAN macro type to intBool.         */
21 /*                                                           */
22 /*      6.30: Added support for passing context information  */
23 /*            to user defined functions.                     */
24 /*                                                           */
25 /*            Support for long long integers.                */
26 /*                                                           */
27 /*            Added const qualifiers to remove C++           */
28 /*            deprecation warnings.                          */
29 /*                                                           */
30 /*            Replaced ALLOW_ENVIRONMENT_GLOBALS macros      */
31 /*            with functions.                                */
32 /*                                                           */
33 /*************************************************************/
34 
35 #ifndef _H_extnfunc
36 
37 #define _H_extnfunc
38 
39 #ifndef _H_symbol
40 #include "symbol.h"
41 #endif
42 #ifndef _H_expressn
43 #include "expressn.h"
44 #endif
45 
46 #include "userdata.h"
47 
48 struct FunctionDefinition
49   {
50    struct symbolHashNode *callFunctionName;
51    const char *actualFunctionName;
52    char returnValueType;
53    int (*functionPointer)(void);
54    struct expr *(*parser)(void *,struct expr *,const char *);
55    const char *restrictions;
56    short int overloadable;
57    short int sequenceuseok;
58    short int environmentAware;
59    short int bsaveIndex;
60    struct FunctionDefinition *next;
61    struct userData *usrData;
62    void *context;
63   };
64 
65 #define ValueFunctionType(target) (((struct FunctionDefinition *) target)->returnValueType)
66 #define ExpressionFunctionType(target) (((struct FunctionDefinition *) ((target)->value))->returnValueType)
67 #define ExpressionFunctionPointer(target) (((struct FunctionDefinition *) ((target)->value))->functionPointer)
68 #define ExpressionFunctionCallName(target) (((struct FunctionDefinition *) ((target)->value))->callFunctionName)
69 #define ExpressionFunctionRealName(target) (((struct FunctionDefinition *) ((target)->value))->actualFunctionName)
70 
71 #define PTIF (int (*)(void))
72 #define PTIEF (int (*)(void *))
73 
74 /*==================*/
75 /* ENVIRONMENT DATA */
76 /*==================*/
77 
78 #define EXTERNAL_FUNCTION_DATA 50
79 
80 struct externalFunctionData
81   {
82    struct FunctionDefinition *ListOfFunctions;
83    struct FunctionHash **FunctionHashtable;
84   };
85 
86 #define ExternalFunctionData(theEnv) ((struct externalFunctionData *) GetEnvironmentData(theEnv,EXTERNAL_FUNCTION_DATA))
87 
88 #ifdef LOCALE
89 #undef LOCALE
90 #endif
91 
92 #ifdef _EXTNFUNC_SOURCE_
93 #define LOCALE
94 #else
95 #define LOCALE extern
96 #endif
97 
98 #ifdef LOCALE
99 struct FunctionHash
100   {
101    struct FunctionDefinition *fdPtr;
102    struct FunctionHash *next;
103   };
104 
105 #define SIZE_FUNCTION_HASH 517
106 #endif
107 
108    LOCALE void                           InitializeExternalFunctionData(void *);
109    LOCALE int                            EnvDefineFunction(void *,const char *,int,
110                                                            int (*)(void *),const char *);
111    LOCALE int                            EnvDefineFunction2(void *,const char *,int,
112                                                             int (*)(void *),const char *,const char *);
113    LOCALE int                            EnvDefineFunctionWithContext(void *,const char *,int,
114                                                            int (*)(void *),const char *,void *);
115    LOCALE int                            EnvDefineFunction2WithContext(void *,const char *,int,
116                                                             int (*)(void *),const char *,const char *,void *);
117    LOCALE int                            DefineFunction3(void *,const char *,int,
118                                                          int (*)(void *),const char *,const char *,intBool,void *);
119    LOCALE int                            AddFunctionParser(void *,const char *,
120                                                            struct expr *(*)( void *,struct expr *,const char *));
121    LOCALE int                            RemoveFunctionParser(void *,const char *);
122    LOCALE int                            FuncSeqOvlFlags(void *,const char *,int,int);
123    LOCALE struct FunctionDefinition     *GetFunctionList(void *);
124    LOCALE void                           InstallFunctionList(void *,struct FunctionDefinition *);
125    LOCALE struct FunctionDefinition     *FindFunction(void *,const char *);
126    LOCALE int                            GetNthRestriction(struct FunctionDefinition *,int);
127    LOCALE const char                    *GetArgumentTypeName(int);
128    LOCALE int                            UndefineFunction(void *,const char *);
129    LOCALE int                            GetMinimumArgs(struct FunctionDefinition *);
130    LOCALE int                            GetMaximumArgs(struct FunctionDefinition *);
131 
132 #if ALLOW_ENVIRONMENT_GLOBALS
133 
134 #if (! RUN_TIME)
135    LOCALE int                            DefineFunction(const char *,int,int (*)(void),const char *);
136    LOCALE int                            DefineFunction2(const char *,int,int (*)(void),const char *,const char *);
137 #endif /* (! RUN_TIME) */
138 
139 #endif /* ALLOW_ENVIRONMENT_GLOBALS */
140 
141 #endif /* _H_extnfunc */
142 
143 
144 
145