From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]); by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 4dac2ca2; for ; Thu, 12 Feb 2015 19:44:46 -0500 (EST) Date: Thu, 12 Feb 2015 19:44:46 -0500 (EST) Message-Id: <11551582095258394612.enqueue@fantadrom.bsd.lv> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: pod2mdoc: If a function is listed in the SYNOPSIS and its name occurs X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- If a function is listed in the SYNOPSIS and its name occurs later in the text, followed by "()", mark it up with `Fn'. This is the first of a number of features assigning markup by looking at earlier content. Portability glue will be added later. Modified Files: -------------- pod2mdoc: Makefile pod2mdoc.1 pod2mdoc.c Added Files: ----------- pod2mdoc: dict.c dict.h Revision Data ------------- --- /dev/null +++ dict.h @@ -0,0 +1,26 @@ +/* $Id: dict.h,v 1.1 2015/02/13 00:44:16 schwarze Exp $ */ +/* + * Copyright (c) 2015 Ingo Schwarze + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +enum mdoc_type { + MDOC_Fo = 0, + 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_destroy(void); Index: pod2mdoc.c =================================================================== RCS file: /home/cvs/mdocml/pod2mdoc/pod2mdoc.c,v retrieving revision 1.36 retrieving revision 1.37 diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.36 -r1.37 --- pod2mdoc.c +++ pod2mdoc.c @@ -1,6 +1,7 @@ -/* $Id$ */ +/* $Id$ */ /* * Copyright (c) 2014 Kristaps Dzonsons + * Copyright (c) 2014, 2015 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -26,6 +27,8 @@ #include #include +#include "dict.h" + /* * In what section can we find Perl module manuals? * Sometimes (Mac OS X) it's 3pm, sometimes (OpenBSD, etc.) 3p. @@ -1107,6 +1110,7 @@ again: putchar('\n'); buf[ifa++] = '\0'; printf(".Fo %s\n", buf + ifo); + dict_put(buf + ifo, MDOC_Fo); buf[ifc++] = '\0'; for (;;) { cp = strchr(buf + ifa, ','); @@ -1333,12 +1337,26 @@ ordinary(struct state *st, const char *b */ last = buf[start++]; - if (' ' == last) { - outbuf_flush(st); - putchar(' '); - st->wantws = 1; - } else + if (' ' != last) { outbuf_addchar(st); + continue; + } + + if ( ! strcmp(st->outbuf + st->outbuflen - 2, "()") && + dict_get(st->outbuf, st->outbuflen - 2) == + MDOC_Fo) { + st->outbuflen -= 2; + st->outbuf[st->outbuflen] = '\0'; + mdoc_newln(st); + fputs(".Fn ", stdout); + outbuf_flush(st); + mdoc_newln(st); + continue; + } + + outbuf_flush(st); + putchar(' '); + st->wantws = 1; } if (start < end - 1 && '<' == buf[start + 1] && @@ -1504,6 +1522,7 @@ dofile(const struct args *args, const ch free(title); + dict_init(); memset(&st, 0, sizeof(struct state)); st.oust = OUST_NL; st.wantws = 1; @@ -1531,6 +1550,7 @@ dofile(const struct args *args, const ch dopar(&st, buf, cur, end); cur = sup; } + dict_destroy(); } /* Index: pod2mdoc.1 =================================================================== RCS file: /home/cvs/mdocml/pod2mdoc/pod2mdoc.1,v retrieving revision 1.13 retrieving revision 1.14 diff -Lpod2mdoc.1 -Lpod2mdoc.1 -u -p -r1.13 -r1.14 --- pod2mdoc.1 +++ pod2mdoc.1 @@ -50,7 +50,7 @@ For compatibility with Ignored. .It Fl d Ar date Set the document date -.Pq Sq Dd +.Pq Sq \&Dd to .Ar date .Po @@ -64,7 +64,7 @@ uses the file modification date or the c standard input. .It Fl n Ar title Set the document title -.Pq Sq Dt +.Pq Sq \&Dt to .Ar title . If unspecified, @@ -77,7 +77,7 @@ if reading from standard input .Pq you probably don't want that . .It Fl s Ar section Set the document section -.Pq Sq Dt +.Pq Sq \&Dt to .Ar section . If unspecified, @@ -141,7 +141,7 @@ Thus, the input .Li B [B<-bar baz>] is rendered as follows: .Bd -literal -\&.Nm foo +\&.Nm foo \&.Oo \&.Fl bar Ar baz \&.Oc @@ -192,6 +192,11 @@ If only a section appears, such as in .Li , the link is rendered with .Sq \&Sx . +.Pp +Words followed by +.Qq Pq +that match function names listed in the SYNOPSIS section are marked up with +.Sq \&Fn . .Sh EXIT STATUS .Ex -std .Sh EXAMPLES @@ -235,8 +240,7 @@ does, append a POD ERRORS section in the .Sh AUTHORS .Nm was written by -.Ar Kristaps Dzonsons , -.Mt kristaps@bsd.lv . +.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv . .Sh CAVEATS By way of being a presentational language, POD is not well-represented by --- /dev/null +++ dict.c @@ -0,0 +1,126 @@ +/* $Id: dict.c,v 1.1 2015/02/13 00:44:16 schwarze Exp $ */ +/* + * Copyright (c) 2015 Ingo Schwarze + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include + +#include +#include +#include +#include +#include +#include + +#include "dict.h" + +struct dict_entry { + enum mdoc_type t; + char s[]; +}; + +static void *dict_malloc(size_t, void *); +static void *dict_calloc(size_t, size_t, void *); +static void dict_free(void *, void *); + +static struct ohash dict_data; + + +void +dict_init(void) +{ + struct ohash_info dict_info; + + dict_info.key_offset = offsetof(struct dict_entry, s); + dict_info.data = NULL; + dict_info.alloc = dict_malloc; + dict_info.calloc = dict_calloc; + dict_info.free = dict_free; + + ohash_init(&dict_data, 4, &dict_info); +} + +enum mdoc_type +dict_get(const char *s, size_t len) +{ + struct dict_entry *entry; + const char *end; + unsigned int slot; + + if (len == 0) + len = strlen(s); + end = s + len; + slot = ohash_qlookupi(&dict_data, s, &end); + entry = ohash_find(&dict_data, slot); + return(entry == NULL ? MDOC_MAX : entry->t); +} + +void +dict_put(const char *s, enum mdoc_type t) +{ + struct dict_entry *entry; + const char *end; + size_t len; + unsigned int slot; + + len = strlen(s); + end = s + len; + slot = ohash_qlookupi(&dict_data, s, &end); + entry = ohash_find(&dict_data, slot); + if (entry == NULL) { + entry = malloc(sizeof(*entry) + len + 1); + if (entry == NULL) { + perror(NULL); + exit(1); + } + memcpy(entry->s, s, len + 1); + ohash_insert(&dict_data, slot, entry); + } + entry->t = t; +} + +void +dict_destroy(void) +{ + struct dict_entry *entry; + unsigned int slot; + + entry = ohash_first(&dict_data, &slot); + while (entry != NULL) { + free(entry); + entry = ohash_next(&dict_data, &slot); + } + ohash_delete(&dict_data); +} + +static void * +dict_malloc(size_t size, void *dummy) +{ + + return(malloc(size)); +} + +static void * +dict_calloc(size_t nmemb, size_t size, void *dummy) +{ + + return(calloc(nmemb, size)); +} + +static void +dict_free(void *ptr, void *dummy) +{ + + free(ptr); +} Index: Makefile =================================================================== RCS file: /home/cvs/mdocml/pod2mdoc/Makefile,v retrieving revision 1.12 retrieving revision 1.13 diff -LMakefile -LMakefile -u -p -r1.12 -r1.13 --- Makefile +++ Makefile @@ -2,8 +2,8 @@ VERSION = 0.1 CFLAGS += -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings WWWPREFIX = /usr/vhosts/mdocml.bsd.lv/www/htdocs/pod2mdoc -pod2mdoc: pod2mdoc.o - $(CC) -o $@ pod2mdoc.o +pod2mdoc: dict.o pod2mdoc.o + $(CC) $(LDFLAGS) -o $@ dict.o pod2mdoc.o -lutil www: index.html pod2mdoc.1.html pod2mdoc-$(VERSION).tgz @@ -29,6 +29,6 @@ pod2mdoc.1.html: pod2mdoc.1 mandoc -Thtml pod2mdoc.1 >$@ clean: - rm -f pod2mdoc pod2mdoc.o pod2mdoc-$(VERSION).tgz \ + rm -f pod2mdoc dict.o pod2mdoc.o pod2mdoc-$(VERSION).tgz \ index.html pod2mdoc.1.html rm -rf pod2mdoc.dSYM -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv