source@mandoc.bsd.lv
 help / color / Atom feed
* mandoc: undocumented options -O outfilename and -O tagfilename to
@ 2020-07-21 15:10 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2020-07-21 15:10 UTC (permalink / raw)
  To: source

Log Message:
-----------
undocumented options -O outfilename and -O tagfilename
to support regression testing without a tty;
no user visible change intended

Modified Files:
--------------
    mandoc:
        main.c
        manconf.h
        manpath.c
        term_tag.c
        term_tag.h

Revision Data
-------------
Index: manconf.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/manconf.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -Lmanconf.h -Lmanconf.h -u -p -r1.8 -r1.9
--- manconf.h
+++ manconf.h
@@ -31,9 +31,11 @@ struct	manpaths {
 struct	manoutput {
 	char	 *includes;
 	char	 *man;
+	char	 *outfilename;
 	char	 *paper;
 	char	 *style;
 	char	 *tag;
+	char	 *tagfilename;
 	size_t	  indent;
 	size_t	  width;
 	int	  fragment;
Index: term_tag.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/term_tag.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -Lterm_tag.c -Lterm_tag.c -u -p -r1.4 -r1.5
--- term_tag.c
+++ term_tag.c
@@ -22,6 +22,7 @@
 #include <sys/types.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <signal.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -46,7 +47,7 @@ static struct tag_files tag_files;
  * but for simplicity, create it anyway.
  */
 struct tag_files *
-term_tag_init(void)
+term_tag_init(const char *outfilename, const char *tagfilename)
 {
 	struct sigaction	 sa;
 	int			 ofd;	/* In /tmp/, dup(2)ed to stdout. */
@@ -83,19 +84,43 @@ term_tag_init(void)
 
 	/* Create both temporary output files. */
 
-	(void)strlcpy(tag_files.ofn, "/tmp/man.XXXXXXXXXX",
-	    sizeof(tag_files.ofn));
-	(void)strlcpy(tag_files.tfn, "/tmp/man.XXXXXXXXXX",
-	    sizeof(tag_files.tfn));
-	if ((ofd = mkstemp(tag_files.ofn)) == -1) {
-		mandoc_msg(MANDOCERR_MKSTEMP, 0, 0,
-		    "%s: %s", tag_files.ofn, strerror(errno));
-		goto fail;
-	}
-	if ((tfd = mkstemp(tag_files.tfn)) == -1) {
-		mandoc_msg(MANDOCERR_MKSTEMP, 0, 0,
-		    "%s: %s", tag_files.tfn, strerror(errno));
-		goto fail;
+	if (outfilename == NULL) {
+		(void)strlcpy(tag_files.ofn, "/tmp/man.XXXXXXXXXX",
+		    sizeof(tag_files.ofn));
+		if ((ofd = mkstemp(tag_files.ofn)) == -1) {
+			mandoc_msg(MANDOCERR_MKSTEMP, 0, 0,
+			    "%s: %s", tag_files.ofn, strerror(errno));
+			goto fail;
+		}
+	} else {
+		(void)strlcpy(tag_files.ofn, outfilename,
+		   sizeof(tag_files.ofn));
+		unlink(outfilename);
+		ofd = open(outfilename, O_WRONLY | O_CREAT | O_EXCL, 0644);
+		if (ofd == -1) {
+			mandoc_msg(MANDOCERR_OPEN, 0, 0,
+			    "%s: %s", outfilename, strerror(errno));
+			goto fail;
+		}
+	}
+	if (tagfilename == NULL) {
+		(void)strlcpy(tag_files.tfn, "/tmp/man.XXXXXXXXXX",
+		    sizeof(tag_files.tfn));
+		if ((tfd = mkstemp(tag_files.tfn)) == -1) {
+			mandoc_msg(MANDOCERR_MKSTEMP, 0, 0,
+			    "%s: %s", tag_files.tfn, strerror(errno));
+			goto fail;
+		}
+	} else {
+		(void)strlcpy(tag_files.tfn, tagfilename,
+		    sizeof(tag_files.tfn));
+		unlink(tagfilename);
+		tfd = open(tagfilename, O_WRONLY | O_CREAT | O_EXCL, 0644);
+		if (tfd == -1) {
+			mandoc_msg(MANDOCERR_OPEN, 0, 0,
+			    "%s: %s", tagfilename, strerror(errno));
+			goto fail;
+		}
 	}
 	if ((tag_files.tfs = fdopen(tfd, "w")) == NULL) {
 		mandoc_msg(MANDOCERR_FDOPEN, 0, 0, "%s", strerror(errno));
@@ -175,11 +200,11 @@ term_tag_unlink(void)
 		    getpgid(tc_pgid) == -1)
 			(void)tcsetpgrp(STDOUT_FILENO, tag_files.tcpgid);
 	}
-	if (*tag_files.ofn != '\0') {
+	if (strncmp(tag_files.ofn, "/tmp/man.", 9) == 0) {
 		unlink(tag_files.ofn);
 		*tag_files.ofn = '\0';
 	}
-	if (*tag_files.tfn != '\0') {
+	if (strncmp(tag_files.tfn, "/tmp/man.", 9) == 0) {
 		unlink(tag_files.tfn);
 		*tag_files.tfn = '\0';
 	}
Index: term_tag.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/term_tag.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lterm_tag.h -Lterm_tag.h -u -p -r1.2 -r1.3
--- term_tag.h
+++ term_tag.h
@@ -19,8 +19,8 @@
  */
 
 struct	tag_files {
-	char	 ofn[20];	/* Output file name. */
-	char	 tfn[20];	/* Tag file name. */
+	char	 ofn[80];	/* Output file name. */
+	char	 tfn[80];	/* Tag file name. */
 	FILE	*tfs;		/* Tag file object. */
 	int	 ofd;		/* Original output file descriptor. */
 	pid_t	 tcpgid;	/* Process group controlling the terminal. */
@@ -28,7 +28,7 @@ struct	tag_files {
 };
 
 
-struct tag_files	*term_tag_init(void);
+struct tag_files	*term_tag_init(const char *, const char *);
 void			 term_tag_write(struct roff_node *, size_t);
 int			 term_tag_close(void);
 void			 term_tag_unlink(void);
Index: manpath.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/manpath.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -Lmanpath.c -Lmanpath.c -u -p -r1.41 -r1.42
--- manpath.c
+++ manpath.c
@@ -224,7 +224,8 @@ manconf_output(struct manoutput *conf, c
 {
 	const char *const toks[] = {
 	    "includes", "man", "paper", "style", "indent", "width",
-	    "tag", "fragment", "mdoc", "noval", "toc"
+	    "tag", "outfilename", "tagfilename",
+	    "fragment", "mdoc", "noval", "toc"
 	};
 	const size_t ntoks = sizeof(toks) / sizeof(toks[0]);
 
@@ -245,11 +246,11 @@ manconf_output(struct manoutput *conf, c
 		}
 	}
 
-	if (tok < 6 && *cp == '\0') {
+	if (tok < 8 && *cp == '\0') {
 		mandoc_msg(MANDOCERR_BADVAL_MISS, 0, 0, "-O %s=?", toks[tok]);
 		return -1;
 	}
-	if (tok > 6 && tok < ntoks && *cp != '\0') {
+	if (tok > 8 && tok < ntoks && *cp != '\0') {
 		mandoc_msg(MANDOCERR_BADVAL, 0, 0, "-O %s=%s", toks[tok], cp);
 		return -1;
 	}
@@ -313,15 +314,29 @@ manconf_output(struct manoutput *conf, c
 		conf->tag = mandoc_strdup(cp);
 		return 0;
 	case 7:
-		conf->fragment = 1;
+		if (conf->outfilename != NULL) {
+			oldval = mandoc_strdup(conf->outfilename);
+			break;
+		}
+		conf->outfilename = mandoc_strdup(cp);
 		return 0;
 	case 8:
-		conf->mdoc = 1;
+		if (conf->tagfilename != NULL) {
+			oldval = mandoc_strdup(conf->tagfilename);
+			break;
+		}
+		conf->tagfilename = mandoc_strdup(cp);
 		return 0;
 	case 9:
-		conf->noval = 1;
+		conf->fragment = 1;
 		return 0;
 	case 10:
+		conf->mdoc = 1;
+		return 0;
+	case 11:
+		conf->noval = 1;
+		return 0;
+	case 12:
 		conf->toc = 1;
 		return 0;
 	default:
Index: main.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/main.c,v
retrieving revision 1.351
retrieving revision 1.352
diff -Lmain.c -Lmain.c -u -p -r1.351 -r1.352
--- main.c
+++ main.c
@@ -165,7 +165,7 @@ main(int argc, char *argv[])
 		return mandocdb(argc, argv);
 
 #if HAVE_PLEDGE
-	if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1) {
+	if (pledge("stdio rpath wpath cpath tmppath tty proc exec", NULL) == -1) {
 		mandoc_msg(MANDOCERR_PLEDGE, 0, 0, "%s", strerror(errno));
 		return mandoc_msg_getrc();
 	}
@@ -373,7 +373,9 @@ main(int argc, char *argv[])
 
 	if (outmode == OUTMODE_FLN ||
 	    outmode == OUTMODE_LST ||
-	    !isatty(STDOUT_FILENO))
+	    (conf.output.outfilename == NULL &&
+	     conf.output.tagfilename == NULL &&
+	     isatty(STDOUT_FILENO) == 0))
 		outst.use_pager = 0;
 
 	if (outst.use_pager &&
@@ -387,12 +389,16 @@ main(int argc, char *argv[])
 	}
 
 #if HAVE_PLEDGE
-	if (outst.use_pager == 0) {
-		if (pledge("stdio rpath", NULL) == -1) {
-			mandoc_msg(MANDOCERR_PLEDGE, 0, 0,
-			    "%s", strerror(errno));
-			return mandoc_msg_getrc();
-		}
+	if (outst.use_pager == 0)
+		c = pledge("stdio rpath", NULL);
+	else if (conf.output.outfilename != NULL ||
+	    conf.output.tagfilename != NULL)
+		c = pledge("stdio rpath wpath cpath", NULL);
+	else
+		c = pledge("stdio rpath tmppath tty proc exec", NULL);
+	if (c == -1) {
+		mandoc_msg(MANDOCERR_PLEDGE, 0, 0, "%s", strerror(errno));
+		return mandoc_msg_getrc();
 	}
 #endif
 
@@ -642,7 +648,9 @@ out:
 		manconf_free(&conf);
 
 	if (outst.tag_files != NULL) {
-		if (term_tag_close() != -1)
+		if (term_tag_close() != -1 &&
+		    conf.output.outfilename == NULL &&
+		    conf.output.tagfilename == NULL)
 			run_pager(&outst, conf.output.tag);
 		term_tag_unlink();
 	} else if (outst.had_output && outst.outtype != OUTT_LINT)
@@ -837,7 +845,15 @@ process_onefile(struct mparse *mp, struc
 
 	if (outst->use_pager) {
 		outst->use_pager = 0;
-		outst->tag_files = term_tag_init();
+		outst->tag_files = term_tag_init(conf->output.outfilename,
+		    conf->output.tagfilename);
+		if ((conf->output.outfilename != NULL ||
+		     conf->output.tagfilename != NULL) &&
+		    pledge("stdio rpath cpath", NULL) == -1) {
+			mandoc_msg(MANDOCERR_PLEDGE, 0, 0,
+			    "%s", strerror(errno));
+			exit(mandoc_msg_getrc());
+		}
 	}
 	if (outst->had_output && outst->outtype <= OUTT_UTF8) {
 		if (outst->outdata == NULL)
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21 15:10 mandoc: undocumented options -O outfilename and -O tagfilename to schwarze

source@mandoc.bsd.lv

Archives are clonable: git clone --mirror http://inbox.vuxu.org/mandoc-source

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.mandoc.source


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git