aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_argv.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-03-17 00:58:14 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-03-17 00:58:14 +0000
commit5ac5955e47f16a7b4767aa4bd138b6ad73e53760 (patch)
tree452927b7f0893a25ae762b874cc3c382f0d73f55 /mdoc_argv.c
parent5f667cb96bf059ee563949cb5cbc804858bc8214 (diff)
downloadmandoc-5ac5955e47f16a7b4767aa4bd138b6ad73e53760.tar.gz
mandoc-5ac5955e47f16a7b4767aa4bd138b6ad73e53760.tar.zst
mandoc-5ac5955e47f16a7b4767aa4bd138b6ad73e53760.zip
Move check for closing punctuation into its own function. This will
later be modified to remove the need for iscdelim(), which will be used to unify delimiter checks, which will then allow for the simple removal of a TODO regarding escaped periods.
Diffstat (limited to 'mdoc_argv.c')
-rw-r--r--mdoc_argv.c67
1 files changed, 42 insertions, 25 deletions
diff --git a/mdoc_argv.c b/mdoc_argv.c
index b4b1745f..c404dae3 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_argv.c,v 1.63 2011/03/16 17:55:39 kristaps Exp $ */
+/* $Id: mdoc_argv.c,v 1.64 2011/03/17 00:58:14 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -48,6 +48,7 @@
static enum mdocargt argv_a2arg(enum mdoct, const char *);
static enum margserr args(struct mdoc *, int, int *,
char *, int, char **);
+static int args_checkpunct(const char *);
static int argv(struct mdoc *, int,
struct mdoc_argv *, int *, char *);
static int argv_single(struct mdoc *, int,
@@ -377,7 +378,6 @@ args(struct mdoc *m, int line, int *pos,
int i;
char *p, *pp;
enum margserr rc;
- enum mdelim d;
/*
* Parse out the terms (like `val' in `.Xx -arg val' or simply
@@ -419,33 +419,20 @@ args(struct mdoc *m, int line, int *pos,
* we ONLY care about closing delimiters.
*/
- if ((fl & ARGS_DELIM) && DELIM_CLOSE == mdoc_iscdelim(buf[*pos])) {
- for (i = *pos; buf[i]; ) {
- d = mdoc_iscdelim(buf[i]);
- if (DELIM_NONE == d || DELIM_OPEN == d)
- break;
- i++;
- if ('\0' == buf[i] || ' ' != buf[i])
- break;
- i++;
- while (buf[i] && ' ' == buf[i])
- i++;
- }
+ *v = &buf[*pos];
- if ('\0' == buf[i]) {
- *v = &buf[*pos];
- if (i && ' ' != buf[i - 1])
- return(ARGS_PUNCT);
- if (ARGS_NOWARN & fl)
- return(ARGS_PUNCT);
- if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE))
- return(ARGS_ERROR);
+ if (ARGS_DELIM & fl && args_checkpunct(&buf[*pos])) {
+ i = strlen(&buf[*pos]) + *pos;
+ if (i && ' ' != buf[i - 1])
return(ARGS_PUNCT);
- }
+ if (ARGS_NOWARN & fl)
+ return(ARGS_PUNCT);
+ /* FIXME: remove conditional messages... */
+ if ( ! mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE))
+ return(ARGS_ERROR);
+ return(ARGS_PUNCT);
}
- *v = &buf[*pos];
-
/*
* First handle TABSEP items, restricted to `Bl -column'. This
* ignores conventional token parsing and instead uses tabs or
@@ -583,6 +570,36 @@ args(struct mdoc *m, int line, int *pos,
return(ARGS_WORD);
}
+/*
+ * Check if the string consists only of space-separated closing
+ * delimiters.
+ */
+static int
+args_checkpunct(const char *p)
+{
+ int i;
+ enum mdelim d;
+
+ i = 0;
+
+ if (DELIM_CLOSE != mdoc_iscdelim(p[i]))
+ return(0);
+
+ while ('\0' != p[i]) {
+ d = mdoc_iscdelim(p[i]);
+ if (DELIM_NONE == d || DELIM_OPEN == d)
+ break;
+ i++;
+ if ('\0' == p[i] || ' ' != p[i])
+ break;
+ i++;
+ while (p[i] && ' ' == p[i])
+ i++;
+ }
+
+ return('\0' == p[i]);
+}
+
/*
* Match up an argument string (e.g., `-foo bar' having "foo") with the
* correrct identifier. It must apply to the given macro. If none was