static void addglobdir (const char *bp, int mandatory) { const char *dir; while (whitespace(*bp)) bp++; dir = bp; if (index(dir, '*') || index(dir, '?') || index(dir, '[')) { char **dp = glob_filename (dir); if (dp && dp != (char **) -1) { while (*dp) adddir(*dp++, mandatory); return; } } adddir(dir, mandatory); }
static void remove_other_catfiles (const char *catfile) { char *pathname; char *t; char **gf; int offset; pathname = my_strdup(catfile); t = rindex(pathname, '.'); if (t == NULL || strcmp(t, getval("COMPRESS_EXT"))) return; offset = t - pathname; strcpy(t, "*"); gf = glob_filename (pathname); if (gf != (char **) -1 && gf != NULL) { for ( ; *gf; gf++) { /* * Only remove files with a known extension, like .Z * (otherwise we might kill a lot when called with * catfile = ".gz" ...) */ if (strlen (*gf) <= offset) { if (strlen (*gf) == offset) /* uncompressed version */ remove_file (*gf); continue; } if (!strcmp (*gf + offset, getval("COMPRESS_EXT"))) continue; if (get_expander (*gf) != NULL) remove_file (*gf); } } }
// 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)); }
/* return 0 when all was OK */ static int do_global_apropos (char *name, char *section) { char **dp, **gf; char *pathname; char *command; int status, res; status = 0; init_manpath(); if (mandirlist) for (dp = mandirlist; *dp; dp++) { if (debug) gripe(SEARCHING, *dp); pathname = my_xsprintf("%s/man%s/*", *dp, section ? section : "*"); gf = glob_filename (pathname); free(pathname); if (gf != (char **) -1 && gf != NULL) { for( ; *gf; gf++) { const char *expander = get_expander (*gf); if (expander) command = my_xsprintf("%s %S | grep '%Q'" "> /dev/null 2> /dev/null", expander, *gf, name); else command = my_xsprintf("grep '%Q' %S" "> /dev/null 2> /dev/null", name, *gf); res = do_system_command (command, 1); status |= res; free (command); if (res == 0) { if (print_where) printf("%s\n", *gf); else { /* should read LOCALE, but libc 4.6.27 doesn't seem to handle LC_RESPONSE yet */ int answer, c; char path[BUFSIZE]; printf("%s? [ynq] ", *gf); fflush(stdout); answer = c = getchar(); while (c != '\n' && c != EOF) c = getchar(); if(index("QqXx", answer)) exit(0); if(index("YyJj", answer)) { char *ri; strcpy(path, *gf); ri = rindex(path, '/'); if (ri) *ri = 0; format_and_display(*gf); } } } } } } return status; }