From dad3c2117152071099f857651e99f8673aa988dd Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sun, 12 Jul 2009 20:50:08 +0000 Subject: Replacement of `Lb' in mdoc_action.c. Added warning against bogus `Lb' (like groff does). Added proper quotes around `Lb' in mdoc_term.c. Moved mdoc_a2lib -> libmdoc (where it belongs). --- libmdoc.h | 4 +++- mdoc.c | 3 ++- mdoc.h | 4 +--- mdoc_action.c | 35 +++++++++++++++++++++++++++++++++-- mdoc_term.c | 22 ++-------------------- mdoc_validate.c | 16 ++++++++++++++-- 6 files changed, 55 insertions(+), 29 deletions(-) diff --git a/libmdoc.h b/libmdoc.h index 1e3cbb3c..c6633890 100644 --- a/libmdoc.h +++ b/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.17 2009/07/12 20:30:35 kristaps Exp $ */ +/* $Id: libmdoc.h,v 1.18 2009/07/12 20:50:08 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -97,6 +97,7 @@ enum merr { EQUOTPHR, ENOCTX, ESPACE, + ELIB, MERRMAX }; @@ -154,6 +155,7 @@ time_t mdoc_atotime(const char *); size_t mdoc_macro2len(int); const char *mdoc_a2att(const char *); +const char *mdoc_a2lib(const char *); const char *mdoc_a2st(const char *); const char *mdoc_a2arch(const char *); const char *mdoc_a2vol(const char *); diff --git a/mdoc.c b/mdoc.c index 45ed32ea..113a4df6 100644 --- a/mdoc.c +++ b/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.89 2009/07/07 09:29:15 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.90 2009/07/12 20:50:08 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -79,6 +79,7 @@ const char *const __mdoc_merrnames[MERRMAX] = { "unterminated quoted phrase", /* EQUOTPHR */ "closure macro without prior context", /* ENOCTX */ "invalid whitespace after control character", /* ESPACE */ + "no description found for library" /* ELIB */ }; const char *const __mdoc_macronames[MDOC_MAX] = { diff --git a/mdoc.h b/mdoc.h index 1f866509..578e1f86 100644 --- a/mdoc.h +++ b/mdoc.h @@ -1,4 +1,4 @@ -/* $Id: mdoc.h,v 1.64 2009/07/12 20:30:35 kristaps Exp $ */ +/* $Id: mdoc.h,v 1.65 2009/07/12 20:50:08 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -295,8 +295,6 @@ const struct mdoc_node *mdoc_node(const struct mdoc *); const struct mdoc_meta *mdoc_meta(const struct mdoc *); int mdoc_endparse(struct mdoc *); -const char *mdoc_a2lib(const char *); - __END_DECLS #endif /*!MDOC_H*/ diff --git a/mdoc_action.c b/mdoc_action.c index 30a75852..dcb938e5 100644 --- a/mdoc_action.c +++ b/mdoc_action.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_action.c,v 1.26 2009/07/12 20:30:35 kristaps Exp $ */ +/* $Id: mdoc_action.c,v 1.27 2009/07/12 20:50:08 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -41,6 +41,7 @@ static int post_bl_width(POST_ARGS); static int post_dd(POST_ARGS); static int post_display(POST_ARGS); static int post_dt(POST_ARGS); +static int post_lb(POST_ARGS); static int post_lk(POST_ARGS); static int post_nm(POST_ARGS); static int post_os(POST_ARGS); @@ -159,7 +160,7 @@ const struct actions mdoc_actions[MDOC_MAX] = { { NULL, NULL }, /* Hf */ { NULL, NULL }, /* Fr */ { NULL, NULL }, /* Ud */ - { NULL, NULL }, /* Lb */ + { NULL, post_lb }, /* Lb */ { NULL, NULL }, /* Lp */ { NULL, post_lk }, /* Lk */ { NULL, NULL }, /* Mt */ @@ -290,6 +291,36 @@ post_nm(POST_ARGS) } +static int +post_lb(POST_ARGS) +{ + const char *p; + char *buf; + size_t sz; + + assert(MDOC_TEXT == m->last->child->type); + p = mdoc_a2lib(m->last->child->string); + if (NULL == p) { + sz = strlen(m->last->child->string) + + 2 + strlen("\\(lqlibrary\\(rq"); + buf = malloc(sz); + if (NULL == buf) + return(mdoc_nerr(m, m->last, EMALLOC)); + (void)snprintf(buf, sz, "library \\(lq%s\\(rq", + m->last->child->string); + free(m->last->child->string); + m->last->child->string = buf; + return(1); + } + + free(m->last->child->string); + m->last->child->string = strdup(p); + if (NULL == m->last->child->string) + return(mdoc_nerr(m, m->last, EMALLOC)); + return(1); +} + + static int post_st(POST_ARGS) { diff --git a/mdoc_term.c b/mdoc_term.c index 122e3534..208dc94c 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.36 2009/07/12 20:30:35 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.37 2009/07/12 20:50:08 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -147,7 +147,6 @@ static int termp_ft_pre(DECL_ARGS); static int termp_ic_pre(DECL_ARGS); static int termp_in_pre(DECL_ARGS); static int termp_it_pre(DECL_ARGS); -static int termp_lb_pre(DECL_ARGS); static int termp_lk_pre(DECL_ARGS); static int termp_ms_pre(DECL_ARGS); static int termp_mt_pre(DECL_ARGS); @@ -281,7 +280,7 @@ static const struct termact termacts[MDOC_MAX] = { { NULL, NULL }, /* Hf */ { NULL, NULL }, /* Fr */ { termp_ud_pre, NULL }, /* Ud */ - { termp_lb_pre, termp_lb_post }, /* Lb */ + { NULL, termp_lb_post }, /* Lb */ { termp_pp_pre, NULL }, /* Lp */ { termp_lk_pre, NULL }, /* Lk */ { termp_mt_pre, NULL }, /* Mt */ @@ -1283,23 +1282,6 @@ termp_bt_pre(DECL_ARGS) } -/* ARGSUSED */ -static int -termp_lb_pre(DECL_ARGS) -{ - const char *lb; - - assert(node->child && MDOC_TEXT == node->child->type); - lb = mdoc_a2lib(node->child->string); - if (lb) { - term_word(p, lb); - return(0); - } - term_word(p, "library"); - return(1); -} - - /* ARGSUSED */ static void termp_lb_post(DECL_ARGS) diff --git a/mdoc_validate.c b/mdoc_validate.c index 1c5d8c9f..24253d05 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.30 2009/07/12 20:30:35 kristaps Exp $ */ +/* $Id: mdoc_validate.c,v 1.31 2009/07/12 20:50:08 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -90,6 +90,7 @@ static int berr_ge1(POST_ARGS); static int hwarn_eq1(POST_ARGS); static int ewarn_ge1(POST_ARGS); static int ebool(POST_ARGS); + static int post_an(POST_ARGS); static int post_args(POST_ARGS); static int post_at(POST_ARGS); @@ -97,6 +98,7 @@ static int post_bf(POST_ARGS); static int post_bl(POST_ARGS); static int post_bl_head(POST_ARGS); static int post_it(POST_ARGS); +static int post_lb(POST_ARGS); static int post_nm(POST_ARGS); static int post_root(POST_ARGS); static int post_sh(POST_ARGS); @@ -133,7 +135,7 @@ static v_post posts_in[] = { eerr_eq1, NULL }; static v_post posts_ss[] = { herr_ge1, NULL }; static v_post posts_nd[] = { berr_ge1, NULL }; static v_post posts_pf[] = { eerr_eq1, NULL }; -static v_post posts_lb[] = { eerr_eq1, NULL }; +static v_post posts_lb[] = { eerr_eq1, post_lb, NULL }; static v_post posts_st[] = { eerr_eq1, post_st, NULL }; static v_post posts_pp[] = { ewarn_eq0, NULL }; static v_post posts_ex[] = { eerr_eq0, post_args, NULL }; @@ -874,6 +876,16 @@ post_bf(POST_ARGS) } +static int +post_lb(POST_ARGS) +{ + + if (mdoc_a2lib(mdoc->last->child->string)) + return(1); + return(mdoc_nwarn(mdoc, mdoc->last, ELIB)); +} + + static int post_nm(POST_ARGS) { -- cgit v1.2.3-56-ge451