diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-07-20 14:09:38 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-07-20 14:09:38 +0000 |
commit | 4a384ead2acef7f2ea8e57f9ee5b8b62b6852181 (patch) | |
tree | 4af3563de4af72bd91d23e3a9b559e00802a5b2b | |
parent | 25c8e13d6e0d017e8ba2fd629708177777d04760 (diff) | |
download | mandoc-4a384ead2acef7f2ea8e57f9ee5b8b62b6852181.tar.gz |
Replaced ugly TABSEP handling with simpler routine.
-rw-r--r-- | libmdoc.h | 1 | ||||
-rw-r--r-- | mdoc.c | 1 | ||||
-rw-r--r-- | mdoc_argv.c | 77 |
3 files changed, 29 insertions, 50 deletions
@@ -43,7 +43,6 @@ struct mdoc { enum merr { ETAILWS = 0, - ECOLEMPTY, EQUOTPARM, EQUOTTERM, EMALLOC, @@ -25,7 +25,6 @@ const char *const __mdoc_merrnames[MERRMAX] = { "trailing whitespace", /* ETAILWS */ - "empty last list column", /* ECOLEMPTY */ "unexpected quoted parameter", /* EQUOTPARM */ "unterminated quoted parameter", /* EQUOTTERM */ "system: malloc error", /* EMALLOC */ diff --git a/mdoc_argv.c b/mdoc_argv.c index 5b27f5bf..8a3b46c1 100644 --- a/mdoc_argv.c +++ b/mdoc_argv.c @@ -376,7 +376,7 @@ static int args(struct mdoc *m, int line, int *pos, char *buf, int fl, char **v) { - int i; + int i, psv; char *p, *pp; assert(*pos); @@ -421,7 +421,9 @@ args(struct mdoc *m, int line, int *pos, */ if (ARGS_TABSEP & fl) { - /* Scan ahead to unescaped tab. */ + psv = *pos; + + /* Scan ahead to tab (can't be escaped). */ p = strchr(*v, '\t'); /* Scan ahead to unescaped `Ta'. */ @@ -434,59 +436,38 @@ args(struct mdoc *m, int line, int *pos, break; } - /* Choose delimiter tab/Ta. */ - if (p && pp) - p = (p < pp ? p : pp); - else if ( ! p && pp) + if (p && pp) { + *pos += pp < p ? 2 : 1; + p = pp < p ? pp : p; + } else if (p && ! pp) { + *pos += 1; + } else if (pp && ! p) { p = pp; + *pos += 2; + } else + p = strchr(*v, 0); - /* Strip delimiter's preceding whitespace. */ - /* FIXME: escaped whitespace? */ - if (p && p > *v) { - pp = p - 1; - while (pp > *v && ' ' == *pp) - pp--; - if (pp == *v && ' ' == *pp) - *pp = 0; - else if (' ' == *pp) - *(pp + 1) = 0; - } - - /* ...in- and proceding whitespace. */ - if (p && ('\t' != *p)) { - *p++ = 0; - *p++ = 0; - } else if (p) - *p++ = 0; - - if (p) { - while (' ' == *p) - p++; - if (0 != *p) - *(p - 1) = 0; - *pos += (int)(p - *v); - } - - /* Some warnings, if applicable. */ - if (p && 0 == *p) - if ( ! mdoc_pwarn(m, line, *pos, ECOLEMPTY)) - return(ARGS_ERROR); - if (p && 0 == *p && p > *v && ' ' == *(p - 1)) + if (0 == *p && ' ' == *(p - 1)) if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(ARGS_ERROR); - /* Non-eoln case returns now. */ - if (p) - return(ARGS_PHRASE); + *p = 0; + *pos += (int)(p - *v); + + /* Strip delimiter's preceding whitespace. */ - /* Configure the eoln case, too. */ - p = strchr(*v, 0); - assert(p); + pp = p - 1; + while (pp > *v && ' ' == *pp) { + if (pp > *v && '\\' == *(pp - 1)) + break; + pp--; + } + *(pp + 1) = 0; - if (p > *v && ' ' == *(p - 1)) - if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) - return(ARGS_ERROR); - *pos += (int)(p - *v); + /* Strip delimiter's proceeding whitespace. */ + + for (pp = &buf[*pos]; ' ' == *pp; pp++, (*pos)++) + /* Skip ahead. */ ; return(ARGS_PHRASE); } |