source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* texi2mdoc: Add reading initial file from stdin.
@ 2015-02-23 22:50 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2015-02-23 22:50 UTC (permalink / raw)
  To: source

Log Message:
-----------
Add reading initial file from stdin.
Ignore some more macros from in GMP.

Modified Files:
--------------
    texi2mdoc:
        extern.h
        index.xml
        main.c
        texi2mdoc.1
        util.c

Added Files:
-----------
    texi2mdoc:
        version_0_1_2.xml

Revision Data
-------------
Index: index.xml
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/index.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lindex.xml -Lindex.xml -u -p -r1.3 -r1.4
--- index.xml
+++ index.xml
@@ -2,36 +2,33 @@
 <html>
 	<head>
 		<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
-		<meta charset='utf-8' /> 
+		<meta charset="utf-8" /> 
 		<title>texi2mdoc | Convert texinfo data to mdoc input </title>
 		<style>
-			html, body { margin: 0; padding: 0; }
-			header { margin-top: 1em; }
-			header span.nm { font-size: 16pt; }
-			header span.nd { font-size: 14pt; }
-			article span.nm, article a.nm { font-style: italic; }
-			header, article, footer { width: 80%; margin-left: auto; margin-right: auto; }
-			body { color: #333; font-family: Times,serif; line-height: 120%; }
-			nav { color: #666; margin-top: 0.5ex; }
-			nav span { border-left: thin solid silver; margin-left: 0.25ex; padding-left: 0.5ex; }
-			nav span:first-child { border: 0; padding: 0; margin: 0; }
+			body { margin: 0; font-size: 13pt; }
+			body > header { background-color: #336699; color: #fff; padding: 1em 5%; }
+			body > header h1 { margin: 0; font-weight: normal; }
+			body > header div { font-size: 18pt; }
+			body > nav { background-color: #ddd; box-shadow: 2px 0 2px #000; padding: 0 5%; color: #666; }
+			body > nav div { padding: 1ex 1ex; display: inline-block; border-left: thin solid silver; }
+			body > nav div:first-child { border-left: none; padding-left: 0; }
+			body > footer { padding: 1em 5%; }
+			body > nav a { color: #000; }
+			article { padding: 1em 5%; }
 			a { text-decoration: none; }
-			footer { margin-top: 1em; font-size: smaller; color: #666; }
-			footer a { color: #000; }
-			h2 { font-size: larger; font-weight: bolder; color: #333; }
 		</style>
 	</head>
 	<body>
 		<header>
-			<span class="nm">texi2mdoc</span>
-			&#8212;
-			<span class="nd">Convert Texinfo data to mdoc input</span>
-			<nav>
-				<span>version <span>@VERSION@</span></span>
-				<span><a href="snapshots/texi2mdoc.tgz">Sources</a> (<a href="snapshots/texi2mdoc.tgz.sha512">SHA</a>)</span>
-				<span><a href="snapshots">Archives</a></span>
-			</nav>
+			<h1>texi2mdoc</h1>
+			<div>Convert Texinfo data to mdoc input</div>
 		</header>
+		<nav>
+			<div>Version <span>@VERSION@</span></div>
+			<div><a href="snapshots/texi2mdoc.tgz">Sources</a></div>
+			<div><a href="snapshots/texi2mdoc.tgz.sha512">SHA512</a></div>
+			<div><a href="snapshots">Archives</a></div>
+		</nav>
 		<article>
 			<p>
 				The <span class="nm">texi2mdoc</span> utility is a converter from <a
@@ -44,6 +41,9 @@
 			<p>
 				Contact <a href="http://kristaps.bsd.lv">Kristaps</a> with questions, but please make sure any formatting issue
 				hasn't already been covered in the <a href="texi2mdoc.1.html">manual</a>.
+				<span class="nm">texi2mdoc</span> is available over <a href="http://mdocml.bsd.lv/anoncvs.html">anoncvs</a>,
+				with the module being <q>texi2mdoc</q> instead of <q>mdocml</q> as noted in the instructions.
+				You can also browse via <a href="http://mdocml.bsd.lv/cgi-bin/cvsweb/?cvsroot=texi2mdoc">cvsweb</a>.
 			</p>
 			<nav data-sblg-nav="1" data-sblg-navsz="4" data-sblg-navcontent="1">
 				Version <span class="version">${sblg-title}</span> (<time datetime="${sblg-date}">${sblg-date}</time>): ${sblg-aside}
Index: util.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/util.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lutil.c -Lutil.c -u -p -r1.11 -r1.12
--- util.c
+++ util.c
@@ -43,7 +43,10 @@ texifilepop(struct texi *p)
 
 	assert(p->filepos > 0);
 	f = &p->files[--p->filepos];
-	munmap(f->map, f->mapsz);
+	if (TEXISRC_FILE == f->type)
+		munmap(f->map, f->mapsz);
+	else
+		free(f->map);
 }
 
 static void
@@ -955,6 +958,47 @@ parseto(struct texi *p, const char *buf,
 }
 
 /*
+ * Like parsefile() but used for reading from stdandard input.
+ * This can only be called for the first file!
+ */
+void
+parsestdin(struct texi *p)
+{
+	struct texifile	*f;
+	size_t		 off;
+	ssize_t		 ssz;
+
+	assert(0 == p->filepos);
+	f = &p->files[p->filepos];
+	memset(f, 0, sizeof(struct texifile));
+
+	f->type = TEXISRC_STDIN;
+	f->name = "<stdin>";
+
+	for (off = 0; ; off += (size_t)ssz) {
+		if (off == f->mapsz) {
+			if (f->mapsz == (1U << 31))
+				texierr(p, "stdin buffer too long");
+			f->mapsz = f->mapsz > 65536 / 2 ? 
+				2 * f->mapsz : 65536;
+			f->map = realloc(f->map, f->mapsz);
+			if (NULL == f->map) 
+				texiabort(p, NULL);
+		}
+		ssz = read(STDIN_FILENO, 
+			f->map + (int)off, f->mapsz - off);
+		if (0 == ssz)
+			break;
+		else if (-1 == ssz) 
+			texiabort(p, NULL);
+	}
+
+	p->filepos++;
+	parseeof(p, f->map, off);
+	texifilepop(p);
+}
+
+/*
  * Memory-map the file "fname" and begin parsing it unless "parse" is
  * zero, in which case we just dump the file to stdout (making sure it
  * doesn't trip up mdoc(7) along the way).
@@ -973,6 +1017,7 @@ parsefile(struct texi *p, const char *fn
 	f = &p->files[p->filepos];
 	memset(f, 0, sizeof(struct texifile));
 
+	f->type = TEXISRC_FILE;
 	f->name = fname;
 	if (-1 == (fd = open(fname, O_RDONLY, 0))) {
 		texiabort(p, fname);
Index: texi2mdoc.1
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/texi2mdoc.1,v
retrieving revision 1.7
retrieving revision 1.8
diff -Ltexi2mdoc.1 -Ltexi2mdoc.1 -u -p -r1.7 -r1.8
--- texi2mdoc.1
+++ texi2mdoc.1
@@ -23,7 +23,7 @@
 .Sh SYNOPSIS
 .Nm texi2mdoc
 .Op Fl I Ar dirs
-.Ar file
+.Op Ar file
 .Sh DESCRIPTION
 The
 .Nm
@@ -34,12 +34,22 @@ documents to
 mixed with
 .Xr tbl 7
 .Pq if applicable .
+By default,
+.Nm
+reads from standard input.
 Its arguments are as follows:
 .Bl -tag -width Ds
 .It Fl I Ar dirs
 Colon-separated directories to search for
 .Li @include
 files.
+.It Ar file
+A Texinfo input file.
+If specified, the directory of
+.Ar file
+is prepended to the list of
+.Fl I
+directories.
 .El
 .Pp
 .Nm
Index: extern.h
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/extern.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lextern.h -Lextern.h -u -p -r1.10 -r1.11
--- extern.h
+++ extern.h
@@ -87,6 +87,8 @@ enum	texicmd {
 	TEXICMD_DIRENTRY,
 	TEXICMD_DISPLAY,
 	TEXICMD_DMN,
+	TEXICMD_DOCUMENTDESCRPITION,
+	TEXICMD_DOCUMENTENCODING,
 	TEXICMD_DOTS,
 	TEXICMD_EMAIL,
 	TEXICMD_EMPH,
@@ -229,15 +231,21 @@ enum	texicmd {
 	TEXICMD__MAX
 };
 
+enum	texisrc {
+	TEXISRC_FILE,
+	TEXISRC_STDIN
+};
+
 /*
  * The file currently being parsed.
  * This keeps track of our location within that file.
  */
 struct	texifile {
+	enum texisrc	 type; /* type of file */
 	const char	*name; /* name of the file */
 	size_t	  	 line; /* current line (from zero) */
 	size_t	  	 col; /* current column in line (from zero) */
-	char		*map; /* mmap'd file */
+	char		*map; /* mmap'd file OR allocated buffer */
 	size_t		 mapsz; /* size of mmap */
 };
 
@@ -258,6 +266,10 @@ struct	texitok {
 	size_t		 len; /* strlen(tok) */
 };
 
+/*
+ * These values instruct us on whether a list (or table) of some type is
+ * currently being parsed.
+ */
 enum	texilist {
 	TEXILIST_NONE = 0,
 	TEXILIST_ITEM,
@@ -265,16 +277,24 @@ enum	texilist {
 	TEXILIST_TABLE
 };
 
+/*
+ * Hold values assigned with @set and retrieved with @value.
+ * These values can contain arbitrary Texinfo.
+ */
 struct	texivalue {
-	char		*key;
-	char		*value;
+	char		*key; /* the nil-terminated value name */
+	char		*value; /* the nil-terminated value */
 };
 
+/*
+ * Macros are (possibly-recursive) Texinfo sequences created with @macro
+ * and filled in by arguments when invoked.
+ */
 struct	teximacro {
-	char		 *key;
-	char		 *value;
-	char		**args;
-	size_t		  argsz;
+	char		 *key; /* nil-terminated macro name */
+	char		 *value; /* nil-terminated value */
+	char		**args; /* array of argument names (or NULL) */
+	size_t		  argsz; /* array size */
 };
 
 /*
@@ -296,8 +316,8 @@ struct	texi {
 	size_t		  indexsz; /* entries in indexs */
 	struct texivalue *vals; /* @value entries */
 	size_t		  valsz; /* entries in vals */
-	struct teximacro *macros;
-	size_t		  macrosz;
+	struct teximacro *macros; /* @macro entries */
+	size_t		  macrosz; /* entries in macros */
 	/*
 	 * The following control what we output to the screen.
 	 * The complexity is required to accomodate for mdoc(7).
@@ -325,6 +345,7 @@ char  **argparse(struct texi *, const ch
 
 int	parsearg(struct texi *, const char *, size_t, size_t *, size_t);
 void	parsebracket(struct texi *, const char *, size_t, size_t *);
+void	parsestdin(struct texi *);
 void	parsefile(struct texi *, const char *, int);
 int	parselinearg(struct texi *, const char *, size_t, size_t *);
 void	parseeof(struct texi *, const char *, size_t);
Index: main.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/main.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -Lmain.c -Lmain.c -u -p -r1.39 -r1.40
--- main.c
+++ main.c
@@ -146,6 +146,8 @@ static	const struct texitok __texitoks[T
 	{ doignblock, "direntry", 8 }, /* TEXICMD_DIRENTRY */
 	{ dodisplay, "display", 7 }, /* TEXICMD_DISPLAY */
 	{ doignbracket, "dmn", 3 }, /* TEXICMD_DMN */
+	{ doignblock, "documentdescription", 19 }, /* TEXICMD_DOCUMENTDESCRIPTION */
+	{ doignline, "documentencoding", 16 }, /* TEXICMD_DOCUMENTENCODING */
 	{ dosymbol, "dots", 4 }, /* TEXICMD_DOTS */
 	{ dolink, "email", 5 }, /* TEXICMD_EMAIL */
 	{ doinline, "emph", 4 }, /* TEXICMD_EMPH */
@@ -1597,7 +1599,7 @@ doignline(struct texi *p, enum texicmd c
 /*
  * Parse colon-separated directories from "cp" (if not NULL) and returns
  * the array of pointers.
- * Prepends "base" to the array.
+ * Prepends "base" to the array, if found.
  * This does NOT sanitise the directories!
  */
 static char **
@@ -1605,26 +1607,27 @@ parsedirs(struct texi *p, const char *ba
 {
 	char	   	 *tok, *str, *tofree;
 	const char 	 *cpp;
-	size_t	    	  i;
+	size_t	    	  i = 0;
 	char		**dirs;
 
-	*sz = NULL != (cpp = cp) ? 2 : 1;
-	if (*sz > 1)
-		for ( ; NULL != (cpp = strchr(cpp, ':')); (*sz)++)
+	/* Count up our expected arguments. */
+	*sz = NULL != base;
+	if (NULL != (cpp = cp))
+		for ((*sz)++; NULL != (cpp = strchr(cpp, ':')); (*sz)++)
 			cpp++;
 
+	if (0 == *sz)
+		return(NULL);
 	if (NULL == (dirs = calloc(*sz, sizeof(char *))))
 		texiabort(p, NULL);
-	else if (NULL == (dirs[0] = strdup(base))) 
+	if (NULL != base && NULL == (dirs[i++] = strdup(base))) 
 		texiabort(p, NULL);
-
 	if (NULL == cp)
 		return(dirs);
-	
 	if (NULL == (tofree = tok = str = strdup(cp)))
 		texiabort(p, NULL);
 
-	for (i = 1; NULL != (tok = strsep(&str, ":")); i++) 
+	for ( ; NULL != (tok = strsep(&str, ":")); i++) 
 		if (NULL == (dirs[i] = strdup(tok))) 
 			texiabort(p, NULL);
 
@@ -1647,6 +1650,7 @@ main(int argc, char *argv[])
 		++progname;
 
 	memset(&texi, 0, sizeof(struct texi));
+	texi.ign = 1;
 	Idir = NULL;
 
 	while (-1 != (c = getopt(argc, argv, "I:"))) 
@@ -1659,32 +1663,33 @@ main(int argc, char *argv[])
 		}
 
 	argv += optind;
-	if (0 == (argc -= optind))
-		goto usage;
+	argc -= optind;
 
-	if (NULL == (dirpath = strdup(argv[0])))
-		texiabort(&texi, NULL);
-	if (NULL == (dir = dirname(dirpath)))
-		texiabort(&texi, NULL);
-
-	if (NULL != (cp = strrchr(argv[0], '/'))) 
-		texi.title = strdup(cp + 1);
-	else
-		texi.title = strdup(argv[0]);
-
-	if (NULL == texi.title)
-		texiabort(&texi, NULL);
-	else if (NULL != (ccp = strchr(texi.title, '.')))
-		*ccp = '\0';
+	if (argc > 0) {
+		if (NULL == (dirpath = strdup(argv[0])))
+			texiabort(&texi, NULL);
+		if (NULL == (dir = dirname(dirpath)))
+			texiabort(&texi, NULL);
+		if (NULL != (cp = strrchr(argv[0], '/'))) 
+			texi.title = strdup(cp + 1);
+		else
+			texi.title = strdup(argv[0]);
+		if (NULL == texi.title)
+			texiabort(&texi, NULL);
+		else if (NULL != (ccp = strchr(texi.title, '.')))
+			*ccp = '\0';
+		texi.dirs = parsedirs(&texi, dir, Idir, &texi.dirsz);
+		free(dirpath);
+		parsefile(&texi, argv[0], 1);
+	} else {
+		texi.title = strdup("Unknown Manual");
+		texi.dirs = parsedirs(&texi, NULL, Idir, &texi.dirsz);
+		parsestdin(&texi);
+	}
 
-	texi.ign = 1;
-	texi.dirs = parsedirs(&texi, dir, Idir, &texi.dirsz);
-	free(dirpath);
-	parsefile(&texi, argv[0], 1);
-	/* We shouldn't get here. */
 	texiexit(&texi);
 	return(EXIT_FAILURE);
 usage:
-	fprintf(stderr, "usage: %s [-Idirs] file\n", progname);
+	fprintf(stderr, "usage: %s [-Idirs] [file]\n", progname);
 	return(EXIT_FAILURE);
 }
--- /dev/null
+++ version_0_1_2.xml
@@ -0,0 +1,12 @@
+<article data-sblg-article="1">
+	<header>
+		<h1>0.1.2</h1>
+		<address>Kristaps Dzonsons</address>
+		<time datetime="2014-02-24">2014-02-24</time>
+	</header>
+	<aside>
+		Ported for running on Linux.
+		Added a few macros for viewing <a href="https://gmplib.org/">GMP</a> manuals.
+		Also allow reading from standard input (instead of always from a file).
+	</aside>
+</article>
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

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

only message in thread, other threads:[~2015-02-23 22:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-23 22:50 texi2mdoc: Add reading initial file from stdin kristaps

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).