source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* pod2mdoc: use .Vt to mark up types mentioned in the SYNOPSIS
@ 2015-02-13 15:35 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-02-13 15:35 UTC (permalink / raw)
  To: source

Log Message:
-----------
use .Vt to mark up types mentioned in the SYNOPSIS

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

Revision Data
-------------
Index: dict.h
===================================================================
RCS file: /home/cvs/mdocml/pod2mdoc/dict.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -Ldict.h -Ldict.h -u -p -r1.2 -r1.3
--- dict.h
+++ dict.h
@@ -18,10 +18,11 @@
 enum mdoc_type {
 	MDOC_Fa = 0,
 	MDOC_Fo,
+	MDOC_Vt,
 	MDOC_MAX
 };
 
 void		 dict_init(void);
 enum mdoc_type	 dict_get(const char *, size_t);
-void		 dict_put(const char *, enum mdoc_type);
+void		 dict_put(const char *, size_t, enum mdoc_type);
 void		 dict_destroy(void);
Index: dict.c
===================================================================
RCS file: /home/cvs/mdocml/pod2mdoc/dict.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Ldict.c -Ldict.c -u -p -r1.2 -r1.3
--- dict.c
+++ dict.c
@@ -72,14 +72,14 @@ dict_get(const char *s, size_t len)
 }
 
 void
-dict_put(const char *s, enum mdoc_type t)
+dict_put(const char *s, size_t len, enum mdoc_type t)
 {
 	struct dict_entry	*entry;
 	const char		*end;
-	size_t			 len;
 	unsigned int		 slot;
 
-	len = strlen(s);
+	if (len == 0)
+		len = strlen(s);
 	end = s + len;
 	slot = ohash_qlookupi(&dict_data, s, &end);
 	entry = ohash_find(&dict_data, slot);
@@ -89,7 +89,8 @@ dict_put(const char *s, enum mdoc_type t
 			perror(NULL);
 			exit(1);
 		}
-		memcpy(entry->s, s, len + 1);
+		memcpy(entry->s, s, len);
+		entry->s[len] = '\0';
 		ohash_insert(&dict_data, slot, entry);
 	}
 	entry->t = t;
Index: pod2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/pod2mdoc/pod2mdoc.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.38 -r1.39
--- pod2mdoc.c
+++ pod2mdoc.c
@@ -479,6 +479,7 @@ formatcode(struct state *st, const char 
 {
 	enum fmt	 fmt;
 	size_t		 i, j, dsz;
+	unsigned char	 uc;
 
 	assert(*start + 1 < end);
 	assert('<' == buf[*start + 1]);
@@ -612,21 +613,28 @@ formatcode(struct state *st, const char 
 				else
 					printf("Ar ");
 				break;
-			} 
-			if (0 == strncmp(buf + *start, "NULL", 4) &&
-			    ('=' == buf[*start + 4] ||
-			     '>' == buf[*start + 4])) {
+			}
+			i = 0;
+			uc = buf[*start];
+			while (isalnum(uc) || '_' == uc || ' ' == uc)
+				uc = buf[*start + ++i];
+			if ('=' != uc && '>' != uc)
+				i = 0;
+			if (4 == i && ! strncmp(buf + *start, "NULL", 4)) {
 				printf("Dv ");
 				break;
 			}
-			i = 0;
-			while (isalnum((unsigned char)buf[*start + i]) ||
-			    '_' == buf[*start + i])
-				i++;
-			if (i && MDOC_Fa == dict_get(buf + *start, i))
+			switch (i ? dict_get(buf + *start, i) : MDOC_MAX) {
+			case MDOC_Fa:
 				printf("Fa ");
-			else
+				break;
+			case MDOC_Vt:
+				printf("Vt ");
+				break;
+			default:
 				printf("Sy ");
+				break;
+			}
 			break;
 		case (FMT_CODE):
 			printf("Qo Li ");
@@ -1014,6 +1022,32 @@ command(struct state *st, const char *bu
 }
 
 /*
+ * Put the type provided as an argument into the dictionary.
+ */
+static void
+register_type(const char *ptype)
+{
+	const char	*pname, *pend;
+
+	pname = ptype;
+	while (isalnum((unsigned char)*pname) || '_' == *pname)
+		pname++;
+	if ((pname - ptype == 6 && ! strncmp(ptype, "struct", 6)) ||
+	    (pname - ptype == 4 && ! strncmp(ptype, "enum", 4))) {
+		while (' ' == *pname)
+			pname++;
+		pend = pname;
+		while (isalnum((unsigned char)*pend) || '_' == *pend)
+			pend++;
+		if (pend > pname)
+			dict_put(pname, pend - pname, MDOC_Vt);
+	} else
+		pend = pname;
+	if (pend > ptype)
+		dict_put(ptype, pend - ptype, MDOC_Vt);
+}
+
+/*
  * Just pump out the line in a verbatim block.
  * From the perspective of external callers,
  * always stays in OUST_NL/wantws mode.
@@ -1110,6 +1144,7 @@ again:
 				if (buf[i] == '\n')
 					buf[i] = ' ';
 			buf[ifo++] = '\0';
+			register_type(buf + ift);
 			printf(".Ft %s", buf + ift);
 			if (buf[ifo] == '*') {
 				fputs(" *", stdout);
@@ -1118,7 +1153,7 @@ again:
 			putchar('\n');
 			buf[ifa++] = '\0';
 			printf(".Fo %s\n", buf + ifo);
-			dict_put(buf + ifo, MDOC_Fo);
+			dict_put(buf + ifo, 0, MDOC_Fo);
 			buf[ifc++] = '\0';
 			for (;;) {
 				cp = strchr(buf + ifa, ',');
@@ -1131,7 +1166,8 @@ again:
 				    '_' == cp2[-1])
 					cp2--;
 				if ('\0' != *cp2)
-					dict_put(cp2, MDOC_Fa);
+					dict_put(cp2, 0, MDOC_Fa);
+				register_type(buf + ifa);
 				printf(".Fa \"%s\"\n", buf + ifa);
 				if (cp == NULL)
 					break;
Index: pod2mdoc.1
===================================================================
RCS file: /home/cvs/mdocml/pod2mdoc/pod2mdoc.1,v
retrieving revision 1.14
retrieving revision 1.15
diff -Lpod2mdoc.1 -Lpod2mdoc.1 -u -p -r1.14 -r1.15
--- pod2mdoc.1
+++ pod2mdoc.1
@@ -197,6 +197,15 @@ Words followed by
 .Qq Pq
 that match function names listed in the SYNOPSIS section are marked up with
 .Sq \&Fn .
+.Pp
+If the contents of a
+.Li B<>
+format code matches a type name mentioned in the SYNOPSIS section,
+it is rendered as
+.Sq \&Vt .
+If it matches a function argument name mentioned there,
+it is rendered as
+.Sq \&Fa .
 .Sh EXIT STATUS
 .Ex -std
 .Sh EXAMPLES
--
 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-13 15:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-13 15:35 pod2mdoc: use .Vt to mark up types mentioned in the SYNOPSIS schwarze

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