* mdocml: Refactoring in preparation for .rm support: Unify parsing of
@ 2011-01-11 0:11 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2011-01-11 0:11 UTC (permalink / raw)
To: source
Log Message:
-----------
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@
Modified Files:
--------------
mdocml:
main.c
mandoc.h
roff.c
Revision Data
-------------
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.51
retrieving revision 1.52
diff -Lmandoc.h -Lmandoc.h -u -p -r1.51 -r1.52
--- mandoc.h
+++ mandoc.h
@@ -114,6 +114,7 @@ enum mandocerr {
MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */
MANDOCERR_BADCHAR, /* skipping bad character */
+ MANDOCERR_NAMESC, /* escaped character not allowed in a name */
MANDOCERR_NOTEXT, /* skipping text before the first section header */
MANDOCERR_MACRO, /* skipping unknown macro */
MANDOCERR_REQUEST, /* NOT IMPLEMENTED: skipping request */
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.120
retrieving revision 1.121
diff -Lroff.c -Lroff.c -u -p -r1.120 -r1.121
--- roff.c
+++ roff.c
@@ -134,6 +134,7 @@ static enum rofferr roff_cond_sub(ROFF_
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))
@@ -1249,6 +1221,41 @@ roff_userdef(ROFF_ARGS)
return(*szp > 1 && '\n' == (*bufp)[(int)*szp - 2] ?
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.
Index: main.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v
retrieving revision 1.136
retrieving revision 1.137
diff -Lmain.c -Lmain.c -u -p -r1.136 -r1.137
--- main.c
+++ main.c
@@ -192,6 +192,7 @@ static const char * const mandocerrs[MAN
"input stack limit exceeded, infinite loop?",
"skipping bad character",
+ "escaped character not allowed in a name",
"skipping text before the first section header",
"skipping unknown macro",
"NOT IMPLEMENTED: skipping request",
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-01-11 0:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-11 0:11 mdocml: Refactoring in preparation for .rm support: Unify parsing of schwarze
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).