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
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.40 07/30/16 */
/* */
/* USER DATA MODULE */
/*******************************************************/
/*************************************************************/
/* Purpose: Routines for attaching user data to constructs, */
/* facts, instances, user functions, etc. */
/* */
/* Principal Programmer(s): */
/* Gary D. Riley */
/* */
/* Revision History: */
/* */
/* 6.40: Pragma once and other inclusion changes. */
/* */
/* Removed use of void pointers for specific */
/* data structures. */
/* */
/*************************************************************/
#include <stdlib.h>
#include "setup.h"
#include "envrnmnt.h"
#include "userdata.h"
/*************************************************/
/* InitializeUserDataData: Allocates environment */
/* data for user data routines. */
/*************************************************/
void InitializeUserDataData(
Environment *theEnv)
{
AllocateEnvironmentData(theEnv,USER_DATA_DATA,sizeof(struct userDataData),NULL);
}
/******************************************************/
/* InstallUserDataRecord: Installs a user data record */
/* in the user data record array and returns the */
/* integer data ID associated with the record. */
/******************************************************/
unsigned char InstallUserDataRecord(
Environment *theEnv,
struct userDataRecord *theRecord)
{
theRecord->dataID = UserDataData(theEnv)->UserDataRecordCount;
UserDataData(theEnv)->UserDataRecordArray[UserDataData(theEnv)->UserDataRecordCount] = theRecord;
return(UserDataData(theEnv)->UserDataRecordCount++);
}
/*****************************************************/
/* FetchUserData: Searches for user data information */
/* from a list of user data structures. A new user */
/* data structure is created if one is not found. */
/*****************************************************/
struct userData *FetchUserData(
Environment *theEnv,
unsigned char userDataID,
struct userData **theList)
{
struct userData *theData;
for (theData = *theList;
theData != NULL;
theData = theData->next)
{
if (theData->dataID == userDataID)
{ return(theData); }
}
theData = (struct userData *) (*UserDataData(theEnv)->UserDataRecordArray[userDataID]->createUserData)(theEnv);
theData->dataID = userDataID;
theData->next = *theList;
*theList = theData;
return(theData);
}
/*****************************************************/
/* TestUserData: Searches for user data information */
/* from a list of user data structures. NULL is */
/* returned if the appropriate user data structure */
/* is not found. */
/*****************************************************/
struct userData *TestUserData(
unsigned char userDataID,
struct userData *theList)
{
struct userData *theData;
for (theData = theList;
theData != NULL;
theData = theData->next)
{
if (theData->dataID == userDataID)
{ return(theData); }
}
return NULL;
}
/***************************************************************/
/* ClearUserDataList: Deallocates a linked list of user data. */
/***************************************************************/
void ClearUserDataList(
Environment *theEnv,
struct userData *theList)
{
struct userData *nextData;
while (theList != NULL)
{
nextData = theList->next;
(*UserDataData(theEnv)->UserDataRecordArray[theList->dataID]->deleteUserData)(theEnv,theList);
theList = nextData;
}
}
/*************************************************/
/* DeleteUserData: Removes user data information */
/* from a list of user data structures. */
/*************************************************/
struct userData *DeleteUserData(
Environment *theEnv,
unsigned char userDataID,
struct userData *theList)
{
struct userData *theData, *lastData = NULL;
for (theData = theList;
theData != NULL;
theData = theData->next)
{
if (theData->dataID == userDataID)
{
if (lastData == NULL)
{ theList = theData->next; }
else
{ lastData->next = theData->next; }
(*UserDataData(theEnv)->UserDataRecordArray[userDataID]->deleteUserData)(theEnv,theData);
return(theList);
}
lastData = theData;
}
return(theList);
}