aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-06-15 12:44:11 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-06-15 12:44:11 +0200
commit6548edd430271f6b6d2b295c77a4fdaec51a2468 (patch)
tree7053bc5c13a44057e3bacb48c4fac50652320982
parent4813a5100d70385118ee23b0171e14bc61c81f30 (diff)
downloadbusybox-w32-6548edd430271f6b6d2b295c77a4fdaec51a2468.tar.gz
busybox-w32-6548edd430271f6b6d2b295c77a4fdaec51a2468.tar.bz2
busybox-w32-6548edd430271f6b6d2b295c77a4fdaec51a2468.zip
vi: do not accept uppercase comments (compat). Closes bug 397.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/vi.c64
1 files changed, 31 insertions, 33 deletions
diff --git a/editors/vi.c b/editors/vi.c
index ee5b5d98a..b5696fb28 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -728,6 +728,7 @@ static void setops(const char *args, const char *opname, int flg_no,
728 const char *a = args + flg_no; 728 const char *a = args + flg_no;
729 int l = strlen(opname) - 1; /* opname have + ' ' */ 729 int l = strlen(opname) - 1; /* opname have + ' ' */
730 730
731 // maybe strncmp? we had tons of erroneous strncasecmp's...
731 if (strncasecmp(a, opname, l) == 0 732 if (strncasecmp(a, opname, l) == 0
732 || strncasecmp(a, short_opname, 2) == 0 733 || strncasecmp(a, short_opname, 2) == 0
733 ) { 734 ) {
@@ -823,7 +824,7 @@ static void colon(char *buf)
823 } 824 }
824 } 825 }
825#if ENABLE_FEATURE_ALLOW_EXEC 826#if ENABLE_FEATURE_ALLOW_EXEC
826 else if (strncmp(cmd, "!", 1) == 0) { // run a cmd 827 else if (cmd[0] == '!') { // run a cmd
827 int retcode; 828 int retcode;
828 // :!ls run the <cmd> 829 // :!ls run the <cmd>
829 go_bottom_and_clear_to_eol(); 830 go_bottom_and_clear_to_eol();
@@ -835,19 +836,19 @@ static void colon(char *buf)
835 Hit_Return(); // let user see results 836 Hit_Return(); // let user see results
836 } 837 }
837#endif 838#endif
838 else if (strncmp(cmd, "=", i) == 0) { // where is the address 839 else if (cmd[0] == '=' && !cmd[1]) { // where is the address
839 if (b < 0) { // no addr given- use defaults 840 if (b < 0) { // no addr given- use defaults
840 b = e = count_lines(text, dot); 841 b = e = count_lines(text, dot);
841 } 842 }
842 status_line("%d", b); 843 status_line("%d", b);
843 } else if (strncasecmp(cmd, "delete", i) == 0) { // delete lines 844 } else if (strncmp(cmd, "delete", i) == 0) { // delete lines
844 if (b < 0) { // no addr given- use defaults 845 if (b < 0) { // no addr given- use defaults
845 q = begin_line(dot); // assume .,. for the range 846 q = begin_line(dot); // assume .,. for the range
846 r = end_line(dot); 847 r = end_line(dot);
847 } 848 }
848 dot = yank_delete(q, r, 1, YANKDEL); // save, then delete lines 849 dot = yank_delete(q, r, 1, YANKDEL); // save, then delete lines
849 dot_skip_over_ws(); 850 dot_skip_over_ws();
850 } else if (strncasecmp(cmd, "edit", i) == 0) { // Edit a file 851 } else if (strncmp(cmd, "edit", i) == 0) { // Edit a file
851 // don't edit, if the current file has been modified 852 // don't edit, if the current file has been modified
852 if (file_modified && !useforce) { 853 if (file_modified && !useforce) {
853 status_line_bold("No write since last change (:edit! overrides)"); 854 status_line_bold("No write since last change (:edit! overrides)");
@@ -888,7 +889,7 @@ static void colon(char *buf)
888 ((readonly_mode) ? " [Readonly]" : ""), 889 ((readonly_mode) ? " [Readonly]" : ""),
889 ) 890 )
890 li, ch); 891 li, ch);
891 } else if (strncasecmp(cmd, "file", i) == 0) { // what File is this 892 } else if (strncmp(cmd, "file", i) == 0) { // what File is this
892 if (b != -1 || e != -1) { 893 if (b != -1 || e != -1) {
893 not_implemented("No address allowed on this command"); 894 not_implemented("No address allowed on this command");
894 goto vc1; 895 goto vc1;
@@ -901,14 +902,14 @@ static void colon(char *buf)
901 // user wants file status info 902 // user wants file status info
902 last_status_cksum = 0; // force status update 903 last_status_cksum = 0; // force status update
903 } 904 }
904 } else if (strncasecmp(cmd, "features", i) == 0) { // what features are available 905 } else if (strncmp(cmd, "features", i) == 0) { // what features are available
905 // print out values of all features 906 // print out values of all features
906 go_bottom_and_clear_to_eol(); 907 go_bottom_and_clear_to_eol();
907 cookmode(); 908 cookmode();
908 show_help(); 909 show_help();
909 rawmode(); 910 rawmode();
910 Hit_Return(); 911 Hit_Return();
911 } else if (strncasecmp(cmd, "list", i) == 0) { // literal print line 912 } else if (strncmp(cmd, "list", i) == 0) { // literal print line
912 if (b < 0) { // no addr given- use defaults 913 if (b < 0) { // no addr given- use defaults
913 q = begin_line(dot); // assume .,. for the range 914 q = begin_line(dot); // assume .,. for the range
914 r = end_line(dot); 915 r = end_line(dot);
@@ -941,8 +942,8 @@ static void colon(char *buf)
941 vc2: 942 vc2:
942#endif 943#endif
943 Hit_Return(); 944 Hit_Return();
944 } else if (strncasecmp(cmd, "quit", i) == 0 // Quit 945 } else if (strncmp(cmd, "quit", i) == 0 // Quit
945 || strncasecmp(cmd, "next", i) == 0 // edit next file 946 || strncmp(cmd, "next", i) == 0 // edit next file
946 ) { 947 ) {
947 if (useforce) { 948 if (useforce) {
948 // force end of argv list 949 // force end of argv list
@@ -968,7 +969,7 @@ static void colon(char *buf)
968 goto vc1; 969 goto vc1;
969 } 970 }
970 editing = 0; 971 editing = 0;
971 } else if (strncasecmp(cmd, "read", i) == 0) { // read file into text[] 972 } else if (strncmp(cmd, "read", i) == 0) { // read file into text[]
972 fn = args; 973 fn = args;
973 if (!fn[0]) { 974 if (!fn[0]) {
974 status_line_bold("No filename given"); 975 status_line_bold("No filename given");
@@ -1000,7 +1001,7 @@ static void colon(char *buf)
1000 dot += ch; 1001 dot += ch;
1001 /*file_modified++; - done by file_insert */ 1002 /*file_modified++; - done by file_insert */
1002 } 1003 }
1003 } else if (strncasecmp(cmd, "rewind", i) == 0) { // rewind cmd line args 1004 } else if (strncmp(cmd, "rewind", i) == 0) { // rewind cmd line args
1004 if (file_modified && !useforce) { 1005 if (file_modified && !useforce) {
1005 status_line_bold("No write since last change (:rewind! overrides)"); 1006 status_line_bold("No write since last change (:rewind! overrides)");
1006 } else { 1007 } else {
@@ -1009,7 +1010,7 @@ static void colon(char *buf)
1009 editing = 0; 1010 editing = 0;
1010 } 1011 }
1011#if ENABLE_FEATURE_VI_SET 1012#if ENABLE_FEATURE_VI_SET
1012 } else if (strncasecmp(cmd, "set", i) == 0) { // set or clear features 1013 } else if (strncmp(cmd, "set", i) == 0) { // set or clear features
1013#if ENABLE_FEATURE_VI_SETOPTS 1014#if ENABLE_FEATURE_VI_SETOPTS
1014 char *argp; 1015 char *argp;
1015#endif 1016#endif
@@ -1040,14 +1041,14 @@ static void colon(char *buf)
1040#if ENABLE_FEATURE_VI_SETOPTS 1041#if ENABLE_FEATURE_VI_SETOPTS
1041 argp = args; 1042 argp = args;
1042 while (*argp) { 1043 while (*argp) {
1043 if (strncasecmp(argp, "no", 2) == 0) 1044 if (strncmp(argp, "no", 2) == 0)
1044 i = 2; // ":set noautoindent" 1045 i = 2; // ":set noautoindent"
1045 setops(argp, "autoindent ", i, "ai", VI_AUTOINDENT); 1046 setops(argp, "autoindent ", i, "ai", VI_AUTOINDENT);
1046 setops(argp, "flash ", i, "fl", VI_ERR_METHOD); 1047 setops(argp, "flash ", i, "fl", VI_ERR_METHOD);
1047 setops(argp, "ignorecase ", i, "ic", VI_IGNORECASE); 1048 setops(argp, "ignorecase ", i, "ic", VI_IGNORECASE);
1048 setops(argp, "showmatch ", i, "ic", VI_SHOWMATCH); 1049 setops(argp, "showmatch ", i, "ic", VI_SHOWMATCH);
1049 /* tabstopXXXX */ 1050 /* tabstopXXXX */
1050 if (strncasecmp(argp + i, "tabstop=%d ", 7) == 0) { 1051 if (strncmp(argp + i, "tabstop=%d ", 7) == 0) {
1051 sscanf(strchr(argp + i, '='), "tabstop=%d" + 7, &ch); 1052 sscanf(strchr(argp + i, '='), "tabstop=%d" + 7, &ch);
1052 if (ch > 0 && ch <= MAX_TABSTOP) 1053 if (ch > 0 && ch <= MAX_TABSTOP)
1053 tabstop = ch; 1054 tabstop = ch;
@@ -1060,7 +1061,7 @@ static void colon(char *buf)
1060#endif /* FEATURE_VI_SETOPTS */ 1061#endif /* FEATURE_VI_SETOPTS */
1061#endif /* FEATURE_VI_SET */ 1062#endif /* FEATURE_VI_SET */
1062#if ENABLE_FEATURE_VI_SEARCH 1063#if ENABLE_FEATURE_VI_SEARCH
1063 } else if (strncasecmp(cmd, "s", 1) == 0) { // substitute a pattern with a replacement pattern 1064 } else if (cmd[0] == 's') { // substitute a pattern with a replacement pattern
1064 char *ls, *F, *R; 1065 char *ls, *F, *R;
1065 int gflag; 1066 int gflag;
1066 1067
@@ -1113,12 +1114,12 @@ static void colon(char *buf)
1113 q = next_line(ls); 1114 q = next_line(ls);
1114 } 1115 }
1115#endif /* FEATURE_VI_SEARCH */ 1116#endif /* FEATURE_VI_SEARCH */
1116 } else if (strncasecmp(cmd, "version", i) == 0) { // show software version 1117 } else if (strncmp(cmd, "version", i) == 0) { // show software version
1117 status_line(BB_VER " " BB_BT); 1118 status_line(BB_VER " " BB_BT);
1118 } else if (strncasecmp(cmd, "write", i) == 0 // write text to file 1119 } else if (strncmp(cmd, "write", i) == 0 // write text to file
1119 || strncasecmp(cmd, "wq", i) == 0 1120 || strncmp(cmd, "wq", i) == 0
1120 || strncasecmp(cmd, "wn", i) == 0 1121 || strncmp(cmd, "wn", i) == 0
1121 || strncasecmp(cmd, "x", i) == 0 1122 || (cmd[0] == 'x' && !cmd[1])
1122 ) { 1123 ) {
1123 // is there a file name to write to? 1124 // is there a file name to write to?
1124 if (args[0]) { 1125 if (args[0]) {
@@ -1166,7 +1167,7 @@ static void colon(char *buf)
1166 vc3:; 1167 vc3:;
1167#endif 1168#endif
1168#if ENABLE_FEATURE_VI_YANKMARK 1169#if ENABLE_FEATURE_VI_YANKMARK
1169 } else if (strncasecmp(cmd, "yank", i) == 0) { // yank lines 1170 } else if (strncmp(cmd, "yank", i) == 0) { // yank lines
1170 if (b < 0) { // no addr given- use defaults 1171 if (b < 0) { // no addr given- use defaults
1171 q = begin_line(dot); // assume .,. for the range 1172 q = begin_line(dot); // assume .,. for the range
1172 r = end_line(dot); 1173 r = end_line(dot);
@@ -1531,13 +1532,10 @@ static char *new_screen(int ro, int co)
1531#if ENABLE_FEATURE_VI_SEARCH 1532#if ENABLE_FEATURE_VI_SEARCH
1532static int mycmp(const char *s1, const char *s2, int len) 1533static int mycmp(const char *s1, const char *s2, int len)
1533{ 1534{
1534 int i;
1535
1536 i = strncmp(s1, s2, len);
1537 if (ENABLE_FEATURE_VI_SETOPTS && ignorecase) { 1535 if (ENABLE_FEATURE_VI_SETOPTS && ignorecase) {
1538 i = strncasecmp(s1, s2, len); 1536 return strncasecmp(s1, s2, len);
1539 } 1537 }
1540 return i; 1538 return strncmp(s1, s2, len);
1541} 1539}
1542 1540
1543// search for pattern starting at p 1541// search for pattern starting at p
@@ -3326,18 +3324,18 @@ static void do_cmd(int c)
3326 cnt = strlen(p); 3324 cnt = strlen(p);
3327 if (cnt <= 0) 3325 if (cnt <= 0)
3328 break; 3326 break;
3329 if (strncasecmp(p, "quit", cnt) == 0 3327 if (strncmp(p, "quit", cnt) == 0
3330 || strncasecmp(p, "q!", cnt) == 0 // delete lines 3328 || strncmp(p, "q!", cnt) == 0 // delete lines
3331 ) { 3329 ) {
3332 if (file_modified && p[1] != '!') { 3330 if (file_modified && p[1] != '!') {
3333 status_line_bold("No write since last change (:quit! overrides)"); 3331 status_line_bold("No write since last change (:quit! overrides)");
3334 } else { 3332 } else {
3335 editing = 0; 3333 editing = 0;
3336 } 3334 }
3337 } else if (strncasecmp(p, "write", cnt) == 0 3335 } else if (strncmp(p, "write", cnt) == 0
3338 || strncasecmp(p, "wq", cnt) == 0 3336 || strncmp(p, "wq", cnt) == 0
3339 || strncasecmp(p, "wn", cnt) == 0 3337 || strncmp(p, "wn", cnt) == 0
3340 || strncasecmp(p, "x", cnt) == 0 3338 || (p[0] == 'x' && !p[1])
3341 ) { 3339 ) {
3342 cnt = file_write(current_filename, text, end - 1); 3340 cnt = file_write(current_filename, text, end - 1);
3343 if (cnt < 0) { 3341 if (cnt < 0) {
@@ -3353,7 +3351,7 @@ static void do_cmd(int c)
3353 editing = 0; 3351 editing = 0;
3354 } 3352 }
3355 } 3353 }
3356 } else if (strncasecmp(p, "file", cnt) == 0) { 3354 } else if (strncmp(p, "file", cnt) == 0) {
3357 last_status_cksum = 0; // force status update 3355 last_status_cksum = 0; // force status update
3358 } else if (sscanf(p, "%d", &j) > 0) { 3356 } else if (sscanf(p, "%d", &j) > 0) {
3359 dot = find_line(j); // go to line # j 3357 dot = find_line(j); // go to line # j