nano

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

commit ab6390cad0e3ef5a9f1644b7eaf13d481d663e70
parent 48124fdba49483676819252b15d27c1f534f0156
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Wed, 18 Sep 2019 15:20:08 +0200

tweaks: remove two superfluous macros, as sizeof(char) is always 1

Diffstat:
Msrc/cut.c | 2+-
Msrc/files.c | 2+-
Msrc/nano.c | 6+++---
Msrc/nano.h | 2--
Msrc/prompt.c | 8++++----
Msrc/text.c | 24++++++++++++------------
6 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/src/cut.c b/src/cut.c @@ -50,7 +50,7 @@ void do_deletion(undo_type action) old_amount = number_of_chunks_in(openfile->current); #endif /* Move the remainder of the line "in", over the current character. */ - charmove(&openfile->current->data[openfile->current_x], + memmove(&openfile->current->data[openfile->current_x], &openfile->current->data[openfile->current_x + charlen], line_len - charlen + 1); #ifndef NANO_TINY diff --git a/src/files.c b/src/files.c @@ -2584,7 +2584,7 @@ char *input_tab(char *buf, bool allow_files, size_t *place, /* If the matches have something in common, show that part. */ if (common_len != *place) { buf = charealloc(buf, common_len + buf_len - *place + 1); - charmove(buf + common_len, buf + *place, buf_len - *place + 1); + memmove(buf + common_len, buf + *place, buf_len - *place + 1); strncpy(buf, mzero, common_len); *place = common_len; } diff --git a/src/nano.c b/src/nano.c @@ -239,7 +239,7 @@ void partition_buffer(linestruct *top, size_t top_x, bot->data[bot_x] = '\0'; /* At the beginning of the partition, remove all text before top_x. */ - charmove(top->data, top->data + top_x, strlen(top->data) - top_x + 1); + memmove(top->data, top->data + top_x, strlen(top->data) - top_x + 1); } /* Unpartition the current buffer so that it is complete again. */ @@ -253,7 +253,7 @@ void unpartition_buffer() /* Restore the text that was on the first partition line before its start. */ openfile->filetop->data = charealloc(openfile->filetop->data, strlen(antedata) + strlen(openfile->filetop->data) + 1); - charmove(openfile->filetop->data + strlen(antedata), + memmove(openfile->filetop->data + strlen(antedata), openfile->filetop->data, strlen(openfile->filetop->data) + 1); strncpy(openfile->filetop->data, antedata, strlen(antedata)); free(antedata); @@ -1808,7 +1808,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) /* Make room for the new character and copy it into the line. */ openfile->current->data = charealloc(openfile->current->data, current_len + charlen + 1); - charmove(openfile->current->data + openfile->current_x + charlen, + memmove(openfile->current->data + openfile->current_x + charlen, openfile->current->data + openfile->current_x, current_len - openfile->current_x + 1); strncpy(openfile->current->data + openfile->current_x, onechar, diff --git a/src/nano.h b/src/nano.h @@ -62,8 +62,6 @@ /* Macros for character allocation and more. */ #define charalloc(howmuch) (char *)nmalloc((howmuch) * sizeof(char)) #define charealloc(ptr, howmuch) (char *)nrealloc(ptr, (howmuch) * sizeof(char)) -#define charmove(dest, src, n) memmove(dest, src, (n) * sizeof(char)) -#define charset(dest, src, n) memset(dest, src, (n) * sizeof(char)) /* In UTF-8 a character is at most six bytes long. */ #ifdef ENABLE_UTF8 diff --git a/src/prompt.c b/src/prompt.c @@ -213,7 +213,7 @@ void do_statusbar_output(int *the_input, size_t input_len, /* Insert the typed character into the existing answer string. */ answer = charealloc(answer, strlen(answer) + charlen + 1); - charmove(answer + typing_x + charlen, answer + typing_x, + memmove(answer + typing_x + charlen, answer + typing_x, strlen(answer) - typing_x + 1); strncpy(answer + typing_x, onechar, charlen); @@ -255,7 +255,7 @@ void do_statusbar_delete(void) if (answer[typing_x] != '\0') { int charlen = char_length(answer + typing_x); - charmove(answer + typing_x, answer + typing_x + charlen, + memmove(answer + typing_x, answer + typing_x + charlen, strlen(answer) - typing_x - charlen + 1); } } @@ -424,12 +424,12 @@ void draw_the_promptbar(void) void add_or_remove_pipe_symbol_from_answer(void) { if (answer[0] == '|') { - charmove(answer, answer + 1, strlen(answer) + 1); + memmove(answer, answer + 1, strlen(answer) + 1); if (typing_x > 0) typing_x--; } else { answer = charealloc(answer, strlen(answer) + 2); - charmove(answer + 1, answer, strlen(answer) + 1); + memmove(answer + 1, answer, strlen(answer) + 1); answer[0] = '|'; typing_x++; } diff --git a/src/text.c b/src/text.c @@ -81,7 +81,7 @@ void do_tab(void) char *spaces = charalloc(tabsize + 1); size_t length = tabsize - (xplustabs() % tabsize); - charset(spaces, ' ', length); + memset(spaces, ' ', length); spaces[length] = '\0'; do_output(spaces, length, TRUE); @@ -105,7 +105,7 @@ void indent_a_line(linestruct *line, char *indentation) /* Add the fabricated indentation to the beginning of the line. */ line->data = charealloc(line->data, length + indent_len + 1); - charmove(line->data + indent_len, line->data, length + 1); + memmove(line->data + indent_len, line->data, length + 1); strncpy(line->data, indentation, indent_len); openfile->totsize += indent_len; @@ -142,7 +142,7 @@ void do_indent(void) /* Set the indentation to either a bunch of spaces or a single tab. */ if (ISSET(TABS_TO_SPACES)) { - charset(indentation, ' ', tabsize); + memset(indentation, ' ', tabsize); indentation[tabsize] = '\0'; } else { indentation[0] = '\t'; @@ -217,7 +217,7 @@ void unindent_a_line(linestruct *line, size_t indent_len) return; /* Remove the first tab's worth of whitespace from this line. */ - charmove(line->data, line->data + indent_len, length - indent_len + 1); + memmove(line->data, line->data + indent_len, length - indent_len + 1); openfile->totsize -= indent_len; @@ -319,10 +319,10 @@ bool comment_line(undo_type action, linestruct *line, const char *comment_seq) /* Make room for the comment sequence(s), move the text right and * copy them in. */ line->data = charealloc(line->data, line_len + pre_len + post_len + 1); - charmove(line->data + pre_len, line->data, line_len + 1); - charmove(line->data, comment_seq, pre_len); + memmove(line->data + pre_len, line->data, line_len + 1); + memmove(line->data, comment_seq, pre_len); if (post_len > 0) - charmove(line->data + pre_len + line_len, post_seq, post_len + 1); + memmove(line->data + pre_len + line_len, post_seq, post_len + 1); openfile->totsize += pre_len + post_len; @@ -345,7 +345,7 @@ bool comment_line(undo_type action, linestruct *line, const char *comment_seq) return TRUE; /* Erase the comment prefix by moving the non-comment part. */ - charmove(line->data, line->data + pre_len, line_len - pre_len); + memmove(line->data, line->data + pre_len, line_len - pre_len); /* Truncate the postfix if there was one. */ line->data[line_len - pre_len - post_len] = '\0'; @@ -1496,7 +1496,7 @@ bool do_wrap(void) line_len = strlen(line->data); line->data = charealloc(line->data, lead_len + line_len + 1); - charmove(line->data + lead_len, line->data, line_len + 1); + memmove(line->data + lead_len, line->data, line_len + 1); strncpy(line->data, line->prev->data, lead_len); openfile->current_x += lead_len; @@ -2047,7 +2047,7 @@ void do_justify(bool full_justify) if (needed_top_extra > 0) { cutbuffer->data = charealloc(cutbuffer->data, line_len + needed_top_extra + 1); - charmove(cutbuffer->data + needed_top_extra, cutbuffer->data, + memmove(cutbuffer->data + needed_top_extra, cutbuffer->data, line_len + 1); strncpy(cutbuffer->data, the_lead, needed_top_extra); line_len += needed_top_extra; @@ -2061,7 +2061,7 @@ void do_justify(bool full_justify) /* Remove extra whitespace after the leading part. */ if (indent_len > 0) - charmove(cutbuffer->data + lead_len, + memmove(cutbuffer->data + lead_len, cutbuffer->data + lead_len + indent_len, line_len - indent_len + 1); @@ -2088,7 +2088,7 @@ void do_justify(bool full_justify) * remove the (now-redundant) addition we made earlier. */ if (top_x > 0) { if (needed_top_extra > 0) - charmove(cutbuffer->data, cutbuffer->data + needed_top_extra, + memmove(cutbuffer->data, cutbuffer->data + needed_top_extra, strlen(cutbuffer->data) - needed_top_extra + 1); else { cutbuffer->prev = make_new_node(NULL);