Change command-line input to allow CONFIG_SITE selection of libtecla,

GNU readline, or built-in EPICS routines.
This commit is contained in:
W. Eric Norum
2002-11-20 20:17:36 +00:00
parent 1e14394d92
commit 1c7428c1cf
16 changed files with 274 additions and 179 deletions
+18 -31
View File
@@ -218,27 +218,14 @@ iocsh (const char *pathname)
int argBufCapacity = 0;
struct iocshCommand *found;
struct iocshFuncDef const *piocshFuncDef;
void *readlineContext;
/*
* See if command interpreter is interactive
*/
if ((pathname == NULL) || (strcmp (pathname, "<telnet>") == 0)) {
const char *historySize;
if ((prompt = getenv ("IOCSH_PS1")) == NULL)
prompt = "epics> ";
if (((historySize = getenv ("IOCSH_HISTSIZE")) == NULL)
&& ((historySize = getenv ("HISTSIZE")) == NULL))
historySize = "20";
if (pathname == NULL) {
epicsStifleHistory (atoi (historySize));
/*
* FIXME: Could enable tab-completion of commands here
*/
epicsBindKeys();
}
else {
fp = stdin;
}
}
else {
fp = fopen (pathname, "r");
@@ -253,24 +240,21 @@ iocsh (const char *pathname)
prompt = NULL;
}
/*
* Create a command-line input context
*/
if ((readlineContext = epicsReadlineBegin(fp)) == NULL) {
fprintf(stderr, "Can't allocate command-line object.\n");
if (fp)
fclose(fp);
return -1;
}
/*
* Read commands till EOF or exit
*/
for (;;) {
/*
* Get a line
*/
while ((line = epicsReadline(prompt, readlineContext)) != NULL) {
lineno++;
free (line);
line = epicsReadline (fp, prompt);
if (line == NULL)
break;
/*
* If using readline, add non-blank lines to history
*/
if ((fp == NULL) && *line)
epicsAddHistory (line);
/*
* Ignore comment lines
@@ -278,8 +262,11 @@ iocsh (const char *pathname)
if (*line == '#')
continue;
if ((prompt == NULL) && *line)
puts(line);
/*
* Echo commands read from scripts
*/
if ((prompt == NULL) && *line)
puts(line);
/*
* Break line into words
@@ -471,10 +458,10 @@ iocsh (const char *pathname)
}
if (fp && (fp != stdin))
fclose (fp);
free (line);
free (argv);
free (argBuf);
errlogFlush();
epicsReadlineEnd(readlineContext);
return 0;
}