version 1.228, 2018/12/21 17:15:19 |
version 1.235, 2022/04/14 16:43:44 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
|
* Copyright (c) 2010, 2012-2021 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@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 above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
#include <string.h> |
#include <string.h> |
#include <time.h> |
#include <time.h> |
|
|
|
#if DEBUG_MEMORY |
|
#include "mandoc_dbg.h" |
|
#endif |
#include "mandoc.h" |
#include "mandoc.h" |
#include "roff.h" |
#include "roff.h" |
#include "mdoc.h" |
#include "mdoc.h" |
Line 61 static void rew_pending(struct roff_man *, |
|
Line 64 static void rew_pending(struct roff_man *, |
|
const struct roff_node *); |
const struct roff_node *); |
|
|
static const struct mdoc_macro mdoc_macros[MDOC_MAX - MDOC_Dd] = { |
static const struct mdoc_macro mdoc_macros[MDOC_MAX - MDOC_Dd] = { |
{ in_line_eoln, MDOC_PROLOGUE }, /* Dd */ |
{ in_line_eoln, MDOC_PROLOGUE | MDOC_JOIN }, /* Dd */ |
{ in_line_eoln, MDOC_PROLOGUE }, /* Dt */ |
{ in_line_eoln, MDOC_PROLOGUE }, /* Dt */ |
{ in_line_eoln, MDOC_PROLOGUE }, /* Os */ |
{ in_line_eoln, MDOC_PROLOGUE }, /* Os */ |
{ blk_full, MDOC_PARSED | MDOC_JOIN }, /* Sh */ |
{ blk_full, MDOC_PARSED | MDOC_JOIN }, /* Sh */ |
Line 200 static const struct mdoc_macro mdoc_macros[MDOC_MAX - |
|
Line 203 static const struct mdoc_macro mdoc_macros[MDOC_MAX - |
|
{ in_line_eoln, MDOC_JOIN }, /* %Q */ |
{ in_line_eoln, MDOC_JOIN }, /* %Q */ |
{ in_line_eoln, 0 }, /* %U */ |
{ in_line_eoln, 0 }, /* %U */ |
{ phrase_ta, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ta */ |
{ phrase_ta, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ta */ |
|
{ in_line_eoln, 0 }, /* Tg */ |
}; |
}; |
|
|
|
|
Line 233 mdoc_endparse(struct roff_man *mdoc) |
|
Line 237 mdoc_endparse(struct roff_man *mdoc) |
|
|
|
/* Rewind to the first. */ |
/* Rewind to the first. */ |
|
|
rew_last(mdoc, mdoc->first); |
rew_last(mdoc, mdoc->meta.first); |
mdoc_state_reset(mdoc); |
|
} |
} |
|
|
/* |
/* |
Line 296 rew_pending(struct roff_man *mdoc, const struct roff_n |
|
Line 299 rew_pending(struct roff_man *mdoc, const struct roff_n |
|
case ROFFT_HEAD: |
case ROFFT_HEAD: |
roff_body_alloc(mdoc, n->line, n->pos, |
roff_body_alloc(mdoc, n->line, n->pos, |
n->tok); |
n->tok); |
|
if (n->tok == MDOC_Ss) |
|
mdoc->flags &= ~ROFF_NONOFILL; |
break; |
break; |
case ROFFT_BLOCK: |
case ROFFT_BLOCK: |
break; |
break; |
Line 697 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 702 blk_exp_close(MACRO_PROT_ARGS) |
|
"%s %s", roff_name[tok], buf + *pos); |
"%s %s", roff_name[tok], buf + *pos); |
if (endbody == NULL && n != NULL) |
if (endbody == NULL && n != NULL) |
rew_pending(mdoc, n); |
rew_pending(mdoc, n); |
|
|
|
/* |
|
* Restore the fill mode that was set before the display. |
|
* This needs to be done here rather than during validation |
|
* such that subsequent nodes get the right flags. |
|
*/ |
|
|
|
if (tok == MDOC_Ed && body != NULL) { |
|
if (body->flags & NODE_NOFILL) |
|
mdoc->flags |= ROFF_NOFILL; |
|
else |
|
mdoc->flags &= ~ROFF_NOFILL; |
|
} |
return; |
return; |
} |
} |
|
|
Line 937 in_line(MACRO_PROT_ARGS) |
|
Line 955 in_line(MACRO_PROT_ARGS) |
|
static void |
static void |
blk_full(MACRO_PROT_ARGS) |
blk_full(MACRO_PROT_ARGS) |
{ |
{ |
int done, la, nl, parsed; |
|
struct mdoc_arg *arg; |
struct mdoc_arg *arg; |
struct roff_node *blk; /* Our own or a broken block. */ |
struct roff_node *blk; /* Our own or a broken block. */ |
struct roff_node *head; /* Our own head. */ |
struct roff_node *head; /* Our own head. */ |
struct roff_node *body; /* Our own body. */ |
struct roff_node *body; /* Our own body. */ |
struct roff_node *n; |
struct roff_node *n; |
enum margserr ac, lac; |
|
char *p; |
char *p; |
|
size_t iarg; |
|
int done, la, nl, parsed; |
|
enum margserr ac, lac; |
|
|
nl = MDOC_NEWLINE & mdoc->flags; |
nl = MDOC_NEWLINE & mdoc->flags; |
|
|
Line 1040 blk_full(MACRO_PROT_ARGS) |
|
Line 1059 blk_full(MACRO_PROT_ARGS) |
|
* regular child nodes. |
* regular child nodes. |
*/ |
*/ |
|
|
|
switch (tok) { |
|
case MDOC_Sh: |
|
mdoc->flags &= ~ROFF_NOFILL; |
|
break; |
|
case MDOC_Ss: |
|
mdoc->flags |= ROFF_NONOFILL; |
|
break; |
|
default: |
|
break; |
|
} |
mdoc_argv(mdoc, line, tok, &arg, pos, buf); |
mdoc_argv(mdoc, line, tok, &arg, pos, buf); |
blk = mdoc_block_alloc(mdoc, line, ppos, tok, arg); |
blk = mdoc_block_alloc(mdoc, line, ppos, tok, arg); |
head = body = NULL; |
head = body = NULL; |
Line 1181 blk_full(MACRO_PROT_ARGS) |
|
Line 1210 blk_full(MACRO_PROT_ARGS) |
|
|
|
rew_last(mdoc, head); |
rew_last(mdoc, head); |
body = roff_body_alloc(mdoc, line, ppos, tok); |
body = roff_body_alloc(mdoc, line, ppos, tok); |
|
if (tok == MDOC_Ss) |
|
mdoc->flags &= ~ROFF_NONOFILL; |
|
|
|
/* |
|
* Set up fill mode for display blocks. |
|
* This needs to be done here up front rather than during |
|
* validation such that child nodes get the right flags. |
|
*/ |
|
|
|
if (tok == MDOC_Bd && arg != NULL) { |
|
for (iarg = 0; iarg < arg->argc; iarg++) { |
|
switch (arg->argv[iarg].arg) { |
|
case MDOC_Unfilled: |
|
case MDOC_Literal: |
|
mdoc->flags |= ROFF_NOFILL; |
|
break; |
|
case MDOC_Filled: |
|
case MDOC_Ragged: |
|
case MDOC_Centred: |
|
mdoc->flags &= ~ROFF_NOFILL; |
|
break; |
|
default: |
|
continue; |
|
} |
|
break; |
|
} |
|
} |
out: |
out: |
if (mdoc->flags & MDOC_FREECOL) { |
if (mdoc->flags & MDOC_FREECOL) { |
rew_last(mdoc, body); |
rew_last(mdoc, body); |
Line 1457 in_line_eoln(MACRO_PROT_ARGS) |
|
Line 1513 in_line_eoln(MACRO_PROT_ARGS) |
|
if (n->tok == MDOC_Nm) |
if (n->tok == MDOC_Nm) |
rew_last(mdoc, n->parent); |
rew_last(mdoc, n->parent); |
} |
} |
|
|
|
#if DEBUG_MEMORY |
|
if (tok == MDOC_Dt) |
|
mandoc_dbg_name(buf); |
|
#endif |
|
|
if (buf[*pos] == '\0' && |
if (buf[*pos] == '\0' && |
(tok == MDOC_Fd || *roff_name[tok] == '%')) { |
(tok == MDOC_Fd || *roff_name[tok] == '%')) { |