diff --git a/src/iocsh/Makefile b/src/iocsh/Makefile index 063f1a732..b12071471 100644 --- a/src/iocsh/Makefile +++ b/src/iocsh/Makefile @@ -26,7 +26,6 @@ INC += envRegister.h # LIBSRCS += ioccrf.cpp -LIBSRCS += epicsReadline.c LIBSRCS += osiRegister.c LIBSRCS += dbStaticRegister.c LIBSRCS += dbTestRegister.c diff --git a/src/iocsh/epicsReadline.c b/src/iocsh/epicsReadline.c deleted file mode 100644 index 44103f208..000000000 --- a/src/iocsh/epicsReadline.c +++ /dev/null @@ -1,54 +0,0 @@ -/* epicsReadline.c */ -/* Author: Eric Norum Date: 18DEC2000 */ - -/* - * Wrappers around readline calls to work around the fact that - * on many machines readline.h declares functions with old-style - * (i.e. non-prototype) syntax. The old syntax is incompatible - * with C++. - */ - -#include - -#ifdef IOCSH_USE_READLINE - -# include -# include - -#else - -/* - * Fake versions of some readline/history routines - */ -# define stifle_history(n) do { } while(0) -# define add_history(l) do { } while(0) -# define rl_bind_key(c,f) do { } while(0) - -#endif - -#define epicsExportSharedSymbols -#include "epicsReadline.h" - -#ifdef IOCSH_USE_READLINE - - char * epicsShareAPI epics_readline (const char *prompt) - { - return readline (prompt); - } - -#endif - -void epicsShareAPI epics_stifle_history (int n) -{ - stifle_history (n); -} - -void epicsShareAPI epics_add_history (const char *line) -{ - add_history (line); -} - -void epicsShareAPI epics_bind_keys (void) -{ - rl_bind_key ('\t', rl_insert); -} diff --git a/src/iocsh/epicsReadline.h b/src/iocsh/epicsReadline.h deleted file mode 100644 index 1355d786c..000000000 --- a/src/iocsh/epicsReadline.h +++ /dev/null @@ -1,29 +0,0 @@ -/* epicsReadline.h */ -/* Author: Eric Norum Date: 18DEC2000 */ - -/* - * Wrappers around readline calls to work around the fact that - * on many machines readline.h declares functions with old-style - * (i.e. non-prototype) syntax. The old syntax is incompatible - * with C++. - */ - -#ifndef _EPICS_READLINE_H_ -#define _EPICS_READLINE_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -epicsShareFunc char * epicsShareAPI epics_readline (const char *prompt); -epicsShareFunc void epicsShareAPI epics_stifle_history (int n); -epicsShareFunc void epicsShareAPI epics_add_history (const char *line); -epicsShareFunc void epicsShareAPI epics_bind_keys (void); - -#ifdef __cplusplus -} -#endif - -#endif /* _EPICS_READLINE_H_ */ diff --git a/src/iocsh/ioccrf.cpp b/src/iocsh/ioccrf.cpp index 3bcd61912..2e87747b6 100644 --- a/src/iocsh/ioccrf.cpp +++ b/src/iocsh/ioccrf.cpp @@ -122,53 +122,6 @@ void epicsShareAPI ioccrfFree(void) commandTableUnlock (); } -/* - * Read a line of input - */ -static char * -my_readline (FILE *fp, const char *prompt) -{ - char c; - char *line = NULL; - int linelen = 0; - int linesize = 50; - - if (fp == NULL) -#ifdef IOCSH_USE_READLINE - return epics_readline (prompt); -#else - fp = stdin; -#endif - line = (char *)malloc (linesize * sizeof *line); - if (line == NULL) { - printf ("Out of memory!\n"); - return NULL; - } - if (prompt) - fputs (prompt, stdout); - while ((c = getc (fp)) != '\n') { - if (c == EOF) { - free (line); - return NULL; - } - if ((linelen + 1) >= linesize) { - char *cp; - - linesize += 50; - cp = (char *)realloc (line, linesize * sizeof *line); - if (cp == NULL) { - printf ("Out of memory!\n"); - free (line); - return NULL; - } - line = cp; - } - line[linelen++] = c; - } - line[linelen] = '\0'; - return line; -} - /* * Report an error */ @@ -269,13 +222,13 @@ ioccrf (const char *pathname) prompt = "iocsh> "; if (((historySize = getenv ("IOCSH_HISTSIZE")) == NULL) && ((historySize = getenv ("HISTSIZE")) == NULL)) - historySize = "10"; + historySize = "20"; if (pathname == NULL) { - epics_stifle_history (atoi (historySize)); + epicsStifleHistory (atoi (historySize)); /* * FIXME: Could enable tab-completion of commands here */ - epics_bind_keys(); + epicsBindKeys(); } else { fp = stdin; @@ -303,7 +256,7 @@ ioccrf (const char *pathname) */ lineno++; free (line); - line = my_readline (fp, prompt); + line = epicsReadline (fp, prompt); if (line == NULL) break; @@ -311,7 +264,7 @@ ioccrf (const char *pathname) * If using readline, add non-blank lines to history */ if ((fp == NULL) && *line) - epics_add_history (line); + epicsAddHistory (line); /* * Ignore comment lines diff --git a/src/libCom/Makefile b/src/libCom/Makefile index c66601200..6798bb417 100644 --- a/src/libCom/Makefile +++ b/src/libCom/Makefile @@ -17,8 +17,11 @@ SRC_DIRS += $(LIBCOM)/ring USR_CFLAGS += -I$(LIBCOM)/ring INC += epicsRingPointer.h INC += epicsRingBytes.h +INC += epicsReadline.h +INC += osdReadline.h SRCS += epicsRingPointer.cpp SRCS += epicsRingBytes.cpp +SRCS += epicsReadline.c SRC_DIRS += $(LIBCOM)/calc #following needed for locating postfixPvt.h and sCalcPostfixPvt.h diff --git a/src/libCom/osi/os/Linux/osdReadline.h b/src/libCom/osi/os/Linux/osdReadline.h new file mode 100644 index 000000000..f5ba886d0 --- /dev/null +++ b/src/libCom/osi/os/Linux/osdReadline.h @@ -0,0 +1,9 @@ +#ifndef _OSD_READLINE_H_ +#define _OSD_READLINE_H_ + +/* + * Use readline library. + */ +#define IOCSH_REAL_READLINE + +#endif /* _OSD_READLINE_H_ */ diff --git a/src/libCom/osi/os/RTEMS/osdReadline.h b/src/libCom/osi/os/RTEMS/osdReadline.h new file mode 100644 index 000000000..f5ba886d0 --- /dev/null +++ b/src/libCom/osi/os/RTEMS/osdReadline.h @@ -0,0 +1,9 @@ +#ifndef _OSD_READLINE_H_ +#define _OSD_READLINE_H_ + +/* + * Use readline library. + */ +#define IOCSH_REAL_READLINE + +#endif /* _OSD_READLINE_H_ */ diff --git a/src/libCom/osi/os/default/epicsReadline.c b/src/libCom/osi/os/default/epicsReadline.c new file mode 100644 index 000000000..02d3b6f8b --- /dev/null +++ b/src/libCom/osi/os/default/epicsReadline.c @@ -0,0 +1,95 @@ +/* ioccrf.cpp */ +/* Author: Eric Norum Date: 12DEC2001 */ + +#include + +#define epicsExportSharedSymbols + +#include +#include + +#if (defined (IOCSH_REAL_READLINE) && defined (IOCSH_FAKE_READLINE)) +# warning "IOCSH_REAL_READLINE and IOCSH_FAKE_READLINE are both defined." +# warning "I am assuming that you want IOCSH_REAL_READLINE support." +# undef IOCSH_FAKE_READLINE +#endif + +#if (defined (IOCSH_REAL_READLINE) || defined (IOCSH_FAKE_READLINE)) + +#include +#include + +#if (defined (IOCSH_REAL_READLINE)) +# include +# include +#endif + +/* + * Read a line of input + */ +char * epicsShareAPI +epicsReadline (FILE *fp, const char *prompt) +{ + char c; + char *line = NULL; + int linelen = 0; + int linesize = 50; + + if (fp == NULL) +#ifdef IOCSH_REAL_READLINE + return readline (prompt); +#else + fp = stdin; +#endif + line = (char *)malloc (linesize * sizeof *line); + if (line == NULL) { + printf ("Out of memory!\n"); + return NULL; + } + if (prompt) + fputs (prompt, stdout); + while ((c = getc (fp)) != '\n') { + if (c == EOF) { + free (line); + return NULL; + } + if ((linelen + 1) >= linesize) { + char *cp; + + linesize += 50; + cp = (char *)realloc (line, linesize * sizeof *line); + if (cp == NULL) { + printf ("Out of memory!\n"); + free (line); + return NULL; + } + line = cp; + } + line[linelen++] = c; + } + line[linelen] = '\0'; + return line; +} + +void epicsShareAPI epicsStifleHistory (int n) +{ +#if (defined (IOCSH_REAL_READLINE)) + stifle_history (n); +#endif +} + +void epicsShareAPI epicsAddHistory (const char *line) +{ +#if (defined (IOCSH_REAL_READLINE)) + add_history (line); +#endif +} + +void epicsShareAPI epicsBindKeys (void) +{ +#if (defined (IOCSH_REAL_READLINE)) + rl_bind_key ('\t', rl_insert); +#endif +} + +#endif /* defined (IOCSH_REAL_READLINE) || defined (IOCSH_FAKE_READLINE) */ diff --git a/src/libCom/osi/os/default/epicsReadline.h b/src/libCom/osi/os/default/epicsReadline.h new file mode 100644 index 000000000..99957c82d --- /dev/null +++ b/src/libCom/osi/os/default/epicsReadline.h @@ -0,0 +1,20 @@ +#ifndef _EPICS_READLINE_H +#define _EPICS_READLINE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +epicsShareFunc char * epicsShareAPI epicsReadline (FILE *fp, const char *prompt); +epicsShareFunc void epicsShareAPI epicsStifleHistory (int n); +epicsShareFunc void epicsShareAPI epicsAddHistory (const char *line); +epicsShareFunc void epicsShareAPI epicsBindKeys (void); + +#ifdef __cplusplus +} +#endif + +#endif /* _EPICS_READLINE_H */ diff --git a/src/libCom/osi/os/default/osdReadline.h b/src/libCom/osi/os/default/osdReadline.h new file mode 100644 index 000000000..5aaa19219 --- /dev/null +++ b/src/libCom/osi/os/default/osdReadline.h @@ -0,0 +1,18 @@ +#ifndef _OSD_READLINE_H_ +#define _OSD_READLINE_H_ + +/* + * Default version of osdReadline + * Don't use readline library, but do provide epicsReadline routines + * + * This wastes a few hundred bytes of memory if you're not using iocsh. + * If that many bytes is really important to you you can save it by + * going to the os-dependent directory and creating an osdReadline.h + * which defines neither of the following macros. + * + */ + +/* #define IOCSH_REAL_READLINE */ +#define IOCSH_FAKE_READLINE + +#endif /* _OSD_READLINE_H_ */