NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
functions.c File Reference

Menu functions. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "functions.h"
#include "lib.h"
#include "enter/lib.h"
#include "opcodes.h"
#include "protos.h"
#include "type.h"
+ Include dependency graph for functions.c:

Go to the source code of this file.

Macros

#define MUTT_SEARCH_UP   1
 
#define MUTT_SEARCH_DOWN   2
 

Functions

static int search (struct Menu *menu, int op)
 Search a menu. More...
 
static int menu_movement (struct Menu *menu, int op)
 Handle all the common Menu movements - Implements menu_function_t -. More...
 
static int menu_search (struct Menu *menu, int op)
 Handle Menu searching - Implements menu_function_t -. More...
 
static int op_help (struct Menu *menu, int op)
 Show the help screen - Implements menu_function_t -. More...
 
static int op_jump (struct Menu *menu, int op)
 Jump to an index number - Implements menu_function_t -. More...
 
int menu_function_dispatcher (struct MuttWindow *win, int op)
 Perform a Menu function - Implements function_dispatcher_t -. More...
 

Variables

char * SearchBuffers []
 
struct MenuFunction MenuFunctions []
 All the NeoMutt functions that the Menu supports. More...
 

Detailed Description

Menu functions.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file functions.c.

Macro Definition Documentation

◆ MUTT_SEARCH_UP

#define MUTT_SEARCH_UP   1

Definition at line 47 of file functions.c.

◆ MUTT_SEARCH_DOWN

#define MUTT_SEARCH_DOWN   2

Definition at line 48 of file functions.c.

Function Documentation

◆ search()

static int search ( struct Menu menu,
int  op 
)
static

Search a menu.

Parameters
menuMenu to search
opSearch operation, e.g. OP_SEARCH_NEXT
Return values
>=0Index of matching item
-1Search failed, or was cancelled

Definition at line 57 of file functions.c.

58{
59 int rc = -1;
60 int wrap = 0;
61 int search_dir;
62 regex_t re = { 0 };
63 struct Buffer *buf = mutt_buffer_pool_get();
64
65 char *search_buf = ((menu->type < MENU_MAX)) ? SearchBuffers[menu->type] : NULL;
66
67 if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
68 {
69 mutt_buffer_strcpy(buf, search_buf && (search_buf[0] != '\0') ? search_buf : "");
70 if ((mutt_buffer_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
71 _("Search for: ") :
72 _("Reverse search for: "),
73 buf, MUTT_COMP_CLEAR, false, NULL, NULL, NULL) != 0) ||
75 {
76 goto done;
77 }
78 if (menu->type < MENU_MAX)
79 {
81 search_buf = SearchBuffers[menu->type];
82 }
83 menu->search_dir = ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
86 }
87
88 search_dir = (menu->search_dir == MUTT_SEARCH_UP) ? -1 : 1;
89 if (op == OP_SEARCH_OPPOSITE)
90 search_dir = -search_dir;
91
92 if (search_buf)
93 {
94 uint16_t flags = mutt_mb_is_lower(search_buf) ? REG_ICASE : 0;
95 rc = REG_COMP(&re, search_buf, REG_NOSUB | flags);
96 }
97
98 if (rc != 0)
99 {
100 regerror(rc, &re, buf->data, buf->dsize);
101 mutt_error("%s", mutt_buffer_string(buf));
102 rc = -1;
103 goto done;
104 }
105
106 rc = menu->current + search_dir;
107search_next:
108 if (wrap)
109 mutt_message(_("Search wrapped to top"));
110 while ((rc >= 0) && (rc < menu->max))
111 {
112 if (menu->search(menu, &re, rc) == 0)
113 {
114 regfree(&re);
115 goto done;
116 }
117
118 rc += search_dir;
119 }
120
121 const bool c_wrap_search = cs_subset_bool(menu->sub, "wrap_search");
122 if (c_wrap_search && (wrap++ == 0))
123 {
124 rc = (search_dir == 1) ? 0 : menu->max - 1;
125 goto search_next;
126 }
127 regfree(&re);
128 mutt_error(_("Not found"));
129 rc = -1;
130
131done:
133 return rc;
134}
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:260
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:327
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
int mutt_buffer_get_field(const char *field, struct Buffer *buf, CompletionFlags complete, bool multiple, struct Mailbox *m, char ***files, int *numfiles)
Ask the user for a string.
Definition: window.c:180
#define mutt_error(...)
Definition: logging.h:87
#define mutt_message(...)
Definition: logging.h:86
bool mutt_mb_is_lower(const char *s)
Does a multi-byte string contain only lowercase characters?
Definition: mbyte.c:355
#define MUTT_SEARCH_DOWN
Definition: functions.c:48
#define MUTT_SEARCH_UP
Definition: functions.c:47
char * SearchBuffers[]
Definition: menu.c:41
#define _(a)
Definition: message.h:28
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:326
#define MUTT_COMP_CLEAR
Clear input if printable character is pressed.
Definition: mutt.h:62
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:53
String manipulation buffer.
Definition: buffer.h:34
size_t dsize
Length of data.
Definition: buffer.h:37
char * data
Pointer to data.
Definition: buffer.h:35
int search_dir
Direction of search.
Definition: lib.h:82
int current
Current entry.
Definition: lib.h:70
int(* search)(struct Menu *menu, regex_t *rx, int line)
Definition: lib.h:109
enum MenuType type
Menu definition for keymap entries.
Definition: lib.h:73
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:77
int max
Number of entries in the menu.
Definition: lib.h:71
@ MENU_MAX
Definition: type.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ SearchBuffers

char* SearchBuffers[]
extern

Definition at line 41 of file menu.c.

◆ MenuFunctions

struct MenuFunction MenuFunctions[]

All the NeoMutt functions that the Menu supports.

Definition at line 280 of file functions.c.