mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 12:31:45 +08:00
Refactor of variable names, for improved readline compat.
This commit is contained in:
parent
67e9aa3f2b
commit
0d9ce0ce06
@ -85,17 +85,16 @@ int rl_quit;
|
|||||||
int rl_susp;
|
int rl_susp;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char NIL[] = "";
|
static char NILSTR[] = "";
|
||||||
static const char *Input = NIL;
|
static const char *el_input = NILSTR;
|
||||||
static const char *Prompt;
|
|
||||||
static char *Yanked;
|
static char *Yanked;
|
||||||
static char *Screen;
|
static char *Screen;
|
||||||
static char NEWLINE[]= CRLF;
|
static char NEWLINE[]= CRLF;
|
||||||
static el_hist_t H;
|
static el_hist_t H;
|
||||||
static int Repeat;
|
static int Repeat;
|
||||||
static int OldPoint;
|
static int old_point;
|
||||||
static int PushBack;
|
static int el_push_back;
|
||||||
static int Pushed;
|
static int el_pushed;
|
||||||
static int el_intr_pending;
|
static int el_intr_pending;
|
||||||
static el_keymap_t Map[];
|
static el_keymap_t Map[];
|
||||||
static el_keymap_t MetaMap[];
|
static el_keymap_t MetaMap[];
|
||||||
@ -112,6 +111,7 @@ int rl_mark;
|
|||||||
int rl_end;
|
int rl_end;
|
||||||
int rl_meta_chars = 0; /* Display 8-bit chars as the actual char(0) or as `M-x'(1)? */
|
int rl_meta_chars = 0; /* Display 8-bit chars as the actual char(0) or as `M-x'(1)? */
|
||||||
char *rl_line_buffer;
|
char *rl_line_buffer;
|
||||||
|
const char *rl_prompt;
|
||||||
const char *rl_readline_name;/* Set by calling program, for conditional parsing of ~/.inputrc - Not supported yet! */
|
const char *rl_readline_name;/* Set by calling program, for conditional parsing of ~/.inputrc - Not supported yet! */
|
||||||
|
|
||||||
/* User definable callbacks. */
|
/* User definable callbacks. */
|
||||||
@ -189,12 +189,12 @@ static int tty_get(void)
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
tty_flush();
|
tty_flush();
|
||||||
if (Pushed) {
|
if (el_pushed) {
|
||||||
Pushed = 0;
|
el_pushed = 0;
|
||||||
return PushBack;
|
return el_push_back;
|
||||||
}
|
}
|
||||||
if (*Input)
|
if (*el_input)
|
||||||
return *Input++;
|
return *el_input++;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
r = read(0, &c, 1);
|
r = read(0, &c, 1);
|
||||||
@ -306,7 +306,7 @@ static void reposition(void)
|
|||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
tty_put('\r');
|
tty_put('\r');
|
||||||
tty_puts(Prompt);
|
tty_puts(rl_prompt);
|
||||||
for (i = rl_point, p = rl_line_buffer; --i >= 0; p++)
|
for (i = rl_point, p = rl_line_buffer; --i >= 0; p++)
|
||||||
tty_show(*p);
|
tty_show(*p);
|
||||||
}
|
}
|
||||||
@ -349,8 +349,8 @@ static el_status_t do_macro(int c)
|
|||||||
name[2] = '_';
|
name[2] = '_';
|
||||||
name[3] = '\0';
|
name[3] = '\0';
|
||||||
|
|
||||||
if ((Input = (char *)getenv((char *)name)) == NULL) {
|
if ((el_input = (char *)getenv((char *)name)) == NULL) {
|
||||||
Input = NIL;
|
el_input = NILSTR;
|
||||||
return ring_bell();
|
return ring_bell();
|
||||||
}
|
}
|
||||||
return CSstay;
|
return CSstay;
|
||||||
@ -387,10 +387,10 @@ static el_status_t do_case(el_case_t type)
|
|||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
do_forward(CSstay);
|
do_forward(CSstay);
|
||||||
if (OldPoint != rl_point) {
|
if (old_point != rl_point) {
|
||||||
if ((count = rl_point - OldPoint) < 0)
|
if ((count = rl_point - old_point) < 0)
|
||||||
count = -count;
|
count = -count;
|
||||||
rl_point = OldPoint;
|
rl_point = old_point;
|
||||||
if ((end = rl_point + count) > rl_end)
|
if ((end = rl_point + count) > rl_end)
|
||||||
end = rl_end;
|
end = rl_end;
|
||||||
for (i = rl_point, p = &rl_line_buffer[i]; i < end; i++, p++) {
|
for (i = rl_point, p = &rl_line_buffer[i]; i < end; i++, p++) {
|
||||||
@ -442,7 +442,7 @@ static void ceol(void)
|
|||||||
|
|
||||||
static void clear_line(void)
|
static void clear_line(void)
|
||||||
{
|
{
|
||||||
rl_point = -(int)strlen(Prompt);
|
rl_point = -(int)strlen(rl_prompt);
|
||||||
tty_put('\r');
|
tty_put('\r');
|
||||||
ceol();
|
ceol();
|
||||||
rl_point = 0;
|
rl_point = 0;
|
||||||
@ -483,8 +483,8 @@ static el_status_t insert_string(const char *p)
|
|||||||
|
|
||||||
static el_status_t redisplay(void)
|
static el_status_t redisplay(void)
|
||||||
{
|
{
|
||||||
tty_puts(NEWLINE);
|
tty_puts(NEWLINE); /* XXX: Use "\r\e[K" to get really neat effect on ANSI capable terminals. */
|
||||||
tty_puts(Prompt);
|
tty_puts(rl_prompt);
|
||||||
tty_string(rl_line_buffer);
|
tty_string(rl_line_buffer);
|
||||||
return CSmove;
|
return CSmove;
|
||||||
}
|
}
|
||||||
@ -616,14 +616,14 @@ static el_status_t h_search(void)
|
|||||||
Searching = 1;
|
Searching = 1;
|
||||||
|
|
||||||
clear_line();
|
clear_line();
|
||||||
old_prompt = Prompt;
|
old_prompt = rl_prompt;
|
||||||
Prompt = "Search: ";
|
rl_prompt = "Search: ";
|
||||||
tty_puts(Prompt);
|
tty_puts(rl_prompt);
|
||||||
move = Repeat == NO_ARG ? prev_hist : next_hist;
|
move = Repeat == NO_ARG ? prev_hist : next_hist;
|
||||||
p = editinput();
|
p = editinput();
|
||||||
Prompt = old_prompt;
|
rl_prompt = old_prompt;
|
||||||
Searching = 0;
|
Searching = 0;
|
||||||
tty_puts(Prompt);
|
tty_puts(rl_prompt);
|
||||||
if (p == NULL && el_intr_pending > 0) {
|
if (p == NULL && el_intr_pending > 0) {
|
||||||
el_intr_pending = 0;
|
el_intr_pending = 0;
|
||||||
clear_line();
|
clear_line();
|
||||||
@ -848,8 +848,8 @@ static el_status_t meta(void)
|
|||||||
if (isdigit(c)) {
|
if (isdigit(c)) {
|
||||||
for (Repeat = c - '0'; (c = tty_get()) != EOF && isdigit(c); )
|
for (Repeat = c - '0'; (c = tty_get()) != EOF && isdigit(c); )
|
||||||
Repeat = Repeat * 10 + c - '0';
|
Repeat = Repeat * 10 + c - '0';
|
||||||
Pushed = 1;
|
el_pushed = 1;
|
||||||
PushBack = c;
|
el_push_back = c;
|
||||||
return CSstay;
|
return CSstay;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -868,13 +868,13 @@ static el_status_t emacs(int c)
|
|||||||
el_keymap_t *kp;
|
el_keymap_t *kp;
|
||||||
|
|
||||||
/* Save point before interpreting input character 'c'. */
|
/* Save point before interpreting input character 'c'. */
|
||||||
OldPoint = rl_point;
|
old_point = rl_point;
|
||||||
|
|
||||||
/* This test makes it impossible to enter eight-bit characters when
|
/* This test makes it impossible to enter eight-bit characters when
|
||||||
* meta-char mode is enabled. */
|
* meta-char mode is enabled. */
|
||||||
if (rl_meta_chars && ISMETA(c)) {
|
if (rl_meta_chars && ISMETA(c)) {
|
||||||
Pushed = 1;
|
el_pushed = 1;
|
||||||
PushBack = UNMETA(c);
|
el_push_back = UNMETA(c);
|
||||||
return meta();
|
return meta();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -883,7 +883,7 @@ static el_status_t emacs(int c)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s = kp->Function ? (*kp->Function)() : insert_char(c);
|
s = kp->Function ? (*kp->Function)() : insert_char(c);
|
||||||
if (!Pushed) {
|
if (!el_pushed) {
|
||||||
/* No pushback means no repeat count; hacky, but true. */
|
/* No pushback means no repeat count; hacky, but true. */
|
||||||
Repeat = NO_ARG;
|
Repeat = NO_ARG;
|
||||||
}
|
}
|
||||||
@ -931,40 +931,50 @@ static char *editinput(void)
|
|||||||
int c;
|
int c;
|
||||||
|
|
||||||
Repeat = NO_ARG;
|
Repeat = NO_ARG;
|
||||||
OldPoint = rl_point = rl_mark = rl_end = 0;
|
old_point = rl_point = rl_mark = rl_end = 0;
|
||||||
rl_line_buffer[0] = '\0';
|
rl_line_buffer[0] = '\0';
|
||||||
|
|
||||||
el_intr_pending = -1;
|
el_intr_pending = -1;
|
||||||
while ((c = tty_get()) != EOF)
|
while ((c = tty_get()) != EOF) {
|
||||||
switch (tty_special(c)) {
|
switch (tty_special(c)) {
|
||||||
case CSdone:
|
case CSdone:
|
||||||
return rl_line_buffer;
|
return rl_line_buffer;
|
||||||
|
|
||||||
case CSeof:
|
case CSeof:
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
case CSsignal:
|
case CSsignal:
|
||||||
return (char *)"";
|
return (char *)"";
|
||||||
|
|
||||||
case CSmove:
|
case CSmove:
|
||||||
reposition();
|
reposition();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CSdispatch:
|
case CSdispatch:
|
||||||
switch (emacs(c)) {
|
switch (emacs(c)) {
|
||||||
case CSdone:
|
case CSdone:
|
||||||
return rl_line_buffer;
|
return rl_line_buffer;
|
||||||
|
|
||||||
case CSeof:
|
case CSeof:
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
case CSsignal:
|
case CSsignal:
|
||||||
return (char *)"";
|
return (char *)"";
|
||||||
|
|
||||||
case CSmove:
|
case CSmove:
|
||||||
reposition();
|
reposition();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CSdispatch:
|
case CSdispatch:
|
||||||
case CSstay:
|
case CSstay:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CSstay:
|
case CSstay:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1030,6 +1040,8 @@ void rl_reset_terminal(char *p __attribute__((__unused__)))
|
|||||||
|
|
||||||
void rl_initialize(void)
|
void rl_initialize(void)
|
||||||
{
|
{
|
||||||
|
if (!rl_prompt)
|
||||||
|
rl_prompt = "? ";
|
||||||
}
|
}
|
||||||
|
|
||||||
char *readline(const char *prompt)
|
char *readline(const char *prompt)
|
||||||
@ -1053,28 +1065,30 @@ char *readline(const char *prompt)
|
|||||||
|
|
||||||
tty_info();
|
tty_info();
|
||||||
rl_ttyset(0);
|
rl_ttyset(0);
|
||||||
hist_add(NIL);
|
hist_add(NILSTR);
|
||||||
ScreenSize = SCREEN_INC;
|
ScreenSize = SCREEN_INC;
|
||||||
Screen = malloc(sizeof(char) * ScreenSize);
|
Screen = malloc(sizeof(char) * ScreenSize);
|
||||||
if (!Screen)
|
if (!Screen)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Prompt = prompt ? prompt : NIL;
|
rl_prompt = prompt ? prompt : NILSTR;
|
||||||
if (el_no_echo) {
|
if (el_no_echo) {
|
||||||
int old = el_no_echo;
|
int old = el_no_echo;
|
||||||
el_no_echo = 0;
|
el_no_echo = 0;
|
||||||
tty_puts(Prompt);
|
tty_puts(rl_prompt);
|
||||||
tty_flush();
|
tty_flush();
|
||||||
el_no_echo = old;
|
el_no_echo = old;
|
||||||
} else {
|
} else {
|
||||||
tty_puts(Prompt);
|
tty_puts(rl_prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
line = editinput();
|
line = editinput();
|
||||||
if (line) {
|
if (line) {
|
||||||
line = strdup(line);
|
line = strdup(line);
|
||||||
tty_puts(NEWLINE);
|
tty_puts(NEWLINE);
|
||||||
tty_flush();
|
tty_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
rl_ttyset(1);
|
rl_ttyset(1);
|
||||||
free(Screen);
|
free(Screen);
|
||||||
free(H.Lines[--H.Size]);
|
free(H.Lines[--H.Size]);
|
||||||
@ -1315,9 +1329,9 @@ static el_status_t fd_kill_word(void)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
do_forward(CSstay);
|
do_forward(CSstay);
|
||||||
if (OldPoint != rl_point) {
|
if (old_point != rl_point) {
|
||||||
i = rl_point - OldPoint;
|
i = rl_point - old_point;
|
||||||
rl_point = OldPoint;
|
rl_point = old_point;
|
||||||
return delete_string(i);
|
return delete_string(i);
|
||||||
}
|
}
|
||||||
return CSstay;
|
return CSstay;
|
||||||
@ -1346,8 +1360,9 @@ static el_status_t bk_word(void)
|
|||||||
static el_status_t bk_kill_word(void)
|
static el_status_t bk_kill_word(void)
|
||||||
{
|
{
|
||||||
bk_word();
|
bk_word();
|
||||||
if (OldPoint != rl_point)
|
if (old_point != rl_point)
|
||||||
return delete_string(OldPoint - rl_point);
|
return delete_string(old_point - rl_point);
|
||||||
|
|
||||||
return CSstay;
|
return CSstay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user