From 4a384ead2acef7f2ea8e57f9ee5b8b62b6852181 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Mon, 20 Jul 2009 14:09:38 +0000 Subject: Replaced ugly TABSEP handling with simpler routine. --- libmdoc.h | 1 - mdoc.c | 1 - mdoc_argv.c | 77 +++++++++++++++++++++++-------------------------------------- 3 files changed, 29 insertions(+), 50 deletions(-) diff --git a/libmdoc.h b/libmdoc.h index 2a261733..a830ff0b 100644 --- a/libmdoc.h +++ b/libmdoc.h @@ -43,7 +43,6 @@ struct mdoc { enum merr { ETAILWS = 0, - ECOLEMPTY, EQUOTPARM, EQUOTTERM, EMALLOC, diff --git a/mdoc.c b/mdoc.c index dccc52d7..39e494b1 100644 --- a/mdoc.c +++ b/mdoc.c @@ -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); } -- cgit