source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* texi2mdoc: First, integrate the new `Xr' notation for linking to
@ 2015-03-12  4:24 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2015-03-12  4:24 UTC (permalink / raw)
  To: source

Log Message:
-----------
First, integrate the new `Xr' notation for linking to sections when
chapter mode is enabled.
Second, refine the @top/@node relationship.
Lastly, specify that we don't break apart by chapters, but directly by
nodes.

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

Revision Data
-------------
Index: util.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/util.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -Lutil.c -Lutil.c -u -p -r1.30 -r1.31
--- util.c
+++ util.c
@@ -109,7 +109,7 @@ texidex_free(struct texidex *p)
 	size_t	 i;
 
 	for (i = 0; i < p->indexsz; i++)
-		free(p->index[i]);
+		free(p->index[i].term);
 
 	free(p->index);
 	free(p->name);
@@ -126,7 +126,7 @@ void
 texindex(struct texi *p, const char *tok,
 	size_t toksz, const char *index, size_t sz)
 {
-	size_t	 i;
+	size_t	 i, isz;
 #ifdef HAVE_INDEX
 	char	*cp;
 #endif
@@ -146,22 +146,21 @@ texindex(struct texi *p, const char *tok
 	}
 
 	assert(i < p->indexsz);
+	isz = p->indexs[i].indexsz;
 	/* Reallocate index's terms. */
 	p->indexs[i].index = realloc
 		(p->indexs[i].index,
-		 (p->indexs[i].indexsz + 1) *
-		 sizeof(char *));
+		 (isz + 1) * sizeof(struct texiterm));
 	if (NULL == p->indexs[i].index)
 		texiabort(p, NULL);
 
 	/* Add term to term array. */
-	p->indexs[i].index[p->indexs[i].indexsz] = 
-		malloc(sz + 1);
-	if (NULL == p->indexs[i].index[p->indexs[i].indexsz])
+	p->indexs[i].index[isz].chapter = p->nodesz - 1;
+	p->indexs[i].index[isz].term = malloc(sz + 1);
+	if (NULL == p->indexs[i].index[isz].term)
 		texiabort(p, NULL);
-	memcpy(p->indexs[i].index[p->indexs[i].indexsz],
-		index, sz);
-	p->indexs[i].index[p->indexs[i].indexsz][sz] = '\0';
+	memcpy(p->indexs[i].index[isz].term, index, sz);
+	p->indexs[i].index[isz].term[sz] = '\0';
 	
 	/* Output mdoc(7) for index. */
 #ifdef HAVE_INDEX
