diff options
author | Ron Yorston <rmy@pobox.com> | 2019-02-12 08:43:06 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-02-12 08:43:06 +0000 |
commit | 7a8bd5ae33d8c390763f0787afe6b8c495e2d978 (patch) | |
tree | 29b0abb320d73b37f4fa4d9b355b3b32db42e836 /editors/vi.c | |
parent | 0eda390d68c456975289471e68b615ae096ab33b (diff) | |
parent | f81e0120f4478c58e126bcadb19b9954ed184e8f (diff) | |
download | busybox-w32-7a8bd5ae33d8c390763f0787afe6b8c495e2d978.tar.gz busybox-w32-7a8bd5ae33d8c390763f0787afe6b8c495e2d978.tar.bz2 busybox-w32-7a8bd5ae33d8c390763f0787afe6b8c495e2d978.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'editors/vi.c')
-rw-r--r-- | editors/vi.c | 78 |
1 files changed, 31 insertions, 47 deletions
diff --git a/editors/vi.c b/editors/vi.c index 3c758cca0..a46339813 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -600,6 +600,7 @@ static void check_context(char); // remember context for '' command | |||
600 | #if ENABLE_FEATURE_VI_UNDO | 600 | #if ENABLE_FEATURE_VI_UNDO |
601 | static void flush_undo_data(void); | 601 | static void flush_undo_data(void); |
602 | static void undo_push(char *, unsigned int, unsigned char); // Push an operation on the undo stack | 602 | static void undo_push(char *, unsigned int, unsigned char); // Push an operation on the undo stack |
603 | static void undo_push_insert(char *, int, int); // convenience function | ||
603 | static void undo_pop(void); // Undo the last operation | 604 | static void undo_pop(void); // Undo the last operation |
604 | # if ENABLE_FEATURE_VI_UNDO_QUEUE | 605 | # if ENABLE_FEATURE_VI_UNDO_QUEUE |
605 | static void undo_queue_commit(void); // Flush any queued objects to the undo stack | 606 | static void undo_queue_commit(void); // Flush any queued objects to the undo stack |
@@ -2013,19 +2014,7 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p' | |||
2013 | c = get_one_char(); | 2014 | c = get_one_char(); |
2014 | *p = c; | 2015 | *p = c; |
2015 | #if ENABLE_FEATURE_VI_UNDO | 2016 | #if ENABLE_FEATURE_VI_UNDO |
2016 | switch (undo) { | 2017 | undo_push_insert(p, 1, undo); |
2017 | case ALLOW_UNDO: | ||
2018 | undo_push(p, 1, UNDO_INS); | ||
2019 | break; | ||
2020 | case ALLOW_UNDO_CHAIN: | ||
2021 | undo_push(p, 1, UNDO_INS_CHAIN); | ||
2022 | break; | ||
2023 | # if ENABLE_FEATURE_VI_UNDO_QUEUE | ||
2024 | case ALLOW_UNDO_QUEUED: | ||
2025 | undo_push(p, 1, UNDO_INS_QUEUED); | ||
2026 | break; | ||
2027 | # endif | ||
2028 | } | ||
2029 | #else | 2018 | #else |
2030 | modified_count++; | 2019 | modified_count++; |
2031 | #endif /* ENABLE_FEATURE_VI_UNDO */ | 2020 | #endif /* ENABLE_FEATURE_VI_UNDO */ |
@@ -2053,19 +2042,7 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p' | |||
2053 | if (c == '\n') | 2042 | if (c == '\n') |
2054 | undo_queue_commit(); | 2043 | undo_queue_commit(); |
2055 | # endif | 2044 | # endif |
2056 | switch (undo) { | 2045 | undo_push_insert(p, 1, undo); |
2057 | case ALLOW_UNDO: | ||
2058 | undo_push(p, 1, UNDO_INS); | ||
2059 | break; | ||
2060 | case ALLOW_UNDO_CHAIN: | ||
2061 | undo_push(p, 1, UNDO_INS_CHAIN); | ||
2062 | break; | ||
2063 | # if ENABLE_FEATURE_VI_UNDO_QUEUE | ||
2064 | case ALLOW_UNDO_QUEUED: | ||
2065 | undo_push(p, 1, UNDO_INS_QUEUED); | ||
2066 | break; | ||
2067 | # endif | ||
2068 | } | ||
2069 | #else | 2046 | #else |
2070 | modified_count++; | 2047 | modified_count++; |
2071 | #endif /* ENABLE_FEATURE_VI_UNDO */ | 2048 | #endif /* ENABLE_FEATURE_VI_UNDO */ |
@@ -2085,7 +2062,7 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p' | |||
2085 | p += bias; | 2062 | p += bias; |
2086 | q += bias; | 2063 | q += bias; |
2087 | #if ENABLE_FEATURE_VI_UNDO | 2064 | #if ENABLE_FEATURE_VI_UNDO |
2088 | undo_push(p, len, UNDO_INS); | 2065 | undo_push_insert(p, len, undo); |
2089 | #endif | 2066 | #endif |
2090 | memcpy(p, q, len); | 2067 | memcpy(p, q, len); |
2091 | p += len; | 2068 | p += len; |
@@ -2339,16 +2316,18 @@ static void undo_push(char *src, unsigned int length, uint8_t u_type) // Add to | |||
2339 | } | 2316 | } |
2340 | break; | 2317 | break; |
2341 | case UNDO_INS_QUEUED: | 2318 | case UNDO_INS_QUEUED: |
2342 | if (length != 1) | 2319 | if (length < 1) |
2343 | return; | 2320 | return; |
2344 | switch (undo_queue_state) { | 2321 | switch (undo_queue_state) { |
2345 | case UNDO_EMPTY: | 2322 | case UNDO_EMPTY: |
2346 | undo_queue_state = UNDO_INS; | 2323 | undo_queue_state = UNDO_INS; |
2347 | undo_queue_spos = src; | 2324 | undo_queue_spos = src; |
2348 | case UNDO_INS: | 2325 | case UNDO_INS: |
2349 | undo_q++; // Don't need to save any data for insertions | 2326 | while (length--) { |
2350 | if (undo_q == CONFIG_FEATURE_VI_UNDO_QUEUE_MAX) | 2327 | undo_q++; // Don't need to save any data for insertions |
2351 | undo_queue_commit(); | 2328 | if (undo_q == CONFIG_FEATURE_VI_UNDO_QUEUE_MAX) |
2329 | undo_queue_commit(); | ||
2330 | } | ||
2352 | return; | 2331 | return; |
2353 | case UNDO_DEL: | 2332 | case UNDO_DEL: |
2354 | // Switch from storing deleted text to inserted text | 2333 | // Switch from storing deleted text to inserted text |
@@ -2394,6 +2373,23 @@ static void undo_push(char *src, unsigned int length, uint8_t u_type) // Add to | |||
2394 | modified_count++; | 2373 | modified_count++; |
2395 | } | 2374 | } |
2396 | 2375 | ||
2376 | static void undo_push_insert(char *p, int len, int undo) | ||
2377 | { | ||
2378 | switch (undo) { | ||
2379 | case ALLOW_UNDO: | ||
2380 | undo_push(p, len, UNDO_INS); | ||
2381 | break; | ||
2382 | case ALLOW_UNDO_CHAIN: | ||
2383 | undo_push(p, len, UNDO_INS_CHAIN); | ||
2384 | break; | ||
2385 | # if ENABLE_FEATURE_VI_UNDO_QUEUE | ||
2386 | case ALLOW_UNDO_QUEUED: | ||
2387 | undo_push(p, len, UNDO_INS_QUEUED); | ||
2388 | break; | ||
2389 | # endif | ||
2390 | } | ||
2391 | } | ||
2392 | |||
2397 | static void undo_pop(void) // Undo the last operation | 2393 | static void undo_pop(void) // Undo the last operation |
2398 | { | 2394 | { |
2399 | int repeat; | 2395 | int repeat; |
@@ -2667,14 +2663,7 @@ static uintptr_t string_insert(char *p, const char *s, int undo) // insert the s | |||
2667 | 2663 | ||
2668 | i = strlen(s); | 2664 | i = strlen(s); |
2669 | #if ENABLE_FEATURE_VI_UNDO | 2665 | #if ENABLE_FEATURE_VI_UNDO |
2670 | switch (undo) { | 2666 | undo_push_insert(p, i, undo); |
2671 | case ALLOW_UNDO: | ||
2672 | undo_push(p, i, UNDO_INS); | ||
2673 | break; | ||
2674 | case ALLOW_UNDO_CHAIN: | ||
2675 | undo_push(p, i, UNDO_INS_CHAIN); | ||
2676 | break; | ||
2677 | } | ||
2678 | #endif | 2667 | #endif |
2679 | bias = text_hole_make(p, i); | 2668 | bias = text_hole_make(p, i); |
2680 | p += bias; | 2669 | p += bias; |
@@ -4263,14 +4252,9 @@ static void do_cmd(int c) | |||
4263 | case 'r': // r- replace the current char with user input | 4252 | case 'r': // r- replace the current char with user input |
4264 | c1 = get_one_char(); // get the replacement char | 4253 | c1 = get_one_char(); // get the replacement char |
4265 | if (*dot != '\n') { | 4254 | if (*dot != '\n') { |
4266 | #if ENABLE_FEATURE_VI_UNDO | 4255 | dot = text_hole_delete(dot, dot, ALLOW_UNDO); |
4267 | undo_push(dot, 1, UNDO_DEL); | 4256 | dot = char_insert(dot, c1, ALLOW_UNDO_CHAIN); |
4268 | *dot = c1; | 4257 | dot_left(); |
4269 | undo_push(dot, 1, UNDO_INS_CHAIN); | ||
4270 | #else | ||
4271 | *dot = c1; | ||
4272 | modified_count++; | ||
4273 | #endif | ||
4274 | } | 4258 | } |
4275 | end_cmd_q(); // stop adding to q | 4259 | end_cmd_q(); // stop adding to q |
4276 | break; | 4260 | break; |