Search a menu.
59{
60 int rc = -1;
61 int wrap = 0;
62 int search_dir;
63 regex_t re = { 0 };
65
67
68 if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
69 {
70 buf_strcpy(buf, search_buf && (search_buf[0] !=
'\0') ? search_buf :
"");
71 if ((
mw_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
_(
"Search for: ") :
_(
"Reverse search for: "),
74 {
75 goto done;
76 }
78 {
81 }
82 menu->
search_dir = ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
85 }
86
88 if (op == OP_SEARCH_OPPOSITE)
89 search_dir = -search_dir;
90
91 if (search_buf)
92 {
94 rc =
REG_COMP(&re, search_buf, REG_NOSUB | flags);
95 }
96
97 if (rc != 0)
98 {
101 rc = -1;
102 goto done;
103 }
104
105 rc = menu->
current + search_dir;
106search_next:
107 if (wrap)
109 while ((rc >= 0) && (rc < menu->max))
110 {
111 if (menu->
search(menu, &re, rc) == 0)
112 {
113 regfree(&re);
114 goto done;
115 }
116
117 rc += search_dir;
118 }
119
121 if (c_wrap_search && (wrap++ == 0))
122 {
123 rc = (search_dir == 1) ? 0 : menu->
max - 1;
124 goto search_next;
125 }
126 regfree(&re);
128 rc = -1;
129
130done:
132 return rc;
133}
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.