From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Move `Mt', `Ar', and `Li' handling from mdoc_action.c into
Date: Mon, 29 Nov 2010 08:02:47 -0500 (EST) [thread overview]
Message-ID: <201011291302.oATD2l2l029749@krisdoz.my.domain> (raw)
Log Message:
-----------
Move `Mt', `Ar', and `Li' handling from mdoc_action.c into mdoc_validate.c.
Clarify that `Mt' gets a default `~' (as per groff 1.20) and document it
in mdoc.7.
Made `Lk' be removed in mdoc_macro.c if it has no arguments. This fixes
segfaults in mdoc_{term,html}.c that nobody's managed to raise yet.
Modified Files:
--------------
mdocml:
mdoc.7
mdoc_action.c
mdoc_html.c
mdoc_macro.c
mdoc_term.c
mdoc_validate.c
Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.122
retrieving revision 1.123
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.122 -r1.123
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -85,6 +85,8 @@ static int post_at(POST_ARGS);
static int post_bf(POST_ARGS);
static int post_bl(POST_ARGS);
static int post_bl_head(POST_ARGS);
+static int post_defaults(POST_ARGS);
+static int post_eoln(POST_ARGS);
static int post_dt(POST_ARGS);
static int post_it(POST_ARGS);
static int post_lb(POST_ARGS);
@@ -95,7 +97,6 @@ static int post_sh(POST_ARGS);
static int post_sh_body(POST_ARGS);
static int post_sh_head(POST_ARGS);
static int post_st(POST_ARGS);
-static int post_eoln(POST_ARGS);
static int post_vt(POST_ARGS);
static int pre_an(PRE_ARGS);
static int pre_bd(PRE_ARGS);
@@ -117,6 +118,7 @@ static v_post posts_bf[] = { hwarn_le1,
static v_post posts_bl[] = { bwarn_ge1, post_bl, NULL };
static v_post posts_bool[] = { eerr_eq1, ebool, NULL };
static v_post posts_eoln[] = { post_eoln, NULL };
+static v_post posts_defaults[] = { post_defaults, NULL };
static v_post posts_dt[] = { post_dt, NULL };
static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL };
static v_post posts_it[] = { post_it, NULL };
@@ -167,7 +169,7 @@ const struct valids mdoc_valids[MDOC_MAX
{ pres_it, posts_it }, /* It */
{ NULL, posts_text }, /* Ad */
{ pres_an, posts_an }, /* An */
- { NULL, NULL }, /* Ar */
+ { NULL, posts_defaults }, /* Ar */
{ NULL, posts_text }, /* Cd */
{ NULL, NULL }, /* Cm */
{ NULL, NULL }, /* Dv */
@@ -181,7 +183,7 @@ const struct valids mdoc_valids[MDOC_MAX
{ NULL, posts_wtext }, /* Ft */
{ NULL, posts_text }, /* Ic */
{ NULL, posts_text1 }, /* In */
- { NULL, NULL }, /* Li */
+ { NULL, posts_defaults }, /* Li */
{ NULL, posts_nd }, /* Nd */
{ NULL, posts_nm }, /* Nm */
{ NULL, posts_wline }, /* Op */
@@ -260,7 +262,7 @@ const struct valids mdoc_valids[MDOC_MAX
{ NULL, posts_lb }, /* Lb */
{ NULL, posts_notext }, /* Lp */
{ NULL, posts_text }, /* Lk */
- { NULL, posts_text }, /* Mt */
+ { NULL, posts_defaults }, /* Mt */
{ NULL, posts_wline }, /* Brq */
{ NULL, NULL }, /* Bro */
{ NULL, NULL }, /* Brc */
@@ -1133,6 +1135,46 @@ post_nm(POST_ARGS)
return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NONAME));
}
+static int
+post_defaults(POST_ARGS)
+{
+ struct mdoc_node *nn;
+
+ /*
+ * The `Ar' defaults to "file ..." if no value is provided as an
+ * argument; the `Mt' macro uses "~"; the `Li' just gets an
+ * empty string.
+ */
+
+ if (mdoc->last->child)
+ return(1);
+
+ nn = mdoc->last;
+ mdoc->next = MDOC_NEXT_CHILD;
+
+ switch (nn->tok) {
+ case (MDOC_Ar):
+ if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "file"))
+ return(0);
+ if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "..."))
+ return(0);
+ break;
+ case (MDOC_Li):
+ if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, ""))
+ return(0);
+ break;
+ case (MDOC_Mt):
+ if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "~"))
+ return(0);
+ break;
+ default:
+ abort();
+ /* NOTREACHED */
+ }
+
+ mdoc->last = nn;
+ return(1);
+}
static int
post_at(POST_ARGS)
Index: mdoc_macro.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_macro.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.95 -r1.96
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -790,7 +790,7 @@ in_line(MACRO_PROT_ARGS)
/* FALLTHROUGH */
case (MDOC_Fl):
/* FALLTHROUGH */
- case (MDOC_Lk):
+ case (MDOC_Mt):
/* FALLTHROUGH */
case (MDOC_Nm):
/* FALLTHROUGH */
Index: mdoc_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v
retrieving revision 1.112
retrieving revision 1.113
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.112 -r1.113
--- mdoc_html.c
+++ mdoc_html.c
@@ -1675,7 +1675,7 @@ mdoc_lk_pre(MDOC_ARGS)
PAIR_HREF_INIT(&tag[1], nn->string);
print_otag(h, TAG_A, 2, tag);
- if (NULL == nn->next)
+ if (NULL == nn || NULL == nn->next)
return(1);
for (nn = nn->next; nn; nn = nn->next)
Index: mdoc_action.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_action.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -Lmdoc_action.c -Lmdoc_action.c -u -p -r1.79 -r1.80
--- mdoc_action.c
+++ mdoc_action.c
@@ -51,7 +51,6 @@ struct actions {
static int concat(struct mdoc *, char *,
const struct mdoc_node *, size_t);
-static int post_ar(POST_ARGS);
static int post_at(POST_ARGS);
static int post_bl(POST_ARGS);
static int post_bl_head(POST_ARGS);
@@ -61,7 +60,6 @@ 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_li(POST_ARGS);
static int post_nm(POST_ARGS);
static int post_os(POST_ARGS);
static int post_pa(POST_ARGS);
@@ -90,7 +88,7 @@ static const struct actions mdoc_actions
{ NULL, NULL }, /* It */
{ NULL, NULL }, /* Ad */
{ NULL, NULL }, /* An */
- { NULL, post_ar }, /* Ar */
+ { NULL, NULL }, /* Ar */
{ NULL, NULL }, /* Cd */
{ NULL, NULL }, /* Cm */
{ NULL, NULL }, /* Dv */
@@ -104,7 +102,7 @@ static const struct actions mdoc_actions
{ NULL, NULL }, /* Ft */
{ NULL, NULL }, /* Ic */
{ NULL, NULL }, /* In */
- { NULL, post_li }, /* Li */
+ { NULL, NULL }, /* Li */
{ NULL, NULL }, /* Nd */
{ NULL, post_nm }, /* Nm */
{ NULL, NULL }, /* Op */
@@ -850,51 +848,6 @@ post_pa(POST_ARGS)
np = n;
m->next = MDOC_NEXT_CHILD;
if ( ! mdoc_word_alloc(m, n->line, n->pos, "~"))
- return(0);
- m->last = np;
- return(1);
-}
-
-
-/*
- * Empty `Li' macros get an empty string to make front-ends add an extra
- * space.
- */
-static int
-post_li(POST_ARGS)
-{
- struct mdoc_node *np;
-
- if (n->child)
- return(1);
-
- np = n;
- m->next = MDOC_NEXT_CHILD;
- if ( ! mdoc_word_alloc(m, n->line, n->pos, ""))
- return(0);
- m->last = np;
- return(1);
-}
-
-
-/*
- * The `Ar' macro defaults to two strings "file ..." if no value is
- * provided as an argument.
- */
-static int
-post_ar(POST_ARGS)
-{
- struct mdoc_node *np;
-
- if (n->child)
- return(1);
-
- np = n;
- m->next = MDOC_NEXT_CHILD;
- /* XXX: make into macro values. */
- if ( ! mdoc_word_alloc(m, n->line, n->pos, "file"))
- return(0);
- if ( ! mdoc_word_alloc(m, n->line, n->pos, "..."))
return(0);
m->last = np;
return(1);
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.194
retrieving revision 1.195
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.194 -r1.195
--- mdoc_term.c
+++ mdoc_term.c
@@ -2076,7 +2076,7 @@ termp_lk_pre(DECL_ARGS)
nn = sv = n->child;
- if (NULL == nn->next)
+ if (NULL == nn || NULL == nn->next)
return(1);
for (nn = nn->next; nn; nn = nn->next)
Index: mdoc.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.7,v
retrieving revision 1.163
retrieving revision 1.164
diff -Lmdoc.7 -Lmdoc.7 -u -p -r1.163 -r1.164
--- mdoc.7
+++ mdoc.7
@@ -2124,6 +2124,9 @@ Examples:
Format a
.Dq mailto:
hyperlink.
+If an argument is not provided, the string
+.Dq \(ti
+is used as a default.
Its syntax is as follows:
.Pp
.D1 Pf \. Sx \&Mt Cm address
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2010-11-29 13:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201011291302.oATD2l2l029749@krisdoz.my.domain \
--to=kristaps@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).