summaryrefslogtreecommitdiffstats
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-04-18 17:28:36 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-04-18 17:28:36 +0000
commitafd3f3a3f381e6bd5e6803a730f57302dd9234d2 (patch)
tree8cc8dbdb77f13ddbce6fe2a22b8d3284143adbc5 /roff.c
parent4534f390e036ac23ee5e8f0373ffb9f4d785a17d (diff)
downloadmandoc-afd3f3a3f381e6bd5e6803a730f57302dd9234d2.tar.gz
Unify {mdoc,man}_{alloc,reset,free}() into roff_man_{alloc,reset,free}().
Minus 80 lines of code, no functional change. Written on the train from Koeln to Wolfsburg returning from p2k15.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c70
1 files changed, 69 insertions, 1 deletions
diff --git a/roff.c b/roff.c
index c1370154..0fb49be0 100644
--- a/roff.c
+++ b/roff.c
@@ -1,6 +1,6 @@
/* $Id$ */
/*
- * Copyright (c) 2010, 2011, 2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2009-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -28,6 +28,7 @@
#include "mandoc.h"
#include "mandoc_aux.h"
+#include "roff.h"
#include "libmandoc.h"
#include "libroff.h"
@@ -412,6 +413,8 @@ static const char *roff_getstrn(const struct roff *,
static enum rofferr roff_insec(ROFF_ARGS);
static enum rofferr roff_it(ROFF_ARGS);
static enum rofferr roff_line_ignore(ROFF_ARGS);
+static void roff_man_alloc1(struct roff_man *);
+static void roff_man_free1(struct roff_man *);
static enum rofferr roff_nr(ROFF_ARGS);
static enum rofft roff_parse(struct roff *, char *, int *,
int, int);
@@ -898,6 +901,71 @@ roff_alloc(struct mparse *parse, const struct mchars *mchars, int options)
return(r);
}
+static void
+roff_man_free1(struct roff_man *man)
+{
+
+ if (man->first != NULL) {
+ if (man->macroset == MACROSET_MDOC)
+ mdoc_node_delete(man, man->first);
+ else
+ man_node_delete(man, man->first);
+ }
+ free(man->meta.msec);
+ free(man->meta.vol);
+ free(man->meta.os);
+ free(man->meta.arch);
+ free(man->meta.title);
+ free(man->meta.name);
+ free(man->meta.date);
+}
+
+static void
+roff_man_alloc1(struct roff_man *man)
+{
+
+ memset(&man->meta, 0, sizeof(man->meta));
+ man->first = mandoc_calloc(1, sizeof(*man->first));
+ man->first->type = ROFFT_ROOT;
+ man->last = man->first;
+ man->last_es = NULL;
+ man->flags = 0;
+ man->macroset = MACROSET_NONE;
+ man->lastsec = man->lastnamed = SEC_NONE;
+ man->next = ROFF_NEXT_CHILD;
+}
+
+void
+roff_man_reset(struct roff_man *man)
+{
+
+ roff_man_free1(man);
+ roff_man_alloc1(man);
+}
+
+void
+roff_man_free(struct roff_man *man)
+{
+
+ roff_man_free1(man);
+ free(man);
+}
+
+struct roff_man *
+roff_man_alloc(struct roff *roff, struct mparse *parse,
+ const char *defos, int quick)
+{
+ struct roff_man *man;
+
+ man = mandoc_calloc(1, sizeof(*man));
+ man->parse = parse;
+ man->roff = roff;
+ man->defos = defos;
+ man->quick = quick;
+ roff_man_alloc1(man);
+ return(man);
+}
+
/*
* In the current line, expand escape sequences that tend to get
* used in numerical expressions and conditional requests.