From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: pod2mdoc: When -s is specified but -n is not, the filename extension is
Date: Fri, 11 Jul 2014 16:45:55 -0400 (EDT) [thread overview]
Message-ID: <201407112045.s6BKjtw3021891@krisdoz.my.domain> (raw)
Log Message:
-----------
When -s is specified but -n is not, the filename extension is not needed
to determine the section number, but it still has to be trimmed from
the page title. Keeping the code readable required a rewrite of the
first half of dofile().
Bug reported by bentley@, thanks!
Modified Files:
--------------
pod2mdoc:
pod2mdoc.c
Revision Data
-------------
Index: pod2mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/pod2mdoc.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.28 -r1.29
--- pod2mdoc.c
+++ pod2mdoc.c
@@ -1178,24 +1178,40 @@ static void
dofile(const struct args *args, const char *fname,
const struct tm *tm, const char *buf, size_t sz)
{
- size_t sup, end, i, cur = 0;
- struct state st;
- const char *section, *date;
char datebuf[64];
+ struct state st;
+ const char *fbase, *fext, *section, *date;
char *title, *cp;
+ size_t sup, end, i, cur = 0;
if (0 == sz)
return;
- /* Title is last path component of the filename. */
+ /*
+ * Parsing the filename is almost always required,
+ * except when both the title and the section
+ * are provided on the command line.
+ */
+
+ if (NULL == args->title || NULL == args->section) {
+ fbase = strrchr(fname, '/');
+ if (NULL == fbase)
+ fbase = fname;
+ else
+ fbase++;
+ fext = strrchr(fbase, '.');
+ } else
+ fext = NULL;
+
+ /*
+ * The title will be converted to uppercase,
+ * so it needs to be copied.
+ */
+
+ title = (NULL != args->title) ? strdup(args->title) :
+ (NULL != fext) ? strndup(fbase, fext - fbase) :
+ strdup(fbase);
- if (NULL != args->title)
- title = strdup(args->title);
- else if (NULL != (cp = strrchr(fname, '/')))
- title = strdup(cp + 1);
- else
- title = strdup(fname);
-
if (NULL == title) {
perror(NULL);
exit(EXIT_FAILURE);
@@ -1203,14 +1219,9 @@ dofile(const struct args *args, const ch
/* Section is 1 unless suffix is "pm". */
- if (NULL == (section = args->section)) {
- section = "1";
- if (NULL != (cp = strrchr(title, '.'))) {
- *cp++ = '\0';
- if (0 == strcmp(cp, "pm"))
- section = PERL_SECTION;
- }
- }
+ section = (NULL != args->section) ? args->section :
+ (NULL == fext || strcmp(fext + 1, "pm")) ? "1" :
+ PERL_SECTION;
/* Date. Or the given "tm" if not supplied. */
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2014-07-11 20:45 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=201407112045.s6BKjtw3021891@krisdoz.my.domain \
--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).