/* * find_open: start iterator without GPATH. * * i) start start directory * If NULL, assumed '.' directory. */ void find_open(const char *start) { struct stack_entry *curp; assert(find_mode == 0); find_mode = FIND_OPEN; /* * This is temporary measures. It doesn't decide how to become final. */ if (getenv("GTAGSALLOWBLANK")) allow_blank = 1; if (!start) start = "./"; /* * setup stack. */ stack = varray_open(sizeof(struct stack_entry), 50); current_entry = 0; curp = varray_assign(stack, current_entry, 1); strlimcpy(dir, start, sizeof(dir)); curp->dirp = dir + strlen(dir); curp->sb = strbuf_open(0); if (getdirs(dir, curp->sb) < 0) die("cannot open '.' directory."); curp->start = curp->p = strbuf_value(curp->sb); curp->end = curp->start + strbuf_getlen(curp->sb); /* * prepare regular expressions. */ prepare_source(); prepare_skip(); }
/* * Find a manpage. */ static int manual(struct man_node *manp, char *name) { struct man_node *p; struct man_node *local; int ndirs = 0; char *ldir; char *ldirs[2]; char *fullname = name; char *slash; if ((slash = strrchr(name, '/')) != NULL) name = slash + 1; /* For each path in MANPATH */ found = 0; for (p = manp; p != NULL; p = p->next) { DPRINTF("-- Searching mandir: %s\n", p->path); if (*localedir != '\0') { ldir = addlocale(p->path); ndirs = getdirs(ldir, NULL, 0); if (ndirs != 0) { ldirs[0] = ldir; ldirs[1] = NULL; local = build_manpath(ldirs, 0); DPRINTF("-- Locale specific subdir: %s\n", ldir); mandir(local->secv, ldir, name, 1); free_manp(local); } free(ldir); } /* * Locale mandir not valid, man page in locale * mandir not found, or -a option present */ if (ndirs == 0 || !found || all) mandir(p->secv, p->path, name, 0); if (found && !all) break; } if (!found) { if (sargs) { (void) fprintf(stderr, gettext( "No manual entry for %s in section(s) %s\n"), fullname, mansec); } else { (void) fprintf(stderr, gettext("No manual entry for %s\n"), fullname); } } return (!found); }
/* * Build whatis databases. */ static void do_makewhatis(struct man_node *manp) { struct man_node *p; char *ldir; for (p = manp; p != NULL; p = p->next) { ldir = addlocale(p->path); if (*localedir != '\0' && getdirs(ldir, NULL, 0) > 0) mwpath(ldir); free(ldir); mwpath(p->path); } }
/* * Find matching whatis or apropos entries. */ static void whatapro(struct man_node *manp, char *word) { char whatpath[MAXPATHLEN]; struct man_node *b; char *ldir; for (b = manp; b != NULL; b = b->next) { if (*localedir != '\0') { ldir = addlocale(b->path); if (getdirs(ldir, NULL, 0) != 0) { (void) snprintf(whatpath, sizeof (whatpath), "%s/%s", ldir, WHATIS); search_whatis(whatpath, word); } free(ldir); } (void) snprintf(whatpath, sizeof (whatpath), "%s/%s", b->path, WHATIS); search_whatis(whatpath, word); } }
/* * find_read_traverse: read path without GPATH. * * r) path */ char * find_read_traverse(void) { static char val[MAXPATHLEN]; char path[MAXPATHLEN]; struct stack_entry *curp = varray_assign(stack, current_entry, 1); for (;;) { while (curp->p < curp->end) { char type = *(curp->p); const char *unit = curp->p + 1; curp->p += strlen(curp->p) + 1; /* * Skip files described in the skip list. */ /* makepath() returns unsafe module local area. */ strlimcpy(path, makepath(dir, unit, NULL), sizeof(path)); if (type == 'd') strcat(path, "/"); if (skipthisfile(path)) continue; if (type == 'f') { /* * Skip the following: * o directory * o file which does not exist * o dead symbolic link */ if (!test("f", path)) { if (test("d", path)) warning("'%s' is a directory. (Ignored)", path); else warning("'%s' not found. (Ignored)", path); continue; } /* * GLOBAL cannot treat path which includes blanks. * It will be improved in the future. */ if (!allow_blank && locatestring(path, " ", MATCH_FIRST)) { warning("'%s' ignored, because it includes blank.", &path[2]); continue; } /* * A blank at the head of path means * other than source file. */ if (regexec(suff, path, 0, 0, 0) == 0) { /* source file */ strlimcpy(val, path, sizeof(val)); } else { /* other file like 'Makefile' */ val[0] = ' '; strlimcpy(&val[1], path, sizeof(val) - 1); } val[sizeof(val) - 1] = '\0'; return val; } if (type == 'd') { STRBUF *sb = strbuf_open(0); char *dirp = curp->dirp; strcat(dirp, unit); strcat(dirp, "/"); if (getdirs(dir, sb) < 0) { warning("cannot open directory '%s'. (Ignored)", dir); strbuf_close(sb); *(curp->dirp) = 0; continue; } /* * Push stack. */ curp = varray_assign(stack, ++current_entry, 1); curp->dirp = dirp + strlen(dirp); curp->sb = sb; curp->start = curp->p = strbuf_value(sb); curp->end = curp->start + strbuf_getlen(sb); } } strbuf_close(curp->sb); curp->sb = NULL; if (current_entry == 0) break; /* * Pop stack. */ curp = varray_assign(stack, --current_entry, 0); *(curp->dirp) = 0; } find_eof = 1; return NULL; }