=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/man/Attic/man.c,v retrieving revision 1.42 retrieving revision 1.43 diff -c -r1.42 -r1.43 *** src/usr.bin/man/Attic/man.c 2011/07/05 05:47:20 1.42 --- src/usr.bin/man/Attic/man.c 2011/07/07 04:24:35 1.43 *************** *** 1,4 **** ! /* $OpenBSD: man.c,v 1.42 2011/07/05 05:47:20 schwarze Exp $ */ /* $NetBSD: man.c,v 1.7 1995/09/28 06:05:34 tls Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: man.c,v 1.43 2011/07/07 04:24:35 schwarze Exp $ */ /* $NetBSD: man.c,v 1.7 1995/09/28 06:05:34 tls Exp $ */ /* *************** *** 83,89 **** static void how(char *); static void jump(char **, char *, char *); static int manual(char *, TAG *, glob_t *); ! static void check_companion(char **); static void onsig(int); static void usage(void); --- 83,89 ---- static void how(char *); static void jump(char **, char *, char *); static int manual(char *, TAG *, glob_t *); ! static void check_companion(char **, TAG *); static void onsig(int); static void usage(void); *************** *** 153,159 **** jump(argv, "-k", "apropos"); /* NOTREACHED */ case 'w': ! f_all = f_where = 1; break; case '?': default: --- 153,159 ---- jump(argv, "-k", "apropos"); /* NOTREACHED */ case 'w': ! f_where = 1; break; case '?': default: *************** *** 434,453 **** { ENTRY *ep, *e_sufp, *e_tag; TAG *missp, *sufp; ! int anyfound, cnt, found; char *p, buf[MAXPATHLEN]; anyfound = 0; buf[0] = '*'; /* For each element in the list... */ e_tag = tag == NULL ? NULL : TAILQ_FIRST(&tag->list); for (; e_tag != NULL; e_tag = TAILQ_NEXT(e_tag, q)) { (void)snprintf(buf, sizeof(buf), "%s/%s.*", e_tag->s, page); ! if (glob(buf, ! GLOB_APPEND | GLOB_BRACE | GLOB_NOSORT | GLOB_QUOTE, NULL, pg)) { ! warn("globbing"); (void)cleanup(0); exit(1); } --- 434,487 ---- { ENTRY *ep, *e_sufp, *e_tag; TAG *missp, *sufp; ! int anyfound, cnt, found, globres; char *p, buf[MAXPATHLEN]; anyfound = 0; buf[0] = '*'; + /* Expand the search path. */ + if (f_all != f_where) { + e_tag = tag == NULL ? NULL : TAILQ_FIRST(&tag->list); + for (; e_tag != NULL; e_tag = TAILQ_NEXT(e_tag, q)) { + if (glob(e_tag->s, GLOB_BRACE | GLOB_NOSORT, + NULL, pg)) { + /* No GLOB_NOMATCH here due to {arch,}. */ + warn("globbing directories"); + (void)cleanup(0); + exit(1); + } + ep = e_tag; + for (cnt = 0; cnt < pg->gl_pathc; cnt++) { + if ((e_tag = malloc(sizeof(ENTRY))) == NULL || + (e_tag->s = strdup(pg->gl_pathv[cnt])) == + NULL) { + warn(NULL); + (void)cleanup(0); + exit(1); + } + TAILQ_INSERT_BEFORE(ep, e_tag, q); + } + free(ep->s); + TAILQ_REMOVE(&tag->list, ep, q); + free(ep); + globfree(pg); + pg->gl_pathc = 0; + } + } + /* For each element in the list... */ e_tag = tag == NULL ? NULL : TAILQ_FIRST(&tag->list); for (; e_tag != NULL; e_tag = TAILQ_NEXT(e_tag, q)) { (void)snprintf(buf, sizeof(buf), "%s/%s.*", e_tag->s, page); ! switch (glob(buf, GLOB_APPEND | GLOB_BRACE | GLOB_NOSORT, NULL, pg)) { ! case (0): ! break; ! case (GLOB_NOMATCH): ! continue; ! default: ! warn("globbing files"); (void)cleanup(0); exit(1); } *************** *** 458,465 **** for (cnt = pg->gl_pathc - pg->gl_matchc; cnt < pg->gl_pathc; ++cnt) { ! if (!f_all) ! check_companion(pg->gl_pathv + cnt); /* * Try the _suffix key words first. --- 492,502 ---- for (cnt = pg->gl_pathc - pg->gl_matchc; cnt < pg->gl_pathc; ++cnt) { ! if (!f_all || !f_where) { ! check_companion(pg->gl_pathv + cnt, tag); ! if (*pg->gl_pathv[cnt] == '\0') ! continue; ! } /* * Try the _suffix key words first. *************** *** 512,518 **** } if (found) { next: anyfound = 1; ! if (!f_all) { /* Delete any other matches. */ while (++cnt< pg->gl_pathc) pg->gl_pathv[cnt] = ""; --- 549,555 ---- } if (found) { next: anyfound = 1; ! if (!f_all && !f_where) { /* Delete any other matches. */ while (++cnt< pg->gl_pathc) pg->gl_pathv[cnt] = ""; *************** *** 525,531 **** pg->gl_pathv[cnt] = ""; } ! if (anyfound && !f_all) break; } --- 562,568 ---- pg->gl_pathv[cnt] = ""; } ! if (anyfound && !f_all && !f_where) break; } *************** *** 551,563 **** /* * check_companion -- ! * Check for a companion [un]formatted page ! * and use the newer one of the two. */ static void ! check_companion(char **orig) { struct stat sb_orig, sb_comp; char *p, *pext, comp[MAXPATHLEN]; size_t len; int found; --- 588,602 ---- /* * check_companion -- ! * Check for a companion [un]formatted page. ! * If one is found, skip this page. ! * Use the companion instead, unless it will be found anyway. */ static void ! check_companion(char **orig, TAG *tag) { struct stat sb_orig, sb_comp; char *p, *pext, comp[MAXPATHLEN]; + ENTRY *entry; size_t len; int found; *************** *** 574,587 **** /* Search for slashes. */ for (found = 0; 1; p--) { /* Did not find /{cat,man}. */ if (p == comp) return; /* Pass over one slash, the one before "page". */ ! if (*p != '/' || !found++) continue; /* Rewrite manN/page.N <-> catN/page.0. */ if (!strncmp(p+1, "man", 3)) { --- 613,630 ---- /* Search for slashes. */ for (found = 0; 1; p--) { + if (*p != '/') + continue; /* Did not find /{cat,man}. */ if (p == comp) return; /* Pass over one slash, the one before "page". */ ! if (!found++) { ! len = p - comp; continue; + } /* Rewrite manN/page.N <-> catN/page.0. */ if (!strncmp(p+1, "man", 3)) { *************** *** 610,615 **** --- 653,667 ---- sb_orig.st_mtim.tv_sec == sb_comp.st_mtim.tv_sec && sb_orig.st_mtim.tv_nsec > sb_comp.st_mtim.tv_nsec)) return; + + /* Drop the companion if it is in the path, too. */ + if (f_all || f_where) + for(entry = TAILQ_FIRST(&tag->list); entry != NULL; + entry = TAILQ_NEXT(entry, q)) + if (!strncmp(entry->s, comp, len)) { + **orig = '\0'; + return; + } /* The companion file is newer, use it. */ free(*orig);