Import ezmlm-idx 0.40
[ezmlm] / constmap.c
index 722e3b8..8c742c2 100644 (file)
@@ -18,6 +18,39 @@ int len;
   return h;
 }
 
+/* Returns index of string in constmap. 1 = first string, 2 = second ... */
+/* 0 not found. Use for commands */ 
+int constmap_index(cm,s,len)
+struct constmap *cm;
+char *s;
+int len;
+{
+  constmap_hash h;
+  int pos;
+  h = hash(s,len);
+  pos = cm->first[h & cm->mask];
+  while (pos != -1) {
+    if (h == cm->hash[pos])
+      if (len == cm->inputlen[pos])
+        if (!case_diffb(cm->input[pos],len,s))
+         return pos + 1;
+    pos = cm->next[pos];
+  }
+  return 0;
+}
+
+/* returns pointer to sz of string with index "idx". 1 = first, 2 = second...*/
+char *constmap_get(cm,idx)
+struct constmap *cm;
+int idx;
+
+{
+  if (idx <= 0 || idx > cm->num)
+    return 0;
+  else
+    return cm->input[idx-1];
+}
+
 char *constmap(cm,s,len)
 struct constmap *cm;
 char *s;
@@ -38,6 +71,9 @@ int len;
 }
 
 int constmap_init(cm,s,len,flagcolon)
+/* if flagcolon is true, we process only the stuff before the colon on */
+/* each line. Otherwise, it's the entire line. Still, the entire line */
+/* is stored! */
 struct constmap *cm;
 char *s;
 int len;