mirror of
https://git.busybox.net/busybox.git
synced 2024-12-14 16:03:26 +08:00
vi-mode changes: eliminate warnings from out-of-range-for-type
case labels that are emitted by gcc4. rearrange macros to eliminate these extra case labels entirely (since the optimizer may no longer do it for us). eliminate static BUFSIZ character deletion buffer -- malloc it, and make it much much smaller.
This commit is contained in:
parent
dfba741457
commit
0f2dd9f4eb
130
shell/cmdedit.c
130
shell/cmdedit.c
@ -442,9 +442,10 @@ static void redraw(int y, int back_cursor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_COMMAND_EDITING_VI
|
#ifdef CONFIG_FEATURE_COMMAND_EDITING_VI
|
||||||
static char delbuf[BUFSIZ]; /* a place to store deleted characters */
|
#define DELBUFSIZ 128
|
||||||
static char *delp = delbuf;
|
static char *delbuf; /* a (malloced) place to store deleted characters */
|
||||||
static int newdelflag; /* whether delbuf should be reused yet */
|
static char *delp;
|
||||||
|
static char newdelflag; /* whether delbuf should be reused yet */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Delete the char in front of the cursor, optionally saving it
|
/* Delete the char in front of the cursor, optionally saving it
|
||||||
@ -459,10 +460,13 @@ static void input_delete(int save)
|
|||||||
#ifdef CONFIG_FEATURE_COMMAND_EDITING_VI
|
#ifdef CONFIG_FEATURE_COMMAND_EDITING_VI
|
||||||
if (save) {
|
if (save) {
|
||||||
if (newdelflag) {
|
if (newdelflag) {
|
||||||
|
if (!delbuf)
|
||||||
|
delbuf = malloc(DELBUFSIZ);
|
||||||
|
/* safe if malloc fails */
|
||||||
delp = delbuf;
|
delp = delbuf;
|
||||||
newdelflag = 0;
|
newdelflag = 0;
|
||||||
}
|
}
|
||||||
if (delp - delbuf < BUFSIZ)
|
if (delbuf && (delp - delbuf < DELBUFSIZ))
|
||||||
*delp++ = command_ps[j];
|
*delp++ = command_ps[j];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1370,23 +1374,18 @@ vi_back_motion(char *command)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the normal emacs mode and vi's insert mode are the same.
|
* the emacs and vi modes share much of the code in the big
|
||||||
* commands entered when in vi command mode ("escape mode") get
|
* command loop. commands entered when in vi's command mode (aka
|
||||||
* an extra bit added to distinguish them. this lets them share
|
* "escape mode") get an extra bit added to distinguish them --
|
||||||
* much of the code in the big switch and while loop. i
|
* this keeps them from being self-inserted. this clutters the
|
||||||
* experimented with an ugly macro to make the case labels for
|
* big switch a bit, but keeps all the code in one place.
|
||||||
* these cases go away entirely when vi mode isn't configured, in
|
|
||||||
* hopes of letting the jump tables get smaller:
|
|
||||||
* #define vcase(caselabel) caselabel
|
|
||||||
* and then
|
|
||||||
* case CNTRL('A'):
|
|
||||||
* case vcase(VICMD('0'):)
|
|
||||||
* but it didn't seem to make any difference in code size,
|
|
||||||
* and the macro-ized code was too ugly.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define VI_cmdbit 0x100
|
#define vbit 0x100
|
||||||
#define VICMD(somecmd) ((somecmd)|VI_cmdbit)
|
|
||||||
|
/* leave out the "vi-mode"-only case labels if vi editing isn't
|
||||||
|
* configured. */
|
||||||
|
#define vi_case(caselabel) USE_FEATURE_COMMAND_EDITING(caselabel)
|
||||||
|
|
||||||
/* convert uppercase ascii to equivalent control char, for readability */
|
/* convert uppercase ascii to equivalent control char, for readability */
|
||||||
#define CNTRL(uc_char) ((uc_char) - 0x40)
|
#define CNTRL(uc_char) ((uc_char) - 0x40)
|
||||||
@ -1398,8 +1397,9 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
int break_out = 0;
|
int break_out = 0;
|
||||||
int lastWasTab = FALSE;
|
int lastWasTab = FALSE;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
unsigned int ic;
|
||||||
#ifdef CONFIG_FEATURE_COMMAND_EDITING_VI
|
#ifdef CONFIG_FEATURE_COMMAND_EDITING_VI
|
||||||
unsigned int ic, prevc;
|
unsigned int prevc;
|
||||||
int vi_cmdmode = 0;
|
int vi_cmdmode = 0;
|
||||||
#endif
|
#endif
|
||||||
/* prepare before init handlers */
|
/* prepare before init handlers */
|
||||||
@ -1438,38 +1438,37 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ])
|
|||||||
/* if we can't read input then exit */
|
/* if we can't read input then exit */
|
||||||
goto prepare_to_die;
|
goto prepare_to_die;
|
||||||
|
|
||||||
|
ic = c;
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_COMMAND_EDITING_VI
|
#ifdef CONFIG_FEATURE_COMMAND_EDITING_VI
|
||||||
newdelflag = 1;
|
newdelflag = 1;
|
||||||
ic = c;
|
|
||||||
if (vi_cmdmode)
|
if (vi_cmdmode)
|
||||||
ic |= VI_cmdbit;
|
ic |= vbit;
|
||||||
switch (ic)
|
|
||||||
#else
|
|
||||||
switch (c)
|
|
||||||
#endif
|
#endif
|
||||||
|
switch (ic)
|
||||||
{
|
{
|
||||||
case '\n':
|
case '\n':
|
||||||
case '\r':
|
case '\r':
|
||||||
case VICMD('\n'):
|
vi_case( case '\n'|vbit: )
|
||||||
case VICMD('\r'):
|
vi_case( case '\r'|vbit: )
|
||||||
/* Enter */
|
/* Enter */
|
||||||
goto_new_line();
|
goto_new_line();
|
||||||
break_out = 1;
|
break_out = 1;
|
||||||
break;
|
break;
|
||||||
case CNTRL('A'):
|
case CNTRL('A'):
|
||||||
case VICMD('0'):
|
vi_case( case '0'|vbit: )
|
||||||
/* Control-a -- Beginning of line */
|
/* Control-a -- Beginning of line */
|
||||||
input_backward(cursor);
|
input_backward(cursor);
|
||||||
break;
|
break;
|
||||||
case CNTRL('B'):
|
case CNTRL('B'):
|
||||||
case VICMD('h'):
|
vi_case( case 'h'|vbit: )
|
||||||
case VICMD('\b'):
|
vi_case( case '\b'|vbit: )
|
||||||
case VICMD(DEL):
|
vi_case( case DEL|vbit: )
|
||||||
/* Control-b -- Move back one character */
|
/* Control-b -- Move back one character */
|
||||||
input_backward(1);
|
input_backward(1);
|
||||||
break;
|
break;
|
||||||
case CNTRL('C'):
|
case CNTRL('C'):
|
||||||
case VICMD(CNTRL('C')):
|
vi_case( case CNTRL('C')|vbit: )
|
||||||
/* Control-c -- stop gathering input */
|
/* Control-c -- stop gathering input */
|
||||||
goto_new_line();
|
goto_new_line();
|
||||||
#ifndef CONFIG_ASH
|
#ifndef CONFIG_ASH
|
||||||
@ -1503,13 +1502,13 @@ prepare_to_die:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CNTRL('E'):
|
case CNTRL('E'):
|
||||||
case VICMD('$'):
|
vi_case( case '$'|vbit: )
|
||||||
/* Control-e -- End of line */
|
/* Control-e -- End of line */
|
||||||
input_end();
|
input_end();
|
||||||
break;
|
break;
|
||||||
case CNTRL('F'):
|
case CNTRL('F'):
|
||||||
case VICMD('l'):
|
vi_case( case 'l'|vbit: )
|
||||||
case VICMD(' '):
|
vi_case( case ' '|vbit: )
|
||||||
/* Control-f -- Move forward one character */
|
/* Control-f -- Move forward one character */
|
||||||
input_forward();
|
input_forward();
|
||||||
break;
|
break;
|
||||||
@ -1530,22 +1529,22 @@ prepare_to_die:
|
|||||||
printf("\033[J");
|
printf("\033[J");
|
||||||
break;
|
break;
|
||||||
case CNTRL('L'):
|
case CNTRL('L'):
|
||||||
case VICMD(CNTRL('L')):
|
vi_case( case CNTRL('L')|vbit: )
|
||||||
/* Control-l -- clear screen */
|
/* Control-l -- clear screen */
|
||||||
printf("\033[H");
|
printf("\033[H");
|
||||||
redraw(0, len-cursor);
|
redraw(0, len-cursor);
|
||||||
break;
|
break;
|
||||||
#if MAX_HISTORY >= 1
|
#if MAX_HISTORY >= 1
|
||||||
case CNTRL('N'):
|
case CNTRL('N'):
|
||||||
case VICMD(CNTRL('N')):
|
vi_case( case CNTRL('N')|vbit: )
|
||||||
case VICMD('j'):
|
vi_case( case 'j'|vbit: )
|
||||||
/* Control-n -- Get next command in history */
|
/* Control-n -- Get next command in history */
|
||||||
if (get_next_history())
|
if (get_next_history())
|
||||||
goto rewrite_line;
|
goto rewrite_line;
|
||||||
break;
|
break;
|
||||||
case CNTRL('P'):
|
case CNTRL('P'):
|
||||||
case VICMD(CNTRL('P')):
|
vi_case( case CNTRL('P')|vbit: )
|
||||||
case VICMD('k'):
|
vi_case( case 'k'|vbit: )
|
||||||
/* Control-p -- Get previous command from history */
|
/* Control-p -- Get previous command from history */
|
||||||
if (cur_history > 0) {
|
if (cur_history > 0) {
|
||||||
get_previous_history();
|
get_previous_history();
|
||||||
@ -1556,7 +1555,7 @@ prepare_to_die:
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case CNTRL('U'):
|
case CNTRL('U'):
|
||||||
case VICMD(CNTRL('U')):
|
vi_case( case CNTRL('U')|vbit: )
|
||||||
/* Control-U -- Clear line before cursor */
|
/* Control-U -- Clear line before cursor */
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
strcpy(command, command + cursor);
|
strcpy(command, command + cursor);
|
||||||
@ -1564,7 +1563,7 @@ prepare_to_die:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CNTRL('W'):
|
case CNTRL('W'):
|
||||||
case VICMD(CNTRL('W')):
|
vi_case( case CNTRL('W')|vbit: )
|
||||||
/* Control-W -- Remove the last word */
|
/* Control-W -- Remove the last word */
|
||||||
while (cursor > 0 && isspace(command[cursor-1]))
|
while (cursor > 0 && isspace(command[cursor-1]))
|
||||||
input_backspace();
|
input_backspace();
|
||||||
@ -1572,58 +1571,58 @@ prepare_to_die:
|
|||||||
input_backspace();
|
input_backspace();
|
||||||
break;
|
break;
|
||||||
#if CONFIG_FEATURE_COMMAND_EDITING_VI
|
#if CONFIG_FEATURE_COMMAND_EDITING_VI
|
||||||
case VICMD('i'):
|
case 'i'|vbit:
|
||||||
vi_cmdmode = 0;
|
vi_cmdmode = 0;
|
||||||
break;
|
break;
|
||||||
case VICMD('I'):
|
case 'I'|vbit:
|
||||||
input_backward(cursor);
|
input_backward(cursor);
|
||||||
vi_cmdmode = 0;
|
vi_cmdmode = 0;
|
||||||
break;
|
break;
|
||||||
case VICMD('a'):
|
case 'a'|vbit:
|
||||||
input_forward();
|
input_forward();
|
||||||
vi_cmdmode = 0;
|
vi_cmdmode = 0;
|
||||||
break;
|
break;
|
||||||
case VICMD('A'):
|
case 'A'|vbit:
|
||||||
input_end();
|
input_end();
|
||||||
vi_cmdmode = 0;
|
vi_cmdmode = 0;
|
||||||
break;
|
break;
|
||||||
case VICMD('x'):
|
case 'x'|vbit:
|
||||||
input_delete(1);
|
input_delete(1);
|
||||||
break;
|
break;
|
||||||
case VICMD('X'):
|
case 'X'|vbit:
|
||||||
if (cursor > 0) {
|
if (cursor > 0) {
|
||||||
input_backward(1);
|
input_backward(1);
|
||||||
input_delete(1);
|
input_delete(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VICMD('W'):
|
case 'W'|vbit:
|
||||||
vi_Word_motion(command, 1);
|
vi_Word_motion(command, 1);
|
||||||
break;
|
break;
|
||||||
case VICMD('w'):
|
case 'w'|vbit:
|
||||||
vi_word_motion(command, 1);
|
vi_word_motion(command, 1);
|
||||||
break;
|
break;
|
||||||
case VICMD('E'):
|
case 'E'|vbit:
|
||||||
vi_End_motion(command);
|
vi_End_motion(command);
|
||||||
break;
|
break;
|
||||||
case VICMD('e'):
|
case 'e'|vbit:
|
||||||
vi_end_motion(command);
|
vi_end_motion(command);
|
||||||
break;
|
break;
|
||||||
case VICMD('B'):
|
case 'B'|vbit:
|
||||||
vi_Back_motion(command);
|
vi_Back_motion(command);
|
||||||
break;
|
break;
|
||||||
case VICMD('b'):
|
case 'b'|vbit:
|
||||||
vi_back_motion(command);
|
vi_back_motion(command);
|
||||||
break;
|
break;
|
||||||
case VICMD('C'):
|
case 'C'|vbit:
|
||||||
vi_cmdmode = 0;
|
vi_cmdmode = 0;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case VICMD('D'):
|
case 'D'|vbit:
|
||||||
goto clear_to_eol;
|
goto clear_to_eol;
|
||||||
|
|
||||||
case VICMD('c'):
|
case 'c'|vbit:
|
||||||
vi_cmdmode = 0;
|
vi_cmdmode = 0;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case VICMD('d'):
|
case 'd'|vbit:
|
||||||
{
|
{
|
||||||
int nc, sc;
|
int nc, sc;
|
||||||
sc = cursor;
|
sc = cursor;
|
||||||
@ -1682,13 +1681,13 @@ prepare_to_die:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VICMD('p'):
|
case 'p'|vbit:
|
||||||
input_forward();
|
input_forward();
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case VICMD('P'):
|
case 'P'|vbit:
|
||||||
put();
|
put();
|
||||||
break;
|
break;
|
||||||
case VICMD('r'):
|
case 'r'|vbit:
|
||||||
if (safe_read(0, &c, 1) < 1)
|
if (safe_read(0, &c, 1) < 1)
|
||||||
goto prepare_to_die;
|
goto prepare_to_die;
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
@ -1700,7 +1699,9 @@ prepare_to_die:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* CONFIG_FEATURE_COMMAND_EDITING_VI */
|
#endif /* CONFIG_FEATURE_COMMAND_EDITING_VI */
|
||||||
case ESC:{
|
|
||||||
|
case ESC:
|
||||||
|
|
||||||
#if CONFIG_FEATURE_COMMAND_EDITING_VI
|
#if CONFIG_FEATURE_COMMAND_EDITING_VI
|
||||||
if (vi_mode) {
|
if (vi_mode) {
|
||||||
/* ESC: insert mode --> command mode */
|
/* ESC: insert mode --> command mode */
|
||||||
@ -1714,8 +1715,8 @@ prepare_to_die:
|
|||||||
goto prepare_to_die;
|
goto prepare_to_die;
|
||||||
/* different vt100 emulations */
|
/* different vt100 emulations */
|
||||||
if (c == '[' || c == 'O') {
|
if (c == '[' || c == 'O') {
|
||||||
case VICMD('['):
|
vi_case( case '['|vbit: )
|
||||||
case VICMD('O'):
|
vi_case( case 'O'|vbit: )
|
||||||
if (safe_read(0, &c, 1) < 1)
|
if (safe_read(0, &c, 1) < 1)
|
||||||
goto prepare_to_die;
|
goto prepare_to_die;
|
||||||
}
|
}
|
||||||
@ -1787,7 +1788,6 @@ rewrite_line:
|
|||||||
beep();
|
beep();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
default: /* If it's regular input, do the normal thing */
|
default: /* If it's regular input, do the normal thing */
|
||||||
#ifdef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT
|
#ifdef CONFIG_FEATURE_NONPRINTABLE_INVERSE_PUT
|
||||||
|
Loading…
Reference in New Issue
Block a user