version 1.237, 2011/11/03 20:36:59 |
version 1.243, 2012/07/11 16:57:43 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2012 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 "mdoc.h" |
#include "mdoc.h" |
#include "main.h" |
#include "main.h" |
|
|
#define INDENT 5 |
|
#define HALFINDENT 3 |
|
|
|
struct termpair { |
struct termpair { |
struct termpair *ppair; |
struct termpair *ppair; |
int count; |
int count; |
Line 72 static void termp_an_post(DECL_ARGS); |
|
Line 69 static void termp_an_post(DECL_ARGS); |
|
static void termp_bd_post(DECL_ARGS); |
static void termp_bd_post(DECL_ARGS); |
static void termp_bk_post(DECL_ARGS); |
static void termp_bk_post(DECL_ARGS); |
static void termp_bl_post(DECL_ARGS); |
static void termp_bl_post(DECL_ARGS); |
static void termp_d1_post(DECL_ARGS); |
static void termp_fd_post(DECL_ARGS); |
static void termp_fo_post(DECL_ARGS); |
static void termp_fo_post(DECL_ARGS); |
static void termp_in_post(DECL_ARGS); |
static void termp_in_post(DECL_ARGS); |
static void termp_it_post(DECL_ARGS); |
static void termp_it_post(DECL_ARGS); |
Line 132 static const struct termact termacts[MDOC_MAX] = { |
|
Line 129 static const struct termact termacts[MDOC_MAX] = { |
|
{ termp_sh_pre, termp_sh_post }, /* Sh */ |
{ termp_sh_pre, termp_sh_post }, /* Sh */ |
{ termp_ss_pre, termp_ss_post }, /* Ss */ |
{ termp_ss_pre, termp_ss_post }, /* Ss */ |
{ termp_sp_pre, NULL }, /* Pp */ |
{ termp_sp_pre, NULL }, /* Pp */ |
{ termp_d1_pre, termp_d1_post }, /* D1 */ |
{ termp_d1_pre, termp_bl_post }, /* D1 */ |
{ termp_d1_pre, termp_d1_post }, /* Dl */ |
{ termp_d1_pre, termp_bl_post }, /* Dl */ |
{ termp_bd_pre, termp_bd_post }, /* Bd */ |
{ termp_bd_pre, termp_bd_post }, /* Bd */ |
{ NULL, NULL }, /* Ed */ |
{ NULL, NULL }, /* Ed */ |
{ termp_bl_pre, termp_bl_post }, /* Bl */ |
{ termp_bl_pre, termp_bl_post }, /* Bl */ |
Line 149 static const struct termact termacts[MDOC_MAX] = { |
|
Line 146 static const struct termact termacts[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Ev */ |
{ NULL, NULL }, /* Ev */ |
{ termp_ex_pre, NULL }, /* Ex */ |
{ termp_ex_pre, NULL }, /* Ex */ |
{ termp_fa_pre, NULL }, /* Fa */ |
{ termp_fa_pre, NULL }, /* Fa */ |
{ termp_fd_pre, NULL }, /* Fd */ |
{ termp_fd_pre, termp_fd_post }, /* Fd */ |
{ termp_fl_pre, NULL }, /* Fl */ |
{ termp_fl_pre, NULL }, /* Fl */ |
{ termp_fn_pre, NULL }, /* Fn */ |
{ termp_fn_pre, NULL }, /* Fn */ |
{ termp_ft_pre, NULL }, /* Ft */ |
{ termp_ft_pre, NULL }, /* Ft */ |
Line 245 static const struct termact termacts[MDOC_MAX] = { |
|
Line 242 static const struct termact termacts[MDOC_MAX] = { |
|
{ NULL, termp____post }, /* %Q */ |
{ NULL, termp____post }, /* %Q */ |
{ termp_sp_pre, NULL }, /* br */ |
{ termp_sp_pre, NULL }, /* br */ |
{ termp_sp_pre, NULL }, /* sp */ |
{ termp_sp_pre, NULL }, /* sp */ |
{ termp_under_pre, termp____post }, /* %U */ |
{ NULL, termp____post }, /* %U */ |
{ NULL, NULL }, /* Ta */ |
{ NULL, NULL }, /* Ta */ |
}; |
}; |
|
|
Line 259 terminal_mdoc(void *arg, const struct mdoc *mdoc) |
|
Line 256 terminal_mdoc(void *arg, const struct mdoc *mdoc) |
|
|
|
p = (struct termp *)arg; |
p = (struct termp *)arg; |
|
|
|
if (0 == p->defindent) |
|
p->defindent = 5; |
|
|
p->overstep = 0; |
p->overstep = 0; |
p->maxrmargin = p->defrmargin; |
p->maxrmargin = p->defrmargin; |
p->tabwidth = term_len(p, 5); |
p->tabwidth = term_len(p, 5); |
Line 562 a2offs(const struct termp *p, const char *v) |
|
Line 562 a2offs(const struct termp *p, const char *v) |
|
else if (0 == strcmp(v, "left")) |
else if (0 == strcmp(v, "left")) |
return(0); |
return(0); |
else if (0 == strcmp(v, "indent")) |
else if (0 == strcmp(v, "indent")) |
return(term_len(p, INDENT + 1)); |
return(term_len(p, p->defindent + 1)); |
else if (0 == strcmp(v, "indent-two")) |
else if (0 == strcmp(v, "indent-two")) |
return(term_len(p, (INDENT + 1) * 2)); |
return(term_len(p, (p->defindent + 1) * 2)); |
else if ( ! a2roffsu(v, &su, SCALE_MAX)) |
else if ( ! a2roffsu(v, &su, SCALE_MAX)) |
SCALE_HS_INIT(&su, term_strlen(p, v)); |
SCALE_HS_INIT(&su, term_strlen(p, v)); |
|
|
Line 727 termp_it_pre(DECL_ARGS) |
|
Line 727 termp_it_pre(DECL_ARGS) |
|
case (LIST_dash): |
case (LIST_dash): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (LIST_hyphen): |
case (LIST_hyphen): |
if (width < term_len(p, 4)) |
/* FALLTHROUGH */ |
width = term_len(p, 4); |
|
break; |
|
case (LIST_enum): |
case (LIST_enum): |
if (width < term_len(p, 5)) |
if (width < term_len(p, 2)) |
width = term_len(p, 5); |
width = term_len(p, 2); |
break; |
break; |
case (LIST_hang): |
case (LIST_hang): |
if (0 == width) |
if (0 == width) |
Line 787 termp_it_pre(DECL_ARGS) |
|
Line 785 termp_it_pre(DECL_ARGS) |
|
*/ |
*/ |
|
|
switch (type) { |
switch (type) { |
|
case (LIST_enum): |
|
/* |
|
* Weird special case. |
|
* Very narrow enum lists actually hang. |
|
*/ |
|
if (width == term_len(p, 2)) |
|
p->flags |= TERMP_HANG; |
|
/* FALLTHROUGH */ |
case (LIST_bullet): |
case (LIST_bullet): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (LIST_dash): |
case (LIST_dash): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (LIST_enum): |
|
/* FALLTHROUGH */ |
|
case (LIST_hyphen): |
case (LIST_hyphen): |
if (MDOC_HEAD == n->type) |
if (MDOC_HEAD == n->type) |
p->flags |= TERMP_NOBREAK; |
p->flags |= TERMP_NOBREAK; |
Line 1407 termp_fd_pre(DECL_ARGS) |
|
Line 1411 termp_fd_pre(DECL_ARGS) |
|
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
|
static void |
|
termp_fd_post(DECL_ARGS) |
|
{ |
|
|
|
term_newln(p); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
static int |
static int |
termp_sh_pre(DECL_ARGS) |
termp_sh_pre(DECL_ARGS) |
{ |
{ |
Line 1424 termp_sh_pre(DECL_ARGS) |
|
Line 1437 termp_sh_pre(DECL_ARGS) |
|
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
break; |
break; |
case (MDOC_BODY): |
case (MDOC_BODY): |
p->offset = term_len(p, INDENT); |
p->offset = term_len(p, p->defindent); |
|
if (SEC_AUTHORS == n->sec) |
|
p->flags &= ~(TERMP_SPLIT|TERMP_NOSPLIT); |
break; |
break; |
default: |
default: |
break; |
break; |
Line 1492 termp_d1_pre(DECL_ARGS) |
|
Line 1507 termp_d1_pre(DECL_ARGS) |
|
if (MDOC_BLOCK != n->type) |
if (MDOC_BLOCK != n->type) |
return(1); |
return(1); |
term_newln(p); |
term_newln(p); |
p->offset += term_len(p, (INDENT + 1)); |
p->offset += term_len(p, p->defindent + 1); |
return(1); |
return(1); |
} |
} |
|
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static void |
|
termp_d1_post(DECL_ARGS) |
|
{ |
|
|
|
if (MDOC_BLOCK != n->type) |
|
return; |
|
term_newln(p); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static int |
static int |
termp_ft_pre(DECL_ARGS) |
termp_ft_pre(DECL_ARGS) |
{ |
{ |
Line 1797 termp_ss_pre(DECL_ARGS) |
|
Line 1801 termp_ss_pre(DECL_ARGS) |
|
break; |
break; |
case (MDOC_HEAD): |
case (MDOC_HEAD): |
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
p->offset = term_len(p, HALFINDENT); |
p->offset = term_len(p, (p->defindent+1)/2); |
break; |
break; |
default: |
default: |
break; |
break; |
Line 2157 termp_li_pre(DECL_ARGS) |
|
Line 2161 termp_li_pre(DECL_ARGS) |
|
static int |
static int |
termp_lk_pre(DECL_ARGS) |
termp_lk_pre(DECL_ARGS) |
{ |
{ |
const struct mdoc_node *nn, *sv; |
const struct mdoc_node *link, *descr; |
|
|
term_fontpush(p, TERMFONT_UNDER); |
if (NULL == (link = n->child)) |
|
return(0); |
|
|
nn = sv = n->child; |
if (NULL != (descr = link->next)) { |
|
term_fontpush(p, TERMFONT_UNDER); |
|
while (NULL != descr) { |
|
term_word(p, descr->string); |
|
descr = descr->next; |
|
} |
|
p->flags |= TERMP_NOSPACE; |
|
term_word(p, ":"); |
|
term_fontpop(p); |
|
} |
|
|
if (NULL == nn || NULL == nn->next) |
|
return(1); |
|
|
|
for (nn = nn->next; nn; nn = nn->next) |
|
term_word(p, nn->string); |
|
|
|
term_fontpop(p); |
|
|
|
p->flags |= TERMP_NOSPACE; |
|
term_word(p, ":"); |
|
|
|
term_fontpush(p, TERMFONT_BOLD); |
term_fontpush(p, TERMFONT_BOLD); |
term_word(p, sv->string); |
term_word(p, link->string); |
term_fontpop(p); |
term_fontpop(p); |
|
|
return(0); |
return(0); |