source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* texi2mdoc: Properly insert the @copying block.
@ 2015-03-05  8:36 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2015-03-05  8:36 UTC (permalink / raw)
  To: source

Log Message:
-----------
Properly insert the @copying block.

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

Revision Data
-------------
Index: main.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/main.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -Lmain.c -Lmain.c -u -p -r1.60 -r1.61
--- main.c
+++ main.c
@@ -42,6 +42,7 @@ static	void doaccent(struct texi *, enum
 static	void doblock(struct texi *, enum texicmd, size_t *);
 static	void dobracket(struct texi *, enum texicmd, size_t *);
 static	void dobye(struct texi *, enum texicmd, size_t *);
+static	void docopying(struct texi *, enum texicmd, size_t *);
 static	void dodefindex(struct texi *, enum texicmd, size_t *);
 static	void dodefn(struct texi *, enum texicmd, size_t *);
 static	void dodisplay(struct texi *, enum texicmd, size_t *);
@@ -54,6 +55,7 @@ static	void doignbracket(struct texi *, 
 static	void doignline(struct texi *, enum texicmd, size_t *);
 static	void doinline(struct texi *, enum texicmd, size_t *);
 static	void doinclude(struct texi *, enum texicmd, size_t *);
+static	void doinsertcopying(struct texi *, enum texicmd, size_t *);
 static	void doitem(struct texi *, enum texicmd, size_t *);
 static	void doitemize(struct texi *, enum texicmd, size_t *);
 static	void dolink(struct texi *, enum texicmd, size_t *);
@@ -115,7 +117,7 @@ static	const struct texitok __texitoks[T
 	{ doignline, "c", 1 }, /* TEXICMD_COMMENT */
 	{ doignline, "comment", 7 }, /* TEXICMD_COMMENT_LONG */
 	{ doignline, "contents", 8 }, /* TEXICMD_CONTENTS */
-	{ doignblock, "copying", 7 }, /* TEXICMD_COPYING */
+	{ docopying, "copying", 7 }, /* TEXICMD_COPYING */
 	{ dosymbol, "copyright", 9 }, /* TEXICMD_COPYRIGHT */
 	{ dodefindex, "defcodeindex", 12 }, /* TEXICMD_DEFCODEINDEX */
 	{ dodefn, "deffn", 5 }, /* TEXICMD_DEFFN */
@@ -214,7 +216,7 @@ static	const struct texitok __texitoks[T
 	{ dodisplay, "indentblock", 11 }, /* TEXICMD_INDENTBLOCK */
 	{ dolink, "indicateurl", 11 }, /* TEXICMD_INDICATEURL */
 	{ dolink, "inforef", 7 }, /* TEXICMD_INFOREF */
-	{ doignline, "insertcopying", 13 }, /* TEXICMD_INSERTCOPYING */
+	{ doinsertcopying, "insertcopying", 13 }, /* TEXICMD_INSERTCOPYING */
 	{ doitem, "item", 4 }, /* TEXICMD_ITEM */
 	{ doitemize, "itemize", 7 }, /* TEXICMD_ITEMIZE */
 	{ doitem, "itemx", 5 }, /* TEXICMD_ITEMX */
@@ -801,6 +803,53 @@ doverb(struct texi *p, enum texicmd cmd,
 }
 
 static void
+doinsertcopying(struct texi *p, enum texicmd cmd, size_t *pos)
+{
+
+	advanceeoln(p, pos, 0);
+	if (NULL == p->copying)
+		return;
+	texisplice(p, p->copying, p->copyingsz, *pos);
+}
+
+static void
+docopying(struct texi *p, enum texicmd cmd, size_t *pos)
+{
+	const char	*end, *term;
+	size_t		 endsz, endpos;
+
+	/* We retain our starting (but not ending) newlines. */
+	end = "\n@end copying\n";
+	endsz = strlen(end);
+	advanceeoln(p, pos, 0);
+	if (*pos == BUFSZ(p)) {
+		texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok);
+		return;
+	}
+
+	term = memmem(&BUF(p)[*pos], BUFSZ(p) - *pos, end, endsz);
+	if (NULL == term) {
+		texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok);
+		endpos = BUFSZ(p);
+	} else
+		endpos = *pos + (size_t)(term - &BUF(p)[*pos]);
+
+	assert(endpos <= BUFSZ(p));
+	assert('\n' == BUF(p)[*pos]);
+	advance(p, pos);
+
+	p->copying = malloc(endpos - *pos + 1);
+	p->copyingsz = endpos - *pos;
+	memcpy(p->copying, &BUF(p)[*pos], p->copyingsz);
+	p->copying[endpos - *pos] = '\0';
+
+	while (*pos < endpos)
+		advance(p, pos);
+	if (*pos < BUFSZ(p))
+		advanceto(p, pos, endpos + endsz);
+}
+
+static void
 doverbatim(struct texi *p, enum texicmd cmd, size_t *pos)
 {
 	const char	*end, *term;
@@ -811,13 +860,13 @@ doverbatim(struct texi *p, enum texicmd 
 	endsz = strlen(end);
 	advanceeoln(p, pos, 0);
 	if (*pos == BUFSZ(p)) {
-		texiwarn(p, "unexpected end of file");
+		texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok);
 		return;
 	}
 
 	term = memmem(&BUF(p)[*pos], BUFSZ(p) - *pos, end, endsz);
 	if (NULL == term) {
-		texiwarn(p, "unterminated verbatim block");
+		texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok);
 		endpos = BUFSZ(p);
 	} else
 		endpos = *pos + (size_t)(term - &BUF(p)[*pos]);
Index: util.c
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/util.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -Lutil.c -Lutil.c -u -p -r1.25 -r1.26
--- util.c
+++ util.c
@@ -100,6 +100,7 @@ texiexit(struct texi *p)
 	free(p->dirs);
 	free(p->subtitle);
 	free(p->title);
+	free(p->copying);
 }
 
 /*
Index: extern.h
===================================================================
RCS file: /home/cvs/mdocml/texi2mdoc/extern.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -Lextern.h -Lextern.h -u -p -r1.25 -r1.26
--- extern.h
+++ extern.h
@@ -377,7 +377,7 @@ struct	texi {
 	size_t		  chapnum; /* current chapter node */
 	char		**dirs; /* texi directories */
 	size_t		  dirsz; /* number of texi directories */
-	FILE		 *outfile;
+	FILE		 *outfile; /* current output stream */
 	/*
 	 * Run-time parameters.
 	 */
@@ -394,6 +394,8 @@ struct	texi {
 	size_t		  valsz; /* entries in vals */
 	struct teximacro *macros; /* @macro entries */
 	size_t		  macrosz; /* entries in macros */
+	char		 *copying; /* the @copying block */
+	size_t		  copyingsz; /* length of @copying */
 	/*
 	 * The following control what we output to the screen.
 	 * The complexity is required to accomodate for mdoc(7).
--
 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-05  8:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05  8:36 texi2mdoc: Properly insert the @copying block 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).