From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: pod2mdoc: use .Vt to mark up types mentioned in the SYNOPSIS
Date: Fri, 13 Feb 2015 10:35:45 -0500 (EST) [thread overview]
Message-ID: <585655987171063034.enqueue@fantadrom.bsd.lv> (raw)
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
reply other threads:[~2015-02-13 15:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=585655987171063034.enqueue@fantadrom.bsd.lv \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).