Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=af3459b262684384dda837443b142a1c3d3f9a89

commit af3459b262684384dda837443b142a1c3d3f9a89
Author: Michel Hermier <[email protected]>
Date:   Mon May 13 12:57:50 2013 +0200

libflib: Add FListAccumulator.

diff --git a/lib/libflib/Makefile.am b/lib/libflib/Makefile.am
index ef9546c..5b15a9f 100644
--- a/lib/libflib/Makefile.am
+++ b/lib/libflib/Makefile.am
@@ -12,6 +12,7 @@ noinst_LTLIBRARIES = libflib.la

libflib_la_SOURCES = \
flist.c \
+       flistaccumulator.c \
fobject.c \
fstdlib.c \
fstring.c \
diff --git a/lib/libflib/flistaccumulator.c b/lib/libflib/flistaccumulator.c
new file mode 100644
index 0000000..8516466
--- /dev/null
+++ b/lib/libflib/flistaccumulator.c
@@ -0,0 +1,71 @@
+/*
+ *  flistaccumulator.c
+ *
+ *  Copyright (c) 2013 by Michel Hermier <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+
+#include "config.h"
+
+#include <assert.h>
+
+#include "flistaccumulator.h"
+
+#include "flist.h"
+
+void f_listaccumulator_init (FListAccumulator *listaccumulator) {
+       listaccumulator->head = listaccumulator->last = NULL;
+}
+
+FList *f_listaccumulator_fini (FListAccumulator *listaccumulator) {
+       FList *ret = listaccumulator->head;
+
+       f_listaccumulator_init (listaccumulator);
+       return ret;
+}
+
+void f_listaccumulator_accumulate (FListAccumulator *listaccumulator, void 
*data) {
+       f_listaccumulator (data, listaccumulator);
+}
+
+void f_listaccumulator_reverse_accumulate (FListAccumulator *listaccumulator, 
void *data) {
+       f_listreverseaccumulator (data, listaccumulator);
+}
+
+void f_listaccumulator (void *data, FListAccumulator *listaccumulator) {
+       FList *item = f_list_alloc (data);
+
+       if (listaccumulator->head != NULL) {
+               f_list_insert_after (listaccumulator->last, item);
+               listaccumulator->last = listaccumulator->last->next;
+       } else {
+               listaccumulator->head = listaccumulator->last = item;
+       }
+}
+
+void f_listreverseaccumulator (void *data, FListAccumulator *listaccumulator) {
+       FList *item = f_list_alloc (data);
+
+       if (listaccumulator->head != NULL) {
+               f_list_insert_before (listaccumulator->head, item);
+               listaccumulator->head = listaccumulator->head->prev;
+       } else {
+               listaccumulator->head = listaccumulator->last = item;
+       }
+}
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libflib/flistaccumulator.h b/lib/libflib/flistaccumulator.h
new file mode 100644
index 0000000..6b3e4a2
--- /dev/null
+++ b/lib/libflib/flistaccumulator.h
@@ -0,0 +1,45 @@
+/*
+ *  flistaccumulator.h
+ *
+ *  Copyright (c) 2013 by Michel Hermier <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+
+#ifndef F_LISTACCUMULATOR_H
+#define F_LISTACCUMULATOR_H
+
+#include "flist.h"
+
+typedef struct FListAccumulator FListAccumulator;
+
+struct FListAccumulator {
+       FList *head;
+       FList *last;
+};
+
+void f_listaccumulator_init (FListAccumulator *listaccumulator);
+FList *f_listaccumulator_fini (FListAccumulator *listaccumulator);
+
+void f_listaccumulator_accumulate (FListAccumulator *listaccumulator, void 
*data);
+void f_listaccumulator_reverse_accumulate (FListAccumulator *listaccumulator, 
void *data);
+
+void f_listaccumulator (void *data, FListAccumulator *listaccumulator);
+void f_listreverseaccumulator (void *data, FListAccumulator *listaccumulator);
+
+#endif /* F_LISTACCUMULATOR_H */
+
+/* vim: set ts=2 sw=2 noet: */
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to