source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: Implement the \\$@ escape sequence (insert all macro arguments,
Date: Tue, 21 Aug 2018 13:15:52 -0500 (EST)	[thread overview]
Message-ID: <c89f23c608c467cb@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Implement the \\$@ escape sequence (insert all macro arguments, 
quoted) in addition to the already supported \\$* (similar, but
unquoted).  Then use \\$@ to improve the implementation of 
the .als request (macro alias).

Needed by groff_hdtbl(7).
Gosh, it feels like the manual pages of the groff package are 
exercising every bloody roff(7) feature under the sun.  In the
manual page source code itself, not merely in the implementation 
of the used macro packages, that is.

Modified Files:
--------------
    mandoc:
        roff.7
        roff.c

Revision Data
-------------
Index: roff.7
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.7,v
retrieving revision 1.101
retrieving revision 1.102
diff -Lroff.7 -Lroff.7 -u -p -r1.101 -r1.102
--- roff.7
+++ roff.7
@@ -634,6 +634,8 @@ produces
 in the input stream, and thus in the output: \fI\^XtFree\^\fP.
 Each occurrence of \e\e$* is replaced with all the arguments,
 joined together with single space characters.
+The variant \e\e$@ is similar, except that each argument is
+individually quoted.
 .Pp
 Since macros and user-defined strings share a common string table,
 defining a macro
@@ -1838,6 +1840,9 @@ Discard the rest of the physical input l
 input line on the next physical input line, joining the text on
 both lines together as if it were on a single input line.
 This is a groff extension.
+.Ss \e$ Ns Ar arg
+Macro argument expansion, see
+.Sx de .
 .Ss \e%
 Hyphenation allowed at this point of the word; ignored by
 .Xr mandoc 1 .
Index: roff.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.c,v
retrieving revision 1.337
retrieving revision 1.338
diff -Lroff.c -Lroff.c -u -p -r1.337 -r1.338
--- roff.c
+++ roff.c
@@ -3156,7 +3156,7 @@ roff_als(ROFF_ARGS)
 	if (oldsz == 0)
 		return ROFF_IGN;
 
-	valsz = mandoc_asprintf(&value, ".%.*s \\$*\\\"\n",
+	valsz = mandoc_asprintf(&value, ".%.*s \\$@\\\"\n",
 	    (int)oldsz, oldn);
 	roff_setstrn(&r->strtab, newn, newsz, value, valsz, 0);
 	roff_setstrn(&r->rentab, newn, newsz, NULL, 0, 0);
@@ -3380,7 +3380,7 @@ roff_userdef(ROFF_ARGS)
 {
 	const char	 *arg[16], *ap;
 	char		 *cp, *n1, *n2;
-	int		  argc, expand_count, i, ib, ie;
+	int		  argc, expand_count, i, ib, ie, quote_args;
 	size_t		  asz, esz, rsz;
 
 	/*
@@ -3415,13 +3415,21 @@ roff_userdef(ROFF_ARGS)
 			continue;
 		if (*cp++ != '$')
 			continue;
-		if (*cp == '*') {  /* \\$* inserts all arguments */
+
+		quote_args = 0;
+		switch (*cp) {
+		case '@':  /* \\$@ inserts all arguments, quoted */
+			quote_args = 1;
+			/* FALLTHROUGH */
+		case '*':  /* \\$* inserts all arguments, unquoted */
 			ib = 0;
 			ie = argc - 1;
-		} else {  /* \\$1 .. \\$9 insert one argument */
+			break;
+		default:  /* \\$1 .. \\$9 insert one argument */
 			ib = ie = *cp - '1';
 			if (ib < 0 || ib > 8)
 				continue;
+			break;
 		}
 		cp -= 2;
 
@@ -3447,6 +3455,8 @@ roff_userdef(ROFF_ARGS)
 
 		asz = ie > ib ? ie - ib : 0;  /* for blanks */
 		for (i = ib; i <= ie; i++) {
+			if (quote_args)
+				asz += 2;
 			for (ap = arg[i]; *ap != '\0'; ap++) {
 				asz++;
 				if (*ap == '"')
@@ -3493,6 +3503,8 @@ roff_userdef(ROFF_ARGS)
 
 		n2 = cp;
 		for (i = ib; i <= ie; i++) {
+			if (quote_args)
+				*n2++ = '"';
 			for (ap = arg[i]; *ap != '\0'; ap++) {
 				if (*ap == '"') {
 					memcpy(n2, "\\(dq", 4);
@@ -3500,6 +3512,8 @@ roff_userdef(ROFF_ARGS)
 				} else
 					*n2++ = *ap;
 			}
+			if (quote_args)
+				*n2++ = '"';
 			if (i < ie)
 				*n2++ = ' ';
 		}
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

                 reply	other threads:[~2018-08-21 18:15 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=c89f23c608c467cb@fantadrom.bsd.lv \
    --to=schwarze@mandoc.bsd.lv \
    --cc=source@mandoc.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).