50 #include "EST_cutils.h"
51 #include "siodeditline.h"
53 FILE *stddebug = NULL;
55 extern char *repl_prompt;
57 #ifndef SUPPORT_EDITLINE
64 int editline_histsize;
66 int siod_el_getc(FILE *f)
72 fprintf(stdout,
"%s",repl_prompt);
85 void siod_el_ungetc(
int c, FILE *f)
90 void siod_el_init(
void)
97 static int possible_commandp(
char *text,
int start,
int end);
98 static int possible_variablep(
char *text,
int start,
int end);
99 static char **command_completion (
char *text,
int start,
int end);
101 static char *el_line = NULL;
103 char *editline_history_file =
".editline_history";
104 static char *full_history_file =
".editline_history";
106 static STATUS siod_display_doc ()
110 const char *docstring;
113 symbol = el_current_sym();
115 docstring = siod_docstring(symbol);
116 for (i=0; docstring[i] !=
'\0'; i++)
117 putc(docstring[i],stderr);
125 static STATUS siod_say_doc ()
132 symbol = el_current_sym();
133 fprintf(stderr,
"\nsynthesizing doc string ...");
135 siod_saydocstring(symbol);
143 static STATUS siod_manual()
149 const char *infostring;
151 symbol = el_current_sym();
152 infostring = siod_manual_sym(symbol);
154 fprintf(stderr,
"%s",infostring);
163 void siod_el_init(
void)
168 home = getenv(
"HOME");
172 walloc(
char,strlen(home)+strlen(editline_history_file)+2);
173 sprintf(full_history_file,
"%s/%s",home,editline_history_file);
174 read_history(full_history_file);
177 el_user_completion_function = command_completion;
178 el_bind_key_in_metamap(
'h',siod_display_doc);
179 el_bind_key_in_metamap(
's',siod_say_doc);
180 el_bind_key_in_metamap(
'm',siod_manual);
183 int siod_el_getc(FILE *f)
189 el_line=readline(repl_prompt);
192 add_history(el_line);
193 write_history(full_history_file);
197 if ((el_line==NULL) ||
198 (strlen(el_line) <= el_pos))
202 else if (el_pos == -1)
213 void siod_el_ungetc(
int c, FILE *f)
219 fprintf(stderr,
"fix ungetc when nothing is there");
223 static int qsort_str_compare(
const void *p1,
const void *p2)
228 s1 = *(
const char **)p1;
229 s2 = *(
const char **)p2;
231 return strcmp(s1,s2);
234 static char **command_completion (
char *text,
int start,
int end)
236 char **matches = NULL;
241 if (possible_commandp(text,start,end))
242 matches = siod_command_generator(text+start,end-start);
243 else if (possible_variablep(text,start,end))
244 matches = siod_variable_generator(text+start,end-start);
246 if (matches && matches[0] && matches[1])
249 for (i=0; matches[i] != NULL; i++);
250 qsort(matches,i,
sizeof(
char **),qsort_str_compare);
256 static int possible_commandp(
char *text,
int start,
int end)
262 for (t=start-1; t >= 0; t--)
263 if (strchr(
" \t\n\r",text[t]) != NULL)
265 else if (text[t] ==
'(')
273 static int possible_variablep(
char *text,
int start,
int end)
279 for (t=start-1; t >= 0; t--)
280 if (strchr(
" \t\n",text[t]) != NULL)
282 else if (text[t] ==
'(')
284 else if ((text[t] ==
'"') &&