Minus 80 lines of code, no functional change.
Written on the train from Koeln to Wolfsburg returning from p2k15.
-/* $OpenBSD: libman.h,v 1.47 2015/04/18 17:01:28 schwarze Exp $ */
+/* $OpenBSD: libman.h,v 1.48 2015/04/18 17:28:08 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
void man_head_alloc(struct roff_man *, int, int, int);
void man_body_alloc(struct roff_man *, int, int, int);
void man_elem_alloc(struct roff_man *, int, int, int);
-void man_node_delete(struct roff_man *, struct roff_node *);
int man_hash_find(const char *);
void man_macroend(struct roff_man *);
void man_valid_post(struct roff_man *);
-/* $OpenBSD: libmandoc.h,v 1.43 2015/04/18 17:01:28 schwarze Exp $ */
+/* $OpenBSD: libmandoc.h,v 1.44 2015/04/18 17:28:08 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
struct eqn;
struct roff;
struct roff_man;
+struct roff_node;
void mandoc_msg(enum mandocerr, struct mparse *,
int, int, const char *);
int mandoc_strntoi(const char *, size_t, int);
const char *mandoc_a2msec(const char*);
-void mdoc_free(struct roff_man *);
-struct roff_man *mdoc_alloc(struct roff *, struct mparse *,
- const char *, int);
-void mdoc_reset(struct roff_man *);
void mdoc_hash_init(void);
+void mdoc_node_delete(struct roff_man *, struct roff_node *);
int mdoc_parseln(struct roff_man *, int, char *, int);
void mdoc_endparse(struct roff_man *);
void mdoc_addspan(struct roff_man *, const struct tbl_span *);
void mdoc_addeqn(struct roff_man *, const struct eqn *);
-void man_free(struct roff_man *);
-struct roff_man *man_alloc(struct roff *, struct mparse *,
- const char *, int);
-void man_reset(struct roff_man *);
void man_hash_init(void);
+void man_node_delete(struct roff_man *, struct roff_node *);
int man_parseln(struct roff_man *, int, char *, int);
void man_endparse(struct roff_man *);
void man_addspan(struct roff_man *, const struct tbl_span *);
void roff_free(struct roff *);
struct roff *roff_alloc(struct mparse *, const struct mchars *, int);
void roff_reset(struct roff *);
+void roff_man_free(struct roff_man *);
+struct roff_man *roff_man_alloc(struct roff *, struct mparse *,
+ const char *, int);
+void roff_man_reset(struct roff_man *);
enum rofferr roff_parseln(struct roff *, int, struct buf *, int *);
void roff_endparse(struct roff *);
void roff_setreg(struct roff *, const char *, int, char sign);
-/* $OpenBSD: libmdoc.h,v 1.72 2015/04/18 17:01:28 schwarze Exp $ */
+/* $OpenBSD: libmdoc.h,v 1.73 2015/04/18 17:28:08 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
struct roff_node *mdoc_body_alloc(struct roff_man *, int, int, int);
struct roff_node *mdoc_endbody_alloc(struct roff_man *, int, int, int,
struct roff_node *, enum mdoc_endbody);
-void mdoc_node_delete(struct roff_man *, struct roff_node *);
void mdoc_node_relink(struct roff_man *, struct roff_node *);
int mdoc_hash_find(const char *);
const char *mdoc_a2att(const char *);
-/* $OpenBSD: man.c,v 1.103 2015/04/18 17:01:28 schwarze Exp $ */
+/* $OpenBSD: man.c,v 1.104 2015/04/18 17:28:08 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
const char * const *man_macronames = __man_macronames;
-static void man_alloc1(struct roff_man *);
static void man_breakscope(struct roff_man *, int);
static void man_descope(struct roff_man *, int, int);
-static void man_free1(struct roff_man *);
static struct roff_node *man_node_alloc(struct roff_man *, int, int,
enum roff_type, int);
static void man_node_append(struct roff_man *,
return(&man->meta);
}
-void
-man_reset(struct roff_man *man)
-{
-
- man_free1(man);
- man_alloc1(man);
-}
-
-void
-man_free(struct roff_man *man)
-{
-
- man_free1(man);
- free(man);
-}
-
-struct roff_man *
-man_alloc(struct roff *roff, struct mparse *parse,
- const char *defos, int quick)
-{
- struct roff_man *p;
-
- p = mandoc_calloc(1, sizeof(*p));
- p->parse = parse;
- p->defos = defos;
- p->quick = quick;
- p->roff = roff;
-
- man_alloc1(p);
- return(p);
-}
-
void
man_endparse(struct roff_man *man)
{
man_ptext(man, ln, buf, offs));
}
-static void
-man_free1(struct roff_man *man)
-{
-
- if (man->first)
- man_node_delete(man, man->first);
- free(man->meta.title);
- free(man->meta.os);
- free(man->meta.date);
- free(man->meta.vol);
- free(man->meta.msec);
-}
-
-static void
-man_alloc1(struct roff_man *man)
-{
-
- memset(&man->meta, 0, sizeof(man->meta));
- man->macroset = MACROSET_MAN;
- man->flags = 0;
- man->last = mandoc_calloc(1, sizeof(*man->last));
- man->first = man->last;
- man->last->type = ROFFT_ROOT;
- man->last->tok = MAN_MAX;
- man->next = ROFF_NEXT_CHILD;
-}
-
-
static void
man_node_append(struct roff_man *man, struct roff_node *p)
{
-/* $OpenBSD: mdoc.c,v 1.133 2015/04/18 17:01:28 schwarze Exp $ */
+/* $OpenBSD: mdoc.c,v 1.134 2015/04/18 17:28:08 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
static void mdoc_node_free(struct roff_node *);
static void mdoc_node_unlink(struct roff_man *,
struct roff_node *);
-static void mdoc_free1(struct roff_man *);
-static void mdoc_alloc1(struct roff_man *);
static struct roff_node *node_alloc(struct roff_man *, int, int,
int, enum roff_type);
static void node_append(struct roff_man *, struct roff_node *);
return(&mdoc->meta);
}
-/*
- * Frees volatile resources (parse tree, meta-data, fields).
- */
-static void
-mdoc_free1(struct roff_man *mdoc)
-{
-
- if (mdoc->first)
- mdoc_node_delete(mdoc, mdoc->first);
- free(mdoc->meta.msec);
- free(mdoc->meta.vol);
- free(mdoc->meta.arch);
- free(mdoc->meta.date);
- free(mdoc->meta.title);
- free(mdoc->meta.os);
- free(mdoc->meta.name);
-}
-
-/*
- * Allocate all volatile resources (parse tree, meta-data, fields).
- */
-static void
-mdoc_alloc1(struct roff_man *mdoc)
-{
-
- memset(&mdoc->meta, 0, sizeof(mdoc->meta));
- mdoc->macroset = MACROSET_MDOC;
- mdoc->flags = 0;
- mdoc->lastnamed = mdoc->lastsec = SEC_NONE;
- mdoc->last = mandoc_calloc(1, sizeof(*mdoc->last));
- mdoc->first = mdoc->last;
- mdoc->last->type = ROFFT_ROOT;
- mdoc->last->tok = MDOC_MAX;
- mdoc->next = ROFF_NEXT_CHILD;
-}
-
-/*
- * Free up volatile resources (see mdoc_free1()) then re-initialises the
- * data with mdoc_alloc1(). After invocation, parse data has been reset
- * and the parser is ready for re-invocation on a new tree; however,
- * cross-parse non-volatile data is kept intact.
- */
-void
-mdoc_reset(struct roff_man *mdoc)
-{
-
- mdoc_free1(mdoc);
- mdoc_alloc1(mdoc);
-}
-
-/*
- * Completely free up all volatile and non-volatile parse resources.
- * After invocation, the pointer is no longer usable.
- */
-void
-mdoc_free(struct roff_man *mdoc)
-{
-
- mdoc_free1(mdoc);
- free(mdoc);
-}
-
-/*
- * Allocate volatile and non-volatile parse resources.
- */
-struct roff_man *
-mdoc_alloc(struct roff *roff, struct mparse *parse,
- const char *defos, int quick)
-{
- struct roff_man *p;
-
- p = mandoc_calloc(1, sizeof(*p));
-
- p->parse = parse;
- p->defos = defos;
- p->quick = quick;
- p->roff = roff;
-
- mdoc_alloc1(p);
- return(p);
-}
-
void
mdoc_endparse(struct roff_man *mdoc)
{
-/* $OpenBSD: read.c,v 1.111 2015/04/18 17:01:28 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.112 2015/04/18 17:28:08 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
}
}
- if (format == MPARSE_MDOC) {
- if (curp->man == NULL)
- curp->man = mdoc_alloc(
- curp->roff, curp, curp->defos,
- MPARSE_QUICK & curp->options ? 1 : 0);
- else
- curp->man->macroset = MACROSET_MDOC;
- mdoc_hash_init();
- return;
+ if (curp->man == NULL) {
+ curp->man = roff_man_alloc(curp->roff, curp, curp->defos,
+ curp->options & MPARSE_QUICK ? 1 : 0);
+ curp->man->macroset = MACROSET_MAN;
+ curp->man->first->tok = MDOC_MAX;
}
- /* Fall back to man(7) as a last resort. */
-
- if (curp->man == NULL)
- curp->man = man_alloc(
- curp->roff, curp, curp->defos,
- MPARSE_QUICK & curp->options ? 1 : 0);
- else
+ if (format == MPARSE_MDOC) {
+ mdoc_hash_init();
+ curp->man->macroset = MACROSET_MDOC;
+ curp->man->first->tok = MDOC_MAX;
+ } else {
+ man_hash_init();
curp->man->macroset = MACROSET_MAN;
- man_hash_init();
+ curp->man->first->tok = MAN_MAX;
+ }
}
/*
{
if (curp->man == NULL && curp->sodest == NULL)
- curp->man = man_alloc(curp->roff, curp, curp->defos,
+ curp->man = roff_man_alloc(curp->roff, curp, curp->defos,
curp->options & MPARSE_QUICK ? 1 : 0);
if (curp->man->macroset == MACROSET_NONE)
curp->man->macroset = MACROSET_MAN;
curp->mchars = mchars;
curp->roff = roff_alloc(curp, curp->mchars, options);
+ curp->man = roff_man_alloc( curp->roff, curp, curp->defos,
+ curp->options & MPARSE_QUICK ? 1 : 0);
if (curp->options & MPARSE_MDOC) {
- curp->man = mdoc_alloc(
- curp->roff, curp, curp->defos,
- curp->options & MPARSE_QUICK ? 1 : 0);
mdoc_hash_init();
- }
- if (curp->options & MPARSE_MAN) {
- curp->man = man_alloc(
- curp->roff, curp, curp->defos,
- curp->options & MPARSE_QUICK ? 1 : 0);
+ curp->man->macroset = MACROSET_MDOC;
+ curp->man->first->tok = MDOC_MAX;
+ } else if (curp->options & MPARSE_MAN) {
man_hash_init();
+ curp->man->macroset = MACROSET_MAN;
+ curp->man->first->tok = MAN_MAX;
}
-
return(curp);
}
roff_reset(curp->roff);
- if (curp->man != NULL) {
- if (curp->man->macroset == MACROSET_MDOC)
- mdoc_reset(curp->man);
- else
- man_reset(curp->man);
- curp->man->macroset = MACROSET_NONE;
- }
+ if (curp->man != NULL)
+ roff_man_reset(curp->man);
if (curp->secondary)
curp->secondary->sz = 0;
mparse_free(struct mparse *curp)
{
- if (curp->man->macroset == MACROSET_MDOC)
- mdoc_free(curp->man);
- if (curp->man->macroset == MACROSET_MAN)
- man_free(curp->man);
+ roff_man_free(curp->man);
if (curp->roff)
roff_free(curp->roff);
if (curp->secondary)
-/* $OpenBSD: roff.c,v 1.136 2015/04/04 13:52:59 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.137 2015/04/18 17:28:08 schwarze Exp $ */
/*
- * 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
#include "mandoc.h"
#include "mandoc_aux.h"
+#include "roff.h"
#include "libmandoc.h"
#include "libroff.h"
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);
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.