version 1.15, 2009/01/20 22:55:46 |
version 1.20, 2009/02/26 16:08:11 |
|
|
* PERFORMANCE OF THIS SOFTWARE. |
* PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
#include <assert.h> |
#include <assert.h> |
|
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
#include <string.h> |
#include <time.h> |
#include <time.h> |
|
|
#include "private.h" |
#include "private.h" |
|
|
|
|
/* Per-macro action routines. */ |
/* Per-macro action routines. */ |
|
|
|
static int post_bl(struct mdoc *); |
static int post_sh(struct mdoc *); |
static int post_sh(struct mdoc *); |
static int post_os(struct mdoc *); |
static int post_os(struct mdoc *); |
static int post_dt(struct mdoc *); |
static int post_dt(struct mdoc *); |
Line 56 const struct actions mdoc_actions[MDOC_MAX] = { |
|
Line 59 const struct actions mdoc_actions[MDOC_MAX] = { |
|
{ NULL }, /* Dl */ |
{ NULL }, /* Dl */ |
{ NULL }, /* Bd */ |
{ NULL }, /* Bd */ |
{ NULL }, /* Ed */ |
{ NULL }, /* Ed */ |
{ NULL }, /* Bl */ |
{ post_bl }, /* Bl */ |
{ NULL }, /* El */ |
{ NULL }, /* El */ |
{ NULL }, /* It */ |
{ NULL }, /* It */ |
{ NULL }, /* Ad */ |
{ NULL }, /* Ad */ |
Line 193 post_sh(struct mdoc *mdoc) |
|
Line 196 post_sh(struct mdoc *mdoc) |
|
return(1); |
return(1); |
if (xstrlcats(buf, mdoc->last->child, 64)) { |
if (xstrlcats(buf, mdoc->last->child, 64)) { |
if (SEC_CUSTOM != (sec = mdoc_atosec(buf))) |
if (SEC_CUSTOM != (sec = mdoc_atosec(buf))) |
mdoc->sec_lastn = sec; |
mdoc->lastnamed = sec; |
mdoc->sec_last = sec; |
mdoc->lastsec = sec; |
return(1); |
return(1); |
} |
} |
|
|
Line 217 post_dt(struct mdoc *mdoc) |
|
Line 220 post_dt(struct mdoc *mdoc) |
|
|
|
assert(NULL == mdoc->meta.title); |
assert(NULL == mdoc->meta.title); |
|
|
|
/* LINTED */ |
for (i = 0, n = mdoc->last->child; n; n = n->next, i++) { |
for (i = 0, n = mdoc->last->child; n; n = n->next, i++) { |
assert(MDOC_TEXT == n->type); |
assert(MDOC_TEXT == n->type); |
p = n->data.text.string; |
p = n->data.text.string; |
Line 244 post_dt(struct mdoc *mdoc) |
|
Line 248 post_dt(struct mdoc *mdoc) |
|
} |
} |
|
|
if (NULL == mdoc->meta.title) |
if (NULL == mdoc->meta.title) |
mdoc->meta.title = xstrdup("untitled"); |
mdoc->meta.title = xstrdup("UNTITLED"); |
|
|
mdoc_msg(mdoc, "title: %s", mdoc->meta.title); |
mdoc_msg(mdoc, "title: %s", mdoc->meta.title); |
|
|
Line 268 post_os(struct mdoc *mdoc) |
|
Line 272 post_os(struct mdoc *mdoc) |
|
return(mdoc_err(mdoc, "macro parameters too long")); |
return(mdoc_err(mdoc, "macro parameters too long")); |
|
|
mdoc->meta.os = xstrdup(buf[0] ? buf : "local"); |
mdoc->meta.os = xstrdup(buf[0] ? buf : "local"); |
mdoc->sec_lastn = mdoc->sec_last = SEC_BODY; |
mdoc->lastnamed = SEC_BODY; |
mdoc->flags |= MDOC_BODYPARSE; |
|
|
|
return(post_prologue(mdoc)); |
return(post_prologue(mdoc)); |
|
} |
|
|
|
|
|
/* |
|
* Transform -width MACRO values into real widths. |
|
*/ |
|
static int |
|
post_bl(struct mdoc *mdoc) |
|
{ |
|
struct mdoc_block *bl; |
|
size_t i, width; |
|
int tok; |
|
char buf[32]; |
|
|
|
if (MDOC_BLOCK != mdoc->last->type) |
|
return(1); |
|
|
|
bl = &mdoc->last->data.block; |
|
|
|
for (i = 0; i < bl->argc; i++) |
|
if (MDOC_Width == bl->argv[i].arg) |
|
break; |
|
|
|
if (i == bl->argc) |
|
return(1); |
|
|
|
assert(1 == bl->argv[i].sz); |
|
if (MDOC_MAX == (tok = mdoc_find(mdoc, *bl->argv[i].value))) |
|
return(1); |
|
|
|
if (0 == (width = mdoc_macro2len(tok))) |
|
return(mdoc_warn(mdoc, WARN_SYNTAX, |
|
"-%s macro has no length", |
|
mdoc_argnames[MDOC_Width])); |
|
|
|
mdoc_msg(mdoc, "re-writing %s argument: %s -> %zun", |
|
mdoc_argnames[MDOC_Width], |
|
*bl->argv[i].value, width); |
|
|
|
/* FIXME: silently truncates. */ |
|
(void)snprintf(buf, sizeof(buf), "%zun", width); |
|
|
|
free(*bl->argv[i].value); |
|
*bl->argv[i].value = strdup(buf); |
|
|
|
return(1); |
} |
} |
|
|
|
|