source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Use proper infix expressions and provide a default.
@ 2011-11-09 23:31 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-11-09 23:31 UTC (permalink / raw)
  To: source

Log Message:
-----------
Use proper infix expressions and provide a default.  (Exact match.)

Modified Files:
--------------
    mdocml:
        db.c

Revision Data
-------------
Index: db.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/db.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Ldb.c -Ldb.c -u -p -r1.2 -r1.3
--- db.c
+++ db.c
@@ -462,30 +462,43 @@ exprcomp(int cs, char *argv[], int argc)
 {
 	struct expr	*p;
 	struct expr	 e;
-	int		 i, ch;
+	int		 i, pos, ch;
 
-	if (3 != argc)
+	pos = 0;
+
+	if (pos > argc)
+		return(NULL);
+
+	for (i = 0; 0 != types[i].mask; i++)
+		if (0 == strcmp(types[i].name, argv[pos]))
+			break;
+
+	if (0 == (e.mask = types[i].mask))
 		return(NULL);
 
-	if (0 == strcmp("-eq", argv[0]))
+	if (++pos > argc--)
+		return(NULL);
+
+	if ('-' != *argv[pos]) 
+		e.match = cs ? MATCH_STRCASE : MATCH_STR;
+	else if (0 == strcmp("-eq", argv[pos]))
 		e.match = cs ? MATCH_STRCASE : MATCH_STR;
-	else if (0 == strcmp("-ieq", argv[0]))
+	else if (0 == strcmp("-ieq", argv[pos]))
 		e.match = MATCH_STRCASE;
-	else if (0 == strcmp("-re", argv[0]))
+	else if (0 == strcmp("-re", argv[pos]))
 		e.match = cs ? MATCH_REGEXCASE : MATCH_REGEX;
-	else if (0 == strcmp("-ire", argv[0]))
+	else if (0 == strcmp("-ire", argv[pos]))
 		e.match = MATCH_REGEXCASE;
 	else
 		return(NULL);
 
-	for (i = 0; 0 != types[i].mask; i++)
-		if (0 == strcmp(types[i].name, argv[1]))
-			break;
+	if ('-' == *argv[pos])
+		pos++;
 
-	if (0 == (e.mask = types[i].mask))
+	if (pos > argc--)
 		return(NULL);
 
-	e.v = mandoc_strdup(argv[2]);
+	e.v = mandoc_strdup(argv[pos]);
 
 	if (MATCH_REGEX == e.match || MATCH_REGEXCASE == e.match) {
 		ch = REG_EXTENDED | REG_NOSUB;
--
 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-11-09 23:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-09 23:31 mdocml: Use proper infix expressions and provide a default 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).