29 |
|
|
30 |
#include "utilities/ascConfig.h" |
#include "utilities/ascConfig.h" |
31 |
#include "utilities/ascMalloc.h" |
#include "utilities/ascMalloc.h" |
32 |
|
#include "utilities/ascPanic.h" |
33 |
#include "general/hashpjw.h" |
#include "general/hashpjw.h" |
34 |
#include "general/list.h" |
#include "general/list.h" |
35 |
#include "general/table.h" |
#include "general/table.h" |
46 |
{ |
{ |
47 |
struct ExternalFunc *result; |
struct ExternalFunc *result; |
48 |
result = (struct ExternalFunc *)ascmalloc(sizeof(struct ExternalFunc)); |
result = (struct ExternalFunc *)ascmalloc(sizeof(struct ExternalFunc)); |
49 |
|
if (result == NULL) { |
50 |
|
return NULL; |
51 |
|
} |
52 |
result->name = name; |
result->name = name; |
53 |
result->n_inputs = 0; |
result->n_inputs = 0; |
54 |
result->n_outputs = 0; |
result->n_outputs = 0; |
70 |
CONST char *help) |
CONST char *help) |
71 |
{ |
{ |
72 |
struct ExternalFunc *efunc; |
struct ExternalFunc *efunc; |
73 |
if (!name) |
if (name == NULL) { |
74 |
return 1; |
return 1; |
75 |
|
} |
76 |
efunc = LookupExtFunc(name); |
efunc = LookupExtFunc(name); |
77 |
if (efunc) { /* name was pre-loaded -- just update the info */ |
if (efunc != NULL) { /* name was pre-loaded -- just update the info */ |
78 |
efunc->n_inputs = n_inputs; |
efunc->n_inputs = n_inputs; |
79 |
efunc->n_outputs = n_outputs; |
efunc->n_outputs = n_outputs; |
80 |
efunc->init = init; |
efunc->init = init; |
81 |
efunc->value = value; |
efunc->value = value; /* should be *value */ |
82 |
efunc->deriv = deriv; |
efunc->deriv = deriv; /* should be *deriv */ |
83 |
efunc->deriv2 = deriv2; |
efunc->deriv2 = deriv2; /* should be *deriv2 */ |
84 |
if (help) { |
if (help) { |
85 |
if (efunc->help) ascfree((char *)efunc->help); |
if (efunc->help) ascfree((char *)efunc->help); |
86 |
efunc->help = (char *)ascmalloc((strlen(help)+1)*sizeof(char)); |
efunc->help = (char *)ascmalloc((strlen(help)+1)*sizeof(char)); |
87 |
|
asc_assert(efunc->help != NULL); |
88 |
strcpy(efunc->help,help); |
strcpy(efunc->help,help); |
89 |
} |
} |
90 |
else |
else |
91 |
efunc->help = NULL; |
efunc->help = NULL; |
92 |
} else { |
} else { |
93 |
efunc = (struct ExternalFunc *)ascmalloc(sizeof(struct ExternalFunc)); |
efunc = (struct ExternalFunc *)ascmalloc(sizeof(struct ExternalFunc)); |
94 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
95 |
efunc->name = SCP(AddSymbol(name)); /* add or find name in symbol table */ |
efunc->name = SCP(AddSymbol(name)); /* add or find name in symbol table */ |
96 |
/* the main symtab owns the string */ |
/* the main symtab owns the string */ |
97 |
efunc->n_inputs = n_inputs; |
efunc->n_inputs = n_inputs; |
98 |
efunc->n_outputs = n_outputs; |
efunc->n_outputs = n_outputs; |
99 |
efunc->init = init; |
efunc->init = init; |
100 |
efunc->value = value; |
efunc->value = value; /* should be *value */ |
101 |
efunc->deriv = deriv; |
efunc->deriv = deriv; /* should be *deriv */ |
102 |
efunc->deriv2 = deriv2; |
efunc->deriv2 = deriv2; /* should be *deriv2 */ |
103 |
if (help) { |
if (help) { |
104 |
efunc->help = (char *)ascmalloc((strlen(help)+1)*sizeof(char)); |
efunc->help = (char *)ascmalloc((strlen(help)+1)*sizeof(char)); |
105 |
|
asc_assert(efunc->help != NULL); |
106 |
strcpy(efunc->help,help); |
strcpy(efunc->help,help); |
107 |
} |
} |
108 |
else |
else |
136 |
|
|
137 |
int (*GetInitFunc(struct ExternalFunc *efunc))(/* */) |
int (*GetInitFunc(struct ExternalFunc *efunc))(/* */) |
138 |
{ |
{ |
139 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
140 |
return efunc->init; |
return efunc->init; |
141 |
} |
} |
142 |
|
|
143 |
ExtBBoxFunc *GetValueFunc(struct ExternalFunc *efunc) |
ExtBBoxFunc *GetValueFunc(struct ExternalFunc *efunc) |
144 |
{ |
{ |
145 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
146 |
return (ExtBBoxFunc *)efunc->value; |
return (ExtBBoxFunc *)efunc->value; |
147 |
} |
} |
148 |
|
|
149 |
|
|
150 |
ExtBBoxFunc *GetDerivFunc(struct ExternalFunc *efunc) |
ExtBBoxFunc *GetDerivFunc(struct ExternalFunc *efunc) |
151 |
{ |
{ |
152 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
153 |
return (ExtBBoxFunc *)efunc->deriv; |
return (ExtBBoxFunc *)efunc->deriv; |
154 |
} |
} |
155 |
|
|
156 |
ExtBBoxFunc *GetDeriv2Func(struct ExternalFunc *efunc) |
ExtBBoxFunc *GetDeriv2Func(struct ExternalFunc *efunc) |
157 |
{ |
{ |
158 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
159 |
return (ExtBBoxFunc *)efunc->deriv2; |
return (ExtBBoxFunc *)efunc->deriv2; |
160 |
} |
} |
161 |
|
|
176 |
|
|
177 |
ExtEvalFunc **GetValueJumpTable(struct ExternalFunc *efunc) |
ExtEvalFunc **GetValueJumpTable(struct ExternalFunc *efunc) |
178 |
{ |
{ |
179 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
180 |
return efunc->value; |
return efunc->value; /* error, efunc->value is not an array of pointers */ |
181 |
} |
} |
182 |
|
|
183 |
ExtEvalFunc **GetDerivJumpTable(struct ExternalFunc *efunc) |
ExtEvalFunc **GetDerivJumpTable(struct ExternalFunc *efunc) |
184 |
{ |
{ |
185 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
186 |
return efunc->deriv; |
return efunc->deriv; /* error, efunc->value is not an array of pointers */ |
187 |
} |
} |
188 |
|
|
189 |
#ifdef THIS_IS_AN_UNUSED_FUNCTION |
#ifdef THIS_IS_AN_UNUSED_FUNCTION |
190 |
static |
static |
191 |
ExtEvalFunc **GetValueDeriv2Table(struct ExternalFunc *efunc) |
ExtEvalFunc **GetValueDeriv2Table(struct ExternalFunc *efunc) |
192 |
{ |
{ |
193 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
194 |
return efunc->deriv2; |
return efunc->deriv2; /* error, efunc->value is not an array of pointers */ |
195 |
} |
} |
196 |
#endif /* THIS_IS_AN_UNUSED_FUNCTION */ |
#endif /* THIS_IS_AN_UNUSED_FUNCTION */ |
197 |
|
|
198 |
|
|
199 |
CONST char *ExternalFuncName(CONST struct ExternalFunc *efunc) |
CONST char *ExternalFuncName(CONST struct ExternalFunc *efunc) |
200 |
{ |
{ |
201 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
202 |
return efunc->name; |
return efunc->name; |
203 |
} |
} |
204 |
|
|
205 |
unsigned long NumberInputArgs(CONST struct ExternalFunc *efunc) |
unsigned long NumberInputArgs(CONST struct ExternalFunc *efunc) |
206 |
{ |
{ |
207 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
208 |
return efunc->n_inputs; |
return efunc->n_inputs; |
209 |
} |
} |
210 |
|
|
211 |
unsigned long NumberOutputArgs(CONST struct ExternalFunc *efunc) |
unsigned long NumberOutputArgs(CONST struct ExternalFunc *efunc) |
212 |
{ |
{ |
213 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
214 |
return efunc->n_outputs; |
return efunc->n_outputs; |
215 |
} |
} |
216 |
|
|
231 |
struct ExternalFunc *found, *tmp; |
struct ExternalFunc *found, *tmp; |
232 |
char *name; |
char *name; |
233 |
|
|
234 |
assert(efunc!=NULL); |
asc_assert(efunc!=NULL); |
235 |
name = (char *)efunc->name; |
name = (char *)efunc->name; |
236 |
found = (struct ExternalFunc *)LookupTableData(ExternalFuncLibrary,name); |
found = (struct ExternalFunc *)LookupTableData(ExternalFuncLibrary,name); |
237 |
if (found) { /* function name already exists */ |
if (found) { /* function name already exists */ |