version 1.52, 2013/09/15 18:48:31 |
version 1.58, 2014/01/22 20:58:39 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2011, 2012, 2013, 2014 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 |
Line 256 static int outflags; |
|
Line 256 static int outflags; |
|
#define MMAN_An_split (1 << 9) /* author mode is "split" */ |
#define MMAN_An_split (1 << 9) /* author mode is "split" */ |
#define MMAN_An_nosplit (1 << 10) /* author mode is "nosplit" */ |
#define MMAN_An_nosplit (1 << 10) /* author mode is "nosplit" */ |
#define MMAN_PD (1 << 11) /* inter-paragraph spacing disabled */ |
#define MMAN_PD (1 << 11) /* inter-paragraph spacing disabled */ |
|
#define MMAN_nbrword (1 << 12) /* do not break the next word */ |
|
|
#define BL_STACK_MAX 32 |
#define BL_STACK_MAX 32 |
|
|
Line 364 print_word(const char *s) |
|
Line 365 print_word(const char *s) |
|
case (ASCII_HYPH): |
case (ASCII_HYPH): |
putchar('-'); |
putchar('-'); |
break; |
break; |
|
case (ASCII_BREAK): |
|
printf("\\:"); |
|
break; |
|
case (' '): |
|
if (MMAN_nbrword & outflags) { |
|
printf("\\ "); |
|
break; |
|
} |
|
/* FALLTHROUGH */ |
default: |
default: |
putchar((unsigned char)*s); |
putchar((unsigned char)*s); |
break; |
break; |
Line 371 print_word(const char *s) |
|
Line 381 print_word(const char *s) |
|
if (TPremain) |
if (TPremain) |
TPremain--; |
TPremain--; |
} |
} |
|
outflags &= ~MMAN_nbrword; |
} |
} |
|
|
static void |
static void |
Line 442 print_offs(const char *v) |
|
Line 453 print_offs(const char *v) |
|
if (Bl_stack_len) |
if (Bl_stack_len) |
sz += Bl_stack[Bl_stack_len - 1]; |
sz += Bl_stack[Bl_stack_len - 1]; |
|
|
snprintf(buf, sizeof(buf), "%ldn", sz); |
snprintf(buf, sizeof(buf), "%zun", sz); |
print_word(buf); |
print_word(buf); |
outflags |= MMAN_nl; |
outflags |= MMAN_nl; |
} |
} |
Line 495 print_width(const char *v, const struct mdoc_node *chi |
|
Line 506 print_width(const char *v, const struct mdoc_node *chi |
|
remain = sz + 2; |
remain = sz + 2; |
} |
} |
if (numeric) { |
if (numeric) { |
snprintf(buf, sizeof(buf), "%ldn", sz + 2); |
snprintf(buf, sizeof(buf), "%zun", sz + 2); |
print_word(buf); |
print_word(buf); |
} else |
} else |
print_word(v); |
print_word(v); |
|
|
pre_sect(DECL_ARGS) |
pre_sect(DECL_ARGS) |
{ |
{ |
|
|
switch (n->type) { |
if (MDOC_HEAD == n->type) { |
case (MDOC_HEAD): |
|
outflags |= MMAN_sp; |
outflags |= MMAN_sp; |
print_block(manacts[n->tok].prefix, 0); |
print_block(manacts[n->tok].prefix, 0); |
print_word(""); |
print_word(""); |
putchar('\"'); |
putchar('\"'); |
outflags &= ~MMAN_spc; |
outflags &= ~MMAN_spc; |
break; |
|
case (MDOC_BODY): |
|
if (MDOC_Sh == n->tok) { |
|
if (MDOC_SYNPRETTY & n->flags) |
|
outflags |= MMAN_Bk; |
|
else |
|
outflags &= ~MMAN_Bk; |
|
} |
|
break; |
|
default: |
|
break; |
|
} |
} |
return(1); |
return(1); |
} |
} |
|
|
post_bk(DECL_ARGS) |
post_bk(DECL_ARGS) |
{ |
{ |
|
|
if (MDOC_BODY == n->type && ! (MDOC_SYNPRETTY & n->flags)) |
if (MDOC_BODY == n->type) |
outflags &= ~MMAN_Bk; |
outflags &= ~MMAN_Bk; |
} |
} |
|
|
Line 1034 post_eo(DECL_ARGS) |
|
Line 1033 post_eo(DECL_ARGS) |
|
static int |
static int |
pre_fa(DECL_ARGS) |
pre_fa(DECL_ARGS) |
{ |
{ |
|
int am_Fa; |
|
|
if (MDOC_Fa == n->tok) |
am_Fa = MDOC_Fa == n->tok; |
|
|
|
if (am_Fa) |
n = n->child; |
n = n->child; |
|
|
while (NULL != n) { |
while (NULL != n) { |
font_push('I'); |
font_push('I'); |
|
if (am_Fa || MDOC_SYNPRETTY & n->flags) |
|
outflags |= MMAN_nbrword; |
print_node(meta, n); |
print_node(meta, n); |
font_pop(); |
font_pop(); |
if (NULL != (n = n->next)) |
if (NULL != (n = n->next)) |
Line 1103 pre_fn(DECL_ARGS) |
|
Line 1107 pre_fn(DECL_ARGS) |
|
if (NULL == n) |
if (NULL == n) |
return(0); |
return(0); |
|
|
|
if (MDOC_SYNPRETTY & n->flags) |
|
print_block(".HP 4n", MMAN_nl); |
|
|
font_push('B'); |
font_push('B'); |
print_node(meta, n); |
print_node(meta, n); |
font_pop(); |
font_pop(); |
Line 1123 post_fn(DECL_ARGS) |
|
Line 1130 post_fn(DECL_ARGS) |
|
print_word(")"); |
print_word(")"); |
if (MDOC_SYNPRETTY & n->flags) { |
if (MDOC_SYNPRETTY & n->flags) { |
print_word(";"); |
print_word(";"); |
outflags |= MMAN_br; |
outflags |= MMAN_PP; |
} |
} |
} |
} |
|
|
Line 1136 pre_fo(DECL_ARGS) |
|
Line 1143 pre_fo(DECL_ARGS) |
|
pre_syn(n); |
pre_syn(n); |
break; |
break; |
case (MDOC_HEAD): |
case (MDOC_HEAD): |
|
if (MDOC_SYNPRETTY & n->flags) |
|
print_block(".HP 4n", MMAN_nl); |
font_push('B'); |
font_push('B'); |
break; |
break; |
case (MDOC_BODY): |
case (MDOC_BODY): |
Line 1148 pre_fo(DECL_ARGS) |
|
Line 1157 pre_fo(DECL_ARGS) |
|
} |
} |
return(1); |
return(1); |
} |
} |
|
|
static void |
static void |
post_fo(DECL_ARGS) |
post_fo(DECL_ARGS) |
{ |
{ |
|
|
|
|
/* Restore the indentation of the enclosing list. */ |
/* Restore the indentation of the enclosing list. */ |
print_line(".RS", MMAN_Bk_susp); |
print_line(".RS", MMAN_Bk_susp); |
snprintf(buf, sizeof(buf), "%ldn", Bl_stack[Bl_stack_len - 1]); |
snprintf(buf, sizeof(buf), "%zun", Bl_stack[Bl_stack_len - 1]); |
print_word(buf); |
print_word(buf); |
|
|
/* Remeber to close out this .RS block later. */ |
/* Remeber to close out this .RS block later. */ |
Line 1408 pre_nm(DECL_ARGS) |
|
Line 1417 pre_nm(DECL_ARGS) |
|
{ |
{ |
char *name; |
char *name; |
|
|
if (MDOC_BLOCK == n->type) |
if (MDOC_BLOCK == n->type) { |
|
outflags |= MMAN_Bk; |
pre_syn(n); |
pre_syn(n); |
|
} |
if (MDOC_ELEM != n->type && MDOC_HEAD != n->type) |
if (MDOC_ELEM != n->type && MDOC_HEAD != n->type) |
return(1); |
return(1); |
name = n->child ? n->child->string : meta->name; |
name = n->child ? n->child->string : meta->name; |
Line 1419 pre_nm(DECL_ARGS) |
|
Line 1430 pre_nm(DECL_ARGS) |
|
if (NULL == n->parent->prev) |
if (NULL == n->parent->prev) |
outflags |= MMAN_sp; |
outflags |= MMAN_sp; |
print_block(".HP", 0); |
print_block(".HP", 0); |
printf(" %ldn", strlen(name) + 1); |
printf(" %zun", strlen(name) + 1); |
outflags |= MMAN_nl; |
outflags |= MMAN_nl; |
} |
} |
font_push('B'); |
font_push('B'); |
|
|
post_nm(DECL_ARGS) |
post_nm(DECL_ARGS) |
{ |
{ |
|
|
if (MDOC_ELEM != n->type && MDOC_HEAD != n->type) |
switch (n->type) { |
return; |
case (MDOC_BLOCK): |
font_pop(); |
outflags &= ~MMAN_Bk; |
|
break; |
|
case (MDOC_HEAD): |
|
/* FALLTHROUGH */ |
|
case (MDOC_ELEM): |
|
font_pop(); |
|
break; |
|
default: |
|
break; |
|
} |
} |
} |
|
|
static int |
static int |