version 1.28, 2014/07/11 10:31:28 |
version 1.29, 2014/07/11 20:45:55 |
|
|
dofile(const struct args *args, const char *fname, |
dofile(const struct args *args, const char *fname, |
const struct tm *tm, const char *buf, size_t sz) |
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]; |
char datebuf[64]; |
|
struct state st; |
|
const char *fbase, *fext, *section, *date; |
char *title, *cp; |
char *title, *cp; |
|
size_t sup, end, i, cur = 0; |
|
|
if (0 == sz) |
if (0 == sz) |
return; |
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) |
if (NULL == args->title || NULL == args->section) { |
title = strdup(args->title); |
fbase = strrchr(fname, '/'); |
else if (NULL != (cp = strrchr(fname, '/'))) |
if (NULL == fbase) |
title = strdup(cp + 1); |
fbase = fname; |
else |
else |
title = strdup(fname); |
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 == title) { |
if (NULL == title) { |
perror(NULL); |
perror(NULL); |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
Line 1203 dofile(const struct args *args, const char *fname, |
|
Line 1219 dofile(const struct args *args, const char *fname, |
|
|
|
/* Section is 1 unless suffix is "pm". */ |
/* Section is 1 unless suffix is "pm". */ |
|
|
if (NULL == (section = args->section)) { |
section = (NULL != args->section) ? args->section : |
section = "1"; |
(NULL == fext || strcmp(fext + 1, "pm")) ? "1" : |
if (NULL != (cp = strrchr(title, '.'))) { |
PERL_SECTION; |
*cp++ = '\0'; |
|
if (0 == strcmp(cp, "pm")) |
|
section = PERL_SECTION; |
|
} |
|
} |
|
|
|
/* Date. Or the given "tm" if not supplied. */ |
/* Date. Or the given "tm" if not supplied. */ |
|
|