source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* pod2mdoc: Account for sections as well as links.
@ 2014-04-03 11:34 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2014-04-03 11:34 UTC (permalink / raw)
  To: source

Log Message:
-----------
Account for sections as well as links.

Modified Files:
--------------
    pod2mdoc:
        pod2mdoc.1
        pod2mdoc.c

Revision Data
-------------
Index: pod2mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/pod2mdoc.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.19 -r1.20
--- pod2mdoc.c
+++ pod2mdoc.c
@@ -215,8 +215,8 @@ trylink(const char *buf, size_t *start, 
 		if ('|' == buf[textsz] || '/' == buf[textsz])
 			break;
 
-	/* If we have a title, find the section. */
 	if (textsz < linkend && '|' == buf[textsz]) {
+		/* With title: set start, then end at section. */
 		linkstart = textsz + 1;
 		textsz = textsz - *start;
 		for (i = linkstart; i < linkend; i++)
@@ -224,32 +224,43 @@ trylink(const char *buf, size_t *start, 
 				break;
 		if (i < linkend)
 			linkend = i;
-	} else {
+	} else if (textsz < linkend && '/' == buf[textsz]) {
+		/* With section: set end at section. */
+		linkend = textsz;
+		textsz = 0;
+	} else
+		/* No title, no section. */
 		textsz = 0;
-		if (textsz < linkend && '/' == buf[textsz])
-			linkend = textsz;
-	}
 
 	*start = realend;
-
 	j = linkend - linkstart;
 
-	if (0 == j)
+	/* Do we have only subsection material? */
+	if (0 == j && '/' == buf[linkend]) {
+		linkstart = linkend + 1;
+		linkend = dsz > 1 ? realend - 1 : realend;
+		if (0 == (j = linkend - linkstart))
+			return(0);
+		printf("Sx %.*s", (int)j, &buf[linkstart]);
+		return(1);
+	} else if (0 == j)
 		return(0);
 
 	/* See if we qualify as being a link or not. */
-	if ((j > 5 && 0 == memcmp("http:", &buf[linkstart], j)) ||
-		(j > 6 && 0 == memcmp("https:", &buf[linkstart], j)) ||
-		(j > 4 && 0 == memcmp("ftp:", &buf[linkstart], j)) ||
-		(j > 5 && 0 == memcmp("sftp:", &buf[linkstart], j)) ||
-		(j > 4 && 0 == memcmp("smb:", &buf[linkstart], j)) ||
-		(j > 4 && 0 == memcmp("afs:", &buf[linkstart], j))) {
-		printf("Lk %.*s", (int)j, &buf[linkstart]);
+	if ((j > 4 && 0 == memcmp("http:", &buf[linkstart], j)) ||
+		(j > 5 && 0 == memcmp("https:", &buf[linkstart], j)) ||
+		(j > 3 && 0 == memcmp("ftp:", &buf[linkstart], j)) ||
+		(j > 4 && 0 == memcmp("sftp:", &buf[linkstart], j)) ||
+		(j > 3 && 0 == memcmp("smb:", &buf[linkstart], j)) ||
+		(j > 3 && 0 == memcmp("afs:", &buf[linkstart], j))) {
+		/* Gross. */
+		printf("Lk %.*s", (int)((dsz > 1 ? realend - 1 : 
+			realend) - linkstart), &buf[linkstart]);
 		return(1);
 	} 
 	
 	/* See if we qualify as a mailto. */
-	if (j > 7 && 0 == memcmp("mailto:", &buf[linkstart], j)) {
+	if (j > 6 && 0 == memcmp("mailto:", &buf[linkstart], j)) {
 		printf("Mt %.*s", (int)j, &buf[linkstart]);
 		return(1);
 	}
Index: pod2mdoc.1
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/pod2mdoc.1,v
retrieving revision 1.9
retrieving revision 1.10
diff -Lpod2mdoc.1 -Lpod2mdoc.1 -u -p -r1.9 -r1.10
--- pod2mdoc.1
+++ pod2mdoc.1
@@ -182,6 +182,10 @@ manpage in section 3P if containing doub
 otherwise.
 The section may be overriden as
 .Li L<foo(5)> .
+If only a section appears, such as in
+.Li </section> ,
+the link is rendered with
+.Sq \&Sx .
 .Sh EXIT STATUS
 .Ex -std
 .Sh EXAMPLES
@@ -248,3 +252,7 @@ will cause the second space to be lost.
 The
 .Li S<>
 escape is discarded.
+.Pp
+Unless solely a section link, the text and section parts of
+.Li L<text|link/section>
+are discarded.
--
 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:[~2014-04-03 11:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-03 11:34 pod2mdoc: Account for sections as well as links 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).