- Use ".TH" lines in unformatted manual pages to find correct section
number. - Always invoke "nroff" if builtin parser for unformatted manual pages fails and try to parse formatted manual page.
This commit is contained in:
parent
bb87fe99b0
commit
fd7e4484fc
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: makewhatis.c,v 1.13 2001/02/19 22:46:14 cgd Exp $ */
|
||||
/* $NetBSD: makewhatis.c,v 1.14 2001/04/08 14:27:50 tron Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\n\
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: makewhatis.c,v 1.13 2001/02/19 22:46:14 cgd Exp $");
|
||||
__RCSID("$NetBSD: makewhatis.c,v 1.14 2001/04/08 14:27:50 tron Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -79,9 +79,11 @@ struct whatisstruct {
|
||||
};
|
||||
|
||||
int main (int, char **);
|
||||
char *findwhitespace(char *);
|
||||
char *GetS(gzFile, char *, int);
|
||||
char *findwhitespace (char *);
|
||||
char *strmove (char *,char *);
|
||||
char *GetS (gzFile, char *, int);
|
||||
int manpagesection (char *);
|
||||
char *createsectionstring(char *);
|
||||
int addmanpage (manpage **, ino_t, char *);
|
||||
int addwhatis (whatis **, char *);
|
||||
char *replacestring (char *, char *, char *);
|
||||
@ -175,6 +177,13 @@ char
|
||||
return str;
|
||||
}
|
||||
|
||||
char
|
||||
*strmove(char *dest,char *src)
|
||||
|
||||
{
|
||||
return memmove(dest, src, strlen(src) + 1);
|
||||
}
|
||||
|
||||
char
|
||||
*GetS(gzFile in, char *buffer, int length)
|
||||
|
||||
@ -212,6 +221,19 @@ manpagesection(char *name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
char
|
||||
*createsectionstring(char *section_id)
|
||||
{
|
||||
char *section;
|
||||
|
||||
if ((section = malloc(strlen(section_id) + 7)) != NULL) {
|
||||
section[0] = ' ';
|
||||
section[1] = '(';
|
||||
(void) strcat(strcpy(§ion[2], section_id), ") - ");
|
||||
}
|
||||
return section;
|
||||
}
|
||||
|
||||
int
|
||||
addmanpage(manpage **tree,ino_t inode,char *name)
|
||||
{
|
||||
@ -410,7 +432,9 @@ manpreprocess(char *line)
|
||||
case '\0':
|
||||
case '-':
|
||||
break;
|
||||
case 'f':
|
||||
case 's':
|
||||
from++;
|
||||
if ((*from=='+') || (*from=='-'))
|
||||
from++;
|
||||
while (isdigit(*from))
|
||||
@ -575,16 +599,28 @@ parsemanpage(gzFile *in, int defaultsection)
|
||||
*end = '\0';
|
||||
|
||||
free(section);
|
||||
if ((section = malloc(strlen(ptr) + 7)) != NULL) {
|
||||
section[0] = ' ';
|
||||
section[1] = '(';
|
||||
(void) strcpy(§ion[2], ptr);
|
||||
(void) strcat(§ion[2], ") - ");
|
||||
section = createsectionstring(ptr);
|
||||
}
|
||||
else if (strncasecmp(buffer, ".TH", 3) == 0) {
|
||||
ptr = &buffer[3];
|
||||
while (isspace(*ptr))
|
||||
ptr++;
|
||||
if ((ptr = findwhitespace(ptr)) != NULL) {
|
||||
char *next;
|
||||
|
||||
while (isspace(*ptr))
|
||||
ptr++;
|
||||
if ((next = findwhitespace(ptr)) != NULL)
|
||||
*next = '\0';
|
||||
free(section);
|
||||
section = createsectionstring(ptr);
|
||||
}
|
||||
}
|
||||
else if (strncasecmp(buffer, ".Ds", 3) == 0)
|
||||
return nroff(in);
|
||||
} while ((strncasecmp(buffer, ".Sh NAME", 8) != 0));
|
||||
else if (strncasecmp(buffer, ".Ds", 3) == 0) {
|
||||
free(section);
|
||||
return NULL;
|
||||
}
|
||||
} while (strncasecmp(buffer, ".Sh NAME", 8) != 0);
|
||||
|
||||
do {
|
||||
if (GetS(in, buffer, sizeof(buffer) - 1) == NULL) {
|
||||
@ -652,12 +688,12 @@ parsemanpage(gzFile *in, int defaultsection)
|
||||
if (*ptr == '.') {
|
||||
char *space;
|
||||
|
||||
if ((space = findwhitespace(ptr)) == NULL)
|
||||
space = findwhitespace(ptr);
|
||||
if (space == NULL)
|
||||
ptr = "";
|
||||
else {
|
||||
space++;
|
||||
(void) memmove(ptr, space,
|
||||
strlen(space) + 1);
|
||||
(void) strmove(ptr, space);
|
||||
}
|
||||
}
|
||||
|
||||
@ -684,12 +720,12 @@ parsemanpage(gzFile *in, int defaultsection)
|
||||
if (*buffer == '.') {
|
||||
char *space;
|
||||
|
||||
if ((space = findwhitespace(buffer)) == NULL) {
|
||||
if ((space = findwhitespace(&buffer[1])) == NULL) {
|
||||
free(section);
|
||||
return NULL;
|
||||
}
|
||||
space++;
|
||||
(void) memmove(buffer, space, strlen(space) + 1);
|
||||
(void) strmove(buffer, space);
|
||||
}
|
||||
|
||||
offset = strlen(buffer) + 1;
|
||||
@ -762,7 +798,13 @@ getwhatisdata(char *name)
|
||||
}
|
||||
|
||||
section = manpagesection(name);
|
||||
data = (section == 0) ? parsecatpage(in) : parsemanpage(in, section);
|
||||
if (section == 0)
|
||||
data = parsecatpage(in);
|
||||
else {
|
||||
data = parsemanpage(in, section);
|
||||
if (data == NULL)
|
||||
data = nroff(in);
|
||||
}
|
||||
|
||||
(void) gzclose(in);
|
||||
return data;
|
||||
|
Loading…
Reference in New Issue
Block a user