=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc_man.c,v retrieving revision 1.124 retrieving revision 1.125 diff -c -r1.124 -r1.125 *** src/usr.bin/mandoc/mdoc_man.c 2018/04/11 17:10:35 1.124 --- src/usr.bin/mandoc/mdoc_man.c 2018/08/17 20:31:52 1.125 *************** *** 1,4 **** ! /* $OpenBSD: mdoc_man.c,v 1.124 2018/04/11 17:10:35 schwarze Exp $ */ /* * Copyright (c) 2011-2018 Ingo Schwarze * --- 1,4 ---- ! /* $OpenBSD: mdoc_man.c,v 1.125 2018/08/17 20:31:52 schwarze Exp $ */ /* * Copyright (c) 2011-2018 Ingo Schwarze * *************** *** 34,40 **** typedef int (*int_fp)(DECL_ARGS); typedef void (*void_fp)(DECL_ARGS); ! struct manact { int_fp cond; /* DON'T run actions */ int_fp pre; /* pre-node action */ void_fp post; /* post-node action */ --- 34,40 ---- typedef int (*int_fp)(DECL_ARGS); typedef void (*void_fp)(DECL_ARGS); ! struct mdoc_man_act { int_fp cond; /* DON'T run actions */ int_fp pre; /* pre-node action */ void_fp post; /* post-node action */ *************** *** 122,128 **** static void print_count(int *); static void print_node(DECL_ARGS); ! static const void_fp roff_manacts[ROFF_MAX] = { pre_br, /* br */ pre_onearg, /* ce */ pre_ft, /* ft */ --- 122,128 ---- static void print_count(int *); static void print_node(DECL_ARGS); ! static const void_fp roff_man_acts[ROFF_MAX] = { pre_br, /* br */ pre_onearg, /* ce */ pre_ft, /* ft */ *************** *** 135,141 **** pre_onearg, /* ti */ }; ! static const struct manact __manacts[MDOC_MAX - MDOC_Dd] = { { NULL, NULL, NULL, NULL, NULL }, /* Dd */ { NULL, NULL, NULL, NULL, NULL }, /* Dt */ { NULL, NULL, NULL, NULL, NULL }, /* Os */ --- 135,141 ---- pre_onearg, /* ti */ }; ! static const struct mdoc_man_act mdoc_man_acts[MDOC_MAX - MDOC_Dd] = { { NULL, NULL, NULL, NULL, NULL }, /* Dd */ { NULL, NULL, NULL, NULL, NULL }, /* Dt */ { NULL, NULL, NULL, NULL, NULL }, /* Os */ *************** *** 257,263 **** { NULL, NULL, post_percent, NULL, NULL }, /* %U */ { NULL, NULL, NULL, NULL, NULL }, /* Ta */ }; ! static const struct manact *const manacts = __manacts - MDOC_Dd; static int outflags; #define MMAN_spc (1 << 0) /* blank character before next word */ --- 257,263 ---- { NULL, NULL, post_percent, NULL, NULL }, /* %U */ { NULL, NULL, NULL, NULL, NULL }, /* Ta */ }; ! static const struct mdoc_man_act *mdoc_man_act(enum roff_tok); static int outflags; #define MMAN_spc (1 << 0) /* blank character before next word */ *************** *** 288,293 **** --- 288,300 ---- } fontqueue; + static const struct mdoc_man_act * + mdoc_man_act(enum roff_tok tok) + { + assert(tok >= MDOC_Dd && tok <= MDOC_MAX); + return mdoc_man_acts + (tok - MDOC_Dd); + } + static int man_strlen(const char *cp) { *************** *** 638,646 **** static void print_node(DECL_ARGS) { ! const struct manact *act; ! struct roff_node *sub; ! int cond, do_sub; if (n->flags & NODE_NOPRT) return; --- 645,653 ---- static void print_node(DECL_ARGS) { ! const struct mdoc_man_act *act; ! struct roff_node *sub; ! int cond, do_sub; if (n->flags & NODE_NOPRT) return; *************** *** 678,692 **** else if (outflags & MMAN_Sm) outflags |= MMAN_spc; } else if (n->tok < ROFF_MAX) { ! (*roff_manacts[n->tok])(meta, n); return; } else { - assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); /* * Conditionally run the pre-node action handler for a * node. */ ! act = manacts + n->tok; cond = act->cond == NULL || (*act->cond)(meta, n); if (cond && act->pre != NULL && (n->end == ENDBODY_NOT || n->child != NULL)) --- 685,698 ---- else if (outflags & MMAN_Sm) outflags |= MMAN_spc; } else if (n->tok < ROFF_MAX) { ! (*roff_man_acts[n->tok])(meta, n); return; } else { /* * Conditionally run the pre-node action handler for a * node. */ ! act = mdoc_man_act(n->tok); cond = act->cond == NULL || (*act->cond)(meta, n); if (cond && act->pre != NULL && (n->end == ENDBODY_NOT || n->child != NULL)) *************** *** 734,740 **** { const char *prefix; ! prefix = manacts[n->tok].prefix; if (NULL == prefix) return 1; print_word(prefix); --- 740,746 ---- { const char *prefix; ! prefix = mdoc_man_act(n->tok)->prefix; if (NULL == prefix) return 1; print_word(prefix); *************** *** 747,753 **** { const char *suffix; ! suffix = manacts[n->tok].suffix; if (NULL == suffix) return; outflags &= ~(MMAN_spc | MMAN_nl); --- 753,759 ---- { const char *suffix; ! suffix = mdoc_man_act(n->tok)->suffix; if (NULL == suffix) return; outflags &= ~(MMAN_spc | MMAN_nl); *************** *** 772,778 **** post_percent(DECL_ARGS) { ! if (pre_em == manacts[n->tok].pre) font_pop(); if (n->next) { print_word(","); --- 778,784 ---- post_percent(DECL_ARGS) { ! if (mdoc_man_act(n->tok)->pre == pre_em) font_pop(); if (n->next) { print_word(","); *************** *** 818,824 **** if (n->type == ROFFT_HEAD) { outflags |= MMAN_sp; ! print_block(manacts[n->tok].prefix, 0); print_word(""); putchar('\"'); outflags &= ~MMAN_spc; --- 824,830 ---- if (n->type == ROFFT_HEAD) { outflags |= MMAN_sp; ! print_block(mdoc_man_act(n->tok)->prefix, 0); print_word(""); putchar('\"'); outflags &= ~MMAN_spc;