[Frugalware-darcs] setup: added data_get() and data_put(), updated skel.c

VMiklos vmiklos at frugalware.org
Thu Mar 30 00:48:15 CEST 2006


[added data_get() and data_put(), updated skel.c
VMiklos <vmiklos at frugalware.org>**20051103222938] {
hunk ./src/plugins/Makefile 18
-bar: bar.o
-	$(CC) $(CFLAGS) -shared -Wl,-soname,bar.so -o 50bar.so $< $(LDFLAGS)
+bar: bar.o ../util.o
+	$(CC) $(CFLAGS) -shared -Wl,-soname,bar.so -o 50bar.so \
+		bar.o ../util.o $(LDFLAGS)
hunk ./src/plugins/bar.c 6
+#include <util.h>
hunk ./src/plugins/bar.c 23
-	int i;
hunk ./src/plugins/skel.c 22
-	// sample: dump the config list
-	for (i=0; i<g_list_length(*config); i++)
-	{
-		data = g_list_nth_data((*config), i);
-		printf("detected conf data: %s (%s)\n", data->name, (char*)data->data);
-	}
+	// sample: gets the string titled "stuff" from the config list
+	printf("%s\n", (char*)data_get(*config, "stuff"));
hunk ./src/plugins/skel.c 26
-	data_t *data = data_new();
-	data->name = strdup("stuff");
-	data->data = strdup("content");
-	*config = g_list_append(*config, data);
+	data_put(config, "stuff", "content");
hunk ./src/util.c 50
+void *data_get(GList *config, char *title)
+{
+	int i;
+	data_t *data;
+	
+	for (i=0; i<g_list_length(config); i++)
+	{
+		data = g_list_nth_data(config, i);
+		if(!strcmp(title, data->name))
+			return data->data;
+	}
+	return(NULL);
+}
+
+void data_put(GList **config, char *name, void *data)
+{
+	data_t *dp = data_new();
+	dp->name = name;
+	dp->data = data;
+	(*config) = g_list_append((*config), dp);
+}
+
hunk ./src/util.h 10
+void *data_get(GList *config, char *title);
+void data_put(GList **config, char *name, void *data);
}


More information about the Frugalware-darcs mailing list