+static int regex_match(const char *string, regex_t *re)
+{
+ int rc;
+
+ rc = regexec(re, string, (size_t) 0, NULL, 0);
+ if (rc)
+ return 0;
+ return 1;
+}
+
+static void show_expr(struct menu *menu, FILE *fp)
+{
+ bool hit = false;
+ fprintf(fp, "Depends:\n ");
+ if (menu->prompt->visible.expr) {
+ if (!hit)
+ hit = true;
+ expr_fprint(menu->prompt->visible.expr, fp);
+ }
+ if (!hit)
+ fprintf(fp, "None");
+ if (menu->sym) {
+ struct property *prop;
+ hit = false;
+ fprintf(fp, "\nSelects:\n ");
+ for_all_properties(menu->sym, prop, P_SELECT) {
+ if (!hit)
+ hit = true;
+ expr_fprint(prop->expr, fp);
+ }
+ if (!hit)
+ fprintf(fp, "None");
+ hit = false;
+ fprintf(fp, "\nSelected by:\n ");
+ if (menu->sym->rev_dep.expr) {
+ hit = true;
+ expr_fprint(menu->sym->rev_dep.expr, fp);
+ }
+ if (!hit)
+ fprintf(fp, "None");
+ }
+}
+
+static void search_conf(char *pattern)
+{
+ struct symbol *sym = NULL;
+ struct menu *menu[32] = { 0 };
+ struct property *prop = NULL;
+ FILE *fp = NULL;
+ bool hit = false;
+ int i, j, k, l;
+ regex_t re;
+
+ if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB))
+ return;
+
+ fp = fopen(".search.tmp", "w");
+ if (fp == NULL) {
+ perror("fopen");
+ return;
+ }
+ for_all_symbols(i, sym) {
+ if (!sym->name)
+ continue;
+ if (!regex_match(sym->name, &re))
+ continue;
+ for_all_prompts(sym, prop) {
+ struct menu *submenu = prop->menu;
+ if (!submenu)
+ continue;
+ j = 0;
+ hit = false;
+ while (submenu) {
+ menu[j++] = submenu;
+ submenu = submenu->parent;
+ }
+ if (j > 0) {
+ if (!hit)
+ hit = true;
+ fprintf(fp, "%s (%s)\n", prop->text, sym->name);
+ fprintf(fp, "Location:\n");
+ }
+ for (k = j-2, l=1; k > 0; k--, l++) {
+ const char *prompt = menu_get_prompt(menu[k]);
+ if (menu[k]->sym)
+ fprintf(fp, "%*c-> %s (%s)\n",
+ l, ' ',
+ prompt,
+ menu[k]->sym->name);
+ else
+ fprintf(fp, "%*c-> %s\n",
+ l, ' ',
+ prompt);
+ }
+ if (hit) {
+ show_expr(menu[0], fp);
+ fprintf(fp, "\n\n\n");
+ }
+ }
+ }
+ if (!hit)
+ fprintf(fp, "No matches found.");
+ regfree(&re);
+ fclose(fp);
+ show_file(".search.tmp", "Search Results", rows, cols);
+ unlink(".search.tmp");
+}
+