summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man.c4
-rw-r--r--man.h4
-rw-r--r--man_action.c161
-rw-r--r--man_macro.c25
4 files changed, 97 insertions, 97 deletions
diff --git a/man.c b/man.c
index 62251b52..9165ad21 100644
--- a/man.c
+++ b/man.c
@@ -133,8 +133,8 @@ man_free1(struct man *man)
man_node_freelist(man->first);
if (man->meta.title)
free(man->meta.title);
- if (man->meta.os)
- free(man->meta.os);
+ if (man->meta.source)
+ free(man->meta.source);
if (man->meta.vol)
free(man->meta.vol);
}
diff --git a/man.h b/man.h
index 0fcffe43..6e66a969 100644
--- a/man.h
+++ b/man.h
@@ -51,10 +51,10 @@ enum man_type {
struct man_meta {
int msec;
- char *vol;
time_t date;
+ char *vol;
char *title;
- char *os;
+ char *source;
};
struct man_node {
diff --git a/man_action.c b/man_action.c
index fdeef50e..95b13fdb 100644
--- a/man_action.c
+++ b/man_action.c
@@ -33,9 +33,12 @@ struct actions {
};
+static int post_TH(struct man *);
+static time_t man_atotime(const char *);
+
const struct actions man_actions[MAN_MAX] = {
{ NULL }, /* __ */
- { NULL }, /* TH */
+ { post_TH }, /* TH */
{ NULL }, /* SH */
{ NULL }, /* SS */
{ NULL }, /* TP */
@@ -78,119 +81,103 @@ man_action_post(struct man *m)
return(1);
}
-#if 0
+
static int
-post_dt(POST_ARGS)
+post_TH(struct man *m)
{
- struct mdoc_node *n;
- const char *cp;
- char *ep;
- long lval;
+ struct man_node *n;
+ char *ep;
+ long lval;
if (m->meta.title)
free(m->meta.title);
if (m->meta.vol)
free(m->meta.vol);
- if (m->meta.arch)
- free(m->meta.arch);
+ if (m->meta.source)
+ free(m->meta.source);
- m->meta.title = m->meta.vol = m->meta.arch = NULL;
+ m->meta.title = m->meta.vol = m->meta.source = NULL;
m->meta.msec = 0;
+ m->meta.date = 0;
- /* Handles: `.Dt'
- * --> title = unknown, volume = local, msec = 0, arch = NULL
- */
+ /* ->TITLE<- MSEC DATE SOURCE VOL */
- if (NULL == (n = m->last->child)) {
- m->meta.title = xstrdup("unknown");
- m->meta.vol = xstrdup("local");
- return(post_prol(m));
- }
+ n = m->last->child;
+ assert(n);
- /* Handles: `.Dt TITLE'
- * --> title = TITLE, volume = local, msec = 0, arch = NULL
- */
+ if (NULL == (m->meta.title = strdup(n->string)))
+ return(man_verr(m, n->line, n->pos, "malloc"));
+
+ /* TITLE ->MSEC<- DATE SOURCE VOL */
+
+ n = n->next;
+ assert(n);
- m->meta.title = xstrdup(n->string);
+ errno = 0;
+ lval = strtol(n->string, &ep, 10);
+ if (n->string[0] != '\0' && *ep == '\0')
+ m->meta.msec = (int)lval;
+ else if ( ! man_vwarn(m, n->line, n->pos, "invalid section"))
+ return(0);
+
+ /* TITLE MSEC ->DATE<- SOURCE VOL */
if (NULL == (n = n->next)) {
- m->meta.vol = xstrdup("local");
- return(post_prol(m));
+ m->meta.date = time(NULL);
+ return(1);
}
- /* Handles: `.Dt TITLE SEC'
- * --> title = TITLE, volume = SEC is msec ?
- * format(msec) : SEC,
- * msec = SEC is msec ? atoi(msec) : 0,
- * arch = NULL
- */
+ if (0 == (m->meta.date = man_atotime(n->string))) {
+ if ( ! man_vwarn(m, n->line, n->pos, "invalid date"))
+ return(0);
+ m->meta.date = time(NULL);
+ }
- cp = mdoc_a2msec(n->string);
- if (cp) {
- m->meta.vol = xstrdup(cp);
- errno = 0;
- lval = strtol(n->string, &ep, 10);
- if (n->string[0] != '\0' && *ep == '\0')
- m->meta.msec = (int)lval;
- } else
- m->meta.vol = xstrdup(n->string);
-
- if (NULL == (n = n->next))
- return(post_prol(m));
-
- /* Handles: `.Dt TITLE SEC VOL'
- * --> title = TITLE, volume = VOL is vol ?
- * format(VOL) :
- * VOL is arch ? format(arch) :
- * VOL
- */
+ /* TITLE MSEC DATE ->SOURCE<- VOL */
- cp = mdoc_a2vol(n->string);
- if (cp) {
- free(m->meta.vol);
- m->meta.vol = xstrdup(cp);
- n = n->next;
- } else {
- cp = mdoc_a2arch(n->string);
- if (NULL == cp) {
- free(m->meta.vol);
- m->meta.vol = xstrdup(n->string);
- } else
- m->meta.arch = xstrdup(cp);
- }
-
- /* Ignore any subsequent parameters... */
-
- return(post_prol(m));
-}
+ if ((n = n->next))
+ if (NULL == (m->meta.source = strdup(n->string)))
+ return(man_verr(m, n->line, n->pos, "malloc"));
-static int
-post_prol(POST_ARGS)
-{
- struct mdoc_node *n;
+ /* TITLE MSEC DATE SOURCE ->VOL<- */
+
+ if ((n = n->next))
+ if (NULL == (m->meta.vol = strdup(n->string)))
+ return(man_verr(m, n->line, n->pos, "malloc"));
/*
* The end document shouldn't have the prologue macros as part
* of the syntax tree (they encompass only meta-data).
*/
- if (m->last->parent->child == m->last)
- m->last->parent->child = m->last->prev;
- if (m->last->prev)
- m->last->prev->next = NULL;
-
+ assert(MAN_ROOT == m->last->parent->type);
+ m->last->parent->child = NULL;
n = m->last;
- assert(NULL == m->last->next);
-
- if (m->last->prev) {
- m->last = m->last->prev;
- m->next = MDOC_NEXT_SIBLING;
- } else {
- m->last = m->last->parent;
- m->next = MDOC_NEXT_CHILD;
- }
+ m->last = m->last->parent;
+ m->next = MAN_NEXT_CHILD;
+ assert(m->last == m->first);
- mdoc_node_freelist(n);
+ man_node_freelist(n);
return(1);
}
-#endif
+
+
+static time_t
+man_atotime(const char *p)
+{
+ struct tm tm;
+ char *pp;
+
+ (void)memset(&tm, 0, sizeof(struct tm));
+
+ if ((pp = strptime(p, "%b %d %Y", &tm)) && 0 == *pp)
+ return(mktime(&tm));
+ if ((pp = strptime(p, "%d %b %Y", &tm)) && 0 == *pp)
+ return(mktime(&tm));
+ if ((pp = strptime(p, "%b %d, %Y", &tm)) && 0 == *pp)
+ return(mktime(&tm));
+ if ((pp = strptime(p, "%b %Y", &tm)) && 0 == *pp)
+ return(mktime(&tm));
+
+ return(0);
+}
diff --git a/man_macro.c b/man_macro.c
index 4431e1b0..87832e1c 100644
--- a/man_macro.c
+++ b/man_macro.c
@@ -56,8 +56,16 @@ man_macro(struct man *man, int tok, int line,
man->next = MAN_NEXT_SIBLING;
}
- for ( ; man->last && man->last != n;
- man->last = man->last->parent) {
+ /*
+ * Note that when TH is pruned, we'll be back at the root, so
+ * make sure that we don't clobber as its sibling.
+ */
+
+ for ( ; man->last; man->last = man->last->parent) {
+ if (man->last == n)
+ break;
+ if (man->last->type == MAN_ROOT)
+ break;
if ( ! man_valid_post(man))
return(0);
if ( ! man_action_post(man))
@@ -66,12 +74,16 @@ man_macro(struct man *man, int tok, int line,
assert(man->last);
- if ( ! man_valid_post(man))
+ /*
+ * Same here regarding whether we're back at the root.
+ */
+
+ if (man->last->type != MAN_ROOT && ! man_valid_post(man))
return(0);
- if ( ! man_action_post(man))
+ if (man->last->type != MAN_ROOT && ! man_action_post(man))
return(0);
-
- man->next = MAN_NEXT_SIBLING;
+ if (man->last->type != MAN_ROOT)
+ man->next = MAN_NEXT_SIBLING;
return(1);
}
@@ -88,6 +100,7 @@ man_macroend(struct man *m)
if ( ! man_action_post(m))
return(0);
}
+ assert(m->last == m->first);
if ( ! man_valid_post(m))
return(0);