=================================================================== RCS file: /cvs/pod2mdoc/pod2mdoc.c,v retrieving revision 1.48 retrieving revision 1.49 diff -u -p -r1.48 -r1.49 --- pod2mdoc/pod2mdoc.c 2015/02/19 10:53:21 1.48 +++ pod2mdoc/pod2mdoc.c 2015/02/19 10:59:35 1.49 @@ -1,4 +1,4 @@ -/* $Id: pod2mdoc.c,v 1.48 2015/02/19 10:53:21 schwarze Exp $ */ +/* $Id: pod2mdoc.c,v 1.49 2015/02/19 10:59:35 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * Copyright (c) 2014, 2015 Ingo Schwarze @@ -1105,6 +1105,24 @@ again: putchar('\n'); if (start < end && '\n' == buf[start]) start++; + + /* Remember #define for Dv or Fn. */ + + if (strncmp(buf + i + 1, "define", 6) || + ! isspace((unsigned char)buf[i + 7])) + goto again; + + ifo = i + 7; + while (ifo < start && + isspace((unsigned char)buf[ifo])) + ifo++; + ifa = ifo; + while ('_' == buf[ifa] || + isalnum((unsigned char)buf[ifa])) + ifa++; + dict_put(buf + ifo, ifa - ifo, + '(' == buf[ifa] ? MDOC_Fo : MDOC_Dv); + goto again; } @@ -1333,6 +1351,7 @@ ordinary(struct state *st, const char *buf, size_t sta size_t i, j, opstack, wend; enum mdoc_type mtype; int eos, noeos, seq; + char savechar; if ( ! st->parsing || st->paused) return; @@ -1437,9 +1456,12 @@ ordinary(struct state *st, const char *buf, size_t sta */ mtype = MDOC_Fa; + savechar = '\0'; if (wend && ')' == st->outbuf[wend] && '(' == st->outbuf[wend - 1]) { mtype = dict_get(st->outbuf, --wend); + if (MDOC_Dv == mtype) + mtype = MDOC_Fo; if (MDOC_Fo == mtype || MDOC_MAX == mtype) { st->outbuflen = wend; st->outbuf[wend] = '\0'; @@ -1450,6 +1472,16 @@ ordinary(struct state *st, const char *buf, size_t sta fputs(".Xr ", stdout); st->oust = OUST_MAC; } + } else { + mtype = dict_get(st->outbuf, wend); + if (MDOC_Dv == mtype) { + savechar = st->outbuf[wend]; + st->outbuf[wend] = '\0'; + mdoc_newln(st); + fputs(".Dv ", stdout); + st->oust = OUST_MAC; + } else + mtype = MDOC_Fa; } /* @@ -1468,12 +1500,15 @@ ordinary(struct state *st, const char *buf, size_t sta islower((unsigned char)st->outbuf[wend - 1]))) { if (MDOC_MAX == mtype) fputs(" 3", stdout); - if (MDOC_Fa != mtype) - for (wend += 2; - '\0' != st->outbuf[wend]; - wend++) + if (MDOC_Fa != mtype) { + if (MDOC_Dv == mtype) + st->outbuf[wend] = savechar; + else + wend += 2; + while ('\0' != st->outbuf[wend]) printf(" %c", - st->outbuf[wend]); + st->outbuf[wend++]); + } mdoc_newln(st); }