Changeset View
Changeset View
Standalone View
Standalone View
contrib/mdocml/mdoc_macro.c
Show All 25 Lines | |||||
#include <string.h> | #include <string.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include "mdoc.h" | #include "mdoc.h" | ||||
#include "mandoc.h" | #include "mandoc.h" | ||||
#include "libmdoc.h" | #include "libmdoc.h" | ||||
#include "libmandoc.h" | #include "libmandoc.h" | ||||
#define CHECK_TOK \ | |||||
do { \ | |||||
if (tok >= MDOC_MAX) { \ | |||||
fprintf(stderr, "DIMDBG %s(%d) %s: tok=%d, MDOC_MAX=%d\n", \ | |||||
__FILE__, __LINE__, __func__, tok, MDOC_MAX); \ | |||||
} \ | |||||
} while (0) | |||||
static void blk_full(MACRO_PROT_ARGS); | static void blk_full(MACRO_PROT_ARGS); | ||||
static void blk_exp_close(MACRO_PROT_ARGS); | static void blk_exp_close(MACRO_PROT_ARGS); | ||||
static void blk_part_exp(MACRO_PROT_ARGS); | static void blk_part_exp(MACRO_PROT_ARGS); | ||||
static void blk_part_imp(MACRO_PROT_ARGS); | static void blk_part_imp(MACRO_PROT_ARGS); | ||||
static void ctx_synopsis(MACRO_PROT_ARGS); | static void ctx_synopsis(MACRO_PROT_ARGS); | ||||
static void in_line_eoln(MACRO_PROT_ARGS); | static void in_line_eoln(MACRO_PROT_ARGS); | ||||
static void in_line_argn(MACRO_PROT_ARGS); | static void in_line_argn(MACRO_PROT_ARGS); | ||||
static void in_line(MACRO_PROT_ARGS); | static void in_line(MACRO_PROT_ARGS); | ||||
▲ Show 20 Lines • Show All 407 Lines • ▼ Show 20 Lines | |||||
* Otherwise, allocate it and return 0. | * Otherwise, allocate it and return 0. | ||||
*/ | */ | ||||
static int | static int | ||||
macro_or_word(MACRO_PROT_ARGS, int parsed) | macro_or_word(MACRO_PROT_ARGS, int parsed) | ||||
{ | { | ||||
char *p; | char *p; | ||||
enum mdoct ntok; | enum mdoct ntok; | ||||
CHECK_TOK; | |||||
p = buf + ppos; | p = buf + ppos; | ||||
ntok = MDOC_MAX; | ntok = MDOC_MAX; | ||||
if (*p == '"') | if (*p == '"') | ||||
p++; | p++; | ||||
else if (parsed && ! (mdoc->flags & MDOC_PHRASELIT)) | else if (parsed && ! (mdoc->flags & MDOC_PHRASELIT)) | ||||
ntok = lookup(mdoc, tok, line, ppos, p); | ntok = lookup(mdoc, tok, line, ppos, p); | ||||
if (ntok == MDOC_MAX) { | if (ntok == MDOC_MAX) { | ||||
▲ Show 20 Lines • Show All 591 Lines • ▼ Show 20 Lines | if (ac == ARGS_PHRASE || | ||||
mdoc->flags |= MDOC_PPHRASE; | mdoc->flags |= MDOC_PPHRASE; | ||||
if (ac == ARGS_PEND && lac == ARGS_PPHRASE) | if (ac == ARGS_PEND && lac == ARGS_PPHRASE) | ||||
mdoc->flags |= MDOC_PPHRASE; | mdoc->flags |= MDOC_PPHRASE; | ||||
parse_rest(mdoc, MDOC_MAX, line, &la, buf); | parse_rest(mdoc, MDOC_MAX, line, &la, buf); | ||||
mdoc->flags &= ~MDOC_PPHRASE; | mdoc->flags &= ~MDOC_PPHRASE; | ||||
continue; | continue; | ||||
} | } | ||||
CHECK_TOK; | |||||
if (macro_or_word(mdoc, tok, line, la, pos, buf, parsed)) | if (macro_or_word(mdoc, tok, line, la, pos, buf, parsed)) | ||||
break; | break; | ||||
} | } | ||||
if (blk->flags & MDOC_VALID) | if (blk->flags & MDOC_VALID) | ||||
return; | return; | ||||
if (head == NULL) | if (head == NULL) | ||||
head = mdoc_head_alloc(mdoc, line, ppos, tok); | head = mdoc_head_alloc(mdoc, line, ppos, tok); | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | if (body == NULL && ac != ARGS_QWORD && | ||||
mdoc_isdelim(p) == DELIM_OPEN) { | mdoc_isdelim(p) == DELIM_OPEN) { | ||||
dword(mdoc, line, la, p, DELIM_OPEN, 0); | dword(mdoc, line, la, p, DELIM_OPEN, 0); | ||||
continue; | continue; | ||||
} | } | ||||
if (body == NULL) | if (body == NULL) | ||||
body = mdoc_body_alloc(mdoc, line, ppos, tok); | body = mdoc_body_alloc(mdoc, line, ppos, tok); | ||||
CHECK_TOK; | |||||
if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) | if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) | ||||
break; | break; | ||||
} | } | ||||
if (body == NULL) | if (body == NULL) | ||||
body = mdoc_body_alloc(mdoc, line, ppos, tok); | body = mdoc_body_alloc(mdoc, line, ppos, tok); | ||||
/* | /* | ||||
* If there is an open sub-block requiring explicit close-out, | * If there is an open sub-block requiring explicit close-out, | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | if (head == NULL) { | ||||
if (tok == MDOC_Eo) /* Not parsed. */ | if (tok == MDOC_Eo) /* Not parsed. */ | ||||
dword(mdoc, line, la, p, DELIM_MAX, 0); | dword(mdoc, line, la, p, DELIM_MAX, 0); | ||||
rew_last(mdoc, head); | rew_last(mdoc, head); | ||||
mdoc_body_alloc(mdoc, line, ppos, tok); | mdoc_body_alloc(mdoc, line, ppos, tok); | ||||
if (tok == MDOC_Eo) | if (tok == MDOC_Eo) | ||||
continue; | continue; | ||||
} | } | ||||
CHECK_TOK; | |||||
if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) | if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) | ||||
break; | break; | ||||
} | } | ||||
/* Clean-up to leave in a consistent state. */ | /* Clean-up to leave in a consistent state. */ | ||||
if (head == NULL) { | if (head == NULL) { | ||||
rew_last(mdoc, mdoc_head_alloc(mdoc, line, ppos, tok)); | rew_last(mdoc, mdoc_head_alloc(mdoc, line, ppos, tok)); | ||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | |||||
parse_rest(struct mdoc *mdoc, enum mdoct tok, int line, int *pos, char *buf) | parse_rest(struct mdoc *mdoc, enum mdoct tok, int line, int *pos, char *buf) | ||||
{ | { | ||||
int la; | int la; | ||||
for (;;) { | for (;;) { | ||||
la = *pos; | la = *pos; | ||||
if (mdoc_args(mdoc, line, pos, buf, tok, NULL) == ARGS_EOLN) | if (mdoc_args(mdoc, line, pos, buf, tok, NULL) == ARGS_EOLN) | ||||
return(0); | return(0); | ||||
CHECK_TOK; | |||||
if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) | if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) | ||||
return(1); | return(1); | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
ctx_synopsis(MACRO_PROT_ARGS) | ctx_synopsis(MACRO_PROT_ARGS) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |