summaryrefslogtreecommitdiffstatshomepage
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
commit112069844468772da75bff132e76dc021a0d51cc (patch)
tree9c1125ca5ca978ffb68fcbaee048ae7ce2fb6a62 /mdoc_strings.c
parent90971a6744219e0420d00c5eadd1d04649c52f33 (diff)
downloadmandoc-112069844468772da75bff132e76dc021a0d51cc.tar.gz
mandoc-112069844468772da75bff132e76dc021a0d51cc.tar.zst
mandoc-112069844468772da75bff132e76dc021a0d51cc.zip
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.c62
1 files changed, 29 insertions, 33 deletions
diff --git a/mdoc_strings.c b/mdoc_strings.c
index 58106391..e9e0b409 100644
--- a/mdoc_strings.c
+++ b/mdoc_strings.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_strings.c,v 1.6 2009/06/17 09:41:00 kristaps Exp $ */
+/* $Id: mdoc_strings.c,v 1.7 2009/06/17 10:53:32 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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));