diff options
-rw-r--r-- | term.c | 136 | ||||
-rw-r--r-- | validate.c | 8 |
2 files changed, 135 insertions, 9 deletions
@@ -48,7 +48,9 @@ #define TTYPE_CONFIG 13 #define TTYPE_CMD 14 #define TTYPE_INCLUDE 15 -#define TTYPE_NMAX 16 +#define TTYPE_SYMB 16 +#define TTYPE_SYMBOL 17 +#define TTYPE_NMAX 18 /* * These define "styles" for element types, like command arguments or @@ -72,7 +74,9 @@ const int ttypes[TTYPE_NMAX] = { TERMP_UNDERLINE, /* TTYPE_EMPH */ TERMP_BOLD, /* TTYPE_CONFIG */ TERMP_BOLD, /* TTYPE_CMD */ - TERMP_BOLD /* TTYPE_INCLUDE */ + TERMP_BOLD, /* TTYPE_INCLUDE */ + TERMP_BOLD, /* TTYPE_SYMB */ + TERMP_BOLD /* TTYPE_SYMBOL */ }; static int arg_hasattr(int, size_t, @@ -102,6 +106,7 @@ DECL_POST(name); DECL_PREPOST(termp_aq); DECL_PREPOST(termp_ar); +DECL_PREPOST(termp_bf); DECL_PREPOST(termp_bd); DECL_PREPOST(termp_bq); DECL_PREPOST(termp_cd); @@ -118,6 +123,7 @@ DECL_PREPOST(termp_ft); DECL_PREPOST(termp_ic); DECL_PREPOST(termp_in); DECL_PREPOST(termp_it); +DECL_PREPOST(termp_ms); DECL_PREPOST(termp_nm); DECL_PREPOST(termp_op); DECL_PREPOST(termp_pa); @@ -128,11 +134,13 @@ DECL_PREPOST(termp_sh); DECL_PREPOST(termp_ss); DECL_PREPOST(termp_sq); DECL_PREPOST(termp_sx); +DECL_PREPOST(termp_sy); DECL_PREPOST(termp_va); DECL_PREPOST(termp_vt); DECL_PRE(termp_at); DECL_PRE(termp_bsx); +DECL_PRE(termp_bt); DECL_PRE(termp_bx); DECL_PRE(termp_ex); DECL_PRE(termp_fx); @@ -207,7 +215,7 @@ const struct termact __termacts[MDOC_MAX] = { { termp_aq_pre, termp_aq_post }, /* Aq */ { termp_at_pre, NULL }, /* At */ { NULL, NULL }, /* Bc */ - { NULL, NULL }, /* Bf */ + { termp_bf_pre, termp_bf_post }, /* Bf */ { termp_bq_pre, termp_bq_post }, /* Bo */ { termp_bq_pre, termp_bq_post }, /* Bq */ { termp_bsx_pre, NULL }, /* Bsx */ @@ -221,7 +229,7 @@ const struct termact __termacts[MDOC_MAX] = { { termp_em_pre, termp_em_post }, /* Em */ { NULL, NULL }, /* Eo */ { termp_fx_pre, NULL }, /* Fx */ - { NULL, NULL }, /* Ms */ + { termp_ms_pre, termp_ms_post }, /* Ms */ { NULL, NULL }, /* No */ { termp_ns_pre, NULL }, /* Ns */ { termp_nx_pre, NULL }, /* Nx */ @@ -241,7 +249,7 @@ const struct termact __termacts[MDOC_MAX] = { { termp_sq_pre, termp_sq_post }, /* Sq */ { NULL, NULL }, /* Sm */ { termp_sx_pre, termp_sx_post }, /* Sx */ - { NULL, NULL }, /* Sy */ + { termp_sy_pre, termp_sy_post }, /* Sy */ { NULL, NULL }, /* Tn */ { termp_ux_pre, NULL }, /* Ux */ { NULL, NULL }, /* Xc */ @@ -252,7 +260,7 @@ const struct termact __termacts[MDOC_MAX] = { { NULL, NULL }, /* Oc */ { NULL, NULL }, /* Bk */ { NULL, NULL }, /* Ek */ - { NULL, NULL }, /* Bt */ + { termp_bt_pre, NULL }, /* Bt */ { NULL, NULL }, /* Hf */ { NULL, NULL }, /* Fr */ { termp_ud_pre, NULL }, /* Ud */ @@ -793,6 +801,16 @@ termp_op_pre(DECL_ARGS) /* ARGSUSED */ static int +termp_bt_pre(DECL_ARGS) +{ + + word(p, "is currently in beta test."); + return(1); +} + + +/* ARGSUSED */ +static int termp_ud_pre(DECL_ARGS) { @@ -1431,6 +1449,8 @@ termp_fo_pre(DECL_ARGS) } else if (MDOC_HEAD != node->type) return(1); + /* XXX - groff shows only first parameter */ + p->flags |= ttypes[TTYPE_FUNC_NAME]; for (n = node->child; n; n = n->next) { assert(MDOC_TEXT == n->type); @@ -1455,3 +1475,107 @@ termp_fo_post(DECL_ARGS) } +/* ARGSUSED */ +static int +termp_bf_pre(DECL_ARGS) +{ + const struct mdoc_node *n; + const struct mdoc_block *b; + + /* XXX - we skip over possible trailing HEAD tokens. */ + + if (MDOC_HEAD == node->type) + return(0); + else if (MDOC_BLOCK != node->type) + return(1); + + b = &node->data.block; + + if (NULL == (n = b->head->child)) { + if (arg_hasattr(MDOC_Emphasis, b->argc, b->argv)) + p->flags |= ttypes[TTYPE_EMPH]; + else if (arg_hasattr(MDOC_Symbolic, b->argc, b->argv)) + p->flags |= ttypes[TTYPE_SYMB]; + + return(1); + } + + assert(MDOC_TEXT == n->type); + + if (0 == strcmp("Em", n->data.text.string)) + p->flags |= ttypes[TTYPE_EMPH]; + else if (0 == strcmp("Sy", n->data.text.string)) + p->flags |= ttypes[TTYPE_SYMB]; + + return(1); +} + + +/* ARGSUSED */ +static void +termp_bf_post(DECL_ARGS) +{ + const struct mdoc_node *n; + const struct mdoc_block *b; + + if (MDOC_BLOCK != node->type) + return; + + b = &node->data.block; + + if (NULL == (n = b->head->child)) { + if (arg_hasattr(MDOC_Emphasis, b->argc, b->argv)) + p->flags &= ~ttypes[TTYPE_EMPH]; + else if (arg_hasattr(MDOC_Symbolic, b->argc, b->argv)) + p->flags &= ~ttypes[TTYPE_SYMB]; + + return; + } + + assert(MDOC_TEXT == n->type); + + if (0 == strcmp("Emphasis", n->data.text.string)) + p->flags &= ~ttypes[TTYPE_EMPH]; + else if (0 == strcmp("Symbolic", n->data.text.string)) + p->flags &= ~ttypes[TTYPE_SYMB]; + + return; +} + + +/* ARGSUSED */ +static int +termp_sy_pre(DECL_ARGS) +{ + + p->flags |= ttypes[TTYPE_SYMB]; + return(1); +} + + +/* ARGSUSED */ +static void +termp_sy_post(DECL_ARGS) +{ + + p->flags &= ~ttypes[TTYPE_SYMB]; +} + + +/* ARGSUSED */ +static int +termp_ms_pre(DECL_ARGS) +{ + + p->flags |= ttypes[TTYPE_SYMBOL]; + return(1); +} + + +/* ARGSUSED */ +static void +termp_ms_post(DECL_ARGS) +{ + + p->flags &= ~ttypes[TTYPE_SYMBOL]; +} @@ -55,6 +55,7 @@ static int check_text(struct mdoc *, size_t, size_t, const char *); static int err_child_lt(struct mdoc *, const char *, int); +static int warn_child_lt(struct mdoc *, const char *, int); static int err_child_gt(struct mdoc *, const char *, int); static int warn_child_gt(struct mdoc *, const char *, int); static int err_child_eq(struct mdoc *, const char *, int); @@ -89,7 +90,7 @@ static int pre_prologue(PRE_ARGS); /* Specific post-child-parse routines. */ static int herr_ge1(POST_ARGS); -static int herr_le1(POST_ARGS); +static int hwarn_le1(POST_ARGS); static int herr_eq0(POST_ARGS); static int eerr_eq0(POST_ARGS); static int eerr_le1(POST_ARGS); @@ -153,7 +154,7 @@ static v_post posts_an[] = { post_an, NULL }; static v_post posts_at[] = { post_at, NULL }; static v_post posts_xr[] = { eerr_ge1, eerr_le2, post_xr, NULL }; static v_post posts_nm[] = { post_nm, NULL }; -static v_post posts_bf[] = { herr_le1, post_bf, NULL }; +static v_post posts_bf[] = { hwarn_le1, post_bf, NULL }; static v_post posts_rs[] = { herr_eq0, bwarn_ge1, NULL }; static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL }; static v_post posts_bk[] = { herr_eq0, bwarn_ge1, NULL }; @@ -432,6 +433,7 @@ CHECK_CHILD_DEFN(err, gt, >) /* err_child_gt() */ CHECK_CHILD_DEFN(warn, eq, ==) /* warn_child_eq() */ CHECK_CHILD_DEFN(err, eq, ==) /* err_child_eq() */ CHECK_CHILD_DEFN(err, lt, <) /* err_child_lt() */ +CHECK_CHILD_DEFN(warn, lt, <) /* warn_child_lt() */ CHECK_BODY_DEFN(ge1, warn, warn_child_gt, 0) /* bwarn_ge1() */ CHECK_ELEM_DEFN(eq1, warn, warn_child_eq, 1) /* ewarn_eq1() */ CHECK_ELEM_DEFN(eq0, warn, warn_child_eq, 0) /* ewarn_eq0() */ @@ -442,7 +444,7 @@ CHECK_ELEM_DEFN(le1, err, err_child_lt, 2) /* eerr_le1() */ CHECK_ELEM_DEFN(eq0, err, err_child_eq, 0) /* eerr_eq0() */ CHECK_ELEM_DEFN(ge1, err, err_child_gt, 0) /* eerr_ge1() */ CHECK_HEAD_DEFN(eq0, err, err_child_eq, 0) /* herr_eq0() */ -CHECK_HEAD_DEFN(le1, err, err_child_lt, 2) /* herr_le1() */ +CHECK_HEAD_DEFN(le1, warn, warn_child_lt, 2) /* hwarn_le1() */ CHECK_HEAD_DEFN(ge1, err, err_child_gt, 0) /* herr_ge1() */ CHECK_HEAD_DEFN(eq1, warn, warn_child_eq, 1) /* hwarn_eq1() */ |