version 1.42, 2011/12/28 00:32:13 |
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 1334 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 1364 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 1402 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 1410 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 1429 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 1461 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 |