summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authortron <tron@NetBSD.org>2001-04-08 14:27:50 +0000
committertron <tron@NetBSD.org>2001-04-08 14:27:50 +0000
commitfd7e4484fcd4404817e010b9176db06a2f6afc95 (patch)
tree65e868f6434296b1d0c9922573034b9971294862 /libexec
parentbb87fe99b0a0a223368ca0dcd66d471331fe9ecd (diff)
- 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.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/makewhatis/makewhatis.c78
1 files changed, 60 insertions, 18 deletions
diff --git a/libexec/makewhatis/makewhatis.c b/libexec/makewhatis/makewhatis.c
index d827e949c8a..73cd56a8c08 100644
--- a/libexec/makewhatis/makewhatis.c
+++ b/libexec/makewhatis/makewhatis.c
@@ -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 *);
@@ -176,6 +178,13 @@ char
}
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(&section[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(&section[2], ptr);
- (void) strcat(&section[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;