Coverage Report

Created: 2023-09-25 07:17

/src/neomutt/history/functions.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * @file
3
 * History functions
4
 *
5
 * @authors
6
 * Copyright (C) 2022 Richard Russon <rich@flatcap.org>
7
 *
8
 * @copyright
9
 * This program is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU General Public License as published by the Free Software
11
 * Foundation, either version 2 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU General Public License along with
20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
/**
24
 * @page history_functions History functions
25
 *
26
 * History functions
27
 */
28
29
#include "config.h"
30
#include "mutt/lib.h"
31
#include "core/lib.h"
32
#include "gui/lib.h"
33
#include "functions.h"
34
#include "menu/lib.h"
35
36
/**
37
 * op_generic_select_entry - Select the current entry - Implements ::history_function_t - @ingroup history_function_api
38
 */
39
static int op_generic_select_entry(struct HistoryData *hd, int op)
40
{
41
  const int index = menu_get_index(hd->menu);
42
  mutt_str_copy(hd->buf, hd->matches[index], hd->buflen);
43
44
  hd->done = true;
45
  hd->selection = true;
46
  return FR_SUCCESS;
47
}
48
49
/**
50
 * op_quit - Quit this menu - Implements ::history_function_t - @ingroup history_function_api
51
 */
52
static int op_quit(struct HistoryData *hd, int op)
53
{
54
  hd->done = true;
55
  hd->selection = false;
56
  return FR_SUCCESS;
57
}
58
59
// -----------------------------------------------------------------------------
60
61
/**
62
 * HistoryFunctions - All the NeoMutt functions that the History supports
63
 */
64
static const struct HistoryFunction HistoryFunctions[] = {
65
  // clang-format off
66
  { OP_GENERIC_SELECT_ENTRY,   op_generic_select_entry },
67
  { OP_QUIT,                   op_quit },
68
  { 0, NULL },
69
  // clang-format on
70
};
71
72
/**
73
 * history_function_dispatcher - Perform a History function - Implements ::function_dispatcher_t - @ingroup dispatcher_api
74
 */
75
int history_function_dispatcher(struct MuttWindow *win, int op)
76
0
{
77
0
  if (!win || !win->wdata)
78
0
    return FR_UNKNOWN;
79
80
0
  struct MuttWindow *dlg = dialog_find(win);
81
0
  if (!dlg)
82
0
    return FR_ERROR;
83
84
0
  struct HistoryData *hd = dlg->wdata;
85
86
0
  int rc = FR_UNKNOWN;
87
0
  for (size_t i = 0; HistoryFunctions[i].op != OP_NULL; i++)
88
0
  {
89
0
    const struct HistoryFunction *fn = &HistoryFunctions[i];
90
0
    if (fn->op == op)
91
0
    {
92
0
      rc = fn->function(hd, op);
93
0
      break;
94
0
    }
95
0
  }
96
97
0
  if (rc == FR_UNKNOWN) // Not our function
98
0
    return rc;
99
100
0
  const char *result = dispatcher_get_retval_name(rc);
101
0
  mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
102
103
0
  return rc;
104
0
}