trunk: changeset 37

Sun, 01 Apr 2001 01:43:46 +0200

author
tuomov
date
Sun, 01 Apr 2001 01:43:46 +0200
changeset 34
828f3afd5c76
parent 33
3a0064eb9421
child 35
5a71d53d0228

trunk: changeset 37
Added StringIntMap

Makefile file | annotate | diff | comparison | revisions
include/libtu/map.h file | annotate | diff | comparison | revisions
include/libtu/optparser.h file | annotate | diff | comparison | revisions
include/libtu/parser.h file | annotate | diff | comparison | revisions
map.c file | annotate | diff | comparison | revisions
--- a/Makefile	Wed Jan 10 19:15:19 2001 +0100
+++ b/Makefile	Sun Apr 01 01:43:46 2001 +0200
@@ -10,7 +10,7 @@
 INCLUDES += -I./include
 CFLAGS += $(POSIX_SOURCE)
 
-OBJS= misc.o output.o util.o optparser.o parser.o tokenizer.o
+OBJS= misc.o output.o util.o optparser.o parser.o tokenizer.o map.o
 
 ifdef LIBTU_NO_ERRMSG
 DEFINES += -DLIBTU_NO_ERRMSG
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libtu/map.h	Sun Apr 01 01:43:46 2001 +0200
@@ -0,0 +1,21 @@
+/*
+ * libtu/map.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2000. 
+ * See the included file LICENSE for details.
+ */
+
+#ifndef LIBTU_MAP_H
+#define LIBTU_MAP_H
+
+typedef struct _StringIntMap{
+	const char *string;
+	int value;
+} StringIntMap;
+
+#define END_STRINGINTMAP {NULL, 0}
+
+/* Return the index of str in map or -1 if not found. */
+extern int stringintmap_ndx(const StringIntMap *map, const char *str);
+					 
+#endif /* LIBTU_MAP_H */
--- a/include/libtu/optparser.h	Wed Jan 10 19:15:19 2001 +0100
+++ b/include/libtu/optparser.h	Sun Apr 01 01:43:46 2001 +0200
@@ -57,6 +57,7 @@
 	const char *about;
 } OptParserCommonInfo;
 
+#define END_OPTPARSEROPTS {0, NULL, 0, NULL, NULL}
 
 enum{
 	OPT_ID_END=0,
--- a/include/libtu/parser.h	Wed Jan 10 19:15:19 2001 +0100
+++ b/include/libtu/parser.h	Sun Apr 01 01:43:46 2001 +0200
@@ -35,6 +35,7 @@
 	struct _ConfOpt *opts;
 } ConfOpt;
 
+#define END_CONFOPTS {NULL, NULL, NULL, NULL}
 
 extern bool parse_config_tokz(Tokenizer *tokz, const ConfOpt *options);
 extern bool parse_config(const char *fname, const ConfOpt *options, int flags);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/map.c	Sun Apr 01 01:43:46 2001 +0200
@@ -0,0 +1,23 @@
+/*
+ * libtu/map.c
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2000. 
+ * See the included file LICENSE for details.
+ */
+
+#include <string.h>
+#include <libtu/map.h>
+
+
+int stringintmap_ndx(const StringIntMap *map, const char *str)
+{
+    int i;
+	
+	for(i=0; map[i].string!=NULL; i++){
+		if(strcmp(str, map[i].string)==0)
+			return i;
+	}
+	
+	return -1;
+}
+

mercurial