X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=vi.c;h=8d7506d0f4db5ac2c84cc554019ac94ff7c4f273;hb=95b520110dc1ee6ee670817fdd6312a8565cf34c;hp=5a68ba9f1f33b9eda320fe2e76e9c88d7ef27a13;hpb=c33ebc9741a475962e29fafe60bb0ba4450854b6;p=oweals%2Fbusybox.git diff --git a/vi.c b/vi.c index 5a68ba9f1..8d7506d0f 100644 --- a/vi.c +++ b/vi.c @@ -18,8 +18,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -char *vi_Version = - "$Id: vi.c,v 1.7 2001/05/07 22:57:47 andersen Exp $"; +static const char vi_Version[] = + "$Id: vi.c,v 1.15 2001/08/02 05:26:41 andersen Exp $"; /* * To compile for standalone use: @@ -65,9 +65,6 @@ char *vi_Version = //#define BB_FEATURE_VI_CRASHME // randomly pick commands to execute #endif /* STANDALONE */ -#ifndef STANDALONE -#include "busybox.h" -#endif /* STANDALONE */ #include #include #include @@ -86,6 +83,9 @@ char *vi_Version = #include #include #include +#ifndef STANDALONE +#include "busybox.h" +#endif /* STANDALONE */ #ifndef TRUE #define TRUE ((int)1) @@ -367,7 +367,7 @@ extern int vi_main(int argc, char **argv) //case 'h': // help -- just use default default: show_help(); - break; + return 1; } } @@ -1982,9 +1982,13 @@ static void colon(Byte * buf) // read after current line- unless user said ":0r foo" if (b != 0) q = next_line(q); +#ifdef BB_FEATURE_VI_READONLY l= readonly; // remember current files' status +#endif ch = file_insert(fn, q, file_size(fn)); +#ifdef BB_FEATURE_VI_READONLY readonly= l; +#endif if (ch < 0) goto vc1; // nothing was inserted // how many lines in text[]? @@ -2076,8 +2080,10 @@ static void colon(Byte * buf) 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++; @@ -2168,6 +2174,12 @@ static void colon(Byte * buf) 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) @@ -2628,12 +2640,12 @@ static Byte *char_insert(Byte * p, Byte c) // insert the char c at 'p' cmdcnt = 0; end_cmd_q(); // stop adding to q strcpy((char *) status_buffer, " "); // clear the status buffer - if (p[-1] != '\n') { + if ((p[-1] != '\n') && (dot>text)) { p--; } } else if (c == erase_char) { // Is this a BS // 123456789 - if (p[-1] != '\n') { + if ((p[-1] != '\n') && (dot>text)) { p--; p = text_hole_delete(p, p); // shrink buffer 1 char #ifdef BB_FEATURE_VI_DOT_CMD @@ -2950,34 +2962,35 @@ static Byte *yank_delete(Byte * start, Byte * stop, int dist, int yf) 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 @@ -3144,8 +3157,10 @@ static void rawmode(void) 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); } @@ -3543,7 +3558,7 @@ static int file_write(Byte * fn, Byte * first, Byte * last) } charcnt = 0; // FIXIT- use the correct umask() - fd = open((char *) fn, (O_RDWR | O_CREAT | O_TRUNC), 0664); + fd = open((char *) fn, (O_WRONLY | O_CREAT | O_TRUNC), 0664); if (fd < 0) return (-1); cnt = last - first + 1;