@@ -169,7 +168,7 @@ texindex(struct texi *p, const char *tok
 	teximacroopen(p, "Ix");
 	texiputchars(p, "idx");
 	texiputchars(p, p->indexs[i].name);
-	cp = p->indexs[i].index[p->indexs[i].indexsz];
+	cp = p->indexs[i].index[isz].term;
 	while ('\n' != *cp) {
 		assert('\0' != *cp);
 		texiputchar(p, *cp++);
@@ -204,7 +203,8 @@ texindex_add(struct texi *p, const char 
 
 	/* Reallocate indices. */
 	p->indexs = realloc(p->indexs, 
-		sizeof(struct texidex) * (p->indexsz + 1));
+		sizeof(struct texidex) * 
+		(p->indexsz + 1));
 	if (NULL == p->indexs)
 		texiabort(p, NULL);
 	if (NULL == (cp = malloc(sz + 1)))
@@ -246,6 +246,7 @@ texiexit(struct texi *p)
 	for (i = 0; i < p->valsz; i++) 
 		texivaluefree(&p->vals[i]);
 
+	free(p->nodes);
 	free(p->macros);
 	free(p->vals);
 	free(p->indexs);
@@ -1654,7 +1655,8 @@ teximdocclose(struct texi *p, int last)
 	/* Print a reference to the "top" node. */
 	if (p->chapnum > 1) {
 		texiputchars(p, "Top node,");
-		snprintf(buf, sizeof(buf), "node1 7");
+		snprintf(buf, sizeof(buf), "%s-1 7", p->chapters);
+		p->seenvs = 0;
 		teximacroopen(p, "Xr ");
 		texiputchars(p, buf);
 		texiputchars(p, " ;");
@@ -1665,7 +1667,8 @@ teximdocclose(struct texi *p, int last)
 	if (p->chapnum > 2) {
 		texiputchars(p, "previous node,");
 		snprintf(buf, sizeof(buf),
-			"node%zu 7", p->chapnum - 1);
+			"%s-%zu 7", p->chapters, p->chapnum - 1);
+		p->seenvs = 0;
 		teximacroopen(p, "Xr ");
 		texiputchars(p, buf);
 		if ( ! last) 
@@ -1680,7 +1683,8 @@ teximdocclose(struct texi *p, int last)
 		else
 			texiputchars(p, "next node,");
 		snprintf(buf, sizeof(buf),
-			"node%zu 7", p->chapnum + 1);
+			"%s-%zu 7", p->chapters, p->chapnum + 1);
+		p->seenvs = 0;
 		teximacroopen(p, "Xr ");
 		texiputchars(p, buf);
 		teximacroclose(p);
@@ -1703,8 +1707,19 @@ teximdocopen(struct texi *p, size_t *pos
 	char	 	 fname[PATH_MAX];
 
 	if (NULL != p->chapters) {
-		snprintf(fname, sizeof(fname), "%s/node%zu.7", 
-			p->chapters, ++p->chapnum);
+		p->chapnum++;
+		snprintf(fname, sizeof(fname), "%s-%zu", 
+			p->chapters, p->chapnum);
+		p->nodes = realloc(p->nodes,
+			(p->nodesz + 1) * sizeof(char *));
+		if (NULL == p->nodes)
+			texiabort(p, NULL);
+		p->nodes[p->nodesz] = strdup(fname);
+		if (NULL == p->nodes[p->nodesz])
+			texiabort(p, NULL);
+		p->nodesz++;
+		snprintf(fname, sizeof(fname), "%s-%zu.7", 
+			p->chapters, p->chapnum);
 		p->outfile = fopen(fname, "w");
 		if (NULL == p->outfile)
 			texiabort(p, fname);
Index: texi2mdoc.1
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/texi2mdoc.1,v
retrieving revision 1.14
retrieving revision 1.15
diff -Ltexi2mdoc.1 -Ltexi2mdoc.1 -u -p -r1.14 -r1.15
--- texi2mdoc.1
+++ texi2mdoc.1
@@ -22,7 +22,7 @@
 .Nd convert texinfo documents to mdoc
 .Sh SYNOPSIS
 .Nm texi2mdoc
-.Op Fl I Ar dir
+.Op Fl C Ar dir
 .Op Fl I Ar dirs
 .Op Ar file
 .Sh DESCRIPTION
@@ -40,13 +40,13 @@ By default,
 reads from standard input.
 Its arguments are as follows:
 .Bl -tag -width Ds
-.It Fl C Ar dir
+.It Fl C Ar prefix
 Instead of producing a single document, break apart the input into
-chapter-level documents placed within
+node-level documents placed within
 .Ar dir ,
 which must exist.
 These are created as
-.Pa nodeNNN.7 .
+.Pa prefix-NNN.7 .
 .It Fl I Ar dirs
 Colon-separated directories to search for
 .Li @include
Index: extern.h
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/extern.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -Lextern.h -Lextern.h -u -p -r1.27 -r1.28
--- extern.h
+++ extern.h
@@ -373,13 +373,23 @@ struct	teximacro {
 };
 
 /*
+ * A term is a word in an index.
+ * For example "@cindex foo" adds the term "foo" to the "cp" index.
+ * This occurs within a chapter ("nodes" in struct texi)
+ */
+struct	texiterm {
+	char		*term;
+	size_t		 chapter;
+};
+
+/*
  * Index tables.
  * These have a two or three letter name (usually) and any number of
  * terms that are associated with it.
  */
 struct	texidex {
 	char		 *name;
-	char		**index;
+	struct texiterm	 *index;
 	size_t		  indexsz;
 };
 
@@ -411,6 +421,8 @@ struct	texi {
 	size_t		  macrosz; /* entries in macros */
 	char		 *copying; /* the @copying block */
 	size_t		  copyingsz; /* length of @copying */
+	char		**nodes;
+	size_t		  nodesz;
 	/*
 	 * The following control what we output to the screen.
 	 * The complexity is required to accomodate for mdoc(7).
Index: main.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/main.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -Lmain.c -Lmain.c -u -p -r1.66 -r1.67
--- main.c
+++ main.c
@@ -76,7 +76,6 @@ static	void donode(struct texi *, enum t
 static	void doprintindex(struct texi *, enum texicmd, size_t *);
 static	void doquotation(struct texi *, enum texicmd, size_t *);
 static	void dotable(struct texi *, enum texicmd, size_t *);
-static	void dotop(struct texi *, enum texicmd, size_t *);
 static	void dosecoffs(struct texi *, enum texicmd, size_t *);
 static	void dosection(struct texi *, enum texicmd, size_t *);
 static	void dosp(struct texi *, enum texicmd, size_t *);
@@ -326,7 +325,7 @@ static	const struct texitok __texitoks[T
 	{ doignline, "title", 5 }, /* TEXICMD_TITLE */
 	{ dobracket, "titlefont", 9 }, /* TEXICMD_TITLEFONT */
 	{ doignblock, "titlepage", 9 }, /* TEXICMD_TITLEPAGE */
-	{ dotop, "top", 3 }, /* TEXICMD_TOP */
+	{ dosection, "top", 3 }, /* TEXICMD_TOP */
 	{ doindex, "tpindex", 7 }, /* TEXICMD_TPINDEX */
 	{ doaccent, "u", 1 }, /* TEXICMD_U */
 	{ doaccent, "ubaraccent", 10 }, /* TEXICMD_UBARACCENT */
@@ -1477,8 +1476,9 @@ doquotation(struct texi *p, enum texicmd
 static int
 indexcmp(const void *p1, const void *p2)
 {
+	const struct texiterm *t1 = p1, *t2 = p2;
 
-	return(strcasecmp(*(const char **)p1, *(const char **)p2));
+	return(strcasecmp(t1->term, t2->term));
 }
 
 static void
@@ -1522,26 +1522,41 @@ doprintindex(struct texi *p, enum texicm
 
 	/* Alphabetically sort our indices. */
 	qsort(p->indexs[i].index, 
-		p->indexs[i].indexsz, sizeof(char *), indexcmp);
+		p->indexs[i].indexsz, 
+		sizeof(struct texiterm), indexcmp);
 
 	texivspace(p);
 	teximacro(p, "Bl -tag -width Ds -compact");
 	for (j = 0; j < p->indexs[i].indexsz; j++) {
 		teximacroopen(p, "It");
 #if HAVE_INDEX
-		teximacroopen(p, "Lkx");
-		texiputchars(p, "\"idx");
-		texiputchars(p, p->indexs[i].name);
-		cp = p->indexs[i].index[j];
-		while ('\n' != *cp) {
-			assert('\0' != *cp);
-			texiputchar(p, *cp++);
+		if (NULL == p->chapters) {
+			teximacroopen(p, "Lkx");
+			texiputchars(p, "\"idx");
+			texiputchars(p, p->indexs[i].name);
+			cp = p->indexs[i].index[j].term;
+			while ('\n' != *cp) {
+				assert('\0' != *cp);
+				texiputchar(p, *cp++);
+			}
+			texiputchars(p, "\" \"");
+			p->literal++;
+		} else {
+			teximacroopen(p, "Xr");
+			texiputchars(p, p->nodes[p->indexs[i].index[j].chapter]);
+			texiputchars(p, " 7 \"idx");
+			texiputchars(p, p->indexs[i].name);
+			cp = p->indexs[i].index[j].term;
+			while ('\n' != *cp) {
+				assert('\0' != *cp);
+				texiputchar(p, *cp++);
+			}
+			texiputchars(p, "\" \"");
+			p->literal++;
 		}
-		texiputchars(p, "\" \"");
-		p->literal++;
 #endif
-		texisplice(p, p->indexs[i].index[j], 
-			strlen(p->indexs[i].index[j]), *pos);
+		texisplice(p, p->indexs[i].index[j].term, 
+			strlen(p->indexs[i].index[j].term), *pos);
 		parseeoln(p, pos);
 #if HAVE_INDEX
 		p->literal--;
@@ -1562,27 +1577,30 @@ donode(struct texi *p, enum texicmd cmd,
 
 	if (NULL != p->chapters) {
 		advanceeoln(p, pos, 1);
-		return;
-	}
-
+		if (0 == p->chapnum)
+			p->ign--;
+		teximdocclose(p, 0);
+		teximdocopen(p, pos);
+	} else {
 #if HAVE_INDEX
-	p->seenvs = -1;
-	teximacroopen(p, "Ix");
-	texiputchars(p, "node");
-	while (*pos < BUFSZ(p) && isws(BUF(p)[*pos]))
-		advance(p, pos);
-	while (*pos < BUFSZ(p)) {
-		if (BUF(p)[*pos] == ',')
-			break;
-		else if (BUF(p)[*pos] == '\n')
-			break;
-		texiputchar(p, BUF(p)[*pos]);
-		advance(p, pos);
-	}
-	teximacroclose(p);
+		p->seenvs = -1;
+		teximacroopen(p, "Ix");
+		texiputchars(p, "node");
+		while (*pos < BUFSZ(p) && isws(BUF(p)[*pos]))
+			advance(p, pos);
+		while (*pos < BUFSZ(p)) {
+			if (BUF(p)[*pos] == ',')
+				break;
+			else if (BUF(p)[*pos] == '\n')
+				break;
+			texiputchar(p, BUF(p)[*pos]);
+			advance(p, pos);
+		}
+		teximacroclose(p);
 #endif
-	advanceeoln(p, pos, 1);
-	p->seenvs = sv;
+		advanceeoln(p, pos, 1);
+		p->seenvs = sv;
+	}
 }
 
 /*
@@ -1595,11 +1613,6 @@ domenu(struct texi *p, enum texicmd cmd,
 {
 	size_t	 start, end, sv;
 
-	if (NULL != p->chapters) {
-		doignblock(p, cmd, pos);
-		return;
-	}
-
 	advanceeoln(p, pos, 1);
 
 	/* 
@@ -1914,11 +1927,6 @@ dosection(struct texi *p, enum texicmd c
 	else 
 		texivspace(p);
 
-	if (0 == sec && NULL != p->chapters) {
-		teximdocclose(p, 0);
-		teximdocopen(p, pos);
-	}
-
 	teximacroopen(p, sects[sec]);
 	parseeoln(p, pos);
 	teximacroclose(p);
@@ -1930,18 +1938,6 @@ dosection(struct texi *p, enum texicmd c
 }
 
 static void
-dotop(struct texi *p, enum texicmd cmd, size_t *pos)
-{
-
-	if (--p->ign)
-		texierr(p, "@top command while ignoring");
-
-	if (NULL == p->chapters)
-		teximdocopen(p, pos);
-	dosection(p, cmd, pos);
-}
-
-static void
 dosp(struct texi *p, enum texicmd cmd, size_t *pos)
 {
 
@@ -2159,8 +2155,10 @@ doindex(struct texi *p, enum texicmd cmd
 		advance(p, pos);
 
 	start = *pos;
-	while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos])
+	while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) {
+		assert('\0' != BUF(p)[*pos]);
 		advance(p, pos);
+	}
 
 	if (*pos == BUFSZ(p)) {
 		texiwarn(p, "unexpected EOF");
--
 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-03-12  4:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-12  4:24 texi2mdoc: First, integrate the new `Xr' notation for linking to 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).