aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2010-07-03 16:02:12 +0000
committerIngo Schwarze <schwarze@openbsd.org>2010-07-03 16:02:12 +0000
commitd88ee3ac2243555d08d940053b987b819361b703 (patch)
tree1e3adc475acbd138f2199a5fcf04bfe7c3d70d10 /roff.c
parent6c211ca8c9060f52eb0d64f7735bd4d4d565d486 (diff)
downloadmandoc-d88ee3ac2243555d08d940053b987b819361b703.tar.gz
mandoc-d88ee3ac2243555d08d940053b987b819361b703.tar.zst
mandoc-d88ee3ac2243555d08d940053b987b819361b703.zip
Rudimentary implementation of user-defined strings;
no time for more refinement right now. In particular, fixes terminfo(3) and mdoc.samples(7). ok kristaps@, who will add the HTML frontend bits
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c117
1 files changed, 115 insertions, 2 deletions
diff --git a/roff.c b/roff.c
index 60aced8b..a644bc85 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.91 2010/06/27 16:36:22 kristaps Exp $ */
+/* $Id: roff.c,v 1.92 2010/07/03 16:02:12 schwarze Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -108,6 +108,12 @@ struct roffmac {
struct roffmac *next;
};
+struct roffstr {
+ char *name;
+ char *string;
+ struct roffstr *next;
+} *first_string;
+
static enum rofferr roff_block(ROFF_ARGS);
static enum rofferr roff_block_text(ROFF_ARGS);
static enum rofferr roff_block_sub(ROFF_ARGS);
@@ -116,6 +122,7 @@ static enum rofferr roff_ccond(ROFF_ARGS);
static enum rofferr roff_cond(ROFF_ARGS);
static enum rofferr roff_cond_text(ROFF_ARGS);
static enum rofferr roff_cond_sub(ROFF_ARGS);
+static enum rofferr roff_ds(ROFF_ARGS);
static enum rofferr roff_line(ROFF_ARGS);
static enum rofferr roff_nr(ROFF_ARGS);
static enum roffrule roff_evalcond(const char *, int *);
@@ -135,7 +142,7 @@ static struct roffmac roffs[ROFF_MAX] = {
{ "de", roff_block, roff_block_text, roff_block_sub, 0, NULL },
{ "dei", roff_block, roff_block_text, roff_block_sub, 0, NULL },
{ "de1", roff_block, roff_block_text, roff_block_sub, 0, NULL },
- { "ds", roff_line, NULL, NULL, 0, NULL },
+ { "ds", roff_ds, NULL, NULL, 0, NULL },
{ "el", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
{ "ie", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
{ "if", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
@@ -268,6 +275,7 @@ roff_free1(struct roff *r)
while (r->last)
roffnode_pop(r);
+ roff_freestr();
}
@@ -879,6 +887,39 @@ roff_cond(ROFF_ARGS)
/* ARGSUSED */
static enum rofferr
+roff_ds(ROFF_ARGS)
+{
+ char *name, *string, *end;
+
+ name = *bufp + pos;
+ if ('\0' == *name)
+ return(ROFF_IGN);
+
+ string = name;
+ while (*string && ' ' != *string)
+ string++;
+ if (*string)
+ *(string++) = NULL;
+ if (*string && '"' == *string)
+ string++;
+ while (*string && ' ' == *string)
+ string++;
+ end = string;
+ while (*end)
+ end++;
+ if (string < end) {
+ end--;
+ if (*end == '"')
+ *end = '\0';
+ }
+
+ roff_setstr(name, string);
+ return(ROFF_IGN);
+}
+
+
+/* ARGSUSED */
+static enum rofferr
roff_nr(ROFF_ARGS)
{
const char *key, *val;
@@ -918,3 +959,75 @@ roff_nr(ROFF_ARGS)
return(ROFF_IGN);
}
+
+
+char *
+roff_setstr(const char *name, const char *string)
+{
+ struct roffstr *n;
+ char *namecopy;
+
+ n = first_string;
+ while (n && strcmp(name, n->name))
+ n = n->next;
+ if (n) {
+ free(n->string);
+ } else {
+ if (NULL == (namecopy = strdup(name)))
+ return(NULL);
+ if (NULL == (n = malloc(sizeof(struct roffstr)))) {
+ free(n);
+ return(NULL);
+ }
+ n->name = namecopy;
+ n->next = first_string;
+ first_string = n;
+ }
+ if (string)
+ n->string = strdup(string);
+ else
+ n->string = NULL;
+ return(n->string);
+}
+
+char *
+roff_getstr(const char *name)
+{
+ struct roffstr *n;
+
+ n = first_string;
+ while (n && strcmp(name, n->name))
+ n = n->next;
+ if (n)
+ return(n->string);
+ else
+ return(NULL);
+}
+
+char *
+roff_getstrn(const char *name, size_t len)
+{
+ struct roffstr *n;
+
+ n = first_string;
+ while (n && (strncmp(name, n->name, len) || '\0' != n->name[len]))
+ n = n->next;
+ if (n)
+ return(n->string);
+ else
+ return(NULL);
+}
+
+void
+roff_freestr(void)
+{
+ struct roffstr *n, *nn;
+
+ for (n = first_string; n; n = nn) {
+ free(n->name);
+ free(n->string);
+ nn = n->next;
+ free(n);
+ }
+ first_string = NULL;
+}