Commit 2e3aeae5 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

convert do_para_search() to use an enum to specify its search type

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1761 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 31 additions and 21 deletions
+31 -21
...@@ -107,6 +107,8 @@ CVS code - ...@@ -107,6 +107,8 @@ CVS code -
- Remove redundant assignment. (DLR) - Remove redundant assignment. (DLR)
do_para_search() do_para_search()
- Remove unneeded edit_update() calls. (David Benbennick) - Remove unneeded edit_update() calls. (David Benbennick)
- Convert to use an enum to specify the search type: JUSTIFY,
BEGIN, or END. (DLR)
do_justify() do_justify()
- Remove unneeded edit_update() calls, and add a few minor - Remove unneeded edit_update() calls, and add a few minor
efficiency tweaks. (David Benbennick) efficiency tweaks. (David Benbennick)
...@@ -167,6 +169,7 @@ CVS code - ...@@ -167,6 +169,7 @@ CVS code -
- nano.h: - nano.h:
- Since REGEXP_COMPILED is only used in search.c, convert it - Since REGEXP_COMPILED is only used in search.c, convert it
from a flag to a static int there. (DLR) from a flag to a static int there. (DLR)
- Add justbegend enum, used in do_para_search(). (DLR)
- proto.h: - proto.h:
- Remove unused xpt() and add_marked_sameline() prototypes. - Remove unused xpt() and add_marked_sameline() prototypes.
(DLR) (DLR)
......
...@@ -2104,16 +2104,17 @@ int break_line(const char *line, int goal, int force) ...@@ -2104,16 +2104,17 @@ int break_line(const char *line, int goal, int force)
return space_loc; return space_loc;
} }
/* Search a paragraph. If search_type is 0, search for the beginning of /* Search a paragraph. If search_type is JUSTIFY, search for the
* the current paragraph or, if we're at the end of it, the beginning of * beginning of the current paragraph or, if we're at the end of it, the
* the next paragraph. If search_type is 1, search for the beginning of * beginning of the next paragraph. If search_type is BEGIN, search for
* the current paragraph or, if we're already there, the beginning of * the beginning of the current paragraph or, if we're already there,
* the previous paragraph. If search_type is 2, search for the end of * the beginning of the previous paragraph. If search_type is END,
* the current paragraph or, if we're already there, the end of the next * search for the end of the current paragraph or, if we're already
* paragraph. Afterwards, save the quote length, paragraph length, and * there, the end of the next paragraph. Afterwards, save the quote
* indentation length in *quote, *par, and *indent if they aren't NULL, * length, paragraph length, and indentation length in *quote, *par, and
* and refresh the screen if do_refresh is TRUE. Return 0 if we found a * *indent if they aren't NULL, and refresh the screen if do_refresh is
* paragraph, or 1 if there was an error or we didn't find a paragraph. * TRUE. Return 0 if we found a paragraph, or 1 if there was an error
* or we didn't find a paragraph.
* *
* To explain the searching algorithm, I first need to define some * To explain the searching algorithm, I first need to define some
* phrases about paragraphs and quotation: * phrases about paragraphs and quotation:
...@@ -2142,8 +2143,8 @@ int break_line(const char *line, int goal, int force) ...@@ -2142,8 +2143,8 @@ int break_line(const char *line, int goal, int force)
* A contiguous set of lines is a "paragraph" if each line is part of * A contiguous set of lines is a "paragraph" if each line is part of
* a paragraph and only the first line is the beginning of a * a paragraph and only the first line is the beginning of a
* paragraph. */ * paragraph. */
int do_para_search(int search_type, size_t *quote, size_t *par, size_t int do_para_search(justbegend search_type, size_t *quote, size_t *par,
*indent, int do_refresh) size_t *indent, int do_refresh)
{ {
size_t quote_len; size_t quote_len;
/* Length of the initial quotation of the paragraph we /* Length of the initial quotation of the paragraph we
...@@ -2215,7 +2216,7 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t ...@@ -2215,7 +2216,7 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
current = current->prev; current = current->prev;
current_y--; current_y--;
} }
} else if (search_type == 1) { } else if (search_type == BEGIN) {
/* This line is not part of a paragraph. Move up until we get /* This line is not part of a paragraph. Move up until we get
* to a non "blank" line, and then move down once. */ * to a non "blank" line, and then move down once. */
do { do {
...@@ -2284,7 +2285,7 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t ...@@ -2284,7 +2285,7 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
par_len++; par_len++;
} }
if (search_type == 1) { if (search_type == BEGIN) {
/* We're on the same line we started on. Move up until we get /* We're on the same line we started on. Move up until we get
* to a non-"blank" line, restart the search from there until we * to a non-"blank" line, restart the search from there until we
* find a line that's part of a paragraph, and search once more * find a line that's part of a paragraph, and search once more
...@@ -2328,7 +2329,7 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t ...@@ -2328,7 +2329,7 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
/* If we're searching for the end of the paragraph, move down the /* If we're searching for the end of the paragraph, move down the
* number of lines in the paragraph. */ * number of lines in the paragraph. */
if (search_type == 2) { if (search_type == END) {
for (; par_len > 0; current_y++, par_len--) for (; par_len > 0; current_y++, par_len--)
current = current->next; current = current->next;
} }
...@@ -2351,12 +2352,12 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t ...@@ -2351,12 +2352,12 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
int do_para_begin(void) int do_para_begin(void)
{ {
return do_para_search(1, NULL, NULL, NULL, TRUE); return do_para_search(BEGIN, NULL, NULL, NULL, TRUE);
} }
int do_para_end(void) int do_para_end(void)
{ {
return do_para_search(2, NULL, NULL, NULL, TRUE); return do_para_search(END, NULL, NULL, NULL, TRUE);
} }
/* If full_justify is TRUE, justify the entire file. Otherwise, justify /* If full_justify is TRUE, justify the entire file. Otherwise, justify
...@@ -2412,7 +2413,8 @@ int do_justify(int full_justify) ...@@ -2412,7 +2413,8 @@ int do_justify(int full_justify)
* where it'll be anyway if we've searched the entire file, and * where it'll be anyway if we've searched the entire file, and
* break out of the loop; otherwise, refresh the screen and get * break out of the loop; otherwise, refresh the screen and get
* out. */ * out. */
if (do_para_search(0, &quote_len, &par_len, &indent_len, FALSE) != 0) { if (do_para_search(JUSTIFY, &quote_len, &par_len, &indent_len,
FALSE) != 0) {
if (full_justify) { if (full_justify) {
/* This should be safe in the event of filebot->prev's /* This should be safe in the event of filebot->prev's
* being NULL, since only last_par_line->next is used if * being NULL, since only last_par_line->next is used if
...@@ -2542,7 +2544,8 @@ int do_justify(int full_justify) ...@@ -2542,7 +2544,8 @@ int do_justify(int full_justify)
if (mark_beginx <= indent_len) if (mark_beginx <= indent_len)
mark_beginx = line_len + 1; mark_beginx = line_len + 1;
else else
mark_beginx = line_len + 1 + mark_beginx - indent_len; mark_beginx = line_len + 1 + mark_beginx -
indent_len;
} else } else
mark_beginx -= break_pos + 1; mark_beginx -= break_pos + 1;
} }
......
...@@ -463,6 +463,10 @@ typedef enum { ...@@ -463,6 +463,10 @@ typedef enum {
TOP, CENTER, NONE TOP, CENTER, NONE
} topmidnone; } topmidnone;
typedef enum {
JUSTIFY, BEGIN, END
} justbegend;
/* Minimum editor window rows required for nano to work correctly. */ /* Minimum editor window rows required for nano to work correctly. */
#define MIN_EDITOR_ROWS 3 #define MIN_EDITOR_ROWS 3
......
...@@ -324,8 +324,8 @@ filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t ...@@ -324,8 +324,8 @@ filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t
quote_len); quote_len);
int breakable(const char *line, int goal); int breakable(const char *line, int goal);
int break_line(const char *line, int goal, int force); int break_line(const char *line, int goal, int force);
int do_para_search(int search_type, size_t *quote, size_t *par, size_t int do_para_search(justbegend search_type, size_t *quote, size_t *par,
*indent, int do_refresh); size_t *indent, int do_refresh);
int do_para_begin(void); int do_para_begin(void);
int do_para_end(void); int do_para_end(void);
int do_justify(int justify_all); int do_justify(int justify_all);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment