version 1.99, 2015/03/20 12:54:22 |
version 1.101, 2015/04/02 21:36:50 |
|
|
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
* copyright notice and this permission notice appear in all copies. |
* copyright notice and this permission notice appear in all copies. |
* |
* |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
|
#include "man.h" |
|
#include "mandoc.h" |
#include "mandoc.h" |
|
#include "roff.h" |
|
#include "man.h" |
#include "libmandoc.h" |
#include "libmandoc.h" |
#include "libman.h" |
#include "libman.h" |
|
|
Line 43 static void in_line_eoln(MACRO_PROT_ARGS); |
|
Line 44 static void in_line_eoln(MACRO_PROT_ARGS); |
|
static int man_args(struct man *, int, |
static int man_args(struct man *, int, |
int *, char *, char **); |
int *, char *, char **); |
|
|
static void rew_scope(enum man_type, |
static void rew_scope(enum roff_type, |
struct man *, enum mant); |
struct man *, enum mant); |
static enum rew rew_dohalt(enum mant, enum man_type, |
static enum rew rew_dohalt(enum mant, enum roff_type, |
const struct man_node *); |
const struct man_node *); |
static enum rew rew_block(enum mant, enum man_type, |
static enum rew rew_block(enum mant, enum roff_type, |
const struct man_node *); |
const struct man_node *); |
|
|
const struct man_macro __man_macros[MAN_MAX] = { |
const struct man_macro __man_macros[MAN_MAX] = { |
Line 79 const struct man_macro __man_macros[MAN_MAX] = { |
|
Line 80 const struct man_macro __man_macros[MAN_MAX] = { |
|
{ blk_exp, MAN_BSCOPE }, /* RS */ |
{ blk_exp, MAN_BSCOPE }, /* RS */ |
{ in_line_eoln, 0 }, /* DT */ |
{ in_line_eoln, 0 }, /* DT */ |
{ in_line_eoln, 0 }, /* UC */ |
{ in_line_eoln, 0 }, /* UC */ |
{ in_line_eoln, 0 }, /* PD */ |
{ in_line_eoln, MAN_NSCOPED }, /* PD */ |
{ in_line_eoln, 0 }, /* AT */ |
{ in_line_eoln, 0 }, /* AT */ |
{ in_line_eoln, 0 }, /* in */ |
{ in_line_eoln, 0 }, /* in */ |
{ in_line_eoln, 0 }, /* ft */ |
{ in_line_eoln, 0 }, /* ft */ |
Line 115 man_unscope(struct man *man, const struct man_node *to |
|
Line 116 man_unscope(struct man *man, const struct man_node *to |
|
if (man->flags & MAN_ELINE) |
if (man->flags & MAN_ELINE) |
man->flags &= ~MAN_ELINE; |
man->flags &= ~MAN_ELINE; |
else { |
else { |
assert(n->type == MAN_HEAD); |
assert(n->type == ROFFT_HEAD); |
n = n->parent; |
n = n->parent; |
man->flags &= ~MAN_BLINE; |
man->flags &= ~MAN_BLINE; |
} |
} |
Line 124 man_unscope(struct man *man, const struct man_node *to |
|
Line 125 man_unscope(struct man *man, const struct man_node *to |
|
man_node_delete(man, man->last); |
man_node_delete(man, man->last); |
continue; |
continue; |
} |
} |
if (n->type == MAN_BLOCK && |
if (n->type == ROFFT_BLOCK && |
man_macros[n->tok].fp == blk_exp) |
man_macros[n->tok].fp == blk_exp) |
mandoc_msg(MANDOCERR_BLK_NOEND, |
mandoc_msg(MANDOCERR_BLK_NOEND, |
man->parse, n->line, n->pos, |
man->parse, n->line, n->pos, |
Line 155 man_unscope(struct man *man, const struct man_node *to |
|
Line 156 man_unscope(struct man *man, const struct man_node *to |
|
} |
} |
|
|
static enum rew |
static enum rew |
rew_block(enum mant ntok, enum man_type type, const struct man_node *n) |
rew_block(enum mant ntok, enum roff_type type, const struct man_node *n) |
{ |
{ |
|
|
if (type == MAN_BLOCK && ntok == n->parent->tok && |
if (type == ROFFT_BLOCK && n->parent->tok == ntok && |
n->parent->type == MAN_BODY) |
n->parent->type == ROFFT_BODY) |
return(REW_REWIND); |
return(REW_REWIND); |
return(ntok == n->tok ? REW_HALT : REW_NOHALT); |
return(ntok == n->tok ? REW_HALT : REW_NOHALT); |
} |
} |
Line 170 rew_block(enum mant ntok, enum man_type type, const st |
|
Line 171 rew_block(enum mant ntok, enum man_type type, const st |
|
* sections and subsections). |
* sections and subsections). |
*/ |
*/ |
static enum rew |
static enum rew |
rew_dohalt(enum mant tok, enum man_type type, const struct man_node *n) |
rew_dohalt(enum mant tok, enum roff_type type, const struct man_node *n) |
{ |
{ |
enum rew c; |
enum rew c; |
|
|
/* We cannot progress beyond the root ever. */ |
/* We cannot progress beyond the root ever. */ |
if (MAN_ROOT == n->type) |
if (n->type == ROFFT_ROOT) |
return(REW_HALT); |
return(REW_HALT); |
|
|
assert(n->parent); |
assert(n->parent); |
|
|
/* Normal nodes shouldn't go to the level of the root. */ |
/* Normal nodes shouldn't go to the level of the root. */ |
if (MAN_ROOT == n->parent->type) |
if (n->parent->type == ROFFT_ROOT) |
return(REW_REWIND); |
return(REW_REWIND); |
|
|
/* Already-validated nodes should be closed out. */ |
/* Already-validated nodes should be closed out. */ |
Line 243 rew_dohalt(enum mant tok, enum man_type type, const st |
|
Line 244 rew_dohalt(enum mant tok, enum man_type type, const st |
|
* scopes. When a scope is closed, it must be validated and actioned. |
* scopes. When a scope is closed, it must be validated and actioned. |
*/ |
*/ |
static void |
static void |
rew_scope(enum man_type type, struct man *man, enum mant tok) |
rew_scope(enum roff_type type, struct man *man, enum mant tok) |
{ |
{ |
struct man_node *n; |
struct man_node *n; |
enum rew c; |
enum rew c; |
Line 288 blk_close(MACRO_PROT_ARGS) |
|
Line 289 blk_close(MACRO_PROT_ARGS) |
|
if ( ! man_args(man, line, pos, buf, &p)) |
if ( ! man_args(man, line, pos, buf, &p)) |
break; |
break; |
for (nn = man->last->parent; nn; nn = nn->parent) |
for (nn = man->last->parent; nn; nn = nn->parent) |
if (nn->tok == ntok && nn->type == MAN_BLOCK) |
if (nn->tok == ntok && nn->type == ROFFT_BLOCK) |
nrew++; |
nrew++; |
target = strtol(p, &p, 10); |
target = strtol(p, &p, 10); |
if (*p != '\0') |
if (*p != '\0') |
Line 312 blk_close(MACRO_PROT_ARGS) |
|
Line 313 blk_close(MACRO_PROT_ARGS) |
|
} |
} |
|
|
for (nn = man->last->parent; nn; nn = nn->parent) |
for (nn = man->last->parent; nn; nn = nn->parent) |
if (nn->tok == ntok && nn->type == MAN_BLOCK && ! --nrew) |
if (nn->tok == ntok && nn->type == ROFFT_BLOCK && ! --nrew) |
break; |
break; |
|
|
if (nn == NULL) { |
if (nn == NULL) { |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, man->parse, |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, man->parse, |
line, ppos, man_macronames[tok]); |
line, ppos, man_macronames[tok]); |
rew_scope(MAN_BLOCK, man, MAN_PP); |
rew_scope(ROFFT_BLOCK, man, MAN_PP); |
} else { |
} else { |
line = man->last->line; |
line = man->last->line; |
ppos = man->last->pos; |
ppos = man->last->pos; |
Line 341 blk_exp(MACRO_PROT_ARGS) |
|
Line 342 blk_exp(MACRO_PROT_ARGS) |
|
char *p; |
char *p; |
int la; |
int la; |
|
|
rew_scope(MAN_BLOCK, man, tok); |
rew_scope(ROFFT_BLOCK, man, tok); |
man_block_alloc(man, line, ppos, tok); |
man_block_alloc(man, line, ppos, tok); |
man_head_alloc(man, line, ppos, tok); |
man_head_alloc(man, line, ppos, tok); |
head = man->last; |
head = man->last; |
Line 360 blk_exp(MACRO_PROT_ARGS) |
|
Line 361 blk_exp(MACRO_PROT_ARGS) |
|
} |
} |
|
|
/* |
/* |
* Parse an implicit-block macro. These contain a MAN_HEAD and a |
* Parse an implicit-block macro. These contain a ROFFT_HEAD and a |
* MAN_BODY contained within a MAN_BLOCK. Rules for closing out other |
* ROFFT_BODY contained within a ROFFT_BLOCK. Rules for closing out other |
* scopes, such as `SH' closing out an `SS', are defined in the rew |
* scopes, such as `SH' closing out an `SS', are defined in the rew |
* routines. |
* routines. |
*/ |
*/ |
Line 372 blk_imp(MACRO_PROT_ARGS) |
|
Line 373 blk_imp(MACRO_PROT_ARGS) |
|
char *p; |
char *p; |
struct man_node *n; |
struct man_node *n; |
|
|
rew_scope(MAN_BODY, man, tok); |
rew_scope(ROFFT_BODY, man, tok); |
rew_scope(MAN_BLOCK, man, tok); |
rew_scope(ROFFT_BLOCK, man, tok); |
man_block_alloc(man, line, ppos, tok); |
man_block_alloc(man, line, ppos, tok); |
man_head_alloc(man, line, ppos, tok); |
man_head_alloc(man, line, ppos, tok); |
n = man->last; |
n = man->last; |
Line 401 blk_imp(MACRO_PROT_ARGS) |
|
Line 402 blk_imp(MACRO_PROT_ARGS) |
|
|
|
/* Close out the head and open the body. */ |
/* Close out the head and open the body. */ |
|
|
rew_scope(MAN_HEAD, man, tok); |
rew_scope(ROFFT_HEAD, man, tok); |
man_body_alloc(man, line, ppos, tok); |
man_body_alloc(man, line, ppos, tok); |
} |
} |
|
|
Line 434 in_line_eoln(MACRO_PROT_ARGS) |
|
Line 435 in_line_eoln(MACRO_PROT_ARGS) |
|
if ( ! man_args(man, line, pos, buf, &p)) |
if ( ! man_args(man, line, pos, buf, &p)) |
break; |
break; |
if (man_macros[tok].flags & MAN_JOIN && |
if (man_macros[tok].flags & MAN_JOIN && |
man->last->type == MAN_TEXT) |
man->last->type == ROFFT_TEXT) |
man_word_append(man, p); |
man_word_append(man, p); |
else |
else |
man_word_alloc(man, line, la, p); |
man_word_alloc(man, line, la, p); |
Line 461 in_line_eoln(MACRO_PROT_ARGS) |
|
Line 462 in_line_eoln(MACRO_PROT_ARGS) |
|
return; |
return; |
} |
} |
|
|
assert(man->last->type != MAN_ROOT); |
assert(man->last->type != ROFFT_ROOT); |
man->next = MAN_NEXT_SIBLING; |
man->next = MAN_NEXT_SIBLING; |
|
|
/* |
/* |
Line 473 in_line_eoln(MACRO_PROT_ARGS) |
|
Line 474 in_line_eoln(MACRO_PROT_ARGS) |
|
for ( ; man->last; man->last = man->last->parent) { |
for ( ; man->last; man->last = man->last->parent) { |
if (man->last == n) |
if (man->last == n) |
break; |
break; |
if (man->last->type == MAN_ROOT) |
if (man->last->type == ROFFT_ROOT) |
break; |
break; |
man_valid_post(man); |
man_valid_post(man); |
} |
} |
Line 484 in_line_eoln(MACRO_PROT_ARGS) |
|
Line 485 in_line_eoln(MACRO_PROT_ARGS) |
|
* Same here regarding whether we're back at the root. |
* Same here regarding whether we're back at the root. |
*/ |
*/ |
|
|
if (man->last->type != MAN_ROOT) |
if (man->last->type != ROFFT_ROOT) |
man_valid_post(man); |
man_valid_post(man); |
} |
} |
|
|