Implement suggestion from Adam Slattery, (don't default to killing closing bug #1190.
[oweals/busybox.git] / vi.c
diff --git a/vi.c b/vi.c
index 5a68ba9f1f33b9eda320fe2e76e9c88d7ef27a13..9e3355685e12af40e360a9ebdc263fd12cf9e6ab 100644 (file)
--- a/vi.c
+++ b/vi.c
@@ -19,7 +19,7 @@
  */
 
 char *vi_Version =
-       "$Id: vi.c,v 1.7 2001/05/07 22:57:47 andersen Exp $";
+       "$Id: vi.c,v 1.11 2001/07/02 18:06:14 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 <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -86,6 +83,9 @@ char *vi_Version =
 #include <assert.h>
 #include <errno.h>
 #include <stdarg.h>
+#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;
                }
        }
 
@@ -2076,8 +2076,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 +2170,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)
@@ -2950,34 +2958,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 +3153,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);
 }