source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Unify mdoc_deroff() and man_deroff() into a common function
Date: Thu, 23 Apr 2015 11:18:15 -0500 (EST)	[thread overview]
Message-ID: <12224571226328924909.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Unify mdoc_deroff() and man_deroff() into a common function deroff().
No functional change except that for mdoc(7), it now skips leading
escape sequences just like it already did for man(7).  
Escape sequences rarely occur in mdoc(7) code and if they do,
skipping them is an improvement in this context.
Minus 30 lines of code.

Modified Files:
--------------
    mdocml:
        man.c
        man.h
        mandocdb.c
        mdoc.c
        mdoc.h
        mdoc_validate.c
        roff.c
        roff.h

Revision Data
-------------
Index: mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc.c,v
retrieving revision 1.251
retrieving revision 1.252
diff -Lmdoc.c -Lmdoc.c -u -p -r1.251 -r1.252
--- mdoc.c
+++ mdoc.c
@@ -507,42 +507,3 @@ mdoc_isdelim(const char *p)
 
 	return(DELIM_NONE);
 }
-
-void
-mdoc_deroff(char **dest, const struct roff_node *n)
-{
-	char	*cp;
-	size_t	 sz;
-
-	if (n->type != ROFFT_TEXT) {
-		for (n = n->child; n; n = n->next)
-			mdoc_deroff(dest, n);
-		return;
-	}
-
-	/* Skip leading whitespace. */
-
-	for (cp = n->string; '\0' != *cp; cp++)
-		if (0 == isspace((unsigned char)*cp))
-			break;
-
-	/* Skip trailing whitespace. */
-
-	for (sz = strlen(cp); sz; sz--)
-		if (0 == isspace((unsigned char)cp[sz-1]))
-			break;
-
-	/* Skip empty strings. */
-
-	if (0 == sz)
-		return;
-
-	if (NULL == *dest) {
-		*dest = mandoc_strndup(cp, sz);
-		return;
-	}
-
-	mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp);
-	free(*dest);
-	*dest = cp;
-}
Index: roff.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -Lroff.h -Lroff.h -u -p -r1.33 -r1.34
--- roff.h
+++ roff.h
@@ -157,3 +157,9 @@ struct	roff_man {
 	enum roff_sec	  lastnamed; /* Last standard section seen. */
 	enum roff_next	  next;    /* Where to put the next node. */
 };
+
+__BEGIN_DECLS
+
+void		 deroff(char **, const struct roff_node *);
+
+__END_DECLS
Index: mdoc.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc.h,v
retrieving revision 1.141
retrieving revision 1.142
diff -Lmdoc.h -Lmdoc.h -u -p -r1.141 -r1.142
--- mdoc.h
+++ mdoc.h
@@ -279,11 +279,3 @@ extern	const char *const *mdoc_macroname
 
 /* Names of macro args.  Index is enum mdocargt. */
 extern	const char *const *mdoc_argnames;
