1 /*******************************************************/
2 /* "C" Language Integrated Production System */
4 /* CLIPS Version 6.30 08/22/14 */
6 /* UTILITY HEADER FILE */
7 /*******************************************************/
9 /*************************************************************/
10 /* Purpose: Provides a set of utility functions useful to */
11 /* other modules. Primarily these are the functions for */
12 /* handling periodic garbage collection and appending */
15 /* Principal Programmer(s): */
18 /* Contributing Programmer(s): */
20 /* Revision History: */
22 /* 6.24: Renamed BOOLEAN macro type to intBool. */
24 /* 6.30: Changed integer type/precision. */
26 /* Changed garbage collection algorithm. */
28 /* Added CopyString, DeleteString, */
29 /* InsertInString,and EnlargeString functions. */
31 /* Used genstrncpy function instead of strncpy */
34 /* Support for typed EXTERNAL_ADDRESS. */
36 /* Support for tracked memory (allows memory to */
37 /* be freed if CLIPS is exited while executing). */
39 /* Added UTF-8 routines. */
41 /* Added const qualifiers to remove C++ */
42 /* deprecation warnings. */
44 /* Converted API macros to function calls. */
46 /*************************************************************/
59 struct callFunctionItem
64 struct callFunctionItem *next;
65 short int environmentAware;
69 struct callFunctionItemWithArg
72 void (*func)(void *,void *);
74 struct callFunctionItemWithArg *next;
75 short int environmentAware;
82 struct trackedMemory *next;
83 struct trackedMemory *prev;
91 struct garbageFrame *priorFrame;
92 struct ephemeron *ephemeralSymbolList;
93 struct ephemeron *ephemeralFloatList;
94 struct ephemeron *ephemeralIntegerList;
95 struct ephemeron *ephemeralBitMapList;
96 struct ephemeron *ephemeralExternalAddressList;
97 struct multifield *ListOfMultifields;
98 struct multifield *LastMultifield;
101 #define UTILITY_DATA 55
105 struct callFunctionItem *ListOfCleanupFunctions;
106 struct callFunctionItem *ListOfPeriodicFunctions;
107 short GarbageCollectionLocks;
108 short PeriodicFunctionsEnabled;
109 short YieldFunctionEnabled;
110 void (*YieldTimeFunction)(void);
111 struct trackedMemory *trackList;
112 struct garbageFrame MasterGarbageFrame;
113 struct garbageFrame *CurrentGarbageFrame;
116 #define UtilityData(theEnv) ((struct utilityData *) GetEnvironmentData(theEnv,UTILITY_DATA))
118 /* Is c the start of a utf8 sequence? */
119 #define IsUTF8Start(ch) (((ch) & 0xC0) != 0x80)
120 #define IsUTF8MultiByteStart(ch) ((((unsigned char) ch) >= 0xC0) && (((unsigned char) ch) <= 0xF7))
121 #define IsUTF8MultiByteContinuation(ch) ((((unsigned char) ch) >= 0x80) && (((unsigned char) ch) <= 0xBF))
123 #ifdef _UTILITY_SOURCE_
126 #define LOCALE extern
129 LOCALE void InitializeUtilityData(void *);
130 LOCALE intBool AddCleanupFunction(void *,const char *,void (*)(void *),int);
131 LOCALE intBool EnvAddPeriodicFunction(void *,const char *,void (*)(void *),int);
132 LOCALE intBool AddPeriodicFunction(const char *,void (*)(void),int);
133 LOCALE intBool RemoveCleanupFunction(void *,const char *);
134 LOCALE intBool EnvRemovePeriodicFunction(void *,const char *);
135 LOCALE char *CopyString(void *,const char *);
136 LOCALE void DeleteString(void *,char *);
137 LOCALE const char *AppendStrings(void *,const char *,const char *);
138 LOCALE const char *StringPrintForm(void *,const char *);
139 LOCALE char *AppendToString(void *,const char *,char *,size_t *,size_t *);
140 LOCALE char *InsertInString(void *,const char *,size_t,char *,size_t *,size_t *);
141 LOCALE char *AppendNToString(void *,const char *,char *,size_t,size_t *,size_t *);
142 LOCALE char *EnlargeString(void *,size_t,char *,size_t *,size_t *);
143 LOCALE char *ExpandStringWithChar(void *,int,char *,size_t *,size_t *,size_t);
144 LOCALE struct callFunctionItem *AddFunctionToCallList(void *,const char *,int,void (*)(void *),
145 struct callFunctionItem *,intBool);
146 LOCALE struct callFunctionItem *AddFunctionToCallListWithContext(void *,const char *,int,void (*)(void *),
147 struct callFunctionItem *,intBool,void *);
148 LOCALE struct callFunctionItem *RemoveFunctionFromCallList(void *,const char *,
149 struct callFunctionItem *,
151 LOCALE void DeallocateCallList(void *,struct callFunctionItem *);
152 LOCALE struct callFunctionItemWithArg *AddFunctionToCallListWithArg(void *,const char *,int,void (*)(void *, void *),
153 struct callFunctionItemWithArg *,intBool);
154 LOCALE struct callFunctionItemWithArg *AddFunctionToCallListWithArgWithContext(void *,const char *,int,void (*)(void *, void *),
155 struct callFunctionItemWithArg *,intBool,void *);
156 LOCALE struct callFunctionItemWithArg *RemoveFunctionFromCallListWithArg(void *,const char *,
157 struct callFunctionItemWithArg *,
159 LOCALE void DeallocateCallListWithArg(void *,struct callFunctionItemWithArg *);
160 LOCALE unsigned long ItemHashValue(void *,unsigned short,void *,unsigned long);
161 LOCALE void YieldTime(void *);
162 LOCALE void EnvIncrementGCLocks(void *);
163 LOCALE void EnvDecrementGCLocks(void *);
164 LOCALE short EnablePeriodicFunctions(void *,short);
165 LOCALE short EnableYieldFunction(void *,short);
166 LOCALE struct trackedMemory *AddTrackedMemory(void *,void *,size_t);
167 LOCALE void RemoveTrackedMemory(void *,struct trackedMemory *);
168 LOCALE void UTF8Increment(const char *,size_t *);
169 LOCALE size_t UTF8Offset(const char *,size_t);
170 LOCALE size_t UTF8Length(const char *);
171 LOCALE size_t UTF8CharNum(const char *,size_t);
172 LOCALE void RestorePriorGarbageFrame(void *,struct garbageFrame *,struct garbageFrame *,struct dataObject *);
173 LOCALE void CallCleanupFunctions(void *);
174 LOCALE void CallPeriodicTasks(void *);
175 LOCALE void CleanCurrentGarbageFrame(void *,struct dataObject *);
177 #if ALLOW_ENVIRONMENT_GLOBALS
179 LOCALE void IncrementGCLocks(void);
180 LOCALE void DecrementGCLocks(void);
181 LOCALE intBool RemovePeriodicFunction(const char *);
183 #endif /* ALLOW_ENVIRONMENT_GLOBALS */
185 #endif /* _H_utility */