Download raw body.
tog: add search_setup fp for consistency
On Sat, Sep 17, 2022 at 01:37:03AM +1000, Mark Jamsek wrote: > As per stsp's suggestion, refactor the previous search setup switch > routine into tog_view function pointers. > > While here, I've added declarations for the new help view methods > (e.g., {close,input,open,reset,show}_help_view) for consistency too. Nice, ok stsp > ----------------------------------------------- > commit cb28de825895f109971cd595bba0afd3963b723f > from: Mark Jamsek <mark@jamsek.dev> > date: Fri Sep 16 15:31:21 2022 UTC > > tog: refactor search setup into tog_view function pointers > > Suggested by stsp. While here, add declarations for new help view routines. > > diff ec2a9698e29a1ee9152c8740cdce9603d84d224d cb28de825895f109971cd595bba0afd3963b723f > commit - ec2a9698e29a1ee9152c8740cdce9603d84d224d > commit + cb28de825895f109971cd595bba0afd3963b723f > blob - b11f730773e3daa0c7f7d516291ac268215a3ecf > blob + f0f8ee12b7aa441a0f5dd2a8e93888e7ba94ed3c > --- tog/tog.c > +++ tog/tog.c > @@ -676,6 +676,8 @@ struct tog_view { > > 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 > @@ -698,6 +700,8 @@ static const struct got_error *input_diff_view(struct > 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 *, > @@ -719,6 +723,8 @@ static const struct got_error *input_blame_view(struct > 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 *); > @@ -738,6 +744,17 @@ static const struct got_error *close_ref_view(struct t > 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; > static volatile sig_atomic_t tog_sigcont_received; > @@ -4770,56 +4787,18 @@ search_start_diff_view(struct tog_view *view) > 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; > + struct tog_diff_view_state *s = &view->state.diff; > > - 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; > - > - *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; > + *match = &s->matched_line; > + *first = &s->first_displayed_line; > + *last = &s->last_displayed_line; > + *selected = &s->selected_line; > } > > static const struct got_error * > @@ -4835,10 +4814,11 @@ search_next_view_match(struct tog_view *view) > 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; > @@ -5062,6 +5042,7 @@ open_diff_view(struct tog_view *view, struct got_objec > 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) > @@ -6105,6 +6086,7 @@ open_blame_view(struct tog_view *view, char *path, > 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); > @@ -6140,6 +6122,21 @@ search_start_blame_view(struct tog_view *view) > 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 * > show_blame_view(struct tog_view *view) > { > @@ -8608,6 +8605,21 @@ search_start_help_view(struct tog_view *view) > 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) > { > @@ -8904,6 +8916,7 @@ open_help_view(struct tog_view *view, struct tog_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); > > > -- > Mark Jamsek <fnc.bsdbox.org> > GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68
tog: add search_setup fp for consistency