summaryrefslogtreecommitdiffstats
path: root/mdoc_strings.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-06-17 10:53:32 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-06-17 10:53:32 +0000
commit08234e1261b84672fa81eab4dd6640e9b55e2f63 (patch)
tree3321dec2f6157aa567b7f0845a6e86753b314ff5 /mdoc_strings.c
parentaa8ebdeebdc3218708b91a72e0b499258a3e5cef (diff)
downloadmandoc-08234e1261b84672fa81eab4dd6640e9b55e2f63.tar.gz
Section orders are more elegantly handled (MDOC_PBODY is a flag).
Cleaned up string->enum conversion for section lookup.
Diffstat (limited to 'mdoc_strings.c')
-rw-r--r--mdoc_strings.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/mdoc_strings.c b/mdoc_strings.c
index d1781a98..25711de7 100644
--- a/mdoc_strings.c
+++ b/mdoc_strings.c
@@ -24,36 +24,34 @@
#include "libmdoc.h"
+/* FIXME: this file is poorly named. */
+
struct mdoc_secname {
const char *name; /* Name of section. */
- int flag;
-#define MSECNAME_META (1 << 0)/* Logical section (not real). */
+ enum mdoc_sec sec; /* Corresponding section. */
};
-/* Section names corresponding to mdoc_sec. */
+#define SECNAME_MAX (18)
-static const struct mdoc_secname secnames[] = {
- { "PROLOGUE", MSECNAME_META },
- { "BODY", MSECNAME_META },
- { "NAME", 0 },
- { "LIBRARY", 0 },
- { "SYNOPSIS", 0 },
- { "DESCRIPTION", 0 },
- { "IMPLEMENTATION NOTES", 0 },
- { "RETURN VALUES", 0 },
- { "ENVIRONMENT", 0 },
- { "FILES", 0 },
- { "EXAMPLES", 0 },
- { "DIAGNOSTICS", 0 },
- { "COMPATIBILITY", 0 },
- { "ERRORS", 0 },
- { "SEE ALSO", 0 },
- { "STANDARDS", 0 },
- { "HISTORY", 0 },
- { "AUTHORS", 0 },
- { "CAVEATS", 0 },
- { "BUGS", 0 },
- { NULL, 0 }
+static const struct mdoc_secname secnames[SECNAME_MAX] = {
+ { "NAME", SEC_NAME },
+ { "LIBRARY", SEC_LIBRARY },
+ { "SYNOPSIS", SEC_SYNOPSIS },
+ { "DESCRIPTION", SEC_DESCRIPTION },
+ { "IMPLEMENTATION NOTES", SEC_IMPLEMENTATION },
+ { "RETURN VALUES", SEC_RETURN_VALUES },
+ { "ENVIRONMENT", SEC_ENVIRONMENT },
+ { "FILES", SEC_FILES },
+ { "EXAMPLES", SEC_EXAMPLES },
+ { "DIAGNOSTICS", SEC_DIAGNOSTICS },
+ { "COMPATIBILITY", SEC_COMPATIBILITY },
+ { "ERRORS", SEC_ERRORS },
+ { "SEE ALSO", SEC_SEE_ALSO },
+ { "STANDARDS", SEC_STANDARDS },
+ { "HISTORY", SEC_HISTORY },
+ { "AUTHORS", SEC_AUTHORS },
+ { "CAVEATS", SEC_CAVEATS },
+ { "BUGS", SEC_BUGS },
};
#ifdef __linux__
@@ -191,13 +189,11 @@ mdoc_isdelim(const char *p)
enum mdoc_sec
mdoc_atosec(const char *p)
{
- const struct mdoc_secname *n;
- int i;
+ int i;
- for (i = 0, n = secnames; n->name; n++, i++)
- if ( ! (n->flag & MSECNAME_META))
- if (0 == strcmp(p, n->name))
- return((enum mdoc_sec)i);
+ for (i = 0; i < SECNAME_MAX; i++)
+ if (0 == strcmp(p, secnames[i].name))
+ return(secnames[i].sec);
return(SEC_CUSTOM);
}
@@ -209,7 +205,7 @@ mdoc_atotime(const char *p)
struct tm tm;
char *pp;
- (void)memset(&tm, 0, sizeof(struct tm));
+ bzero(&tm, sizeof(struct tm));
if (0 == strcmp(p, "$" "Mdocdate$"))
return(time(NULL));