diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-08-09 17:13:01 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-08-09 17:13:01 +0000 |
commit | 87048fd6b09d015939a4406bda591118a91dc017 (patch) | |
tree | be67024f33cb2b9d761d76fe3766b16f62fe6e13 /usr.bin | |
parent | e46cdd25bbf0fc4e16f486c6e642a1265e16535f (diff) |
sync to 1.8.2: fix and cleanup .Bl -column phrase handling
by using the normal argument parsing from mdoc_argv.c
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/mdoc_macro.c | 86 |
1 files changed, 26 insertions, 60 deletions
diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c index dca9159dc5d..03ccd6b12eb 100644 --- a/usr.bin/mandoc/mdoc_macro.c +++ b/usr.bin/mandoc/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.16 2009/08/09 17:02:46 schwarze Exp $ */ +/* $Id: mdoc_macro.c,v 1.17 2009/08/09 17:13:00 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -1385,78 +1385,44 @@ obsolete(MACRO_PROT_ARGS) } +/* + * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs. + * They're unusual because they're basically free-form text until a + * macro is encountered. + */ static int phrase(struct mdoc *mdoc, int line, int ppos, char *buf) { - int i, la, c, quoted; - - /* - * Parse over words in a phrase. We have to handle this - * specially because we assume no calling context -- in normal - * circumstances, we switch argument parsing based on whether - * the parent macro accepts quotes, tabs, etc. Here, anything - * goes. - */ - - for (i = ppos; buf[i]; ) { - assert(' ' != buf[i]); - la = i; - quoted = 0; + int c, w, la, pos; + char *p; - /* - * Read to next token. If quoted (check not escaped), - * scan ahead to next unescaped quote. If not quoted or - * escape-quoted, then scan ahead to next space. - */ + for (pos = ppos; ; ) { + la = pos; - if ((i && '\"' == buf[i] && '\\' != buf[i - 1]) || - (0 == i && '\"' == buf[i])) { - for (la = ++i; buf[i]; i++) - if ('\"' != buf[i]) - continue; - else if ('\\' != buf[i - 1]) - break; - if (0 == buf[i]) - return(mdoc_perr(mdoc, line, la, EQUOTPHR)); - quoted = 1; - } else - for ( ; buf[i]; i++) - if (i && ' ' == buf[i]) { - if ('\\' != buf[i - 1]) - break; - } else if (' ' == buf[i]) - break; - - /* If not end-of-line, terminate argument. */ - - if (buf[i]) - buf[i++] = 0; - - /* Read to next argument. */ - - for ( ; buf[i] && ' ' == buf[i]; i++) - /* Spin. */ ; + /* Note: no calling context! */ + w = mdoc_zargs(mdoc, line, &pos, buf, &p); - /* - * If we're a non-quoted string, try to look up the - * value as a macro and execute it, if found. - */ + if (ARGS_ERROR == w) + return(0); + if (ARGS_EOLN == w) + break; - c = quoted ? MDOC_MAX : - mdoc_hash_find(mdoc->htab, &buf[la]); + c = ARGS_QWORD == w ? MDOC_MAX : + mdoc_hash_find(mdoc->htab, p); - if (MDOC_MAX != c) { - if ( ! mdoc_macro(mdoc, c, line, la, &i, buf)) + if (MDOC_MAX != c && -1 != c) { + if ( ! mdoc_macro(mdoc, c, line, la, &pos, buf)) return(0); - return(append_delims(mdoc, line, &i, buf)); - } - - /* A regular word or quoted string. */ + return(append_delims(mdoc, line, &pos, buf)); + } else if (-1 == c) + return(0); - if ( ! mdoc_word_alloc(mdoc, line, la, &buf[la])) + if ( ! mdoc_word_alloc(mdoc, line, la, p)) return(0); mdoc->next = MDOC_NEXT_SIBLING; } return(1); } + + |