Search a menu.
60{
61 int rc = -1;
62 int wrap = 0;
63 int search_dir;
64 regex_t re = { 0 };
66
68
69 if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
70 {
71 buf_strcpy(buf, search_buf && (search_buf[0] !=
'\0') ? search_buf :
"");
72 if ((
mw_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
_(
"Search for: ") :
_(
"Reverse search for: "),
75 {
76 goto done;
77 }
79 {
82 }
83 menu->
search_dir = ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
86 }
87
89 if (op == OP_SEARCH_OPPOSITE)
90 search_dir = -search_dir;
91
92 if (search_buf)
93 {
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);
102 rc = -1;
103 goto done;
104 }
105
106 rc = menu->
current + search_dir;
107search_next:
108 if (wrap)
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
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);
129 rc = -1;
130
131done:
133 return rc;
134}
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.