nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 68acc1dfc5405010ac88e4a4c616b7fb6cdb4a79
parent 1a4ec6c2d329be3074d9a00a9488c4609fd9a921
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Fri, 24 Jun 2016 10:17:06 +0200

tabs: compute the number of required spaces without iterating

Diffstat:
Msrc/text.c | 21+++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/text.c b/src/text.c @@ -247,25 +247,18 @@ void do_tab(void) { #ifndef NANO_TINY if (ISSET(TABS_TO_SPACES)) { - char *output; - size_t output_len = 0, new_pww = xplustabs(); + char *spaces = charalloc(tabsize + 1); + size_t length = tabsize - (xplustabs() % tabsize); - do { - new_pww++; - output_len++; - } while (new_pww % tabsize != 0); + charset(spaces, ' ', length); + spaces[length] = '\0'; - output = charalloc(output_len + 1); + do_output(spaces, length, TRUE); - charset(output, ' ', output_len); - output[output_len] = '\0'; - - do_output(output, output_len, TRUE); - - free(output); + free(spaces); } else #endif - do_output((char *) "\t", 1, TRUE); + do_output((char *)"\t", 1, TRUE); } #ifndef NANO_TINY