-/* $Id: argv.c,v 1.16 2009/01/17 20:10:36 kristaps Exp $ */
+/* $Id: argv.c,v 1.21 2009/01/20 13:49:36 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
#include "private.h"
+/*
+ * Parse arguments and parameters of macros. Arguments follow the
+ * syntax of `-arg [val [valN...]]', while parameters are free-form text
+ * following arguments (if any). This file must correctly handle the
+ * strange punctuation rules dictated by groff.
+ */
/* FIXME: .It called with -column and quoted arguments. */
if ( ! mdoc_iscdelim(buf[i]))
break;
i++;
- if (0 == buf[i] || ! isspace(buf[i]))
+ if (0 == buf[i] || ! isspace((int)buf[i]))
break;
i++;
- while (buf[i] && isspace(buf[i]))
+ while (buf[i] && isspace((int)buf[i]))
i++;
}
if (0 == buf[i]) {
/* Parse routine for non-quoted string. */
- if ('\"' != buf[*pos]) {
+ assert(*pos > 0);
+ if ('\"' != buf[*pos] || ! (ARGS_QUOTED & fl)) {
*v = &buf[*pos];
/* FIXME: UGLY tab-sep processing. */
}
(*pos)++;
}
- else
- while (buf[*pos] && ! isspace(buf[*pos]))
+ else {
+ while (buf[*pos]) {
+ if (isspace((int)buf[*pos]))
+ if ('\\' != buf[*pos - 1])
+ break;
(*pos)++;
+ }
+ }
if (0 == buf[*pos])
return(ARGS_WORD);
return(ARGS_WORD);
if ( ! (ARGS_TABSEP & fl))
- while (buf[*pos] && isspace(buf[*pos]))
+ while (buf[*pos] && isspace((int)buf[*pos]))
(*pos)++;
if (buf[*pos])
buf[(*pos)++] = 0;
if (0 == buf[*pos])
- return(ARGS_WORD);
+ return(ARGS_QWORD);
- while (buf[*pos] && isspace(buf[*pos]))
+ while (buf[*pos] && isspace((int)buf[*pos]))
(*pos)++;
if (buf[*pos])
- return(ARGS_WORD);
+ return(ARGS_QWORD);
if ( ! mdoc_pwarn(mdoc, line, *pos, WARN_COMPAT, "whitespace at end-of-line"))
return(ARGS_ERROR);
- return(ARGS_WORD);
+ return(ARGS_QWORD);
}
if (0 == buf[*pos])
return(ARGV_EOLN);
- assert( ! isspace(buf[*pos]));
+ assert( ! isspace((int)buf[*pos]));
if ('-' != buf[*pos])
return(ARGV_WORD);
v->line = line;
v->pos = *pos;
- while (buf[*pos] && ! isspace(buf[*pos]))
+ assert(*pos > 0);
+ while (buf[*pos]) {
+ if (isspace((int)buf[*pos]))
+ if ('\\' != buf[*pos - 1])
+ break;
(*pos)++;
+ }
if (buf[*pos])
buf[(*pos)++] = 0;
return(ARGV_WORD);
}
- while (buf[*pos] && isspace(buf[*pos]))
+ while (buf[*pos] && isspace((int)buf[*pos]))
(*pos)++;
/* FIXME: whitespace if no value. */