aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-21 00:03:42 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-21 00:03:42 +0000
commitf9234135f8bade7e40c6275481ee34237938c036 (patch)
tree0e34e4aa049ebf66f9f7a11b90cbd85347665021
parent4f93cde77f6a048e9ff91ad6323cffc5e35fe97a (diff)
downloadbusybox-w32-f9234135f8bade7e40c6275481ee34237938c036.tar.gz
busybox-w32-f9234135f8bade7e40c6275481ee34237938c036.tar.bz2
busybox-w32-f9234135f8bade7e40c6275481ee34237938c036.zip
vi: support $EXINIT and -c
-rw-r--r--editors/vi.c67
1 files changed, 53 insertions, 14 deletions
diff --git a/editors/vi.c b/editors/vi.c
index a66f20d39..77967fb02 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -257,6 +257,7 @@ static void crash_dummy();
257static void crash_test(); 257static void crash_test();
258static int crashme = 0; 258static int crashme = 0;
259#endif 259#endif
260static char *initial_cmds[] = { NULL, NULL , NULL }; // currently 2 entries, NULL terminated
260 261
261 262
262static void write1(const char *out) 263static void write1(const char *out)
@@ -300,10 +301,15 @@ int vi_main(int argc, char **argv)
300 modifying_cmds = (Byte *) "aAcCdDiIJoOpPrRsxX<>~"; // cmds modifying text[] 301 modifying_cmds = (Byte *) "aAcCdDiIJoOpPrRsxX<>~"; // cmds modifying text[]
301#endif 302#endif
302 303
303 // 1- process $HOME/.exrc file 304 // 1- process $HOME/.exrc file (not inplemented yet)
304 // 2- process EXINIT variable from environment 305 // 2- process EXINIT variable from environment
305 // 3- process command line args 306 // 3- process command line args
306 while ((c = getopt(argc, argv, "hCR")) != -1) { 307 {
308 char *p = getenv("EXINIT");
309 if (p && *p)
310 initial_cmds[0] = xstrdup(p);
311 }
312 while ((c = getopt(argc, argv, "hCRc:")) != -1) {
307 switch (c) { 313 switch (c) {
308#if ENABLE_FEATURE_VI_CRASHME 314#if ENABLE_FEATURE_VI_CRASHME
309 case 'C': 315 case 'C':
@@ -319,6 +325,10 @@ int vi_main(int argc, char **argv)
319 //case 'r': // recover flag- ignore- we don't use tmp file 325 //case 'r': // recover flag- ignore- we don't use tmp file
320 //case 'x': // encryption flag- ignore 326 //case 'x': // encryption flag- ignore
321 //case 'c': // execute command first 327 //case 'c': // execute command first
328 case 'c': // cmd line vi command
329 if (*optarg)
330 initial_cmds[initial_cmds[0] != 0] = xstrdup(optarg);
331 break;
322 //case 'h': // help -- just use default 332 //case 'h': // help -- just use default
323 default: 333 default:
324 show_help(); 334 show_help();
@@ -418,6 +428,25 @@ static void edit_file(Byte * fn)
418 redraw(FALSE); // dont force every col re-draw 428 redraw(FALSE); // dont force every col re-draw
419 show_status_line(); 429 show_status_line();
420 430
431 {
432 char *p, *q;
433 int n = 0;
434
435 while ((p = initial_cmds[n])) {
436 do {
437 q = p;
438 p = strchr(q,'\n');
439 if (p)
440 while(*p == '\n')
441 *p++ = '\0';
442 if (*q)
443 colon(q);
444 } while (p);
445 free(initial_cmds[n]);
446 initial_cmds[n] = NULL;
447 n++;
448 }
449 }
421 //------This is the main Vi cmd handling loop ----------------------- 450 //------This is the main Vi cmd handling loop -----------------------
422 while (editing > 0) { 451 while (editing > 0) {
423#if ENABLE_FEATURE_VI_CRASHME 452#if ENABLE_FEATURE_VI_CRASHME
@@ -902,9 +931,11 @@ static void colon(Byte * buf)
902 editing = 0; 931 editing = 0;
903 } 932 }
904#if ENABLE_FEATURE_VI_SET 933#if ENABLE_FEATURE_VI_SET
905 } else if (strncasecmp((char *) cmd, "set", i) == 0) { // set or clear features 934 } else if (strncasecmp(cmd, "set", i) == 0) { // set or clear features
935 char *argp;
906 i = 0; // offset into args 936 i = 0; // offset into args
907 if (strlen((char *) args) == 0) { 937 // only blank is regarded as args delmiter. What about tab '\t' ?
938 if (!args[0] || strcasecmp(args, "all") == 0) {
908 // print out values of all options 939 // print out values of all options
909 place_cursor(rows - 1, 0, FALSE); // go to Status line, bottom of screen 940 place_cursor(rows - 1, 0, FALSE); // go to Status line, bottom of screen
910 clear_to_eol(); // clear the line 941 clear_to_eol(); // clear the line
@@ -927,17 +958,25 @@ static void colon(Byte * buf)
927 printf("\r\n"); 958 printf("\r\n");
928 goto vc2; 959 goto vc2;
929 } 960 }
930 if (strncasecmp((char *) args, "no", 2) == 0)
931 i = 2; // ":set noautoindent"
932#if ENABLE_FEATURE_VI_SETOPTS 961#if ENABLE_FEATURE_VI_SETOPTS
933 setops(args, "autoindent ", i, "ai", VI_AUTOINDENT); 962 argp = (char *)args;
934 setops(args, "flash ", i, "fl", VI_ERR_METHOD); 963 while (*argp) {
935 setops(args, "ignorecase ", i, "ic", VI_IGNORECASE); 964 if (strncasecmp(argp, "no", 2) == 0)
936 setops(args, "showmatch ", i, "ic", VI_SHOWMATCH); 965 i = 2; // ":set noautoindent"
937 if (strncasecmp((char *) args + i, "tabstop=%d ", 7) == 0) { 966 setops(argp, "autoindent ", i, "ai", VI_AUTOINDENT);
938 sscanf(strchr((char *) args + i, '='), "=%d", &ch); 967 setops(argp, "flash ", i, "fl", VI_ERR_METHOD);
939 if (ch > 0 && ch < columns - 1) 968 setops(argp, "ignorecase ", i, "ic", VI_IGNORECASE);
940 tabstop = ch; 969 setops(argp, "showmatch ", i, "ic", VI_SHOWMATCH);
970 /* tabstopXXXX */
971 if (strncasecmp(argp + i, "tabstop=%d ", 7) == 0) {
972 sscanf(strchr(argp + i, '='), "=%d", &ch);
973 if (ch > 0 && ch < columns - 1)
974 tabstop = ch;
975 }
976 while (*argp && *argp != ' ')
977 argp++; // skip to arg delimiter (i.e. blank)
978 while (*argp && *argp == ' ')
979 argp++; // skip all delimiting blanks
941 } 980 }
942#endif /* FEATURE_VI_SETOPTS */ 981#endif /* FEATURE_VI_SETOPTS */
943#endif /* FEATURE_VI_SET */ 982#endif /* FEATURE_VI_SET */