summaryrefslogtreecommitdiffstats
path: root/core/structured_list.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-05-30 18:29:36 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-06-19 13:11:10 -0700
commit6200909ba4ffba2d79770b7eacdb615eeb2c88c1 (patch)
treea5c63427daf5a3d73f179d5c63177edffe03c2e4 /core/structured_list.h
parent46c69fccb79911b4ef1bc12606f39b072cbf19d3 (diff)
downloadsubsurface-6200909ba4ffba2d79770b7eacdb615eeb2c88c1.tar.gz
Cleanup: move tag functions into own translation unit
Make dive.h a bit slimmer. It's only a drop in the bucket - but at least when modifying tag functions not the *whole* application is rebuilt anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/structured_list.h')
-rw-r--r--core/structured_list.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/structured_list.h b/core/structured_list.h
new file mode 100644
index 000000000..232e4ee34
--- /dev/null
+++ b/core/structured_list.h
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef STRUCTURED_LIST_H
+#define STRUCTURED_LIST_H
+
+/* Clear everything but the first element;
+ * this works for taglist, picturelist, even dive computers */
+#define STRUCTURED_LIST_FREE(_type, _start, _free) \
+ { \
+ _type *_ptr = _start; \
+ while (_ptr) { \
+ _type *_next = _ptr->next; \
+ _free(_ptr); \
+ _ptr = _next; \
+ } \
+ }
+
+#define STRUCTURED_LIST_COPY(_type, _first, _dest, _cpy) \
+ { \
+ _type *_sptr = _first; \
+ _type **_dptr = &_dest; \
+ while (_sptr) { \
+ *_dptr = malloc(sizeof(_type)); \
+ _cpy(_sptr, *_dptr); \
+ _sptr = _sptr->next; \
+ _dptr = &(*_dptr)->next; \
+ } \
+ *_dptr = 0; \
+ }
+
+#endif