version 1.72, 2009/03/16 22:19:19 |
version 1.76, 2009/03/21 09:42:07 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the |
* purpose with or without fee is hereby granted, provided that the |
Line 197 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
Line 197 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
{ in_line_eoln, 0 }, /* %C */ |
{ in_line_eoln, 0 }, /* %C */ |
{ obsolete, 0 }, /* Es */ |
{ obsolete, 0 }, /* Es */ |
{ obsolete, 0 }, /* En */ |
{ obsolete, 0 }, /* En */ |
|
{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Dx */ |
|
{ in_line_eoln, 0 }, /* %Q */ |
}; |
}; |
|
|
const struct mdoc_macro * const mdoc_macros = __mdoc_macros; |
const struct mdoc_macro * const mdoc_macros = __mdoc_macros; |
Line 405 rew_alt(int tok) |
|
Line 407 rew_alt(int tok) |
|
} |
} |
|
|
|
|
static int |
/* |
|
* Rewind rules. This indicates whether to stop rewinding |
|
* (REWIND_HALT) without touching our current scope, stop rewinding and |
|
* close our current scope (REWIND_REWIND), or continue (REWIND_NOHALT). |
|
* The scope-closing and so on occurs in the various rew_* routines. |
|
*/ |
|
static int |
rew_dohalt(int tok, enum mdoc_type type, const struct mdoc_node *p) |
rew_dohalt(int tok, enum mdoc_type type, const struct mdoc_node *p) |
{ |
{ |
|
|
Line 415 rew_dohalt(int tok, enum mdoc_type type, const struct |
|
Line 423 rew_dohalt(int tok, enum mdoc_type type, const struct |
|
return(REWIND_NOHALT); |
return(REWIND_NOHALT); |
|
|
switch (tok) { |
switch (tok) { |
/* One-liner implicit-scope. */ |
|
case (MDOC_Aq): |
case (MDOC_Aq): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Bq): |
case (MDOC_Bq): |
Line 442 rew_dohalt(int tok, enum mdoc_type type, const struct |
|
Line 449 rew_dohalt(int tok, enum mdoc_type type, const struct |
|
if (type == p->type && tok == p->tok) |
if (type == p->type && tok == p->tok) |
return(REWIND_REWIND); |
return(REWIND_REWIND); |
break; |
break; |
|
|
/* Multi-line implicit-scope. */ |
|
case (MDOC_It): |
case (MDOC_It): |
assert(MDOC_TAIL != type); |
assert(MDOC_TAIL != type); |
if (type == p->type && tok == p->tok) |
if (type == p->type && tok == p->tok) |
Line 462 rew_dohalt(int tok, enum mdoc_type type, const struct |
|
Line 467 rew_dohalt(int tok, enum mdoc_type type, const struct |
|
if (MDOC_BODY == p->type && MDOC_Sh == p->tok) |
if (MDOC_BODY == p->type && MDOC_Sh == p->tok) |
return(REWIND_HALT); |
return(REWIND_HALT); |
break; |
break; |
|
|
/* Multi-line explicit scope start. */ |
|
case (MDOC_Ao): |
case (MDOC_Ao): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Bd): |
case (MDOC_Bd): |
Line 543 rew_dohalt(int tok, enum mdoc_type type, const struct |
|
Line 546 rew_dohalt(int tok, enum mdoc_type type, const struct |
|
} |
} |
|
|
|
|
|
/* |
|
* See if we can break an encountered scope (the rew_dohalt has returned |
|
* REWIND_NOHALT). |
|
*/ |
static int |
static int |
rew_dobreak(int tok, const struct mdoc_node *p) |
rew_dobreak(int tok, const struct mdoc_node *p) |
{ |
{ |
Line 556 rew_dobreak(int tok, const struct mdoc_node *p) |
|
Line 563 rew_dobreak(int tok, const struct mdoc_node *p) |
|
return(1); |
return(1); |
|
|
switch (tok) { |
switch (tok) { |
/* Implicit rules. */ |
|
case (MDOC_It): |
case (MDOC_It): |
return(MDOC_It == p->tok); |
return(MDOC_It == p->tok); |
case (MDOC_Ss): |
case (MDOC_Ss): |
Line 565 rew_dobreak(int tok, const struct mdoc_node *p) |
|
Line 571 rew_dobreak(int tok, const struct mdoc_node *p) |
|
if (MDOC_Ss == p->tok) |
if (MDOC_Ss == p->tok) |
return(1); |
return(1); |
return(MDOC_Sh == p->tok); |
return(MDOC_Sh == p->tok); |
|
|
/* Extra scope rules. */ |
|
case (MDOC_El): |
case (MDOC_El): |
if (MDOC_It == p->tok) |
if (MDOC_It == p->tok) |
return(1); |
return(1); |
break; |
break; |
|
case (MDOC_Oc): |
|
/* XXX - experimental! */ |
|
if (MDOC_Op == p->tok) |
|
return(1); |
|
break; |
default: |
default: |
break; |
break; |
} |
} |
|
|
blk_part_imp(MACRO_PROT_ARGS) |
blk_part_imp(MACRO_PROT_ARGS) |
{ |
{ |
int lastarg, c; |
int lastarg, c; |
char *p; |
char *p; |
|
struct mdoc_node *blk, *body, *n; |
|
|
if ( ! mdoc_block_alloc(mdoc, line, ppos, tok, NULL)) |
if ( ! mdoc_block_alloc(mdoc, line, ppos, tok, NULL)) |
return(0); |
return(0); |
mdoc->next = MDOC_NEXT_CHILD; |
mdoc->next = MDOC_NEXT_CHILD; |
|
blk = mdoc->last; |
|
|
if ( ! mdoc_head_alloc(mdoc, line, ppos, tok)) |
if ( ! mdoc_head_alloc(mdoc, line, ppos, tok)) |
return(0); |
return(0); |
mdoc->next = MDOC_NEXT_SIBLING; |
mdoc->next = MDOC_NEXT_SIBLING; |
|
|
if ( ! mdoc_body_alloc(mdoc, line, ppos, tok)) |
if ( ! mdoc_body_alloc(mdoc, line, ppos, tok)) |
return(0); |
return(0); |
mdoc->next = MDOC_NEXT_CHILD; |
mdoc->next = MDOC_NEXT_CHILD; |
|
body = mdoc->last; |
|
|
/* XXX - no known argument macros. */ |
/* XXX - no known argument macros. */ |
|
|
Line 1035 blk_part_imp(MACRO_PROT_ARGS) |
|
Line 1048 blk_part_imp(MACRO_PROT_ARGS) |
|
break; |
break; |
} |
} |
|
|
if (1 == ppos) { |
/* |
if ( ! rew_subblock(MDOC_BODY, mdoc, tok, line, ppos)) |
* Since we know what our context is, we can rewind directly to |
return(0); |
* it. This allows us to accomodate for our scope being |
if ( ! append_delims(mdoc, line, pos, buf)) |
* violated by another token. |
return(0); |
*/ |
} else if ( ! rew_subblock(MDOC_BODY, mdoc, tok, line, ppos)) |
|
|
for (n = mdoc->last; n; n = n->parent) |
|
if (body == n) |
|
break; |
|
|
|
if (n && ! rew_last(mdoc, body)) |
return(0); |
return(0); |
return(rew_impblock(mdoc, tok, line, ppos)); |
|
|
if (1 == ppos && ! append_delims(mdoc, line, pos, buf)) |
|
return(0); |
|
|
|
if (n && ! rew_last(mdoc, blk)) |
|
return(0); |
|
|
|
return(1); |
} |
} |
|
|
|
|