// Get list of sources into SOURCES_LIST void get_gdb_sources(StringArray& sources_list) { static const StringArray empty; sources_list = empty; string ans = gdb_question("info sources"); if (ans != NO_GDB_ANSWER) { // Create a newline-separated list of sources string new_ans; while (!ans.empty()) { string line = ans.before('\n'); ans = ans.after('\n'); if (line.empty() || line.contains(':', -1)) continue; line.gsub(", ", "\n"); new_ans += line + '\n'; } ans = new_ans; while (!ans.empty()) { string line = ans.before('\n'); ans = ans.after('\n'); sources_list += line; } smart_sort(sources_list); uniq(sources_list); } }
// Update combo box containing TEXT static void update_combo_box(Widget text, HistoryFilter filter) { StringArray entries; for (int i = gdb_history.size() - 1; i >= 0; i--) { const string& entry = gdb_history[i]; string arg = filter(entry); if (arg.empty()) continue; // Empty arg if (entries.size() > 0 && entries[entries.size() - 1] == arg) continue; // Adjacent duplicate if (app_data.popdown_history_size > 0 && entries.size() >= int(app_data.popdown_history_size)) break; // Enough entries bool found_duplicate = false; if (!app_data.sort_popdown_history) { // We'll not be sorted. If we already have this value, // ignore new entry. for (int j = 0; !found_duplicate && j < entries.size(); j++) found_duplicate = (entries[j] == arg); } if (!found_duplicate) entries += arg; } if (app_data.sort_popdown_history) { smart_sort(entries); uniq(entries); } ComboBoxSetList(text, entries); }
// Search for local files and directories, using the predicate IS_OKAY static void searchLocal(Widget fs, XmFileSelectionBoxCallbackStruct *cbs, bool is_okay(const string& file_name)) { String mask; if (!XmStringGetLtoR(cbs->mask, MSTRING_DEFAULT_CHARSET, &mask)) return; char **files = glob_filename(mask); if (files == (char **)0) { std::cerr << mask << ": glob failed\n"; } else if (files == (char **)-1) { post_error(string(mask) + ": " + strerror(errno)); } else { StatusDelay delay(delay_message); int count; for (count = 0; files[count] != 0; count++) ; smart_sort(files, count); XmStringTable items = XmStringTable(XtMalloc(count * sizeof(XmString))); int nitems = 0; int i; for (i = 0; files[i] != 0; i++) { if (is_okay(files[i])) items[nitems++] = XmStringCreateLtoR(files[i], MSTRING_DEFAULT_CHARSET); free(files[i]); int percent = (i * 100) / count; int old_percent = ((i - 1) * 100) / count; if (percent % 10 == 0 && old_percent % 10 != 0) { std::ostringstream status; status << delay_message << "... (" << percent << "% processed)"; string s(status); set_status(s, true); } } free((char *)files); if (nitems > 0) { XtVaSetValues(fs, XmNfileListItems, items, XmNfileListItemCount, nitems, XmNdirSpec, items[0], XmNlistUpdated, True, XtPointer(0)); } freeXmStringTable(items, nitems); if (nitems > 0) return; } // Error or nothing found XtVaSetValues(fs, XmNfileListItems, 0, XmNfileListItemCount, 0, XmNlistUpdated, True, XtPointer(0)); }