commit - fc2737d5cdf003ae6a96db1af639d7fa39643f75
commit + 2a7d3cd7fd18be5657ca71a452a73ba70a8530e5
blob - 221455845af381fd0fbfaf6cb1a802f0fa557cbe
blob + d338b7cb55c642cdd9c04cf53565845ae158d065
--- tog/tog.c
+++ tog/tog.c
const struct got_error *(*search_start)(struct tog_view *);
const struct got_error *(*search_next)(struct tog_view *);
+ void (*search_setup)(struct tog_view *, FILE **, off_t **, size_t *,
+ int **, int **, int **, int **);
int search_started;
int searching;
#define TOG_SEARCH_FORWARD 1
static const struct got_error *reset_diff_view(struct tog_view *);
static const struct got_error* close_diff_view(struct tog_view *);
static const struct got_error *search_start_diff_view(struct tog_view *);
+static void search_setup_diff_view(struct tog_view *, FILE **, off_t **,
+ size_t *, int **, int **, int **, int **);
static const struct got_error *search_next_view_match(struct tog_view *);
static const struct got_error *open_log_view(struct tog_view *,
static const struct got_error *reset_blame_view(struct tog_view *);
static const struct got_error *close_blame_view(struct tog_view *);
static const struct got_error *search_start_blame_view(struct tog_view *);
+static void search_setup_blame_view(struct tog_view *, FILE **, off_t **,
+ size_t *, int **, int **, int **, int **);
static const struct got_error *open_tree_view(struct tog_view *,
struct got_object_id *, const char *, struct got_repository *);
static const struct got_error *close_ref_view(struct tog_view *);
static const struct got_error *search_start_ref_view(struct tog_view *);
static const struct got_error *search_next_ref_view(struct tog_view *);
+
+static const struct got_error *open_help_view(struct tog_view *,
+ struct tog_view *);
+static const struct got_error *show_help_view(struct tog_view *);
+static const struct got_error *input_help_view(struct tog_view **,
+ struct tog_view *, int);
+static const struct got_error *reset_help_view(struct tog_view *);
+static const struct got_error* close_help_view(struct tog_view *);
+static const struct got_error *search_start_help_view(struct tog_view *);
+static void search_setup_help_view(struct tog_view *, FILE **, off_t **,
+ size_t *, int **, int **, int **, int **);
static volatile sig_atomic_t tog_sigwinch_received;
static volatile sig_atomic_t tog_sigpipe_received;
return NULL;
}
-static const struct got_error *
-search_set_view(struct tog_view *view, FILE **f, off_t **line_offsets,
+static void
+search_setup_diff_view(struct tog_view *view, FILE **f, off_t **line_offsets,
size_t *nlines, int **first, int **last, int **match, int **selected)
{
- *f = NULL;
- *first = *last = *match = *selected = NULL;
- *line_offsets = NULL;
-
- switch (view->type) {
- case (TOG_VIEW_DIFF): {
- struct tog_diff_view_state *s = &view->state.diff;
-
- *f = s->f;
- *nlines = s->nlines;
- *match = &s->matched_line;
- *first = &s->first_displayed_line;
- *last = &s->last_displayed_line;
- *selected = &s->selected_line;
- break;
- }
- case (TOG_VIEW_BLAME): {
- struct tog_blame_view_state *s = &view->state.blame;
+ struct tog_diff_view_state *s = &view->state.diff;
- *f = s->blame.f;
- *nlines = s->blame.nlines;
- *line_offsets = s->blame.line_offsets;
- *match = &s->matched_line;
- *first = &s->first_displayed_line;
- *last = &s->last_displayed_line;
- *selected = &s->selected_line;
- break;
- }
- case (TOG_VIEW_HELP): {
- struct tog_help_view_state *s = &view->state.help;
-
- *f = s->f;
- *nlines = s->nlines;
- *line_offsets = s->line_offsets;
- *match = &s->matched_line;
- *first = &s->first_displayed_line;
- *last = &s->last_displayed_line;
- *selected = &s->selected_line;
- break;
- }
- default:
- return got_error_msg(GOT_ERR_NOT_IMPL,
- "view search not supported");
- }
-
- return NULL;
+ *f = s->f;
+ *nlines = s->nlines;
+ *line_offsets = NULL;
+ *match = &s->matched_line;
+ *first = &s->first_displayed_line;
+ *last = &s->last_displayed_line;
+ *selected = &s->selected_line;
}
static const struct got_error *
size_t nlines = 0;
int *first, *last, *match, *selected;
- err = search_set_view(view, &f, &line_offsets, &nlines, &first, &last,
+ if (!view->search_setup)
+ return got_error_msg(GOT_ERR_NOT_IMPL,
+ "view search not supported");
+ view->search_setup(view, &f, &line_offsets, &nlines, &first, &last,
&match, &selected);
- if (err)
- return err;
if (!view->searching) {
view->search_next_done = TOG_SEARCH_HAVE_MORE;
view->reset = reset_diff_view;
view->close = close_diff_view;
view->search_start = search_start_diff_view;
+ view->search_setup = search_setup_diff_view;
view->search_next = search_next_view_match;
done:
if (err)
view->reset = reset_blame_view;
view->close = close_blame_view;
view->search_start = search_start_blame_view;
+ view->search_setup = search_setup_blame_view;
view->search_next = search_next_view_match;
return run_blame(view);
s->matched_line = 0;
return NULL;
+}
+
+static void
+search_setup_blame_view(struct tog_view *view, FILE **f, off_t **line_offsets,
+ size_t *nlines, int **first, int **last, int **match, int **selected)
+{
+ struct tog_blame_view_state *s = &view->state.blame;
+
+ *f = s->blame.f;
+ *nlines = s->blame.nlines;
+ *line_offsets = s->blame.line_offsets;
+ *match = &s->matched_line;
+ *first = &s->first_displayed_line;
+ *last = &s->last_displayed_line;
+ *selected = &s->selected_line;
}
static const struct got_error *
return NULL;
}
+static void
+search_setup_help_view(struct tog_view *view, FILE **f, off_t **line_offsets,
+ size_t *nlines, int **first, int **last, int **match, int **selected)
+{
+ struct tog_help_view_state *s = &view->state.help;
+
+ *f = s->f;
+ *nlines = s->nlines;
+ *line_offsets = s->line_offsets;
+ *match = &s->matched_line;
+ *first = &s->first_displayed_line;
+ *last = &s->last_displayed_line;
+ *selected = &s->selected_line;
+}
+
static const struct got_error *
show_help_view(struct tog_view *view)
{
view->reset = reset_help_view;
view->close = close_help_view;
view->search_start = search_start_help_view;
+ view->search_setup = search_setup_help_view;
view->search_next = search_next_view_match;
err = create_help(s);