Search a menu.
59{
60 int rc = -1;
61 int wrap = 0;
62 int search_dir;
63 regex_t re = { 0 };
65
68 NULL;
69
70 if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
71 {
72 buf_strcpy(buf, search_buf && (search_buf[0] !=
'\0') ? search_buf :
"");
73 if ((
mw_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
_(
"Search for: ") :
_(
"Reverse search for: "),
76 {
77 goto done;
78 }
80 {
83 }
84 menu->
search_dir = ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
87 }
88
90 if (op == OP_SEARCH_OPPOSITE)
91 search_dir = -search_dir;
92
93 if (search_buf)
94 {
96 rc =
REG_COMP(&re, search_buf, REG_NOSUB | flags);
97 }
98
99 if (rc != 0)
100 {
101 regerror(rc, &re, buf->
data, buf->
dsize);
103 rc = -1;
104 goto done;
105 }
106
107 rc = menu->
current + search_dir;
108search_next:
109 if (wrap)
111 while ((rc >= 0) && (rc < menu->max))
112 {
113 if (menu->
search(menu, &re, rc) == 0)
114 {
115 regfree(&re);
116 goto done;
117 }
118
119 rc += search_dir;
120 }
121
123 if (c_wrap_search && (wrap++ == 0))
124 {
125 rc = (search_dir == 1) ? 0 : menu->max - 1;
126 goto search_next;
127 }
128 regfree(&re);
130 rc = -1;
131
132done:
134 return rc;
135}
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.
#define MUTT_COMP_CLEAR
Clear input if printable character is pressed.
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.
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.