docs
This commit is contained in:
parent
cddb8191c8
commit
a3c09d66be
102
os/readline.c
102
os/readline.c
@ -19,7 +19,8 @@ static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file includes the interface to the readline library, if installed in the system.
|
||||
* This file includes the interface to the readline library, if installed in the
|
||||
*system.
|
||||
*
|
||||
*/
|
||||
|
||||
@ -58,6 +59,8 @@ static char SccsId[] = "%W% %G%";
|
||||
static int ReadlineGetc(int);
|
||||
static int ReadlinePutc(int, int);
|
||||
|
||||
static const char *history_file;
|
||||
|
||||
#define READLINE_OUT_BUF_MAX 256
|
||||
|
||||
typedef struct scan_atoms {
|
||||
@ -65,20 +68,17 @@ typedef struct scan_atoms {
|
||||
Atom atom;
|
||||
} scan_atoms_t;
|
||||
|
||||
static char *
|
||||
atom_enumerate(const char *prefix, int state)
|
||||
{
|
||||
static char *atom_enumerate(const char *prefix, int state) {
|
||||
CACHE_REGS
|
||||
struct scan_atoms *index;
|
||||
Atom catom;
|
||||
Int i;
|
||||
|
||||
if ( !state )
|
||||
{ index = (struct scan_atoms *)malloc(sizeof(struct scan_atoms));
|
||||
if (!state) {
|
||||
index = (struct scan_atoms *)malloc(sizeof(struct scan_atoms));
|
||||
i = 0;
|
||||
catom = NIL;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
CACHE_REGS
|
||||
index = LOCAL_search_atoms;
|
||||
catom = index->atom;
|
||||
@ -115,13 +115,11 @@ atom_enumerate(const char *prefix, int state)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *atom_generator(const char *prefix, int state) {
|
||||
char *s = atom_enumerate(prefix, state);
|
||||
|
||||
static char *
|
||||
atom_generator(const char *prefix, int state)
|
||||
{ char *s = atom_enumerate(prefix, state);
|
||||
|
||||
if ( s )
|
||||
{ char *copy = malloc(1 + strlen(s));
|
||||
if (s) {
|
||||
char *copy = malloc(1 + strlen(s));
|
||||
|
||||
if (copy) /* else pretend no completion */
|
||||
strcpy(copy, s);
|
||||
@ -131,35 +129,27 @@ atom_generator(const char *prefix, int state)
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
static char **
|
||||
prolog_completion(const char *text, int start, int end)
|
||||
{ char **matches = NULL;
|
||||
static char **prolog_completion(const char *text, int start, int end) {
|
||||
char **matches = NULL;
|
||||
|
||||
if ((start == 1 && rl_line_buffer[0] == '[') || /* [file */
|
||||
(start == 2 && strncmp(rl_line_buffer, "['", 2)))
|
||||
matches = rl_completion_matches((char *)text, /* for pre-4.2 */
|
||||
rl_filename_completion_function);
|
||||
else
|
||||
matches = rl_completion_matches((char *)text,
|
||||
atom_generator);
|
||||
matches = rl_completion_matches((char *)text, atom_generator);
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Yap_ReadlineFlush( int sno )
|
||||
{
|
||||
void Yap_ReadlineFlush(int sno) {
|
||||
if (GLOBAL_Stream[sno].status & Tty_Stream_f &&
|
||||
GLOBAL_Stream[sno].status & Output_Stream_f) {
|
||||
rl_redisplay();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool Yap_ReadlinePrompt( StreamDesc * s )
|
||||
{
|
||||
bool Yap_ReadlinePrompt(StreamDesc *s) {
|
||||
if (s->status & Tty_Stream_f) {
|
||||
s->stream_getc = ReadlineGetc;
|
||||
if (GLOBAL_Stream[0].status & Tty_Stream_f &&
|
||||
@ -170,9 +160,7 @@ bool Yap_ReadlinePrompt( StreamDesc * s )
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
Yap_ReadlineOps( StreamDesc *s )
|
||||
{
|
||||
bool Yap_ReadlineOps(StreamDesc *s) {
|
||||
if (s->status & Tty_Stream_f) {
|
||||
if (GLOBAL_Stream[0].status & Tty_Stream_f &&
|
||||
is_same_tty(s->file, GLOBAL_Stream[0].file))
|
||||
@ -183,16 +171,13 @@ Yap_ReadlineOps( StreamDesc *s )
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
prolog_complete(int ignore, int key)
|
||||
{ if ( rl_point > 0 && rl_line_buffer[rl_point-1] != ' ' )
|
||||
{
|
||||
#if HAVE_DECL_RL_CATCH_SIGNALS_ /* actually version >= 1.2, or true readline */
|
||||
static int prolog_complete(int ignore, int key) {
|
||||
if (rl_point > 0 && rl_line_buffer[rl_point - 1] != ' ') {
|
||||
#if HAVE_DECL_RL_CATCH_SIGNALS_ /* actually version >= 1.2, or true readline \
|
||||
*/
|
||||
rl_begin_undo_group();
|
||||
rl_complete(ignore, key);
|
||||
if ( rl_point > 0 && rl_line_buffer[rl_point-1] == ' ' )
|
||||
{
|
||||
if (rl_point > 0 && rl_line_buffer[rl_point - 1] == ' ') {
|
||||
rl_delete_text(rl_point - 1, rl_point);
|
||||
rl_point -= 1;
|
||||
rl_delete(-1, key);
|
||||
@ -205,8 +190,7 @@ prolog_complete(int ignore, int key)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
InitReadline(void) {
|
||||
static void InitReadline(void) {
|
||||
// don't call readline within emacs
|
||||
// if (getenv("ËMACS"))
|
||||
// return;
|
||||
@ -218,8 +202,8 @@ InitReadline(void) {
|
||||
rl_outstream = stderr;
|
||||
using_history();
|
||||
char *s = Yap_AbsoluteFile("~/.YAP.history", NULL, true);
|
||||
if (!read_history (s))
|
||||
{ FILE *f = fopen(s, "w");
|
||||
if (!read_history(s)) {
|
||||
FILE *f = fopen(s, "w");
|
||||
if (f) {
|
||||
fclose(f);
|
||||
read_history(s);
|
||||
@ -232,12 +216,9 @@ InitReadline(void) {
|
||||
#else
|
||||
rl_add_defun("prolog-complete", (void *)prolog_complete, '\t');
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static bool
|
||||
getLine( int inp, int out )
|
||||
{
|
||||
static bool getLine(int inp, int out) {
|
||||
CACHE_REGS
|
||||
rl_instream = GLOBAL_Stream[inp].file;
|
||||
rl_outstream = GLOBAL_Stream[out].file;
|
||||
@ -275,22 +256,18 @@ getLine( int inp, int out )
|
||||
return false;
|
||||
if (myrl_line[0] != '\0' && myrl_line[1] != '\0') {
|
||||
add_history(myrl_line);
|
||||
write_history ( Yap_AbsoluteFile("~/.YAP.history", NULL, true));
|
||||
append_history(1, history_file);
|
||||
}
|
||||
s->u.irl.ptr = s->u.irl.buf = myrl_line;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int
|
||||
ReadlinePutc (int sno, int ch)
|
||||
{
|
||||
static int ReadlinePutc(int sno, int ch) {
|
||||
StreamDesc *s = &GLOBAL_Stream[sno];
|
||||
#if MAC || _MSC_VER || defined(__MINGW32__)
|
||||
if (ch == 10)
|
||||
{
|
||||
if (ch == 10) {
|
||||
putc('\n', s->file);
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif
|
||||
putc(ch, s->file);
|
||||
console_count_output_char(ch, s);
|
||||
@ -300,15 +277,11 @@ ReadlinePutc (int sno, int ch)
|
||||
return ((int)ch);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
reading from the console is complicated because we need to
|
||||
know whether to prompt and so on...
|
||||
*/
|
||||
static int
|
||||
ReadlineGetc(int sno)
|
||||
{
|
||||
static int ReadlineGetc(int sno) {
|
||||
StreamDesc *s = &GLOBAL_Stream[sno];
|
||||
int ch;
|
||||
bool fetch = (s->u.irl.buf == NULL);
|
||||
@ -327,9 +300,7 @@ ReadlineGetc(int sno)
|
||||
return console_post_process_read_char(ch, s);
|
||||
}
|
||||
|
||||
int
|
||||
Yap_ReadlineForSIGINT(void)
|
||||
{
|
||||
int Yap_ReadlineForSIGINT(void) {
|
||||
CACHE_REGS
|
||||
int ch;
|
||||
StreamDesc *s = &GLOBAL_Stream[StdInStream];
|
||||
@ -354,8 +325,7 @@ Yap_ReadlineForSIGINT(void)
|
||||
}
|
||||
}
|
||||
|
||||
static Int has_readline(USES_REGS1)
|
||||
{
|
||||
static Int has_readline(USES_REGS1) {
|
||||
#if USE_READLINE
|
||||
return true;
|
||||
#else
|
||||
@ -363,9 +333,9 @@ static Int has_readline(USES_REGS1)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Yap_InitReadline(void) {
|
||||
Yap_InitCPred ("$has_readline", 0, has_readline, SafePredFlag|HiddenPredFlag);
|
||||
Yap_InitCPred("$has_readline", 0, has_readline,
|
||||
SafePredFlag | HiddenPredFlag);
|
||||
InitReadline();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user