aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/roff.c b/roff.c
index 4960d947..a9dbce22 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.140 2011/05/24 15:22:14 kristaps Exp $ */
+/* $Id: roff.c,v 1.141 2011/05/24 21:18:06 kristaps Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -28,6 +28,7 @@
#include "libroff.h"
#include "libmandoc.h"
+/* Maximum number of nested if-else conditionals. */
#define RSTACK_MAX 128
enum rofft {
@@ -60,7 +61,7 @@ enum rofft {
ROFF_EQ,
ROFF_EN,
ROFF_cblock,
- ROFF_ccond, /* FIXME: remove this. */
+ ROFF_ccond,
ROFF_USERDEF,
ROFF_MAX
};
@@ -124,6 +125,14 @@ struct roffmac {
struct roffmac *next;
};
+struct predef {
+ const char *name; /* predefined input name */
+ const char *str; /* replacement symbol */
+};
+
+#define PREDEF(__name, __str) \
+ { (__name), (__str) },
+
static enum rofferr roff_block(ROFF_ARGS);
static enum rofferr roff_block_text(ROFF_ARGS);
static enum rofferr roff_block_sub(ROFF_ARGS);
@@ -195,6 +204,12 @@ static struct roffmac roffs[ROFF_MAX] = {
{ NULL, roff_userdef, NULL, NULL, 0, NULL },
};
+/* Array of injected predefined strings. */
+#define PREDEFS_MAX 38
+static const struct predef predefs[PREDEFS_MAX] = {
+#include "predefs.in"
+};
+
static void roff_free1(struct roff *);
static enum rofft roff_hash_find(const char *, size_t);
static void roff_hash_init(void);
@@ -228,7 +243,6 @@ roff_hash_init(void)
}
}
-
/*
* Look up a roff token by its name. Returns ROFF_MAX if no macro by
* the nil-terminated string name could be found.
@@ -351,6 +365,7 @@ struct roff *
roff_alloc(struct regset *regs, struct mparse *parse)
{
struct roff *r;
+ int i;
r = mandoc_calloc(1, sizeof(struct roff));
r->regs = regs;
@@ -358,6 +373,10 @@ roff_alloc(struct regset *regs, struct mparse *parse)
r->rstackpos = -1;
roff_hash_init();
+
+ for (i = 0; i < PREDEFS_MAX; i++)
+ roff_setstr(r, predefs[i].name, predefs[i].str, 0);
+
return(r);
}