aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2011-01-11 00:11:45 +0000
committerIngo Schwarze <schwarze@openbsd.org>2011-01-11 00:11:45 +0000
commit0fe0edf89487fb5d13d2cd07f35eecdb45e87af7 (patch)
tree872b070e0e504f46df83351f34d291e93c667416 /roff.c
parent8532b513ad046c8c7407add6f29b742c717bb60e (diff)
downloadmandoc-0fe0edf89487fb5d13d2cd07f35eecdb45e87af7.tar.gz
mandoc-0fe0edf89487fb5d13d2cd07f35eecdb45e87af7.tar.zst
mandoc-0fe0edf89487fb5d13d2cd07f35eecdb45e87af7.zip
Refactoring in preparation for .rm support:
Unify parsing of names given as roff request arguments into a new function roff_getname(), which is rather different from the parsing function for normal arguments, mandoc_getarg(), because names cannot be quoted and cannot contain whitespace or escaped characters. The new function now throws an ERROR when finding escaped characters in a name. "I'm fine with this." kristaps@
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c85
1 files changed, 46 insertions, 39 deletions
diff --git a/roff.c b/roff.c
index 5053bef5..56106228 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.120 2011/01/03 23:24:16 schwarze Exp $ */
+/* $Id: roff.c,v 1.121 2011/01/11 00:11:45 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -134,6 +134,7 @@ static enum rofferr roff_cond_sub(ROFF_ARGS);
static enum rofferr roff_ds(ROFF_ARGS);
static enum roffrule roff_evalcond(const char *, int *);
static void roff_freestr(struct roff *);
+static char *roff_getname(struct roff *, char **, int, int);
static const char *roff_getstrn(const struct roff *,
const char *, size_t);
static enum rofferr roff_line_ignore(ROFF_ARGS);
@@ -520,7 +521,7 @@ roff_endparse(struct roff *r)
{
if (r->last)
- (*r->msg)(MANDOCERR_SCOPEEXIT, r->data,
+ (*r->msg)(MANDOCERR_SCOPEEXIT, r->data,
r->last->line, r->last->col, NULL);
if (r->tbl) {
@@ -1056,25 +1057,13 @@ roff_ds(ROFF_ARGS)
* will have `bar " ' as its value.
*/
- name = *bufp + pos;
+ string = *bufp + pos;
+ name = roff_getname(r, &string, ln, pos);
if ('\0' == *name)
return(ROFF_IGN);
- string = name;
- /* Read until end of name. */
- while (*string && ' ' != *string)
- string++;
-
- /* Nil-terminate name. */
- if (*string)
- *(string++) = '\0';
-
- /* Read past spaces. */
- while (*string && ' ' == *string)
- string++;
-
- /* Read passed initial double-quote. */
- if (*string && '"' == *string)
+ /* Read past initial double-quote. */
+ if ('"' == *string)
string++;
/* The rest is the value. */
@@ -1087,31 +1076,14 @@ roff_ds(ROFF_ARGS)
static enum rofferr
roff_nr(ROFF_ARGS)
{
- const char *key, *val;
+ const char *key;
+ char *val;
struct reg *rg;
- key = &(*bufp)[pos];
+ val = *bufp + pos;
+ key = roff_getname(r, &val, ln, pos);
rg = r->regs->regs;
- /* Parse register request. */
- while ((*bufp)[pos] && ' ' != (*bufp)[pos])
- pos++;
-
- /*
- * Set our nil terminator. Because this line is going to be
- * ignored anyway, we can munge it as we please.
- */
- if ((*bufp)[pos])
- (*bufp)[pos++] = '\0';
-
- /* Skip whitespace to register token. */
- while ((*bufp)[pos] && ' ' == (*bufp)[pos])
- pos++;
-
- val = &(*bufp)[pos];
-
- /* Process register token. */
-
if (0 == strcmp(key, "nS")) {
rg[(int)REG_nS].set = 1;
if ( ! roff_parse_nat(val, &rg[(int)REG_nS].v.u))
@@ -1250,6 +1222,41 @@ roff_userdef(ROFF_ARGS)
ROFF_REPARSE : ROFF_APPEND);
}
+
+static char *
+roff_getname(struct roff *r, char **cpp, int ln, int pos)
+{
+ char *name, *cp;
+
+ name = *cpp;
+ if ('\0' == *name)
+ return(name);
+
+ /* Read until end of name. */
+ for (cp = name; '\0' != *cp && ' ' != *cp; cp++) {
+ if ('\\' != *cp)
+ continue;
+ cp++;
+ if ('\\' == *cp)
+ continue;
+ (*r->msg)(MANDOCERR_NAMESC, r->data, ln, pos, NULL);
+ *cp = '\0';
+ name = cp;
+ }
+
+ /* Nil-terminate name. */
+ if ('\0' != *cp)
+ *(cp++) = '\0';
+
+ /* Read past spaces. */
+ while (' ' == *cp)
+ cp++;
+
+ *cpp = cp;
+ return(name);
+}
+
+
/*
* Store *string into the user-defined string called *name.
* In multiline mode, append to an existing entry and append '\n';