[PATCH] Small cleanup
Michael Bienia <[email protected]>
| Newsgroups | gmane.network.tin.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello, Changes: * use t_function in search() to signal search type and direction Michael
patch-20050307.diff
(text/plain, 6.1 KB)
include/proto.h | 2 +-
include/tin.h | 6 ------
src/group.c | 16 ++++++----------
src/page.c | 2 +-
src/search.c | 17 ++++++++++++-----
src/thread.c | 10 +++-------
6 files changed, 23 insertions(+), 30 deletions(-)
diff -Nurp tin-1.7.8/include/proto.h tin-1.7.8.new/include/proto.h
--- tin-1.7.8/include/proto.h 2005-02-12 14:21:31.000000000 +0100
+++ tin-1.7.8.new/include/proto.h 2005-03-07 15:24:03.486927443 +0100
@@ -578,7 +578,7 @@ extern void wait_message(unsigned int sd
/* search.c */
extern int get_search_vectors(int *start, int *end);
-extern int search(int key, int current_art, t_bool forward, t_bool repeat);
+extern int search(t_function func, int current_art, t_bool repeat);
extern int search_active(t_bool forward, t_bool repeat);
extern int search_article(t_bool forward, t_bool repeat, int start_line, int lines, t_lineinfo *line, int reveal_ctrl_l_lines, FILE *fp);
extern int search_config(t_bool forward, t_bool repeat, int current, int last);
diff -Nurp tin-1.7.8/include/tin.h tin-1.7.8.new/include/tin.h
--- tin-1.7.8/include/tin.h 2005-02-01 17:15:54.000000000 +0100
+++ tin-1.7.8.new/include/tin.h 2005-03-07 15:24:03.491926562 +0100
@@ -1204,12 +1204,6 @@ enum {
#define SORT_THREADS_BY_SCORE_ASCEND 2
/*
- * Search keys
- */
-#define SEARCH_SUBJ 1
-#define SEARCH_AUTH 2
-
-/*
* Different values of strip_bogus - the ways to handle bogus groups
*/
#define BOGUS_KEEP 0 /* not used */
diff -Nurp tin-1.7.8/src/group.c tin-1.7.8.new/src/group.c
--- tin-1.7.8/src/group.c 2005-02-14 16:41:18.000000000 +0100
+++ tin-1.7.8.new/src/group.c 2005-03-07 15:29:26.043568617 +0100
@@ -56,7 +56,7 @@ struct t_group *curr_group;
/*
* Local prototypes
*/
-static int do_search(int type, t_bool forward, t_bool repeat);
+static int do_search(t_function func, t_bool repeat);
static int enter_pager(int art, t_bool ignore_unavail);
static int enter_thread(int depth, t_pagerinfo *page);
static int group_catchup(t_function func);
@@ -284,13 +284,9 @@ group_page(
case GLOBAL_SEARCH_AUTHOR_FORWARD:
case GLOBAL_SEARCH_AUTHOR_BACKWARD:
- if ((thread_depth = do_search(SEARCH_AUTH, (func == GLOBAL_SEARCH_AUTHOR_FORWARD), repeat_search)) != 0)
- ret_code = enter_thread(thread_depth, NULL);
- break;
-
case GLOBAL_SEARCH_SUBJECT_FORWARD:
case GLOBAL_SEARCH_SUBJECT_BACKWARD:
- if ((thread_depth = do_search(SEARCH_SUBJ, (func == GLOBAL_SEARCH_SUBJECT_FORWARD), repeat_search)) != 0)
+ if ((thread_depth = do_search(func, repeat_search)) != 0)
ret_code = enter_thread(thread_depth, NULL);
break;
@@ -1435,8 +1431,7 @@ show_group_title(
*/
static int
do_search(
- int type,
- t_bool forward,
+ t_function func,
t_bool repeat)
{
int start, n;
@@ -1447,9 +1442,10 @@ do_search(
/*
* Not intuitive to search current thread in fwd search
*/
- start = (forward && grpmenu.curr < grpmenu.max - 1) ? prev_response((int) base[grpmenu.curr + 1]) : (int) base[grpmenu.curr];
+ start = ((func == GLOBAL_SEARCH_SUBJECT_FORWARD || func == GLOBAL_SEARCH_AUTHOR_FORWARD)
+ && grpmenu.curr < grpmenu.max - 1) ? prev_response((int) base[grpmenu.curr + 1]) : (int) base[grpmenu.curr];
- if ((n = search(type, start, forward, repeat)) != -1) {
+ if ((n = search(func, start, repeat)) != -1) {
grpmenu.curr = which_thread(n);
/*
diff -Nurp tin-1.7.8/src/page.c tin-1.7.8.new/src/page.c
--- tin-1.7.8/src/page.c 2005-02-12 14:23:07.000000000 +0100
+++ tin-1.7.8.new/src/page.c 2005-03-07 15:24:03.501924799 +0100
@@ -726,7 +726,7 @@ page_goto_next_unread:
case GLOBAL_SEARCH_AUTHOR_FORWARD: /* author search forward */
case GLOBAL_SEARCH_AUTHOR_BACKWARD: /* author search backward */
- if ((n = search(SEARCH_AUTH, this_resp, (func == GLOBAL_SEARCH_AUTHOR_FORWARD), repeat_search)) < 0)
+ if ((n = search(func, this_resp, repeat_search)) < 0)
break;
if ((i = load_article(n, group)) < 0) {
XFACE_CLEAR();
diff -Nurp tin-1.7.8/src/search.c tin-1.7.8.new/src/search.c
--- tin-1.7.8/src/search.c 2005-02-01 11:26:55.000000000 +0100
+++ tin-1.7.8.new/src/search.c 2005-03-07 15:24:03.506923917 +0100
@@ -475,22 +475,29 @@ search_group(
*/
int
search(
- int key,
+ t_function func,
int current_art,
- t_bool forward,
t_bool repeat)
{
char *buf = NULL;
int (*search_func) (int i, char *searchbuff) = author_search;
+ t_bool forward;
- switch (key) {
- case SEARCH_SUBJ:
+ if (func == GLOBAL_SEARCH_SUBJECT_FORWARD || func == GLOBAL_SEARCH_AUTHOR_FORWARD)
+ forward = TRUE;
+ else
+ forward = FALSE;
+
+ switch (func) {
+ case GLOBAL_SEARCH_SUBJECT_FORWARD:
+ case GLOBAL_SEARCH_SUBJECT_BACKWARD:
if (!(buf = get_search_pattern(&forward, repeat, _(txt_search_forwards), _(txt_search_backwards), tinrc.default_search_subject, HIST_SUBJECT_SEARCH)))
return -1;
search_func = subject_search;
break;
- case SEARCH_AUTH:
+ case GLOBAL_SEARCH_AUTHOR_FORWARD:
+ case GLOBAL_SEARCH_AUTHOR_BACKWARD:
default:
if (!(buf = get_search_pattern(&forward, repeat, _(txt_author_search_forwards), _(txt_author_search_backwards), tinrc.default_search_author, HIST_AUTHOR_SEARCH)))
return -1;
diff -Nurp tin-1.7.8/src/thread.c tin-1.7.8.new/src/thread.c
--- tin-1.7.8/src/thread.c 2005-02-12 14:24:18.000000000 +0100
+++ tin-1.7.8.new/src/thread.c 2005-03-07 15:30:35.681867146 +0100
@@ -638,15 +638,11 @@ thread_page(
}
break;
- case GLOBAL_SEARCH_SUBJECT_FORWARD: /* subject search */
- case GLOBAL_SEARCH_SUBJECT_BACKWARD:
- if ((n = search(SEARCH_SUBJ, find_response(thread_basenote, thdmenu.curr), (func == GLOBAL_SEARCH_SUBJECT_FORWARD), repeat_search)) != -1)
- fixup_thread(n, TRUE);
- break;
-
case GLOBAL_SEARCH_AUTHOR_FORWARD: /* author search */
case GLOBAL_SEARCH_AUTHOR_BACKWARD:
- if ((n = search(SEARCH_AUTH, find_response(thread_basenote, thdmenu.curr), (func == GLOBAL_SEARCH_AUTHOR_FORWARD), repeat_search)) != -1)
+ case GLOBAL_SEARCH_SUBJECT_FORWARD: /* subject search */
+ case GLOBAL_SEARCH_SUBJECT_BACKWARD:
+ if ((n = search(func, find_response(thread_basenote, thdmenu.curr), repeat_search)) != -1)
fixup_thread(n, TRUE);
break;