Search a menu.
58{
59 int rc = -1;
60 int wrap = 0;
61 int search_dir;
62 regex_t re = { 0 };
64
66
67 if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
68 {
69 buf_strcpy(buf, search_buf && (search_buf[0] !=
'\0') ? search_buf :
"");
70 if ((
mw_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
_(
"Search for: ") :
_(
"Reverse search for: "),
73 {
74 goto done;
75 }
77 {
80 }
81 menu->
search_dir = ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
84 }
85
87 if (op == OP_SEARCH_OPPOSITE)
88 search_dir = -search_dir;
89
90 if (search_buf)
91 {
93 rc =
REG_COMP(&re, search_buf, REG_NOSUB | flags);
94 }
95
96 if (rc != 0)
97 {
100 rc = -1;
101 goto done;
102 }
103
104 rc = menu->
current + search_dir;
105search_next:
106 if (wrap)
108 while ((rc >= 0) && (rc < menu->max))
109 {
110 if (menu->
search(menu, &re, rc) == 0)
111 {
112 regfree(&re);
113 goto done;
114 }
115
116 rc += search_dir;
117 }
118
120 if (c_wrap_search && (wrap++ == 0))
121 {
122 rc = (search_dir == 1) ? 0 : menu->
max - 1;
123 goto search_next;
124 }
125 regfree(&re);
127 rc = -1;
128
129done:
131 return rc;
132}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
int mw_get_field(const char *prompt, struct Buffer *buf, CompletionFlags complete, enum HistoryClass hclass, const struct CompleteOps *comp_api, void *cdata)
Ask the user for a string -.
#define mutt_message(...)
@ HC_OTHER
Miscellaneous strings.
bool mutt_mb_is_lower(const char *s)
Does a multi-byte string contain only lowercase characters?
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
#define MUTT_COMP_CLEAR
Clear input if printable character is pressed.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
String manipulation buffer.
size_t dsize
Length of data.
char * data
Pointer to data.