summaryrefslogtreecommitdiffstats
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
commitbb8eca89831f88bbc271b59fb94e94b2db26ee1e (patch)
treea89a66e8a581c86f4a5ddb4614cdc8fe37f318a7 /roff.c
parent63533c987d5ade538a926058188d4d64518a36f5 (diff)
downloadmandoc-bb8eca89831f88bbc271b59fb94e94b2db26ee1e.tar.gz
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.c115
1 files changed, 114 insertions, 1 deletions
diff --git a/roff.c b/roff.c
index 9d2294c6..c3016d8c 100644
--- a/roff.c
+++ b/roff.c
@@ -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;
+}