version 1.39, 2011/12/25 14:58:39 |
version 1.43, 2011/12/31 18:47:52 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
#include <assert.h> |
#include <assert.h> |
|
#include <ctype.h> |
#include <dirent.h> |
#include <dirent.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <getopt.h> |
#include <getopt.h> |
Line 129 static void ofile_argbuild(int, char *[], struct of |
|
Line 130 static void ofile_argbuild(int, char *[], struct of |
|
static void ofile_dirbuild(const char *, const char *, |
static void ofile_dirbuild(const char *, const char *, |
const char *, int, struct of **); |
const char *, int, struct of **); |
static void ofile_free(struct of *); |
static void ofile_free(struct of *); |
static void pformatted(DB *, struct buf *, struct buf *, |
static void pformatted(DB *, struct buf *, |
const struct of *); |
struct buf *, const struct of *); |
static int pman_node(MAN_ARGS); |
static int pman_node(MAN_ARGS); |
static void pmdoc_node(MDOC_ARGS); |
static void pmdoc_node(MDOC_ARGS); |
static int pmdoc_head(MDOC_ARGS); |
static int pmdoc_head(MDOC_ARGS); |
Line 615 index_merge(const struct of *of, struct mparse *mp, |
|
Line 616 index_merge(const struct of *of, struct mparse *mp, |
|
|
|
/* |
/* |
* By default, skip a file if the manual section |
* By default, skip a file if the manual section |
* and architecture given in the file disagree |
* given in the file disagrees with the directory |
* with the directory where the file is located. |
* where the file is located. |
*/ |
*/ |
|
|
skip = 0; |
skip = 0; |
Line 631 index_merge(const struct of *of, struct mparse *mp, |
|
Line 632 index_merge(const struct of *of, struct mparse *mp, |
|
skip = 1; |
skip = 1; |
} |
} |
|
|
|
/* |
|
* Manual page directories exist for each kernel |
|
* architecture as returned by machine(1). |
|
* However, many manuals only depend on the |
|
* application architecture as returned by arch(1). |
|
* For example, some (2/ARM) manuals are shared |
|
* across the "armish" and "zaurus" kernel |
|
* architectures. |
|
* A few manuals are even shared across completely |
|
* different architectures, for example fdformat(1) |
|
* on amd64, i386, sparc, and sparc64. |
|
* Thus, warn about architecture mismatches, |
|
* but don't skip manuals for this reason. |
|
*/ |
|
|
assert(of->arch); |
assert(of->arch); |
assert(march); |
assert(march); |
if (strcasecmp(march, of->arch)) { |
if (strcasecmp(march, of->arch)) { |
Line 639 index_merge(const struct of *of, struct mparse *mp, |
|
Line 655 index_merge(const struct of *of, struct mparse *mp, |
|
"architecture \"%s\" manual " |
"architecture \"%s\" manual " |
"in \"%s\" directory\n", |
"in \"%s\" directory\n", |
fn, march, of->arch); |
fn, march, of->arch); |
skip = 1; |
march = of->arch; |
} |
} |
|
|
/* |
/* |
Line 1319 pman_node(MAN_ARGS) |
|
Line 1335 pman_node(MAN_ARGS) |
|
|
|
if (0 == strncmp(start, "-", 1)) |
if (0 == strncmp(start, "-", 1)) |
start += 1; |
start += 1; |
|
else if (0 == strncmp(start, "\\-\\-", 4)) |
|
start += 4; |
else if (0 == strncmp(start, "\\-", 2)) |
else if (0 == strncmp(start, "\\-", 2)) |
start += 2; |
start += 2; |
else if (0 == strncmp(start, "\\(en", 4)) |
else if (0 == strncmp(start, "\\(en", 4)) |
Line 1349 pman_node(MAN_ARGS) |
|
Line 1367 pman_node(MAN_ARGS) |
|
* By necessity, this involves rather crude guesswork. |
* By necessity, this involves rather crude guesswork. |
*/ |
*/ |
static void |
static void |
pformatted(DB *hash, struct buf *buf, struct buf *dbuf, |
pformatted(DB *hash, struct buf *buf, |
const struct of *of) |
struct buf *dbuf, const struct of *of) |
{ |
{ |
FILE *stream; |
FILE *stream; |
char *line, *p; |
char *line, *p, *title; |
size_t len, plen; |
size_t len, plen, titlesz; |
|
|
if (NULL == (stream = fopen(of->fname, "r"))) { |
if (NULL == (stream = fopen(of->fname, "r"))) { |
if (warnings) |
if (warnings) |
Line 1387 pformatted(DB *hash, struct buf *buf, struct buf *dbuf |
|
Line 1405 pformatted(DB *hash, struct buf *buf, struct buf *dbuf |
|
while (NULL != (line = fgetln(stream, &len))) |
while (NULL != (line = fgetln(stream, &len))) |
if ('\n' != *line && ' ' != *line) |
if ('\n' != *line && ' ' != *line) |
break; |
break; |
|
|
|
/* |
|
* Read up until the next section into a buffer. |
|
* Strip the leading and trailing newline from each read line, |
|
* appending a trailing space. |
|
* Ignore empty (whitespace-only) lines. |
|
*/ |
|
|
|
titlesz = 0; |
|
title = NULL; |
|
|
|
while (NULL != (line = fgetln(stream, &len))) { |
|
if (' ' != *line || '\n' != line[(int)len - 1]) |
|
break; |
|
while (len > 0 && isspace((unsigned char)*line)) { |
|
line++; |
|
len--; |
|
} |
|
if (1 == len) |
|
continue; |
|
title = mandoc_realloc(title, titlesz + len); |
|
memcpy(title + titlesz, line, len); |
|
titlesz += len; |
|
title[(int)titlesz - 1] = ' '; |
|
} |
|
|
|
|
/* |
/* |
* If no page content can be found, or the input line |
* If no page content can be found, or the input line |
* is already the next section header, or there is no |
* is already the next section header, or there is no |
Line 1395 pformatted(DB *hash, struct buf *buf, struct buf *dbuf |
|
Line 1439 pformatted(DB *hash, struct buf *buf, struct buf *dbuf |
|
* description. |
* description. |
*/ |
*/ |
|
|
line = fgetln(stream, &len); |
if (NULL == title || '\0' == *title) { |
if (NULL == line || ' ' != *line || '\n' != line[(int)len - 1]) { |
|
if (warnings) |
if (warnings) |
fprintf(stderr, "%s: cannot find NAME section\n", |
fprintf(stderr, "%s: cannot find NAME section\n", |
of->fname); |
of->fname); |
buf_appendb(dbuf, buf->cp, buf->size); |
buf_appendb(dbuf, buf->cp, buf->size); |
hash_put(hash, buf, TYPE_Nd); |
hash_put(hash, buf, TYPE_Nd); |
fclose(stream); |
fclose(stream); |
|
free(title); |
return; |
return; |
} |
} |
|
|
line[(int)--len] = '\0'; |
title = mandoc_realloc(title, titlesz + 1); |
|
title[(int)titlesz] = '\0'; |
|
|
/* |
/* |
* Skip to the first dash. |
* Skip to the first dash. |
Line 1414 pformatted(DB *hash, struct buf *buf, struct buf *dbuf |
|
Line 1459 pformatted(DB *hash, struct buf *buf, struct buf *dbuf |
|
* bytes). |
* bytes). |
*/ |
*/ |
|
|
if (NULL != (p = strstr(line, "- "))) { |
if (NULL != (p = strstr(title, "- "))) { |
for (p += 2; ' ' == *p || '\b' == *p; p++) |
for (p += 2; ' ' == *p || '\b' == *p; p++) |
/* Skip to next word. */ ; |
/* Skip to next word. */ ; |
} else { |
} else { |
if (warnings) |
if (warnings) |
fprintf(stderr, "%s: no dash in title line\n", |
fprintf(stderr, "%s: no dash in title line\n", |
of->fname); |
of->fname); |
p = line; |
p = title; |
} |
} |
|
|
if ((plen = strlen(p)) > 70) { |
plen = strlen(p); |
plen = 70; |
|
p[plen] = '\0'; |
|
} |
|
|
|
/* Strip backspace-encoding from line. */ |
/* Strip backspace-encoding from line. */ |
|
|
Line 1446 pformatted(DB *hash, struct buf *buf, struct buf *dbuf |
|
Line 1488 pformatted(DB *hash, struct buf *buf, struct buf *dbuf |
|
buf_appendb(buf, p, plen + 1); |
buf_appendb(buf, p, plen + 1); |
hash_put(hash, buf, TYPE_Nd); |
hash_put(hash, buf, TYPE_Nd); |
fclose(stream); |
fclose(stream); |
|
free(title); |
} |
} |
|
|
static void |
static void |
ofile_argbuild(int argc, char *argv[], struct of **of) |
ofile_argbuild(int argc, char *argv[], struct of **of) |
{ |
{ |
char buf[MAXPATHLEN]; |
char buf[MAXPATHLEN]; |
char *sec, *arch, *title, *p; |
const char *sec, *arch, *title; |
|
char *p; |
int i, src_form; |
int i, src_form; |
struct of *nof; |
struct of *nof; |
|
|
Line 1538 ofile_argbuild(int argc, char *argv[], struct of **of) |
|
Line 1582 ofile_argbuild(int argc, char *argv[], struct of **of) |
|
* Recursively build up a list of files to parse. |
* Recursively build up a list of files to parse. |
* We use this instead of ftw() and so on because I don't want global |
* We use this instead of ftw() and so on because I don't want global |
* variables hanging around. |
* variables hanging around. |
* This ignores the mandoc.db and mandoc.index files, but assumes that |
* This ignores the whatis.db and whatis.index files, but assumes that |
* everything else is a manual. |
* everything else is a manual. |
* Pass in a pointer to a NULL structure for the first invocation. |
* Pass in a pointer to a NULL structure for the first invocation. |
*/ |
*/ |
Line 1756 ofile_dirbuild(const char *dir, const char* psec, cons |
|
Line 1800 ofile_dirbuild(const char *dir, const char* psec, cons |
|
|
|
if (verb > 1) |
if (verb > 1) |
printf("%s: scheduling\n", buf); |
printf("%s: scheduling\n", buf); |
|
|
if (NULL == *of) { |
if (NULL == *of) { |
*of = nof; |
*of = nof; |
(*of)->first = nof; |
(*of)->first = nof; |
Line 1774 ofile_free(struct of *of) |
|
Line 1819 ofile_free(struct of *of) |
|
{ |
{ |
struct of *nof; |
struct of *nof; |
|
|
while (of) { |
if (NULL != of) |
|
of = of->first; |
|
|
|
while (NULL != of) { |
nof = of->next; |
nof = of->next; |
free(of->fname); |
free(of->fname); |
free(of->sec); |
free(of->sec); |