version 1.143, 2014/11/19 03:08:17 |
version 1.146, 2014/12/28 14:42:27 |
Line 50 const char * const *man_macronames = __man_macronames; |
|
Line 50 const char * const *man_macronames = __man_macronames; |
|
|
|
static struct man_node *man_node_alloc(struct man *, int, int, |
static struct man_node *man_node_alloc(struct man *, int, int, |
enum man_type, enum mant); |
enum man_type, enum mant); |
static int man_node_append(struct man *, |
static void man_node_append(struct man *, struct man_node *); |
struct man_node *); |
|
static void man_node_free(struct man_node *); |
static void man_node_free(struct man_node *); |
static void man_node_unlink(struct man *, |
static void man_node_unlink(struct man *, |
struct man_node *); |
struct man_node *); |
Line 59 static int man_ptext(struct man *, int, char *, int) |
|
Line 58 static int man_ptext(struct man *, int, char *, int) |
|
static int man_pmacro(struct man *, int, char *, int); |
static int man_pmacro(struct man *, int, char *, int); |
static void man_free1(struct man *); |
static void man_free1(struct man *); |
static void man_alloc1(struct man *); |
static void man_alloc1(struct man *); |
static int man_descope(struct man *, int, int); |
static void man_descope(struct man *, int, int); |
|
|
|
|
const struct man_node * |
const struct man_node * |
Line 93 man_free(struct man *man) |
|
Line 92 man_free(struct man *man) |
|
} |
} |
|
|
struct man * |
struct man * |
man_alloc(struct roff *roff, struct mparse *parse, int quick) |
man_alloc(struct roff *roff, struct mparse *parse, |
|
const char *defos, int quick) |
{ |
{ |
struct man *p; |
struct man *p; |
|
|
Line 101 man_alloc(struct roff *roff, struct mparse *parse, int |
|
Line 101 man_alloc(struct roff *roff, struct mparse *parse, int |
|
|
|
man_hash_init(); |
man_hash_init(); |
p->parse = parse; |
p->parse = parse; |
|
p->defos = defos; |
p->quick = quick; |
p->quick = quick; |
p->roff = roff; |
p->roff = roff; |
|
|
|
|
man_endparse(struct man *man) |
man_endparse(struct man *man) |
{ |
{ |
|
|
return(man_macroend(man)); |
man_macroend(man); |
|
return(1); |
} |
} |
|
|
int |
int |
Line 133 man_free1(struct man *man) |
|
Line 135 man_free1(struct man *man) |
|
|
|
if (man->first) |
if (man->first) |
man_node_delete(man, man->first); |
man_node_delete(man, man->first); |
if (man->meta.title) |
free(man->meta.title); |
free(man->meta.title); |
free(man->meta.source); |
if (man->meta.source) |
free(man->meta.date); |
free(man->meta.source); |
free(man->meta.vol); |
if (man->meta.date) |
free(man->meta.msec); |
free(man->meta.date); |
|
if (man->meta.vol) |
|
free(man->meta.vol); |
|
if (man->meta.msec) |
|
free(man->meta.msec); |
|
} |
} |
|
|
static void |
static void |
Line 159 man_alloc1(struct man *man) |
|
Line 156 man_alloc1(struct man *man) |
|
} |
} |
|
|
|
|
static int |
static void |
man_node_append(struct man *man, struct man_node *p) |
man_node_append(struct man *man, struct man_node *p) |
{ |
{ |
|
|
assert(man->last); |
assert(man->last); |
assert(man->first); |
assert(man->first); |
assert(MAN_ROOT != p->type); |
assert(p->type != MAN_ROOT); |
|
|
switch (man->next) { |
switch (man->next) { |
case MAN_NEXT_SIBLING: |
case MAN_NEXT_SIBLING: |
Line 191 man_node_append(struct man *man, struct man_node *p) |
|
Line 188 man_node_append(struct man *man, struct man_node *p) |
|
man->flags &= ~MAN_LITERAL; |
man->flags &= ~MAN_LITERAL; |
break; |
break; |
case MAN_HEAD: |
case MAN_HEAD: |
assert(MAN_BLOCK == p->parent->type); |
assert(p->parent->type == MAN_BLOCK); |
p->parent->head = p; |
p->parent->head = p; |
break; |
break; |
case MAN_TAIL: |
|
assert(MAN_BLOCK == p->parent->type); |
|
p->parent->tail = p; |
|
break; |
|
case MAN_BODY: |
case MAN_BODY: |
assert(MAN_BLOCK == p->parent->type); |
assert(p->parent->type == MAN_BLOCK); |
p->parent->body = p; |
p->parent->body = p; |
break; |
break; |
default: |
default: |
Line 212 man_node_append(struct man *man, struct man_node *p) |
|
Line 205 man_node_append(struct man *man, struct man_node *p) |
|
case MAN_TBL: |
case MAN_TBL: |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case MAN_TEXT: |
case MAN_TEXT: |
if ( ! man_valid_post(man)) |
man_valid_post(man); |
return(0); |
|
break; |
break; |
default: |
default: |
break; |
break; |
} |
} |
|
|
return(1); |
|
} |
} |
|
|
static struct man_node * |
static struct man_node * |
Line 234 man_node_alloc(struct man *man, int line, int pos, |
|
Line 224 man_node_alloc(struct man *man, int line, int pos, |
|
p->type = type; |
p->type = type; |
p->tok = tok; |
p->tok = tok; |
|
|
if (MAN_NEWLINE & man->flags) |
if (man->flags & MAN_NEWLINE) |
p->flags |= MAN_LINE; |
p->flags |= MAN_LINE; |
man->flags &= ~MAN_NEWLINE; |
man->flags &= ~MAN_NEWLINE; |
return(p); |
return(p); |
} |
} |
|
|
int |
void |
man_elem_alloc(struct man *man, int line, int pos, enum mant tok) |
man_elem_alloc(struct man *man, int line, int pos, enum mant tok) |
{ |
{ |
struct man_node *p; |
struct man_node *p; |
|
|
p = man_node_alloc(man, line, pos, MAN_ELEM, tok); |
p = man_node_alloc(man, line, pos, MAN_ELEM, tok); |
if ( ! man_node_append(man, p)) |
man_node_append(man, p); |
return(0); |
|
man->next = MAN_NEXT_CHILD; |
man->next = MAN_NEXT_CHILD; |
return(1); |
|
} |
} |
|
|
int |
void |
man_tail_alloc(struct man *man, int line, int pos, enum mant tok) |
|
{ |
|
struct man_node *p; |
|
|
|
p = man_node_alloc(man, line, pos, MAN_TAIL, tok); |
|
if ( ! man_node_append(man, p)) |
|
return(0); |
|
man->next = MAN_NEXT_CHILD; |
|
return(1); |
|
} |
|
|
|
int |
|
man_head_alloc(struct man *man, int line, int pos, enum mant tok) |
man_head_alloc(struct man *man, int line, int pos, enum mant tok) |
{ |
{ |
struct man_node *p; |
struct man_node *p; |
|
|
p = man_node_alloc(man, line, pos, MAN_HEAD, tok); |
p = man_node_alloc(man, line, pos, MAN_HEAD, tok); |
if ( ! man_node_append(man, p)) |
man_node_append(man, p); |
return(0); |
|
man->next = MAN_NEXT_CHILD; |
man->next = MAN_NEXT_CHILD; |
return(1); |
|
} |
} |
|
|
int |
void |
man_body_alloc(struct man *man, int line, int pos, enum mant tok) |
man_body_alloc(struct man *man, int line, int pos, enum mant tok) |
{ |
{ |
struct man_node *p; |
struct man_node *p; |
|
|
p = man_node_alloc(man, line, pos, MAN_BODY, tok); |
p = man_node_alloc(man, line, pos, MAN_BODY, tok); |
if ( ! man_node_append(man, p)) |
man_node_append(man, p); |
return(0); |
|
man->next = MAN_NEXT_CHILD; |
man->next = MAN_NEXT_CHILD; |
return(1); |
|
} |
} |
|
|
int |
void |
man_block_alloc(struct man *man, int line, int pos, enum mant tok) |
man_block_alloc(struct man *man, int line, int pos, enum mant tok) |
{ |
{ |
struct man_node *p; |
struct man_node *p; |
|
|
p = man_node_alloc(man, line, pos, MAN_BLOCK, tok); |
p = man_node_alloc(man, line, pos, MAN_BLOCK, tok); |
if ( ! man_node_append(man, p)) |
man_node_append(man, p); |
return(0); |
|
man->next = MAN_NEXT_CHILD; |
man->next = MAN_NEXT_CHILD; |
return(1); |
|
} |
} |
|
|
int |
void |
man_word_alloc(struct man *man, int line, int pos, const char *word) |
man_word_alloc(struct man *man, int line, int pos, const char *word) |
{ |
{ |
struct man_node *n; |
struct man_node *n; |
|
|
n = man_node_alloc(man, line, pos, MAN_TEXT, MAN_MAX); |
n = man_node_alloc(man, line, pos, MAN_TEXT, MAN_MAX); |
n->string = roff_strdup(man->roff, word); |
n->string = roff_strdup(man->roff, word); |
|
man_node_append(man, n); |
if ( ! man_node_append(man, n)) |
|
return(0); |
|
|
|
man->next = MAN_NEXT_SIBLING; |
man->next = MAN_NEXT_SIBLING; |
return(1); |
|
} |
} |
|
|
void |
void |
|
|
man_node_free(struct man_node *p) |
man_node_free(struct man_node *p) |
{ |
{ |
|
|
if (p->string) |
free(p->string); |
free(p->string); |
|
free(p); |
free(p); |
} |
} |
|
|
Line 354 man_node_delete(struct man *man, struct man_node *p) |
|
Line 319 man_node_delete(struct man *man, struct man_node *p) |
|
man_node_free(p); |
man_node_free(p); |
} |
} |
|
|
int |
void |
man_addeqn(struct man *man, const struct eqn *ep) |
man_addeqn(struct man *man, const struct eqn *ep) |
{ |
{ |
struct man_node *n; |
struct man_node *n; |
Line 363 man_addeqn(struct man *man, const struct eqn *ep) |
|
Line 328 man_addeqn(struct man *man, const struct eqn *ep) |
|
n->eqn = ep; |
n->eqn = ep; |
if (ep->ln > man->last->line) |
if (ep->ln > man->last->line) |
n->flags |= MAN_LINE; |
n->flags |= MAN_LINE; |
|
man_node_append(man, n); |
if ( ! man_node_append(man, n)) |
|
return(0); |
|
|
|
man->next = MAN_NEXT_SIBLING; |
man->next = MAN_NEXT_SIBLING; |
return(man_descope(man, ep->ln, ep->pos)); |
man_descope(man, ep->ln, ep->pos); |
} |
} |
|
|
int |
void |
man_addspan(struct man *man, const struct tbl_span *sp) |
man_addspan(struct man *man, const struct tbl_span *sp) |
{ |
{ |
struct man_node *n; |
struct man_node *n; |
|
|
n = man_node_alloc(man, sp->line, 0, MAN_TBL, MAN_MAX); |
n = man_node_alloc(man, sp->line, 0, MAN_TBL, MAN_MAX); |
n->span = sp; |
n->span = sp; |
|
man_node_append(man, n); |
if ( ! man_node_append(man, n)) |
|
return(0); |
|
|
|
man->next = MAN_NEXT_SIBLING; |
man->next = MAN_NEXT_SIBLING; |
return(man_descope(man, sp->line, 0)); |
man_descope(man, sp->line, 0); |
} |
} |
|
|
static int |
static void |
man_descope(struct man *man, int line, int offs) |
man_descope(struct man *man, int line, int offs) |
{ |
{ |
/* |
/* |
Line 395 man_descope(struct man *man, int line, int offs) |
|
Line 354 man_descope(struct man *man, int line, int offs) |
|
* out the block scope (also if applicable). |
* out the block scope (also if applicable). |
*/ |
*/ |
|
|
if (MAN_ELINE & man->flags) { |
if (man->flags & MAN_ELINE) { |
man->flags &= ~MAN_ELINE; |
man->flags &= ~MAN_ELINE; |
if ( ! man_unscope(man, man->last->parent)) |
man_unscope(man, man->last->parent); |
return(0); |
|
} |
} |
|
if ( ! (man->flags & MAN_BLINE)) |
if ( ! (MAN_BLINE & man->flags)) |
return; |
return(1); |
|
man->flags &= ~MAN_BLINE; |
man->flags &= ~MAN_BLINE; |
|
man_unscope(man, man->last->parent); |
if ( ! man_unscope(man, man->last->parent)) |
man_body_alloc(man, line, offs, man->last->tok); |
return(0); |
|
return(man_body_alloc(man, line, offs, man->last->tok)); |
|
} |
} |
|
|
static int |
static int |
Line 417 man_ptext(struct man *man, int line, char *buf, int of |
|
Line 372 man_ptext(struct man *man, int line, char *buf, int of |
|
|
|
/* Literal free-form text whitespace is preserved. */ |
/* Literal free-form text whitespace is preserved. */ |
|
|
if (MAN_LITERAL & man->flags) { |
if (man->flags & MAN_LITERAL) { |
if ( ! man_word_alloc(man, line, offs, buf + offs)) |
man_word_alloc(man, line, offs, buf + offs); |
return(0); |
man_descope(man, line, offs); |
return(man_descope(man, line, offs)); |
return(1); |
} |
} |
|
|
for (i = offs; ' ' == buf[i]; i++) |
for (i = offs; buf[i] == ' '; i++) |
/* Skip leading whitespace. */ ; |
/* Skip leading whitespace. */ ; |
|
|
/* |
/* |
Line 431 man_ptext(struct man *man, int line, char *buf, int of |
|
Line 386 man_ptext(struct man *man, int line, char *buf, int of |
|
* but add a single vertical space elsewhere. |
* but add a single vertical space elsewhere. |
*/ |
*/ |
|
|
if ('\0' == buf[i]) { |
if (buf[i] == '\0') { |
/* Allocate a blank entry. */ |
/* Allocate a blank entry. */ |
if (MAN_SH != man->last->tok && |
if (man->last->tok != MAN_SH && |
MAN_SS != man->last->tok) { |
man->last->tok != MAN_SS) { |
if ( ! man_elem_alloc(man, line, offs, MAN_sp)) |
man_elem_alloc(man, line, offs, MAN_sp); |
return(0); |
|
man->next = MAN_NEXT_SIBLING; |
man->next = MAN_NEXT_SIBLING; |
} |
} |
return(1); |
return(1); |
Line 463 man_ptext(struct man *man, int line, char *buf, int of |
|
Line 417 man_ptext(struct man *man, int line, char *buf, int of |
|
|
|
buf[i] = '\0'; |
buf[i] = '\0'; |
} |
} |
|
man_word_alloc(man, line, offs, buf + offs); |
|
|
if ( ! man_word_alloc(man, line, offs, buf + offs)) |
|
return(0); |
|
|
|
/* |
/* |
* End-of-sentence check. If the last character is an unescaped |
* End-of-sentence check. If the last character is an unescaped |
* EOS character, then flag the node as being the end of a |
* EOS character, then flag the node as being the end of a |
Line 477 man_ptext(struct man *man, int line, char *buf, int of |
|
Line 429 man_ptext(struct man *man, int line, char *buf, int of |
|
if (mandoc_eos(buf, (size_t)i)) |
if (mandoc_eos(buf, (size_t)i)) |
man->last->flags |= MAN_EOS; |
man->last->flags |= MAN_EOS; |
|
|
return(man_descope(man, line, offs)); |
man_descope(man, line, offs); |
|
return(1); |
} |
} |
|
|
static int |
static int |
Line 528 man_pmacro(struct man *man, int ln, char *buf, int off |
|
Line 481 man_pmacro(struct man *man, int ln, char *buf, int off |
|
|
|
/* Jump to the next non-whitespace word. */ |
/* Jump to the next non-whitespace word. */ |
|
|
while (buf[offs] && ' ' == buf[offs]) |
while (buf[offs] && buf[offs] == ' ') |
offs++; |
offs++; |
|
|
/* |
/* |
Line 536 man_pmacro(struct man *man, int ln, char *buf, int off |
|
Line 489 man_pmacro(struct man *man, int ln, char *buf, int off |
|
* into the parser as "text", so we only warn about spaces here. |
* into the parser as "text", so we only warn about spaces here. |
*/ |
*/ |
|
|
if ('\0' == buf[offs] && ' ' == buf[offs - 1]) |
if (buf[offs] == '\0' && buf[offs - 1] == ' ') |
mandoc_msg(MANDOCERR_SPACE_EOL, man->parse, |
mandoc_msg(MANDOCERR_SPACE_EOL, man->parse, |
ln, offs - 1, NULL); |
ln, offs - 1, NULL); |
|
|
Line 546 man_pmacro(struct man *man, int ln, char *buf, int off |
|
Line 499 man_pmacro(struct man *man, int ln, char *buf, int off |
|
* macros---they don't print text---so we let those slip by. |
* macros---they don't print text---so we let those slip by. |
*/ |
*/ |
|
|
if ( ! (MAN_NSCOPED & man_macros[tok].flags) && |
if ( ! (man_macros[tok].flags & MAN_NSCOPED) && |
man->flags & MAN_ELINE) { |
man->flags & MAN_ELINE) { |
n = man->last; |
n = man->last; |
assert(MAN_TEXT != n->type); |
assert(MAN_TEXT != n->type); |
|
|
/* Remove repeated NSCOPED macros causing ELINE. */ |
/* Remove repeated NSCOPED macros causing ELINE. */ |
|
|
if (MAN_NSCOPED & man_macros[n->tok].flags) |
if (man_macros[n->tok].flags & MAN_NSCOPED) |
n = n->parent; |
n = n->parent; |
|
|
mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line, |
mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line, |
Line 568 man_pmacro(struct man *man, int ln, char *buf, int off |
|
Line 521 man_pmacro(struct man *man, int ln, char *buf, int off |
|
* Remove prior BLINE macro that is being clobbered. |
* Remove prior BLINE macro that is being clobbered. |
*/ |
*/ |
if ((man->flags & MAN_BLINE) && |
if ((man->flags & MAN_BLINE) && |
(MAN_BSCOPE & man_macros[tok].flags)) { |
(man_macros[tok].flags & MAN_BSCOPE)) { |
n = man->last; |
n = man->last; |
|
|
/* Might be a text node like 8 in |
/* Might be a text node like 8 in |
* .TP 8 |
* .TP 8 |
* .SH foo |
* .SH foo |
*/ |
*/ |
if (MAN_TEXT == n->type) |
if (n->type == MAN_TEXT) |
n = n->parent; |
n = n->parent; |
|
|
/* Remove element that didn't end BLINE, if any. */ |
/* Remove element that didn't end BLINE, if any. */ |
if ( ! (MAN_BSCOPE & man_macros[n->tok].flags)) |
if ( ! (man_macros[n->tok].flags & MAN_BSCOPE)) |
n = n->parent; |
n = n->parent; |
|
|
assert(MAN_HEAD == n->type); |
assert(n->type == MAN_HEAD); |
n = n->parent; |
n = n->parent; |
assert(MAN_BLOCK == n->type); |
assert(n->type == MAN_BLOCK); |
assert(MAN_SCOPED & man_macros[n->tok].flags); |
assert(man_macros[n->tok].flags & MAN_SCOPED); |
|
|
mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line, |
mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse, n->line, |
n->pos, "%s breaks %s", man_macronames[tok], |
n->pos, "%s breaks %s", man_macronames[tok], |
Line 602 man_pmacro(struct man *man, int ln, char *buf, int off |
|
Line 555 man_pmacro(struct man *man, int ln, char *buf, int off |
|
/* Call to handler... */ |
/* Call to handler... */ |
|
|
assert(man_macros[tok].fp); |
assert(man_macros[tok].fp); |
if ( ! (*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf)) |
(*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf); |
return(0); |
|
|
|
/* In quick mode (for mandocdb), abort after the NAME section. */ |
/* In quick mode (for mandocdb), abort after the NAME section. */ |
|
|
if (man->quick && MAN_SH == tok) { |
if (man->quick && tok == MAN_SH) { |
n = man->last; |
n = man->last; |
if (MAN_BODY == n->type && |
if (n->type == MAN_BODY && |
strcmp(n->prev->child->string, "NAME")) |
strcmp(n->prev->child->string, "NAME")) |
return(2); |
return(2); |
} |
} |
Line 624 man_pmacro(struct man *man, int ln, char *buf, int off |
|
Line 576 man_pmacro(struct man *man, int ln, char *buf, int off |
|
man_macros[tok].flags & MAN_NSCOPED) |
man_macros[tok].flags & MAN_NSCOPED) |
return(1); |
return(1); |
|
|
assert(MAN_BLINE & man->flags); |
assert(man->flags & MAN_BLINE); |
man->flags &= ~MAN_BLINE; |
man->flags &= ~MAN_BLINE; |
|
|
if ( ! man_unscope(man, man->last->parent)) |
man_unscope(man, man->last->parent); |
return(0); |
man_body_alloc(man, ln, ppos, man->last->tok); |
return(man_body_alloc(man, ln, ppos, man->last->tok)); |
return(1); |
} |
} |
|
|
/* |
/* |
Line 687 man_deroff(char **dest, const struct man_node *n) |
|
Line 639 man_deroff(char **dest, const struct man_node *n) |
|
char *cp; |
char *cp; |
size_t sz; |
size_t sz; |
|
|
if (MAN_TEXT != n->type) { |
if (n->type != MAN_TEXT) { |
for (n = n->child; n; n = n->next) |
for (n = n->child; n; n = n->next) |
man_deroff(dest, n); |
man_deroff(dest, n); |
return; |
return; |