97 |
|
return(fnum); |
98 |
|
} |
99 |
|
|
100 |
+ |
/* Retrieve the indexed field from parameter (first field index is 1) */ |
101 |
+ |
IDF_FIELD * |
102 |
+ |
idf_getfield(IDF_PARAMETER *param, int fn) |
103 |
+ |
{ |
104 |
+ |
IDF_FIELD *fld; |
105 |
+ |
|
106 |
+ |
if ((param == NULL) | (fn <= 0)) |
107 |
+ |
return(NULL); |
108 |
+ |
fld = param->flist; |
109 |
+ |
while ((--fn > 0) & (fld != NULL)) |
110 |
+ |
fld = fld->next; |
111 |
+ |
return(fld); |
112 |
+ |
} |
113 |
+ |
|
114 |
|
/* Delete the specified parameter from loaded IDF */ |
115 |
|
int |
116 |
|
idf_delparam(IDF_LOADED *idf, IDF_PARAMETER *param) |
177 |
|
if (skipwhite && isspace(c)) |
178 |
|
continue; |
179 |
|
skipwhite = 0; |
180 |
< |
if (cp-buf < IDF_MAXLINE-1) |
180 |
> |
if (cp-buf < IDF_MAXARGL-1) |
181 |
|
*cp++ = c; |
182 |
|
} |
183 |
|
if (trim) |
200 |
|
buf = &dummyc; |
201 |
|
len = 1; |
202 |
|
} |
203 |
< |
while ((c = getc(fp)) != EOF && isspace(c) | incomm) { |
204 |
< |
if (c == '!') |
205 |
< |
++incomm; |
192 |
< |
else if (c == '\n') |
203 |
> |
while ((c = getc(fp)) != EOF && |
204 |
> |
(isspace(c) || (incomm += (c == '!')))) { |
205 |
> |
if (c == '\n') |
206 |
|
incomm = 0; |
207 |
|
if (cp-buf < len-1) |
208 |
|
*cp++ = c; |
216 |
|
IDF_PARAMETER * |
217 |
|
idf_readparam(IDF_LOADED *idf, FILE *fp) |
218 |
|
{ |
219 |
< |
char abuf[IDF_MAXLINE], cbuf[IDF_MAXLINE]; |
219 |
> |
char abuf[IDF_MAXARGL], cbuf[IDF_MAXLINE]; |
220 |
|
int delim; |
221 |
|
IDF_PARAMETER *pnew; |
222 |
|
|
230 |
|
idf_addfield(pnew, abuf, cbuf); |
231 |
|
} |
232 |
|
if (delim != ';') |
233 |
< |
fprintf(stderr, "Expected ';' at end of parameter list\n"); |
233 |
> |
fputs("Expected ';' at end of parameter list!\n", stderr); |
234 |
|
return(pnew); |
235 |
|
} |
236 |
|
|
237 |
+ |
/* Upper-case string hashing function */ |
238 |
+ |
static unsigned long |
239 |
+ |
strcasehash(const char *s) |
240 |
+ |
{ |
241 |
+ |
char strup[IDF_MAXARGL]; |
242 |
+ |
char *cdst = strup; |
243 |
+ |
|
244 |
+ |
while ((*cdst++ = toupper(*s++))) |
245 |
+ |
if (cdst >= strup+(sizeof(strup)-1)) { |
246 |
+ |
*cdst = '\0'; |
247 |
+ |
break; |
248 |
+ |
} |
249 |
+ |
return(lu_shash(strup)); |
250 |
+ |
} |
251 |
+ |
|
252 |
|
/* Initialize an IDF struct */ |
253 |
|
IDF_LOADED * |
254 |
|
idf_create(const char *hdrcomm) |
257 |
|
|
258 |
|
if (idf == NULL) |
259 |
|
return(NULL); |
260 |
< |
idf->ptab.hashf = &lu_shash; |
261 |
< |
idf->ptab.keycmp = &strcmp; |
260 |
> |
idf->ptab.hashf = &strcasehash; |
261 |
> |
idf->ptab.keycmp = &strcasecmp; |
262 |
|
idf->ptab.freek = &free; |
263 |
|
lu_init(&idf->ptab, 200); |
264 |
|
if (hdrcomm != NULL && *hdrcomm) { |
273 |
|
IDF_LOADED * |
274 |
|
idf_load(const char *fname) |
275 |
|
{ |
276 |
< |
char *hdrcomm; |
276 |
> |
char hdrcomm[300*IF_MAXLINE]; |
277 |
|
FILE *fp; |
278 |
|
IDF_LOADED *idf; |
279 |
|
|
282 |
|
else if ((fp = fopen(fname, "r")) == NULL) |
283 |
|
return(NULL); |
284 |
|
/* read header comments */ |
285 |
< |
hdrcomm = (char *)malloc(100*IDF_MAXLINE); |
258 |
< |
idf_read_comment(hdrcomm, 100*IDF_MAXLINE, fp); |
285 |
> |
idf_read_comment(hdrcomm, sizeof(hdrcomm), fp); |
286 |
|
idf = idf_create(hdrcomm); /* create IDF struct */ |
260 |
– |
free(hdrcomm); |
287 |
|
if (idf == NULL) |
288 |
|
return(NULL); |
289 |
|
/* read each parameter */ |