-/* $Id: mandoc-db.c,v 1.16 2011/05/03 10:08:09 kristaps Exp $ */
+/* $Id: mandoc-db.c,v 1.21 2011/05/12 23:44:51 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
MANDOC_UTILITY,
MANDOC_INCLUDES,
MANDOC_VARIABLE,
- MANDOC_STANDARD
+ MANDOC_STANDARD,
+ MANDOC_AUTHOR,
+ MANDOC_CONFIG
};
#define MAN_ARGS DB *db, \
static void pmdoc(DB *, const char *, DBT *, size_t *,
DBT *, DBT *, size_t *, struct mdoc *);
static void pmdoc_node(MDOC_ARGS);
+static void pmdoc_An(MDOC_ARGS);
+static void pmdoc_Cd(MDOC_ARGS);
static void pmdoc_Fd(MDOC_ARGS);
static void pmdoc_In(MDOC_ARGS);
static void pmdoc_Fn(MDOC_ARGS);
NULL, /* El */
NULL, /* It */
NULL, /* Ad */
- NULL, /* An */
+ pmdoc_An, /* An */
NULL, /* Ar */
- NULL, /* Cd */
+ pmdoc_Cd, /* Cd */
NULL, /* Cm */
NULL, /* Dv */
NULL, /* Er */
char *fn; /* current file being parsed */
const char *msec, /* manual section */
*mtitle, /* manual title */
+ *arch, /* manual architecture */
*dir; /* result dir (default: cwd) */
char ibuf[MAXPATHLEN], /* index fname */
ibbuf[MAXPATHLEN], /* index backup fname */
mtitle = NULL != mdoc ?
mdoc_meta(mdoc)->title :
man_meta(man)->title;
+ arch = NULL != mdoc ? mdoc_meta(mdoc)->arch : NULL;
assert(msec);
assert(mtitle);
dbt_appendb(&rval, &rsz, fn, strlen(fn) + 1);
dbt_appendb(&rval, &rsz, msec, strlen(msec) + 1);
dbt_appendb(&rval, &rsz, mtitle, strlen(mtitle) + 1);
+ dbt_appendb(&rval, &rsz, arch ? arch : "",
+ arch ? strlen(arch) + 1 : 1);
+
sv = rval.size;
/* Fix the record number in the btree value. */
dbt_appendb(key, ksz, cp, sz + 1);
}
+/* ARGSUSED */
+static void
+pmdoc_An(MDOC_ARGS)
+{
+ uint32_t fl;
+
+ if (SEC_AUTHORS != n->sec)
+ return;
+
+ for (n = n->child; n; n = n->next)
+ if (MDOC_TEXT == n->type)
+ dbt_append(key, ksz, n->string);
+
+ fl = MANDOC_AUTHOR;
+ memcpy(val->data, &fl, 4);
+}
+
/* ARGSUSED */
static void
pmdoc_Fd(MDOC_ARGS)
if ('>' == *end || '"' == *end)
end--;
- dbt_appendb(key, ksz, start, end - start + 1);
+ assert(end >= start);
+ dbt_appendb(key, ksz, start, (size_t)(end - start + 1));
dbt_appendb(key, ksz, "", 1);
fl = MANDOC_INCLUDES;
memcpy(val->data, &fl, 4);
}
+/* ARGSUSED */
+static void
+pmdoc_Cd(MDOC_ARGS)
+{
+ uint32_t fl;
+
+ if (SEC_SYNOPSIS != n->sec)
+ return;
+
+ for (n = n->child; n; n = n->next)
+ if (MDOC_TEXT == n->type)
+ dbt_append(key, ksz, n->string);
+
+ fl = MANDOC_CONFIG;
+ memcpy(val->data, &fl, 4);
+}
+
/* ARGSUSED */
static void
pmdoc_In(MDOC_ARGS)
if (0 == (sz = strlen(start)))
return;
- if (';' == start[sz - 1])
+ if (';' == start[(int)sz - 1])
sz--;
if (0 == sz)
/*
* Go through a special heuristic dance here.
* This is why -man manuals are great!
+ * (I'm being sarcastic: my eyes are bleeding.)
* Conventionally, one or more manual names are
* comma-specified prior to a whitespace, then a
* dash, then a description. Try to puzzle out
while (' ' == *start)
start++;
- if ('\\' == *start && '-' == *(start + 1))
+ if (0 == strncmp(start, "-", 1))
+ start += 1;
+ else if (0 == strncmp(start, "\\-", 2))
start += 2;
- else if ('-' == *start)
- start++;
+ else if (0 == strncmp(start, "\\(en", 4))
+ start += 4;
+ else if (0 == strncmp(start, "\\(em", 4))
+ start += 4;
while (' ' == *start)
start++;