1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.40 10/24/17 */
/* */
/* EXTERNAL FUNCTIONS HEADER FILE */
/*******************************************************/
/*************************************************************/
/* Purpose: Routines for adding new user or system defined */
/* functions. */
/* */
/* Principal Programmer(s): */
/* Gary D. Riley */
/* */
/* Contributing Programmer(s): */
/* */
/* Revision History: */
/* */
/* 6.24: Renamed BOOLEAN macro type to intBool. */
/* */
/* 6.30: Added support for passing context information */
/* to user defined functions. */
/* */
/* Support for long long integers. */
/* */
/* Added const qualifiers to remove C++ */
/* deprecation warnings. */
/* */
/* Replaced ALLOW_ENVIRONMENT_GLOBALS macros */
/* with functions. */
/* */
/* 6.40: Changed restrictions from char * to */
/* CLIPSLexeme * to support strings */
/* originating from sources that are not */
/* statically allocated. */
/* */
/* Removed LOCALE definition. */
/* */
/* Pragma once and other inclusion changes. */
/* */
/* Added support for booleans with <stdbool.h>. */
/* */
/* Removed use of void pointers for specific */
/* data structures. */
/* */
/* ALLOW_ENVIRONMENT_GLOBALS no longer supported. */
/* */
/* Callbacks must be environment aware. */
/* */
/* UDF redesign. */
/* */
/*************************************************************/
#ifndef _H_extnfunc
#pragma once
#define _H_extnfunc
#include "entities.h"
#include "evaluatn.h"
#include "expressn.h"
#include "symbol.h"
#include "userdata.h"
typedef void UserDefinedFunction(Environment *,UDFContext *,UDFValue *);
struct functionDefinition
{
CLIPSLexeme *callFunctionName;
const char *actualFunctionName;
unsigned unknownReturnValueType;
void (*functionPointer)(Environment *,UDFContext *,UDFValue *);
struct expr *(*parser)(Environment *,struct expr *,const char *);
CLIPSLexeme *restrictions;
unsigned short minArgs;
unsigned short maxArgs;
bool overloadable;
bool sequenceuseok;
bool neededFunction;
unsigned long bsaveIndex;
struct functionDefinition *next;
struct userData *usrData;
void *context;
};
#define UnknownFunctionType(target) (((struct functionDefinition *) target)->unknownReturnValueType)
#define ExpressionFunctionPointer(target) ((target)->functionValue->functionPointer)
#define ExpressionFunctionCallName(target) ((target)->functionValue->callFunctionName)
#define ExpressionFunctionRealName(target) ((target)->functionValue->actualFunctionName)
#define ExpressionUnknownFunctionType(target) ((target)->functionValue->unknownReturnValueType)
/*==================*/
/* ENVIRONMENT DATA */
/*==================*/
#define EXTERNAL_FUNCTION_DATA 50
struct externalFunctionData
{
struct functionDefinition *ListOfFunctions;
struct FunctionHash **FunctionHashtable;
};
#define ExternalFunctionData(theEnv) ((struct externalFunctionData *) GetEnvironmentData(theEnv,EXTERNAL_FUNCTION_DATA))
typedef enum
{
AUE_NO_ERROR = 0,
AUE_MIN_EXCEEDS_MAX_ERROR,
AUE_FUNCTION_NAME_IN_USE_ERROR,
AUE_INVALID_ARGUMENT_TYPE_ERROR,
AUE_INVALID_RETURN_TYPE_ERROR
} AddUDFError;
struct FunctionHash
{
struct functionDefinition *fdPtr;
struct FunctionHash *next;
};
#define SIZE_FUNCTION_HASH 517
void InitializeExternalFunctionData(Environment *);
AddUDFError AddUDF(Environment *,const char *,const char *,
unsigned short,unsigned short,const char *,
UserDefinedFunction *,
const char *,void *);
bool AddFunctionParser(Environment *,const char *,
struct expr *(*)( Environment *,struct expr *,const char *));
bool RemoveFunctionParser(Environment *,const char *);
bool FuncSeqOvlFlags(Environment *,const char *,bool,bool);
struct functionDefinition *GetFunctionList(Environment *);
void InstallFunctionList(Environment *,struct functionDefinition *);
struct functionDefinition *FindFunction(Environment *,const char *);
unsigned GetNthRestriction(Environment *,struct functionDefinition *,unsigned int);
bool RemoveUDF(Environment *,const char *);
int GetMinimumArgs(struct functionDefinition *);
int GetMaximumArgs(struct functionDefinition *);
unsigned int UDFArgumentCount(UDFContext *);
bool UDFNthArgument(UDFContext *,unsigned int,unsigned,UDFValue *);
void UDFInvalidArgumentMessage(UDFContext *,const char *);
const char *UDFContextFunctionName(UDFContext *);
void PrintTypesString(Environment *,const char *,unsigned,bool);
bool UDFFirstArgument(UDFContext *,unsigned,UDFValue *);
bool UDFNextArgument(UDFContext *,unsigned,UDFValue *);
void UDFThrowError(UDFContext *);
void *GetUDFContext(Environment *,const char *);
#define UDFHasNextArgument(context) (context->lastArg != NULL)
#endif /* _H_extnfunc */