version 1.33, 2009/03/08 11:41:22 |
version 1.42, 2009/03/16 22:19:19 |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <time.h> |
|
|
|
#include "private.h" |
#include "private.h" |
|
|
Line 60 static int post_dt(struct mdoc *); |
|
Line 59 static int post_dt(struct mdoc *); |
|
static int post_nm(struct mdoc *); |
static int post_nm(struct mdoc *); |
static int post_os(struct mdoc *); |
static int post_os(struct mdoc *); |
static int post_sh(struct mdoc *); |
static int post_sh(struct mdoc *); |
static int post_ex(struct mdoc *); |
static int post_std(struct mdoc *); |
static int post_prologue(struct mdoc *); |
static int post_prologue(struct mdoc *); |
|
|
|
#define merr(m, t) nerr((m), (m)->last, (t)) |
|
#define mwarn(m, t) nwarn((m), (m)->last, (t)) |
|
|
const struct actions mdoc_actions[MDOC_MAX] = { |
const struct actions mdoc_actions[MDOC_MAX] = { |
{ NULL }, /* \" */ |
{ NULL }, /* \" */ |
{ post_dd }, /* Dd */ |
{ post_dd }, /* Dd */ |
Line 86 const struct actions mdoc_actions[MDOC_MAX] = { |
|
Line 88 const struct actions mdoc_actions[MDOC_MAX] = { |
|
{ NULL }, /* Dv */ |
{ NULL }, /* Dv */ |
{ NULL }, /* Er */ |
{ NULL }, /* Er */ |
{ NULL }, /* Ev */ |
{ NULL }, /* Ev */ |
{ post_ex }, /* Ex */ |
{ post_std }, /* Ex */ |
{ NULL }, /* Fa */ |
{ NULL }, /* Fa */ |
{ NULL }, /* Fd */ |
{ NULL }, /* Fd */ |
{ NULL }, /* Fl */ |
{ NULL }, /* Fl */ |
Line 100 const struct actions mdoc_actions[MDOC_MAX] = { |
|
Line 102 const struct actions mdoc_actions[MDOC_MAX] = { |
|
{ NULL }, /* Op */ |
{ NULL }, /* Op */ |
{ NULL }, /* Ot */ |
{ NULL }, /* Ot */ |
{ NULL }, /* Pa */ |
{ NULL }, /* Pa */ |
{ NULL }, /* Rv */ |
{ post_std }, /* Rv */ |
{ NULL }, /* St */ |
{ NULL }, /* St */ |
{ NULL }, /* Va */ |
{ NULL }, /* Va */ |
{ NULL }, /* Vt */ |
{ NULL }, /* Vt */ |
Line 171 const struct actions mdoc_actions[MDOC_MAX] = { |
|
Line 173 const struct actions mdoc_actions[MDOC_MAX] = { |
|
{ NULL }, /* Fr */ |
{ NULL }, /* Fr */ |
{ NULL }, /* Ud */ |
{ NULL }, /* Ud */ |
{ NULL }, /* Lb */ |
{ NULL }, /* Lb */ |
|
{ NULL }, /* Ap */ |
|
{ NULL }, /* Lp */ |
|
{ NULL }, /* Lk */ |
|
{ NULL }, /* Mt */ |
|
{ NULL }, /* Brq */ |
|
{ NULL }, /* Bro */ |
|
{ NULL }, /* Brc */ |
|
{ NULL }, /* %C */ |
|
{ NULL }, /* Es */ |
|
{ NULL }, /* En */ |
}; |
}; |
|
|
|
|
#define merr(m, t) nerr((m), (m)->last, (t)) |
|
static int |
static int |
nerr(struct mdoc *m, const struct mdoc_node *n, enum merr type) |
nerr(struct mdoc *m, const struct mdoc_node *n, enum merr type) |
{ |
{ |
Line 193 nerr(struct mdoc *m, const struct mdoc_node *n, enum m |
|
Line 204 nerr(struct mdoc *m, const struct mdoc_node *n, enum m |
|
} |
} |
|
|
|
|
#define mwarn(m, t) nwarn((m), (m)->last, (t)) |
|
static int |
static int |
nwarn(struct mdoc *m, const struct mdoc_node *n, enum mwarn type) |
nwarn(struct mdoc *m, const struct mdoc_node *n, enum mwarn type) |
{ |
{ |
Line 222 nwarn(struct mdoc *m, const struct mdoc_node *n, enum |
|
Line 232 nwarn(struct mdoc *m, const struct mdoc_node *n, enum |
|
|
|
|
|
static int |
static int |
post_ex(struct mdoc *mdoc) |
post_std(struct mdoc *mdoc) |
{ |
{ |
|
|
/* |
/* |
* If `.Ex -std' is invoked without an argument, fill it in with |
* If '-std' is invoked without an argument, fill it in with our |
* our name (if it's been set). |
* name (if it's been set). |
*/ |
*/ |
|
|
if (NULL == mdoc->last->args) |
if (NULL == mdoc->last->args) |
Line 241 post_ex(struct mdoc *mdoc) |
|
Line 251 post_ex(struct mdoc *mdoc) |
|
mdoc_argnames[MDOC_Std], |
mdoc_argnames[MDOC_Std], |
mdoc->meta.name); |
mdoc->meta.name); |
|
|
assert(1 == mdoc->last->args->argv[0].sz); |
|
|
|
mdoc->last->args->argv[0].sz = 1; |
|
mdoc->last->args->argv[0].value = xcalloc(1, sizeof(char *)); |
mdoc->last->args->argv[0].value = xcalloc(1, sizeof(char *)); |
|
mdoc->last->args->argv[0].sz = 1; |
mdoc->last->args->argv[0].value[0] = xstrdup(mdoc->meta.name); |
mdoc->last->args->argv[0].value[0] = xstrdup(mdoc->meta.name); |
return(1); |
return(1); |
} |
} |
Line 514 post_bl_width(struct mdoc *m) |
|
Line 522 post_bl_width(struct mdoc *m) |
|
size_t width; |
size_t width; |
int i, tok; |
int i, tok; |
char buf[32]; |
char buf[32]; |
char **p; |
char *p; |
|
|
if (NULL == m->last->args) |
if (NULL == m->last->args) |
return(merr(m, ENOWIDTH)); |
return(merr(m, ENOWIDTH)); |
Line 526 post_bl_width(struct mdoc *m) |
|
Line 534 post_bl_width(struct mdoc *m) |
|
if (i == (int)m->last->args->argc) |
if (i == (int)m->last->args->argc) |
return(merr(m, ENOWIDTH)); |
return(merr(m, ENOWIDTH)); |
|
|
p = &m->last->args->argv[i].value[0]; |
p = m->last->args->argv[i].value[0]; |
|
|
/* |
/* |
* If the value to -width is a macro, then we re-write it to be |
* If the value to -width is a macro, then we re-write it to be |
* the macro's width as set in share/tmac/mdoc/doc-common. |
* the macro's width as set in share/tmac/mdoc/doc-common. |
*/ |
*/ |
|
|
if (xstrcmp(*p, "Ds")) |
if (xstrcmp(p, "Ds")) |
width = 8; |
width = 8; |
else if (MDOC_MAX == (tok = mdoc_tokhash_find(m->htab, *p))) |
else if (MDOC_MAX == (tok = mdoc_tokhash_find(m->htab, p))) |
return(1); |
return(1); |
else if (0 == (width = mdoc_macro2len(tok))) |
else if (0 == (width = mdoc_macro2len(tok))) |
return(mwarn(m, WNOWIDTH)); |
return(mwarn(m, WNOWIDTH)); |
|
|
mdoc_msg(m, "re-writing %s argument: %s -> %zun", |
mdoc_msg(m, "re-writing %s argument: %s -> %zun", |
mdoc_argnames[MDOC_Width], *p, width); |
mdoc_argnames[MDOC_Width], p, width); |
|
|
/* The value already exists: free and reallocate it. */ |
/* The value already exists: free and reallocate it. */ |
|
|
(void)snprintf(buf, sizeof(buf), "%zun", width); |
(void)snprintf(buf, sizeof(buf), "%zun", width); |
|
|
free(*p); |
free(m->last->args->argv[i].value[0]); |
*p = xstrdup(buf); |
m->last->args->argv[i].value[0] = xstrdup(buf); |
|
|
return(1); |
return(1); |
} |
} |