source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Reduce code duplication by reusing the same argument parser  for
Date: Fri, 28 Nov 2014 23:31:35 -0500 (EST)	[thread overview]
Message-ID: <14938041160432633951.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Reduce code duplication by reusing the same argument parser 
for in_line_eoln() macros and .Bl -column phrases.
No functional change.

Modified Files:
--------------
    mdocml:
        mdoc_macro.c

Revision Data
-------------
Index: mdoc_macro.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_macro.c,v
retrieving revision 1.153
retrieving revision 1.154
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.153 -r1.154
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -57,7 +57,8 @@ static	enum mdoct	lookup(enum mdoct, con
 static	int		macro_or_word(MACRO_PROT_ARGS, int);
 static	int		make_pending(struct mdoc_node *, enum mdoct,
 				struct mdoc *, int, int);
-static	void		phrase(struct mdoc *, int, int *, char *);
+static	int		parse_rest(struct mdoc *, enum mdoct,
+				int, int *, char *);
 static	enum mdoct	rew_alt(enum mdoct);
 static	enum rew	rew_dohalt(enum mdoct, enum mdoc_type,
 				const struct mdoc_node *);
@@ -1181,7 +1182,7 @@ blk_full(MACRO_PROT_ARGS)
 				mdoc->flags |= MDOC_PPHRASE;
 			if (ac == ARGS_PEND && lac == ARGS_PPHRASE)
 				mdoc->flags |= MDOC_PPHRASE;
-			phrase(mdoc, line, &la, buf);
+			parse_rest(mdoc, MDOC_MAX, line, &la, buf);
 			mdoc->flags &= ~MDOC_PPHRASE;
 			continue;
 		}
@@ -1473,7 +1474,6 @@ in_line_argn(MACRO_PROT_ARGS)
 static void
 in_line_eoln(MACRO_PROT_ARGS)
 {
-	int		 la;
 	struct mdoc_arg	*arg;
 
 	if (tok == MDOC_Pp)
@@ -1481,15 +1481,28 @@ in_line_eoln(MACRO_PROT_ARGS)
 
 	mdoc_argv(mdoc, line, tok, &arg, pos, buf);
 	mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
+	if (parse_rest(mdoc, tok, line, pos, buf))
+		return;
+	rew_elem(mdoc, tok);
+}
+
+/*
+ * The simplest argument parser available: Parse the remaining
+ * words until the end of the phrase or line and return 0
+ * or until the next macro, call that macro, and return 1.
+ */
+static int
+parse_rest(struct mdoc *mdoc, enum mdoct tok, int line, int *pos, char *buf)
+{
+	int		 la;
 
 	for (;;) {
 		la = *pos;
 		if (mdoc_args(mdoc, line, pos, buf, tok, NULL) == ARGS_EOLN)
-			break;
+			return(0);
 		if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))
-			return;
+			return(1);
 	}
-	rew_elem(mdoc, tok);
 }
 
 static void
@@ -1512,17 +1525,6 @@ ctx_synopsis(MACRO_PROT_ARGS)
  * macro is encountered.
  */
 static void
-phrase(struct mdoc *mdoc, int line, int *pos, char *buf)
-{
-	int		 la;
-
-	do
-		la = *pos;
-	while (mdoc_args(mdoc, line, pos, buf, MDOC_MAX, NULL) != ARGS_EOLN &&
-	    !macro_or_word(mdoc, MDOC_MAX, line, la, pos, buf, 1));
-}
-
-static void
 phrase_ta(MACRO_PROT_ARGS)
 {
 	struct mdoc_node *n;
@@ -1542,5 +1544,5 @@ phrase_ta(MACRO_PROT_ARGS)
 
 	rew_sub(MDOC_BODY, mdoc, MDOC_It, line, ppos);
 	mdoc_body_alloc(mdoc, line, ppos, MDOC_It);
-	phrase(mdoc, line, pos, buf);
+	parse_rest(mdoc, MDOC_MAX, line, pos, buf);
 }
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-11-29  4:31 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=14938041160432633951.enqueue@fantadrom.bsd.lv \
    --to=schwarze@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).