version 1.34, 2003/09/14 22:15:23 |
version 1.35, 2003/09/26 17:44:51 |
Line 51 __RCSID("$NetBSD$"); |
|
Line 51 __RCSID("$NetBSD$"); |
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <limits.h> |
#include <limits.h> |
|
#include <vis.h> |
#ifdef HAVE_ALLOCA_H |
#ifdef HAVE_ALLOCA_H |
#include <alloca.h> |
#include <alloca.h> |
#endif |
#endif |
Line 78 FILE *rl_outstream = NULL; |
|
Line 79 FILE *rl_outstream = NULL; |
|
int rl_point = 0; |
int rl_point = 0; |
int rl_end = 0; |
int rl_end = 0; |
char *rl_line_buffer = NULL; |
char *rl_line_buffer = NULL; |
|
VFunction *rl_linefunc = NULL; |
|
|
int history_base = 1; /* probably never subject to change */ |
int history_base = 1; /* probably never subject to change */ |
int history_length = 0; |
int history_length = 0; |
Line 144 static int _rl_complete_show_all = 0; |
|
Line 146 static int _rl_complete_show_all = 0; |
|
|
|
static History *h = NULL; |
static History *h = NULL; |
static EditLine *e = NULL; |
static EditLine *e = NULL; |
|
static Function *map[256]; |
static int el_rl_complete_cmdnum = 0; |
static int el_rl_complete_cmdnum = 0; |
|
|
/* internal functions */ |
/* internal functions */ |
Line 251 rl_initialize(void) |
|
Line 254 rl_initialize(void) |
|
el_get(e, EL_TERMINAL, &rl_terminal_name); |
el_get(e, EL_TERMINAL, &rl_terminal_name); |
|
|
/* |
/* |
* Word completition - this has to go AFTER rebinding keys |
* Word completion - this has to go AFTER rebinding keys |
* to emacs-style. |
* to emacs-style. |
*/ |
*/ |
el_set(e, EL_ADDFN, "rl_complete", |
el_set(e, EL_ADDFN, "rl_complete", |
"ReadLine compatible completition function", |
"ReadLine compatible completion function", |
_el_rl_complete); |
_el_rl_complete); |
el_set(e, EL_BIND, "^I", "rl_complete", NULL); |
el_set(e, EL_BIND, "^I", "rl_complete", NULL); |
/* |
/* |
Line 1241 history_search_pos(const char *str, |
|
Line 1244 history_search_pos(const char *str, |
|
|
|
|
|
/********************************/ |
/********************************/ |
/* completition functions */ |
/* completion functions */ |
|
|
/* |
/* |
* does tilde expansion of strings of type ``~user/foo'' |
* does tilde expansion of strings of type ``~user/foo'' |
Line 1451 _el_rl_complete(EditLine *el __attribute |
|
Line 1454 _el_rl_complete(EditLine *el __attribute |
|
|
|
|
|
/* |
/* |
* returns list of completitions for text given |
* returns list of completions for text given |
*/ |
*/ |
char ** |
char ** |
completion_matches(const char *text, CPFunction *genfunc) |
completion_matches(const char *text, CPFunction *genfunc) |
Line 1638 rl_complete_internal(int what_to_do) |
|
Line 1641 rl_complete_internal(int what_to_do) |
|
if (matches[2] == NULL && strcmp(matches[0], matches[1]) == 0) { |
if (matches[2] == NULL && strcmp(matches[0], matches[1]) == 0) { |
/* |
/* |
* We found exact match. Add a space after |
* We found exact match. Add a space after |
* it, unless we do filename completition and the |
* it, unless we do filename completion and the |
* object is a directory. |
* object is a directory. |
*/ |
*/ |
size_t alen = strlen(matches[0]); |
size_t alen = strlen(matches[0]); |
Line 1806 rl_insert(int count, int c) |
|
Line 1809 rl_insert(int count, int c) |
|
|
|
return (0); |
return (0); |
} |
} |
|
|
|
/*ARGSUSED*/ |
|
int |
|
rl_newline(int count, int c) |
|
{ |
|
/* |
|
* Readline-4.0 appears to ignore the args. |
|
*/ |
|
return rl_insert(1, '\n'); |
|
} |
|
|
|
/*ARGSUSED*/ |
|
static unsigned char |
|
rl_bind_wrapper(EditLine *el, unsigned char c) |
|
{ |
|
if (map[c] == NULL) |
|
return CC_ERROR; |
|
(*map[c])(NULL, c); |
|
return CC_NORM; |
|
} |
|
|
|
int |
|
rl_add_defun(const char *name, Function *fun, int c) |
|
{ |
|
char dest[8]; |
|
if (c >= sizeof(map) / sizeof(map[0]) || c < 0) |
|
return -1; |
|
map[(unsigned char)c] = fun; |
|
el_set(e, EL_ADDFN, name, name, rl_bind_wrapper); |
|
el_set(e, EL_BIND, vis(dest, c, VIS_WHITE, 0), name); |
|
return 0; |
|
} |
|
|
|
void |
|
rl_callback_read_char() |
|
{ |
|
int count = 0; |
|
const char *buf = el_gets(e, &count); |
|
char *wbuf; |
|
|
|
if (buf == NULL || count-- <= 0) |
|
return; |
|
if ((buf[count] == '\n' || buf[count] == '\r') && rl_linefunc != NULL) { |
|
el_set(e, EL_UNBUFFERED, 0); |
|
if ((wbuf = strdup(buf)) != NULL) |
|
wbuf[count] = '\0'; |
|
(*(void (*)(const char *))rl_linefunc)(wbuf); |
|
} |
|
} |
|
|
|
void |
|
rl_callback_handler_install (const char *prompt, VFunction *linefunc) |
|
{ |
|
if (e == NULL) { |
|
rl_initialize(); |
|
} |
|
if (rl_prompt) |
|
free(rl_prompt); |
|
rl_prompt = prompt ? strdup(strchr(prompt, *prompt)) : NULL; |
|
rl_linefunc = linefunc; |
|
el_set(e, EL_UNBUFFERED, 1); |
|
} |
|
|
|
void |
|
rl_callback_handler_remove(void) |
|
{ |
|
el_set(e, EL_UNBUFFERED, 0); |
|
} |
|
|
|
void |
|
rl_redisplay(void) |
|
{ |
|
char a[2]; |
|
a[0] = CTRL('r'); |
|
a[1] = '\0'; |
|
el_push(e, a); |
|
} |
|
|
|
int |
|
rl_get_previous_history(int count, int key) |
|
{ |
|
char a[2]; |
|
a[0] = key; |
|
a[1] = '\0'; |
|
while (count--) |
|
el_push(e, a); |
|
return 0; |
|
} |