30 #include "EST_String.h"
31 #include "EST_THash.h"
32 #include "EST_StringTrie.h"
33 #include "EST_cutils.h"
34 #include "EST_strcasecmp.h"
37 #include "siodeditline.h"
39 extern "C" const char * repl_prompt;
44 #if defined(INSTANTIATE_TEMPLATES)
45 #include "../base_class/EST_THash.cc"
47 Instantiate_TStringHash_T(
EST_Regex *, hash_string_regex)
52 int siod_init(
int heap_size)
59 char *char_heap_size=getenv(
"SIODHEAPSIZE");
60 if ((char_heap_size == 0) ||
61 (atoi(char_heap_size) < 1000))
62 actual_heap_size=ACTUAL_DEFAULT_HEAP_SIZE;
64 actual_heap_size=atoi(char_heap_size);
67 actual_heap_size = heap_size;
69 init_storage(actual_heap_size);
80 LISP siod_get_lval(
const char *name,
const char *message)
88 if (symbol_boundp(iii,current_env) == NIL)
94 rval = symbol_value(iii, current_env);
99 LISP siod_set_lval(
const char *name,LISP val)
106 rval = setvar(iii,val,current_env);
111 LISP siod_assoc_str(
const char *key,LISP alist)
117 for (l=alist; CONSP(l); l=CDR(l))
123 if (NULLP(lcc))
continue;
124 else if TYPEP(lcc,tc_symbol)
126 if (strcmp(key,PNAME(lcc))==0)
129 else if TYPEP(lcc,tc_flonum)
131 if (FLONMPNAME(lcc) == NULL)
134 sprintf(b,
"%g",FLONM(lcc));
135 FLONMPNAME(lcc) = (
char *)must_malloc(strlen(b)+1);
136 sprintf(FLONMPNAME(lcc),
"%s",b);
138 if (strcmp(key,FLONMPNAME(lcc))==0)
141 else if TYPEP(lcc,tc_string)
143 if (strcmp(key,lcc->storage_as.string.data)==0)
153 LISP siod_member_str(
const char *key,LISP list)
158 for (l=list; CONSP(l); l=CDR(l))
159 if (strcmp(key,get_c_string(CAR(l))) == 0)
165 LISP siod_regex_member_str(
const EST_String &key,LISP list)
170 for (l=list; CONSP(l); l=CDR(l))
171 if (key.
matches(make_regex(get_c_string(CAR(l)))))
177 LISP siod_member_int(
const int key,LISP list)
182 for (l=list; CONSP(l); l=CDR(l))
183 if (key == get_c_int(CAR(l)))
188 int siod_llength(LISP list)
194 for (len=0,l=list; CONSP(l); l=CDR(l),len++);
200 LISP siod_nth(
int n,LISP list)
206 for (i=0,l=list; CONSP(l); l=CDR(l),i++)
214 int siod_atomic_list(LISP list)
219 for (p=list; p != NIL; p=cdr(p))
226 int siod_eof(LISP item)
230 (cdr(item) == NIL) &&
231 (SYMBOLP(car(item))) &&
232 (strcmp(
"eof",get_c_string(car(item))) == 0))
241 return cons(rintern(
"quote"),cons(l,NIL));
244 LISP siod_last(LISP list)
248 if ((list == NIL) || (NCONSP(list)))
252 for (l=list; cdr(l) != NIL; l=cdr(l));
257 int get_param_int(
const char *name, LISP params,
int defval)
263 pair = siod_assoc_str(name,params);
267 else if FLONUMP(car(cdr(pair)))
268 return (
int)FLONM(car(cdr(pair)));
271 cerr <<
"param " << name <<
" not of type int" << endl;
278 float get_param_float(
const char *name, LISP params,
float defval)
284 pair = siod_assoc_str(name,params);
288 else if (FLONUMP(car(cdr(pair))))
289 return (
float)FLONM(car(cdr(pair)));
292 cerr <<
"param " << name <<
" not of type float" << endl;
299 const char *get_param_str(
const char *name, LISP params,
const char *defval)
305 pair = siod_assoc_str(name,params);
310 return get_c_string(car(cdr(pair)));
313 LISP get_param_lisp(
const char *name, LISP params, LISP defval)
319 pair = siod_assoc_str(name,params);
324 return car(cdr(pair));
327 LISP make_param_str(
const char *name,
const char *val)
329 return cons(rintern(name),cons(rintern(val),NIL));
332 LISP make_param_int(
const char *name,
int val)
334 return cons(rintern(name),cons(flocons(val),NIL));
337 LISP make_param_float(
const char *name,
float val)
339 return cons(rintern(name),cons(flocons(val),NIL));
342 LISP make_param_lisp(
const char *name,LISP val)
344 return cons(rintern(name),cons(val,NIL));
355 rx = regexes.val(sr,found);
359 regexes.add_item(sr,rx);
365 LISP apply_hooks(LISP hooks,LISP arg)
373 if (hooks && (!CONSP(hooks)))
374 r = leval(cons(hooks,cons(quote(arg),NIL)),NIL);
376 for (h=hooks; h != NIL; h=cdr(h))
377 r = leval(cons(car(h),cons(quote(arg),NIL)),NIL);
381 LISP apply_hooks_right(LISP hooks,LISP args)
391 else if (!CONSP(hooks))
392 r = apply(hooks,args);
394 for (r=args,h=hooks; h != NIL; h=cdr(h))
399 LISP apply(LISP func,LISP args)
403 for (qa=NIL,a=args; a; a=cdr(a))
404 qa = cons(quote(car(a)),qa);
405 return leval(cons(func,reverse(qa)),NIL);
408 LISP stringexplode(
const char *str)
416 for (i=0; i < strlen(str); i++)
419 l = cons(rintern(
id),l);
427 char **siod_variable_generator(
char *text,
int length)
431 char **matches = NULL;
435 for(lmatches=NIL,l=oblistvar;CONSP(l);l=CDR(l))
437 if (VCELL(car(l)) == NIL)
continue;
438 switch(TYPE(VCELL(CAR(l))))
452 name = PNAME(CAR(l));
453 if (strncmp(name, text, length) == 0)
454 lmatches = cons(CAR(l),lmatches);
459 matches = walloc(
char *,siod_llength(lmatches)+1);
460 for (l=lmatches,i=0; l; l=cdr(l),i++)
461 matches[i] = wstrdup(PNAME(car(l)));
467 char **siod_command_generator (
char *text,
int length)
471 char **matches = NULL;
475 for(lmatches=NIL,l=oblistvar;CONSP(l);l=CDR(l))
477 if (VCELL(car(l)) == NIL)
continue;
478 switch(TYPE(VCELL(CAR(l))))
490 name = PNAME(CAR(l));
491 if (strncmp(name, text, length) == 0)
492 lmatches = cons(CAR(l),lmatches);
498 matches = walloc(
char *,siod_llength(lmatches)+1);
499 for (l=lmatches,i=0; l; l=cdr(l),i++)
500 matches[i] = wstrdup(PNAME(car(l)));
513 for (b=l; b != NIL; b=cdr(b))
514 a.
append(get_c_string(car(b)));
524 for (p=a.head(); p != 0; p=p->next())
525 b = cons(rintern(a(p)),b);
A Regular expression class to go with the CSTR EST_String class.
A specialised hash table for when the key is an EST_String.
void append(const T &item)
add item onto end of list
An open hash table. The number of buckets should be set to allow enough space that there are relative...
int matches(const char *e, int pos=0) const
Exactly match this string?
void clear(void)
remove all items in list