diff options
author | Ron Yorston <rmy@pobox.com> | 2018-12-05 08:38:55 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-12-05 08:38:55 +0000 |
commit | 2a34d6d4e3122df2f84eb1290221128be47dc36b (patch) | |
tree | a7035842113f36823c4e7c16744416259f0a8bf6 /editors/vi.c | |
parent | 5448a3893434a64d184055be81a58f47ea6af51b (diff) | |
parent | d08206dce1291f512d7de9037d9ef1ffbf705cac (diff) | |
download | busybox-w32-2a34d6d4e3122df2f84eb1290221128be47dc36b.tar.gz busybox-w32-2a34d6d4e3122df2f84eb1290221128be47dc36b.tar.bz2 busybox-w32-2a34d6d4e3122df2f84eb1290221128be47dc36b.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'editors/vi.c')
-rw-r--r-- | editors/vi.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/editors/vi.c b/editors/vi.c index 05d30f2ff..57fac59ad 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -255,8 +255,8 @@ enum { | |||
255 | YANKDEL = TRUE, | 255 | YANKDEL = TRUE, |
256 | FORWARD = 1, // code depends on "1" for array index | 256 | FORWARD = 1, // code depends on "1" for array index |
257 | BACK = -1, // code depends on "-1" for array index | 257 | BACK = -1, // code depends on "-1" for array index |
258 | LIMITED = 0, // how much of text[] in char_search | 258 | LIMITED = 0, // char_search() only current line |
259 | FULL = 1, // how much of text[] in char_search | 259 | FULL = 1, // char_search() to the end/beginning of entire text |
260 | 260 | ||
261 | S_BEFORE_WS = 1, // used in skip_thing() for moving "dot" | 261 | S_BEFORE_WS = 1, // used in skip_thing() for moving "dot" |
262 | S_TO_WS = 2, // used in skip_thing() for moving "dot" | 262 | S_TO_WS = 2, // used in skip_thing() for moving "dot" |
@@ -563,7 +563,7 @@ static void indicate_error(void); // use flash or beep to indicate error | |||
563 | static void Hit_Return(void); | 563 | static void Hit_Return(void); |
564 | 564 | ||
565 | #if ENABLE_FEATURE_VI_SEARCH | 565 | #if ENABLE_FEATURE_VI_SEARCH |
566 | static char *char_search(char *, const char *, int, int); // search for pattern starting at p | 566 | static char *char_search(char *, const char *, int); // search for pattern starting at p |
567 | #endif | 567 | #endif |
568 | #if ENABLE_FEATURE_VI_COLON | 568 | #if ENABLE_FEATURE_VI_COLON |
569 | static char *get_one_address(char *, int *); // get colon addr, if present | 569 | static char *get_one_address(char *, int *); // get colon addr, if present |
@@ -940,7 +940,7 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present | |||
940 | p = q; | 940 | p = q; |
941 | if (*p == '/') | 941 | if (*p == '/') |
942 | p++; | 942 | p++; |
943 | q = char_search(dot, pat, FORWARD, FULL); | 943 | q = char_search(dot, pat, (FORWARD << 1) | FULL); |
944 | if (q != NULL) { | 944 | if (q != NULL) { |
945 | *addr = count_lines(text, q); | 945 | *addr = count_lines(text, q); |
946 | } | 946 | } |
@@ -1444,7 +1444,7 @@ static void colon(char *buf) | |||
1444 | char *ls = q; // orig line start | 1444 | char *ls = q; // orig line start |
1445 | char *found; | 1445 | char *found; |
1446 | vc4: | 1446 | vc4: |
1447 | found = char_search(q, F, FORWARD, LIMITED); // search cur line only for "find" | 1447 | found = char_search(q, F, (FORWARD << 1) | LIMITED); // search cur line only for "find" |
1448 | if (found) { | 1448 | if (found) { |
1449 | uintptr_t bias; | 1449 | uintptr_t bias; |
1450 | // we found the "find" pattern - delete it | 1450 | // we found the "find" pattern - delete it |
@@ -1897,13 +1897,14 @@ static char *new_screen(int ro, int co) | |||
1897 | # if ENABLE_FEATURE_VI_REGEX_SEARCH | 1897 | # if ENABLE_FEATURE_VI_REGEX_SEARCH |
1898 | 1898 | ||
1899 | // search for pattern starting at p | 1899 | // search for pattern starting at p |
1900 | static char *char_search(char *p, const char *pat, int dir, int range) | 1900 | static char *char_search(char *p, const char *pat, int dir_and_range) |
1901 | { | 1901 | { |
1902 | struct re_pattern_buffer preg; | 1902 | struct re_pattern_buffer preg; |
1903 | const char *err; | 1903 | const char *err; |
1904 | char *q; | 1904 | char *q; |
1905 | int i; | 1905 | int i; |
1906 | int size; | 1906 | int size; |
1907 | int range; | ||
1907 | 1908 | ||
1908 | re_syntax_options = RE_SYNTAX_POSIX_EXTENDED; | 1909 | re_syntax_options = RE_SYNTAX_POSIX_EXTENDED; |
1909 | if (ignorecase) | 1910 | if (ignorecase) |
@@ -1916,10 +1917,16 @@ static char *char_search(char *p, const char *pat, int dir, int range) | |||
1916 | return p; | 1917 | return p; |
1917 | } | 1918 | } |
1918 | 1919 | ||
1919 | // assume a LIMITED forward search | 1920 | range = (dir_and_range & 1); |
1920 | q = end - 1; | 1921 | q = end - 1; // if FULL |
1921 | if (dir == BACK) | 1922 | if (range == LIMITED) |
1923 | q = next_line(p); | ||
1924 | if (dir_and_range < 0) { // BACK? | ||
1922 | q = text; | 1925 | q = text; |
1926 | if (range == LIMITED) | ||
1927 | q = prev_line(p); | ||
1928 | } | ||
1929 | |||
1923 | // RANGE could be negative if we are searching backwards | 1930 | // RANGE could be negative if we are searching backwards |
1924 | range = q - p; | 1931 | range = q - p; |
1925 | q = p; | 1932 | q = p; |
@@ -1942,7 +1949,7 @@ static char *char_search(char *p, const char *pat, int dir, int range) | |||
1942 | regfree(&preg); | 1949 | regfree(&preg); |
1943 | if (i < 0) | 1950 | if (i < 0) |
1944 | return NULL; | 1951 | return NULL; |
1945 | if (dir == FORWARD) | 1952 | if (dir_and_range > 0) // FORWARD? |
1946 | p = p + i; | 1953 | p = p + i; |
1947 | else | 1954 | else |
1948 | p = p - i; | 1955 | p = p - i; |
@@ -1963,13 +1970,15 @@ static int mycmp(const char *s1, const char *s2, int len) | |||
1963 | # define mycmp strncmp | 1970 | # define mycmp strncmp |
1964 | # endif | 1971 | # endif |
1965 | 1972 | ||
1966 | static char *char_search(char *p, const char *pat, int dir, int range) | 1973 | static char *char_search(char *p, const char *pat, int dir_and_range) |
1967 | { | 1974 | { |
1968 | char *start, *stop; | 1975 | char *start, *stop; |
1969 | int len; | 1976 | int len; |
1977 | int range; | ||
1970 | 1978 | ||
1971 | len = strlen(pat); | 1979 | len = strlen(pat); |
1972 | if (dir == FORWARD) { | 1980 | range = (dir_and_range & 1); |
1981 | if (dir_and_range > 0) { //FORWARD? | ||
1973 | stop = end - 1; // assume range is p..end-1 | 1982 | stop = end - 1; // assume range is p..end-1 |
1974 | if (range == LIMITED) | 1983 | if (range == LIMITED) |
1975 | stop = next_line(p); // range is to next line | 1984 | stop = next_line(p); // range is to next line |
@@ -1978,7 +1987,7 @@ static char *char_search(char *p, const char *pat, int dir, int range) | |||
1978 | return start; | 1987 | return start; |
1979 | } | 1988 | } |
1980 | } | 1989 | } |
1981 | } else if (dir == BACK) { | 1990 | } else { //BACK |
1982 | stop = text; // assume range is text..p | 1991 | stop = text; // assume range is text..p |
1983 | if (range == LIMITED) | 1992 | if (range == LIMITED) |
1984 | stop = prev_line(p); // range is to prev line | 1993 | stop = prev_line(p); // range is to prev line |
@@ -2357,7 +2366,7 @@ static void undo_push(char *src, unsigned int length, uint8_t u_type) // Add to | |||
2357 | // Allocate a new undo object | 2366 | // Allocate a new undo object |
2358 | if (u_type == UNDO_DEL || u_type == UNDO_DEL_CHAIN) { | 2367 | if (u_type == UNDO_DEL || u_type == UNDO_DEL_CHAIN) { |
2359 | // For UNDO_DEL objects, save deleted text | 2368 | // For UNDO_DEL objects, save deleted text |
2360 | if ((src + length) == end) | 2369 | if ((text + length) == end) |
2361 | length--; | 2370 | length--; |
2362 | // If this deletion empties text[], strip the newline. When the buffer becomes | 2371 | // If this deletion empties text[], strip the newline. When the buffer becomes |
2363 | // zero-length, a newline is added back, which requires this to compensate. | 2372 | // zero-length, a newline is added back, which requires this to compensate. |
@@ -3865,7 +3874,7 @@ static void do_cmd(int c) | |||
3865 | p = dot - 1; | 3874 | p = dot - 1; |
3866 | } | 3875 | } |
3867 | dc4: | 3876 | dc4: |
3868 | q = char_search(p, last_search_pattern + 1, dir, FULL); | 3877 | q = char_search(p, last_search_pattern + 1, (dir << 1) | FULL); |
3869 | if (q != NULL) { | 3878 | if (q != NULL) { |
3870 | dot = q; // good search, update "dot" | 3879 | dot = q; // good search, update "dot" |
3871 | msg = NULL; | 3880 | msg = NULL; |
@@ -3876,7 +3885,7 @@ static void do_cmd(int c) | |||
3876 | if (dir == BACK) { | 3885 | if (dir == BACK) { |
3877 | p = end - 1; | 3886 | p = end - 1; |
3878 | } | 3887 | } |
3879 | q = char_search(p, last_search_pattern + 1, dir, FULL); | 3888 | q = char_search(p, last_search_pattern + 1, (dir << 1) | FULL); |
3880 | if (q != NULL) { // found something | 3889 | if (q != NULL) { // found something |
3881 | dot = q; // found new pattern- goto it | 3890 | dot = q; // found new pattern- goto it |
3882 | msg = "search hit BOTTOM, continuing at TOP"; | 3891 | msg = "search hit BOTTOM, continuing at TOP"; |
@@ -3892,13 +3901,13 @@ static void do_cmd(int c) | |||
3892 | } while (--cmdcnt > 0); | 3901 | } while (--cmdcnt > 0); |
3893 | break; | 3902 | break; |
3894 | case '{': // {- move backward paragraph | 3903 | case '{': // {- move backward paragraph |
3895 | q = char_search(dot, "\n\n", BACK, FULL); | 3904 | q = char_search(dot, "\n\n", (BACK << 1) | FULL); |
3896 | if (q != NULL) { // found blank line | 3905 | if (q != NULL) { // found blank line |
3897 | dot = next_line(q); // move to next blank line | 3906 | dot = next_line(q); // move to next blank line |
3898 | } | 3907 | } |
3899 | break; | 3908 | break; |
3900 | case '}': // }- move forward paragraph | 3909 | case '}': // }- move forward paragraph |
3901 | q = char_search(dot, "\n\n", FORWARD, FULL); | 3910 | q = char_search(dot, "\n\n", (FORWARD << 1) | FULL); |
3902 | if (q != NULL) { // found blank line | 3911 | if (q != NULL) { // found blank line |
3903 | dot = next_line(q); // move to next blank line | 3912 | dot = next_line(q); // move to next blank line |
3904 | } | 3913 | } |