-
-__BEGIN_DECLS
-
-struct	roff_man;
-
-void mdoc_deroff(char **, const struct roff_node *);
-
-__END_DECLS
Index: mandocdb.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandocdb.c,v
retrieving revision 1.193
retrieving revision 1.194
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.193 -r1.194
--- mandocdb.c
+++ mandocdb.c
@@ -1476,7 +1476,7 @@ parse_man(struct mpage *mpage, const str
 			 */
 
 			title = NULL;
-			man_deroff(&title, body);
+			deroff(&title, body);
 			if (NULL == title)
 				return;
 
@@ -1720,7 +1720,7 @@ parse_mdoc_Nd(struct mpage *mpage, const
 {
 
 	if (n->type == ROFFT_BODY)
-		mdoc_deroff(&mpage->desc, n);
+		deroff(&mpage->desc, n);
 	return(0);
 }
 
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_validate.c,v
retrieving revision 1.290
retrieving revision 1.291
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.290 -r1.291
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -969,7 +969,7 @@ post_nm(POST_ARGS)
 	if (NULL != mdoc->meta.name)
 		return;
 
-	mdoc_deroff(&mdoc->meta.name, n);
+	deroff(&mdoc->meta.name, n);
 
 	if (NULL == mdoc->meta.name)
 		mandoc_msg(MANDOCERR_NM_NONAME, mdoc->parse,
@@ -1883,7 +1883,7 @@ post_sh_head(POST_ARGS)
 
 	secname = NULL;
 	sec = SEC_CUSTOM;
-	mdoc_deroff(&secname, mdoc->last);
+	deroff(&secname, mdoc->last);
 	sec = NULL == secname ? SEC_CUSTOM : a2sec(secname);
 
 	/* The NAME should be first. */
@@ -2132,7 +2132,7 @@ post_dd(POST_ARGS)
 	}
 
 	datestr = NULL;
-	mdoc_deroff(&datestr, n);
+	deroff(&datestr, n);
 	if (mdoc->quick)
 		mdoc->meta.date = datestr;
 	else {
@@ -2267,7 +2267,7 @@ post_os(POST_ARGS)
 
 	free(mdoc->meta.os);
 	mdoc->meta.os = NULL;
-	mdoc_deroff(&mdoc->meta.os, n);
+	deroff(&mdoc->meta.os, n);
 	if (mdoc->meta.os)
 		goto out;
 
Index: man.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man.h,v
retrieving revision 1.74
retrieving revision 1.75
diff -Lman.h -Lman.h -u -p -r1.74 -r1.75
--- man.h
+++ man.h
@@ -64,6 +64,5 @@ __BEGIN_DECLS
 struct	roff_man;
 
 const struct mparse   *man_mparse(const struct roff_man *);
-void man_deroff(char **, const struct roff_node *);
 
 __END_DECLS
Index: roff.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.c,v
retrieving revision 1.268
retrieving revision 1.269
diff -Lroff.c -Lroff.c -u -p -r1.268 -r1.269
--- roff.c
+++ roff.c
@@ -1230,6 +1230,52 @@ roff_node_delete(struct roff_man *man, s
 	roff_node_free(n);
 }
 
+void
+deroff(char **dest, const struct roff_node *n)
+{
+	char	*cp;
+	size_t	 sz;
+
+	if (n->type != ROFFT_TEXT) {
+		for (n = n->child; n != NULL; n = n->next)
+			deroff(dest, n);
+		return;
+	}
+
+	/* Skip leading whitespace and escape sequences. */
+
+	cp = n->string;
+	while (*cp != '\0') {
+		if ('\\' == *cp) {
+			cp++;
+			mandoc_escape((const char **)&cp, NULL, NULL);
+		} else if (isspace((unsigned char)*cp))
+			cp++;
+		else
+			break;
+	}
+
+	/* Skip trailing whitespace. */
+
+	for (sz = strlen(cp); sz; sz--)
+		if ( ! isspace((unsigned char)cp[sz-1]))
+			break;
+
+	/* Skip empty strings. */
+
+	if (sz == 0)
+		return;
+
+	if (*dest == NULL) {
+		*dest = mandoc_strndup(cp, sz);
+		return;
+	}
+
+	mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp);
+	free(*dest);
+	*dest = cp;
+}
+
 /* --- main functions of the roff parser ---------------------------------- */
 
 /*
Index: man.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man.c,v
retrieving revision 1.162
retrieving revision 1.163
diff -Lman.c -Lman.c -u -p -r1.162 -r1.163
--- man.c
+++ man.c
@@ -318,49 +318,3 @@ man_mparse(const struct roff_man *man)
 	assert(man && man->parse);
 	return(man->parse);
 }
-
-void
-man_deroff(char **dest, const struct roff_node *n)
-{
-	char	*cp;
-	size_t	 sz;
-
-	if (n->type != ROFFT_TEXT) {
-		for (n = n->child; n; n = n->next)
-			man_deroff(dest, n);
-		return;
-	}
-
-	/* Skip leading whitespace and escape sequences. */
-
-	cp = n->string;
-	while ('\0' != *cp) {
-		if ('\\' == *cp) {
-			cp++;
-			mandoc_escape((const char **)&cp, NULL, NULL);
-		} else if (isspace((unsigned char)*cp))
-			cp++;
-		else
-			break;
-	}
-
-	/* Skip trailing whitespace. */
-
-	for (sz = strlen(cp); sz; sz--)
-		if (0 == isspace((unsigned char)cp[sz-1]))
-			break;
-
-	/* Skip empty strings. */
-
-	if (0 == sz)
-		return;
-
-	if (NULL == *dest) {
-		*dest = mandoc_strndup(cp, sz);
-		return;
-	}
-
-	mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp);
-	free(*dest);
-	*dest = cp;
-}
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2015-04-23 16:18 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=12224571226328924909.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).