diff sbr/smatch.c @ 0:bce86c4163a3

Initial revision
author kono
date Mon, 18 Apr 2005 23:46:02 +0900
parents
children 441a2190cfae
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbr/smatch.c	Mon Apr 18 23:46:02 2005 +0900
@@ -0,0 +1,47 @@
+/* smatch.c - match a switch */
+#ifndef	lint
+static char ident[] = "@(#)$Id$";
+#endif	/* lint */
+
+#include "../h/mh.h"
+
+#ifndef abs
+#define abs(i) (i < 0 ? -i : i)
+#endif
+
+smatch(string, swp)
+register char *string;
+register struct swit *swp;
+{
+    register char  *sp,
+                   *tcp;
+    struct swit *tp;
+    int     firstone,
+            stringlen;
+
+    firstone = UNKWNSW;
+
+    if (string == 0)
+	return firstone;
+
+    for (stringlen = strlen (string), tp = swp; tcp = tp -> sw; tp++) {
+	if (stringlen < abs (tp -> minchars))
+	    continue;		/* no match */
+	for (sp = string; *sp == *tcp++;) {
+	    if (*sp++ == 0)
+		return (tp - swp);/* exact match */
+	}
+	if (*sp != 0) {
+	    if (*sp != ' ')
+		continue;	/* no match */
+	    if (*--tcp == 0)
+		return (tp - swp);/* exact match */
+	}
+	if (firstone == UNKWNSW)
+	    firstone = tp - swp;
+	else
+	    firstone = AMBIGSW;
+    }
+
+    return (firstone);
+}