Move readline support to src/libCom/osi/os/xxx/.
The single source file is in src/libCom/osi/os/default/epicsReadline.c which uses the readline library routines or uses local code to read lines of input. Selection is made by src/libCom/osi/os/XXX/osdReadline.h. The default version does not cause the readline library routines to be used.
This commit is contained in:
@@ -26,7 +26,6 @@ INC += envRegister.h
|
||||
#
|
||||
|
||||
LIBSRCS += ioccrf.cpp
|
||||
LIBSRCS += epicsReadline.c
|
||||
LIBSRCS += osiRegister.c
|
||||
LIBSRCS += dbStaticRegister.c
|
||||
LIBSRCS += dbTestRegister.c
|
||||
|
||||
@@ -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 <stdio.h>
|
||||
|
||||
#ifdef IOCSH_USE_READLINE
|
||||
|
||||
# include <readline/readline.h>
|
||||
# include <readline/history.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
@@ -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 <shareLib.h>
|
||||
|
||||
#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_ */
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
9
src/libCom/osi/os/Linux/osdReadline.h
Normal file
9
src/libCom/osi/os/Linux/osdReadline.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _OSD_READLINE_H_
|
||||
#define _OSD_READLINE_H_
|
||||
|
||||
/*
|
||||
* Use readline library.
|
||||
*/
|
||||
#define IOCSH_REAL_READLINE
|
||||
|
||||
#endif /* _OSD_READLINE_H_ */
|
||||
9
src/libCom/osi/os/RTEMS/osdReadline.h
Normal file
9
src/libCom/osi/os/RTEMS/osdReadline.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _OSD_READLINE_H_
|
||||
#define _OSD_READLINE_H_
|
||||
|
||||
/*
|
||||
* Use readline library.
|
||||
*/
|
||||
#define IOCSH_REAL_READLINE
|
||||
|
||||
#endif /* _OSD_READLINE_H_ */
|
||||
95
src/libCom/osi/os/default/epicsReadline.c
Normal file
95
src/libCom/osi/os/default/epicsReadline.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/* ioccrf.cpp */
|
||||
/* Author: Eric Norum Date: 12DEC2001 */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
|
||||
#include <epicsReadline.h>
|
||||
#include <osdReadline.h>
|
||||
|
||||
#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 <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#if (defined (IOCSH_REAL_READLINE))
|
||||
# include <readline/readline.h>
|
||||
# include <readline/history.h>
|
||||
#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) */
|
||||
20
src/libCom/osi/os/default/epicsReadline.h
Normal file
20
src/libCom/osi/os/default/epicsReadline.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef _EPICS_READLINE_H
|
||||
#define _EPICS_READLINE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <shareLib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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 */
|
||||
18
src/libCom/osi/os/default/osdReadline.h
Normal file
18
src/libCom/osi/os/default/osdReadline.h
Normal file
@@ -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_ */
|
||||
Reference in New Issue
Block a user