source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Move check for closing punctuation into its own function.
@ 2011-03-17  0:58 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-03-17  0:58 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mdocml:
        mdoc_argv.c

Revision Data
-------------
Index: mdoc_argv.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_argv.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -Lmdoc_argv.c -Lmdoc_argv.c -u -p -r1.63 -r1.64
--- mdoc_argv.c
+++ mdoc_argv.c
@@ -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
@@ -581,6 +568,36 @@ args(struct mdoc *m, int line, int *pos,
 			return(ARGS_ERROR);
 
 	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]);
 }
 
 /*
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-03-17  0:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-17  0:58 mdocml: Move check for closing punctuation into its own function kristaps

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).