-/* $Id: mdoc_argv.c,v 1.18 2009/07/18 18:59:33 kristaps Exp $ */
+/* $Id: mdoc_argv.c,v 1.21 2009/07/20 14:12:27 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
}
+int
+mdoc_zargs(struct mdoc *m, int line, int *pos, char *buf, char **v)
+{
+
+ return(args(m, line, pos, buf, 0, v));
+}
+
+
int
mdoc_args(struct mdoc *m, int line,
int *pos, char *buf, int tok, char **v)
*/
if (ARGS_TABSEP & fl) {
- /* Scan ahead to unescaped tab. */
+ /* Scan ahead to tab (can't be escaped). */
p = strchr(*v, '\t');
/* Scan ahead to unescaped `Ta'. */
break;
}
- /* Choose delimiter tab/Ta. */
- if (p && pp)
- p = (p < pp ? p : pp);
- else if ( ! p && pp)
+ /*
+ * Adjust new-buffer position to be beyond delimiter
+ * mark (e.g., Ta -> end + 2).
+ */
+ 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))
+ /* Whitespace check for eoln case... */
+ 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);
+ *pos += (int)(p - *v);
- /* Configure the eoln case, too. */
- p = strchr(*v, 0);
- assert(p);
+ /* Strip delimiter's preceding whitespace. */
+ 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);
}