diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-01 13:59:38 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-01 13:59:38 +0200 |
commit | 363a2bc9b15fb0b6cf2d5840d6c7cdcfe9bd8074 (patch) | |
tree | 33d88e68e3d11f014b9cd2e38b3b24f38ed82aeb | |
parent | 24bd350aaa3cd593a9a8304042cea689d716aba2 (diff) | |
download | busybox-w32-363a2bc9b15fb0b6cf2d5840d6c7cdcfe9bd8074.tar.gz busybox-w32-363a2bc9b15fb0b6cf2d5840d6c7cdcfe9bd8074.tar.bz2 busybox-w32-363a2bc9b15fb0b6cf2d5840d6c7cdcfe9bd8074.zip |
vi: rearrange functions, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 149 |
1 files changed, 75 insertions, 74 deletions
diff --git a/editors/vi.c b/editors/vi.c index 406119371..cfb1a71ea 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -511,7 +511,6 @@ static char *char_insert(char *, char, int); // insert the char c at 'p' | |||
511 | // might reallocate text[]! use p += stupid_insert(p, ...), | 511 | // might reallocate text[]! use p += stupid_insert(p, ...), |
512 | // and be careful to not use pointers into potentially freed text[]! | 512 | // and be careful to not use pointers into potentially freed text[]! |
513 | static uintptr_t stupid_insert(char *, char); // stupidly insert the char c at 'p' | 513 | static uintptr_t stupid_insert(char *, char); // stupidly insert the char c at 'p' |
514 | static int find_range(char **, char **, char); // return pointers for an object | ||
515 | static int st_test(char *, int, int, char *); // helper for skip_thing() | 514 | static int st_test(char *, int, int, char *); // helper for skip_thing() |
516 | static char *skip_thing(char *, int, int, int); // skip some object | 515 | static char *skip_thing(char *, int, int, int); // skip some object |
517 | static char *find_pair(char *, char); // find matching pair () [] {} | 516 | static char *find_pair(char *, char); // find matching pair () [] {} |
@@ -1874,79 +1873,6 @@ static uintptr_t stupid_insert(char *p, char c) // stupidly insert the char c at | |||
1874 | return bias; | 1873 | return bias; |
1875 | } | 1874 | } |
1876 | 1875 | ||
1877 | static int find_range(char **start, char **stop, char c) | ||
1878 | { | ||
1879 | char *save_dot, *p, *q, *t; | ||
1880 | int cnt, multiline = 0; | ||
1881 | |||
1882 | save_dot = dot; | ||
1883 | p = q = dot; | ||
1884 | |||
1885 | if (strchr("cdy><", c)) { | ||
1886 | // these cmds operate on whole lines | ||
1887 | p = q = begin_line(p); | ||
1888 | for (cnt = 1; cnt < cmdcnt; cnt++) { | ||
1889 | q = next_line(q); | ||
1890 | } | ||
1891 | q = end_line(q); | ||
1892 | } else if (strchr("^%$0bBeEfth\b\177", c)) { | ||
1893 | // These cmds operate on char positions | ||
1894 | do_cmd(c); // execute movement cmd | ||
1895 | q = dot; | ||
1896 | } else if (strchr("wW", c)) { | ||
1897 | do_cmd(c); // execute movement cmd | ||
1898 | // if we are at the next word's first char | ||
1899 | // step back one char | ||
1900 | // but check the possibilities when it is true | ||
1901 | if (dot > text && ((isspace(dot[-1]) && !isspace(dot[0])) | ||
1902 | || (ispunct(dot[-1]) && !ispunct(dot[0])) | ||
1903 | || (isalnum(dot[-1]) && !isalnum(dot[0])))) | ||
1904 | dot--; // move back off of next word | ||
1905 | if (dot > text && *dot == '\n') | ||
1906 | dot--; // stay off NL | ||
1907 | q = dot; | ||
1908 | } else if (strchr("H-k{", c)) { | ||
1909 | // these operate on multi-lines backwards | ||
1910 | q = end_line(dot); // find NL | ||
1911 | do_cmd(c); // execute movement cmd | ||
1912 | dot_begin(); | ||
1913 | p = dot; | ||
1914 | } else if (strchr("L+j}\r\n", c)) { | ||
1915 | // these operate on multi-lines forwards | ||
1916 | p = begin_line(dot); | ||
1917 | do_cmd(c); // execute movement cmd | ||
1918 | dot_end(); // find NL | ||
1919 | q = dot; | ||
1920 | } else { | ||
1921 | // nothing -- this causes any other values of c to | ||
1922 | // represent the one-character range under the | ||
1923 | // cursor. this is correct for ' ' and 'l', but | ||
1924 | // perhaps no others. | ||
1925 | // | ||
1926 | } | ||
1927 | if (q < p) { | ||
1928 | t = q; | ||
1929 | q = p; | ||
1930 | p = t; | ||
1931 | } | ||
1932 | |||
1933 | // backward char movements don't include start position | ||
1934 | if (q > p && strchr("^0bBh\b\177", c)) q--; | ||
1935 | |||
1936 | multiline = 0; | ||
1937 | for (t = p; t <= q; t++) { | ||
1938 | if (*t == '\n') { | ||
1939 | multiline = 1; | ||
1940 | break; | ||
1941 | } | ||
1942 | } | ||
1943 | |||
1944 | *start = p; | ||
1945 | *stop = q; | ||
1946 | dot = save_dot; | ||
1947 | return multiline; | ||
1948 | } | ||
1949 | |||
1950 | static int st_test(char *p, int type, int dir, char *tested) | 1876 | static int st_test(char *p, int type, int dir, char *tested) |
1951 | { | 1877 | { |
1952 | char c, c0, ci; | 1878 | char c, c0, ci; |
@@ -3177,6 +3103,81 @@ static void refresh(int full_screen) | |||
3177 | #undef old_offset | 3103 | #undef old_offset |
3178 | } | 3104 | } |
3179 | 3105 | ||
3106 | static void do_cmd(int c); | ||
3107 | |||
3108 | static int find_range(char **start, char **stop, char c) | ||
3109 | { | ||
3110 | char *save_dot, *p, *q, *t; | ||
3111 | int cnt, multiline = 0; | ||
3112 | |||
3113 | save_dot = dot; | ||
3114 | p = q = dot; | ||
3115 | |||
3116 | if (strchr("cdy><", c)) { | ||
3117 | // these cmds operate on whole lines | ||
3118 | p = q = begin_line(p); | ||
3119 | for (cnt = 1; cnt < cmdcnt; cnt++) { | ||
3120 | q = next_line(q); | ||
3121 | } | ||
3122 | q = end_line(q); | ||
3123 | } else if (strchr("^%$0bBeEfth\b\177", c)) { | ||
3124 | // These cmds operate on char positions | ||
3125 | do_cmd(c); // execute movement cmd | ||
3126 | q = dot; | ||
3127 | } else if (strchr("wW", c)) { | ||
3128 | do_cmd(c); // execute movement cmd | ||
3129 | // if we are at the next word's first char | ||
3130 | // step back one char | ||
3131 | // but check the possibilities when it is true | ||
3132 | if (dot > text && ((isspace(dot[-1]) && !isspace(dot[0])) | ||
3133 | || (ispunct(dot[-1]) && !ispunct(dot[0])) | ||
3134 | || (isalnum(dot[-1]) && !isalnum(dot[0])))) | ||
3135 | dot--; // move back off of next word | ||
3136 | if (dot > text && *dot == '\n') | ||
3137 | dot--; // stay off NL | ||
3138 | q = dot; | ||
3139 | } else if (strchr("H-k{", c)) { | ||
3140 | // these operate on multi-lines backwards | ||
3141 | q = end_line(dot); // find NL | ||
3142 | do_cmd(c); // execute movement cmd | ||
3143 | dot_begin(); | ||
3144 | p = dot; | ||
3145 | } else if (strchr("L+j}\r\n", c)) { | ||
3146 | // these operate on multi-lines forwards | ||
3147 | p = begin_line(dot); | ||
3148 | do_cmd(c); // execute movement cmd | ||
3149 | dot_end(); // find NL | ||
3150 | q = dot; | ||
3151 | } else { | ||
3152 | // nothing -- this causes any other values of c to | ||
3153 | // represent the one-character range under the | ||
3154 | // cursor. this is correct for ' ' and 'l', but | ||
3155 | // perhaps no others. | ||
3156 | // | ||
3157 | } | ||
3158 | if (q < p) { | ||
3159 | t = q; | ||
3160 | q = p; | ||
3161 | p = t; | ||
3162 | } | ||
3163 | |||
3164 | // backward char movements don't include start position | ||
3165 | if (q > p && strchr("^0bBh\b\177", c)) q--; | ||
3166 | |||
3167 | multiline = 0; | ||
3168 | for (t = p; t <= q; t++) { | ||
3169 | if (*t == '\n') { | ||
3170 | multiline = 1; | ||
3171 | break; | ||
3172 | } | ||
3173 | } | ||
3174 | |||
3175 | *start = p; | ||
3176 | *stop = q; | ||
3177 | dot = save_dot; | ||
3178 | return multiline; | ||
3179 | } | ||
3180 | |||
3180 | //--------------------------------------------------------------------- | 3181 | //--------------------------------------------------------------------- |
3181 | //----- the Ascii Chart ----------------------------------------------- | 3182 | //----- the Ascii Chart ----------------------------------------------- |
3182 | // 00 nul 01 soh 02 stx 03 etx 04 eot 05 enq 06 ack 07 bel | 3183 | // 00 nul 01 soh 02 stx 03 etx 04 eot 05 enq 06 ack 07 bel |