From 59040169ed55f02ea1632a736c9d61658f771d6f Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 29 Mar 2020 20:17:32 +0200 Subject: [PATCH] tweaks: get rid of a bunch of annoying casts, and thus condense the code --- src/cut.c | 3 +-- src/files.c | 3 +-- src/proto.h | 5 ++--- src/search.c | 3 +-- src/text.c | 15 ++++++--------- src/utils.c | 5 ++--- src/winio.c | 2 +- 7 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/cut.c b/src/cut.c index b85a221e..2cc07467 100644 --- a/src/cut.c +++ b/src/cut.c @@ -434,8 +434,7 @@ void cut_marked_region(void) linestruct *top, *bot; size_t top_x, bot_x; - get_region((const linestruct **)&top, &top_x, - (const linestruct **)&bot, &bot_x); + get_region(&top, &top_x, &bot, &bot_x); extract_segment(top, top_x, bot, bot_x); diff --git a/src/files.c b/src/files.c index 3a7bdeff..97315ac7 100644 --- a/src/files.c +++ b/src/files.c @@ -2026,8 +2026,7 @@ bool write_marked_file(const char *name, FILE *stream, bool tmp, size_t top_x, bot_x; /* Partition the buffer so that it contains only the marked text. */ - get_region((const linestruct **)&top, &top_x, - (const linestruct **)&bot, &bot_x); + get_region(&top, &top_x, &bot, &bot_x); partition_buffer(top, top_x, bot, bot_x); /* If we are using a magic line, and the last line of the partition diff --git a/src/proto.h b/src/proto.h index 66acdb93..154c4209 100644 --- a/src/proto.h +++ b/src/proto.h @@ -573,9 +573,8 @@ void remove_magicline(void); #endif #ifndef NANO_TINY bool mark_is_before_cursor(void); -void get_region(const linestruct **top, size_t *top_x, - const linestruct **bot, size_t *bot_x); -void get_range(const linestruct **top, const linestruct **bot); +void get_region(linestruct **top, size_t *top_x, linestruct **bot, size_t *bot_x); +void get_range(linestruct **top, linestruct **bot); #endif size_t get_totsize(const linestruct *begin, const linestruct *end); #ifndef NANO_TINY diff --git a/src/search.c b/src/search.c index 4abb3954..205a925b 100644 --- a/src/search.c +++ b/src/search.c @@ -522,8 +522,7 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only, /* If the mark is on, frame the region, and turn the mark off. */ if (openfile->mark) { - get_region((const linestruct **)&top, &top_x, - (const linestruct **)&bot, &bot_x); + get_region(&top, &top_x, &bot, &bot_x); openfile->mark = NULL; modus = INREGION; diff --git a/src/text.c b/src/text.c index afaedb60..17b6b0ca 100644 --- a/src/text.c +++ b/src/text.c @@ -120,7 +120,7 @@ void do_indent(void) linestruct *top, *bot, *line; /* Use either all the marked lines or just the current line. */ - get_range((const linestruct **)&top, (const linestruct **)&bot); + get_range(&top, &bot); /* Skip any leading empty lines. */ while (top != bot->next && top->data[0] == '\0') @@ -241,7 +241,7 @@ void do_unindent(void) linestruct *top, *bot, *line; /* Use either all the marked lines or just the current line. */ - get_range((const linestruct **)&top, (const linestruct **)&bot); + get_range(&top, &bot); /* Skip any leading lines that cannot be unindented. */ while (top != bot->next && length_of_white(top->data) == 0) @@ -386,7 +386,7 @@ void do_comment(void) #endif /* Determine which lines to work on. */ - get_range((const linestruct **)&top, (const linestruct **)&bot); + get_range(&top, &bot); /* If only the magic line is selected, don't do anything. */ if (top == bot && bot == openfile->filebot && !ISSET(NO_NEWLINES)) { @@ -1744,8 +1744,7 @@ void do_justify(bool full_justify) size_t quot_len, fore_len, other_quot_len, other_white_len; linestruct *sampleline; - get_region((const linestruct **)&startline, &start_x, - (const linestruct **)&endline, &end_x); + get_region(&startline, &start_x, &endline, &end_x); /* When the marked region is empty, do nothing. */ if (startline == endline && start_x == end_x) { @@ -2034,8 +2033,7 @@ bool fix_spello(const char *word) #ifndef NANO_TINY /* If the mark is on, start at the beginning of the marked region. */ if (openfile->mark) { - get_region((const linestruct **)&top, &top_x, - (const linestruct **)&bot, &bot_x); + get_region(&top, &top_x, &bot, &bot_x); /* If the region is marked normally, swap the end points, so that * (current, current_x) (where searching starts) is at the top. */ if (right_side_up) { @@ -2913,8 +2911,7 @@ void do_wordlinechar_count(void) /* If the mark is on, partition the buffer so that it * contains only the marked text, and turn the mark off. */ if (openfile->mark) { - get_region((const linestruct **)&top, &top_x, - (const linestruct **)&bot, &bot_x); + get_region(&top, &top_x, &bot, &bot_x); partition_buffer(top, top_x, bot, bot_x); } diff --git a/src/utils.c b/src/utils.c index 4424cf1c..094e6d77 100644 --- a/src/utils.c +++ b/src/utils.c @@ -460,8 +460,7 @@ bool mark_is_before_cursor(void) /* Return in (top, top_x) and (bot, bot_x) the start and end "coordinates" * of the marked region. */ -void get_region(const linestruct **top, size_t *top_x, - const linestruct **bot, size_t *bot_x) +void get_region(linestruct **top, size_t *top_x, linestruct **bot, size_t *bot_x) { if (mark_is_before_cursor()) { *top = openfile->mark; @@ -479,7 +478,7 @@ void get_region(const linestruct **top, size_t *top_x, /* Get the set of lines to work on -- either just the current line, or the * first to last lines of the marked region. When the cursor (or mark) is * at the start of the last line of the region, exclude that line. */ -void get_range(const linestruct **top, const linestruct **bot) +void get_range(linestruct **top, linestruct **bot) { if (!openfile->mark) { *top = openfile->current; diff --git a/src/winio.c b/src/winio.c index 5c6ab66b..0506c132 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2677,7 +2677,7 @@ void draw_row(int row, const char *converted, linestruct *line, size_t from_col) line->lineno <= openfile->current->lineno) || (line->lineno <= openfile->mark->lineno && line->lineno >= openfile->current->lineno))) { - const linestruct *top, *bot; + linestruct *top, *bot; /* The lines where the marked region begins and ends. */ size_t top_x, bot_x; /* The x positions where the marked region begins and ends. */