VI: all commands not seem functional. Still at least on display artifact and probably some things not properly tested

This commit is contained in:
Gregory Nutt 2014-01-21 11:29:49 -06:00
parent 1919b2f6a3
commit c21071dfd3
3 changed files with 29 additions and 12 deletions

View File

@ -806,4 +806,6 @@
is still very much a work-in-progress on initial check-in (2014-1-20). is still very much a work-in-progress on initial check-in (2014-1-20).
* apps/netutils/uiplib: Support new definitions and state passing for * apps/netutils/uiplib: Support new definitions and state passing for
network device status. From Maz Holtzberg (2014-1-21). network device status. From Maz Holtzberg (2014-1-21).
* apps/system/vi: Tiny VI is basically functional. All commands seem
to work. There are still some display artifacts and probably several
untested conditions (2014-1-21).

View File

@ -72,7 +72,7 @@
* *
****************************************************************************/ ****************************************************************************/
int uip_getifstatus(const char *ifname, uint8_t *flags) int uip_getifstatus(FAR const char *ifname, FAR uint8_t *flags)
{ {
int ret = ERROR; int ret = ERROR;
if (ifname) if (ifname)

View File

@ -766,7 +766,7 @@ static void vi_error(FAR struct vi_s *vi, FAR const char *fmt, ...)
* the error is cleared. * the error is cleared.
*/ */
vi->error = TRUE; vi->error = true;
VI_BEL(vi); VI_BEL(vi);
} }
@ -2054,14 +2054,15 @@ static void vi_gotoline(FAR struct vi_s *vi)
static void vi_cmd_mode(FAR struct vi_s *vi) static void vi_cmd_mode(FAR struct vi_s *vi)
{ {
int ch;
vivdbg("Enter command mode\n"); vivdbg("Enter command mode\n");
/* Loop while we are in command mode */ /* Loop while we are in command mode */
while (vi->mode == MODE_COMMAND) while (vi->mode == MODE_COMMAND)
{ {
bool preserve;
int ch;
/* Make sure that the display reflects the current state */ /* Make sure that the display reflects the current state */
vi_showtext(vi); vi_showtext(vi);
@ -2109,8 +2110,13 @@ static void vi_cmd_mode(FAR struct vi_s *vi)
continue; continue;
} }
/* Then handle the non-numeric character */ /* Then handle the non-numeric character. Normally the accumulated
* value will be reset after processing the command. There are a few
* exceptions; 'preserve' will be set to 'true' in those exceptional
* cases.
*/
preserve = false;
switch (ch) switch (ch)
{ {
case KEY_CMDMODE_UP: /* Move the cursor up one line */ case KEY_CMDMODE_UP: /* Move the cursor up one line */
@ -2196,6 +2202,7 @@ static void vi_cmd_mode(FAR struct vi_s *vi)
else else
{ {
vi->delarm = true; vi->delarm = true;
preserve = true;
} }
} }
break; break;
@ -2210,6 +2217,7 @@ static void vi_cmd_mode(FAR struct vi_s *vi)
else else
{ {
vi->yankarm = true; vi->yankarm = true;
preserve = true;
} }
} }
break; break;
@ -2223,6 +2231,7 @@ static void vi_cmd_mode(FAR struct vi_s *vi)
case KEY_CMDMODE_REPLACECH: /* Replace character(s) under cursor */ case KEY_CMDMODE_REPLACECH: /* Replace character(s) under cursor */
{ {
vi_setmode(vi, SUBMODE_REPLACECH, vi->value); vi_setmode(vi, SUBMODE_REPLACECH, vi->value);
preserve = true;
} }
break; break;
@ -2326,11 +2335,17 @@ static void vi_cmd_mode(FAR struct vi_s *vi)
} }
/* Any non-numeric input will reset the accumulated value (after it has /* Any non-numeric input will reset the accumulated value (after it has
* been used). For the double character sequences, we need to retain * been used). There are a few exceptions:
* the value until the next character is entered. *
* - For the double character sequences, we need to retain the value
* until the next character is entered.
* - If we are changing modes, then we may need to preserve the 'value'
* as well; in some cases settings are passed to the new mode in
* 'value' (vi_setmode() will have set or cleared 'value'
* appropriately).
*/ */
if (!vi->delarm && !vi->yankarm) if (!preserve)
{ {
vi->value = 0; vi->value = 0;
} }
@ -3020,7 +3035,7 @@ static void vi_replacech_submode(FAR struct vi_s *vi)
/* Now replace with the character nchar times */ /* Now replace with the character nchar times */
while (nchars > 0) for (; nchars > 0; nchars--)
{ {
vi_replacech(vi, ch); vi_replacech(vi, ch);
} }
@ -3222,7 +3237,7 @@ static void vi_replace_mode(FAR struct vi_s *vi)
{ {
if (vi->curpos > start) if (vi->curpos > start)
{ {
vi_cursorleft(vi, vi->curpos, 1); vi->curpos = vi_cursorleft(vi, vi->curpos, 1);
} }
} }
break; break;
@ -3272,7 +3287,7 @@ static void vi_replace_mode(FAR struct vi_s *vi)
{ {
/* Insert the filtered character into the text buffer */ /* Insert the filtered character into the text buffer */
vi_replacech(vi, '\n'); vi_replacech(vi, ch);
} }
else else
{ {