*/
char *vi_Version =
- "$Id: vi.c,v 1.6 2001/05/07 17:37:43 andersen Exp $";
+ "$Id: vi.c,v 1.11 2001/07/02 18:06:14 andersen Exp $";
/*
* To compile for standalone use:
//#define BB_FEATURE_VI_CRASHME // randomly pick commands to execute
#endif /* STANDALONE */
-#ifndef STANDALONE
-#include "busybox.h"
-#endif /* STANDALONE */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
+#ifndef STANDALONE
+#include "busybox.h"
+#endif /* STANDALONE */
#ifndef TRUE
#define TRUE ((int)1)
//case 'h': // help -- just use default
default:
show_help();
- break;
+ return 1;
}
}
while (isblnk(*buf))
buf++;
strcpy((char *) args, (char *) buf);
- if (last_char_is((char *)cmd, '!')) {
+ buf1 = last_char_is((char *)cmd, '!');
+ if (buf1) {
useforce = TRUE;
- cmd[strlen((char *) cmd) - 1] = '\0'; // get rid of !
+ *buf1 = '\0'; // get rid of !
}
if (b >= 0) {
// if there is only one addr, then the addr
c = orig_buf[1]; // what is the delimiter
F = orig_buf + 2; // start of "find"
R = (Byte *) strchr((char *) F, c); // middle delimiter
+ if (!R) goto colon_s_fail;
*R++ = '\0'; // terminate "find"
buf1 = (Byte *) strchr((char *) R, c);
+ if (!buf1) goto colon_s_fail;
*buf1++ = '\0'; // terminate "replace"
if (*buf1 == 'g') { // :s/foo/bar/g
buf1++;
vc1:
dot = bound_dot(dot); // make sure "dot" is valid
return;
+#ifdef BB_FEATURE_VI_SEARCH
+colon_s_fail:
+ psb(":s expression missing delimiters");
+ return;
+#endif
+
}
static void Hit_Return(void)
static void show_help(void)
{
- printf("These features are available:\n");
+ puts("These features are available:"
#ifdef BB_FEATURE_VI_SEARCH
- printf("\tPattern searches with / and ?\n");
+ "\n\tPattern searches with / and ?"
#endif /* BB_FEATURE_VI_SEARCH */
#ifdef BB_FEATURE_VI_DOT_CMD
- printf("\tLast command repeat with \'.\'\n");
+ "\n\tLast command repeat with \'.\'"
#endif /* BB_FEATURE_VI_DOT_CMD */
#ifdef BB_FEATURE_VI_YANKMARK
- printf("\tLine marking with 'x\n");
- printf("\tNamed buffers with \"x\n");
+ "\n\tLine marking with 'x"
+ "\n\tNamed buffers with \"x"
#endif /* BB_FEATURE_VI_YANKMARK */
#ifdef BB_FEATURE_VI_READONLY
- printf("\tReadonly if vi is called as \"view\"\n");
- printf("\tReadonly with -R command line arg\n");
+ "\n\tReadonly if vi is called as \"view\""
+ "\n\tReadonly with -R command line arg"
#endif /* BB_FEATURE_VI_READONLY */
#ifdef BB_FEATURE_VI_SET
- printf("\tSome colon mode commands with \':\'\n");
+ "\n\tSome colon mode commands with \':\'"
#endif /* BB_FEATURE_VI_SET */
#ifdef BB_FEATURE_VI_SETOPTS
- printf("\tSettable options with \":set\"\n");
+ "\n\tSettable options with \":set\""
#endif /* BB_FEATURE_VI_SETOPTS */
#ifdef BB_FEATURE_VI_USE_SIGNALS
- printf("\tSignal catching- ^C\n");
- printf("\tJob suspend and resume with ^Z\n");
+ "\n\tSignal catching- ^C"
+ "\n\tJob suspend and resume with ^Z"
#endif /* BB_FEATURE_VI_USE_SIGNALS */
#ifdef BB_FEATURE_VI_WIN_RESIZE
- printf("\tAdapt to window re-sizes\n");
+ "\n\tAdapt to window re-sizes"
#endif /* BB_FEATURE_VI_WIN_RESIZE */
+ );
}
static void print_literal(Byte * buf, Byte * s) // copy s to buf, convert unprintable
term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG ON- allow intr's
term_vi.c_iflag &= (~IXON & ~ICRNL);
term_vi.c_oflag &= (~ONLCR);
+#ifndef linux
term_vi.c_cc[VMIN] = 1;
term_vi.c_cc[VTIME] = 0;
+#endif
erase_char = term_vi.c_cc[VERASE];
tcsetattr(0, TCSANOW, &term_vi);
}
}
}
- place_cursor(crow, ccol, (crow == last_row) ? TRUE : FALSE);
#ifdef BB_FEATURE_VI_OPTIMIZE_CURSOR
+ place_cursor(crow, ccol, (crow == last_row) ? TRUE : FALSE);
last_row = crow;
+#else
+ place_cursor(crow, ccol, FALSE);
#endif /* BB_FEATURE_VI_OPTIMIZE_CURSOR */
if (offset != old_offset)