summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.h10
-rw-r--r--divelist.c2
-rw-r--r--info.c2
-rw-r--r--statistics.c2
4 files changed, 13 insertions, 3 deletions
diff --git a/dive.h b/dive.h
index 7ceab643a..ab854e37e 100644
--- a/dive.h
+++ b/dive.h
@@ -295,6 +295,16 @@ static inline struct dive *get_dive(unsigned int nr)
return dive_table.dives[nr];
}
+/*
+ * Iterate over each dive, with the first parameter being the index
+ * iterator variable, and the second one being the dive one.
+ *
+ * I don't think anybody really wants the index, and we could make
+ * it local to the for-loop, but that would make us requires C99.
+ */
+#define for_each_dive(_i,_x) \
+ for ((_i) = 0; ((_x) = get_dive(_i)) != NULL; (_i)++)
+
extern void parse_xml_init(void);
extern void parse_xml_buffer(const char *url, const char *buf, int size, GError **error);
extern void set_filename(const char *filename);
diff --git a/divelist.c b/divelist.c
index 3fd53ffa5..30bd2d8e9 100644
--- a/divelist.c
+++ b/divelist.c
@@ -85,7 +85,7 @@ void dump_selection(void)
struct dive *dive;
printf("currently selected are %d dives:", amount_selected);
- for (i = 0; (dive = get_dive(i)) != NULL; i++) {
+ for_each_dive(i, dive) {
if (dive->selected)
printf(" %d", i);
}
diff --git a/info.c b/info.c
index 242e4b24d..8db606344 100644
--- a/info.c
+++ b/info.c
@@ -519,7 +519,7 @@ int edit_multi_dive_info(struct dive *single_dive)
int i;
struct dive *dive;
- for (i = 0; (dive = get_dive(i)) != NULL; i++) {
+ for_each_dive(i, dive) {
if (dive == master || !dive->selected)
continue;
/* copy all "info" fields */
diff --git a/statistics.c b/statistics.c
index 0a23f9022..b9d2c3b95 100644
--- a/statistics.c
+++ b/statistics.c
@@ -151,7 +151,7 @@ void process_selected_dives(void)
memset(&stats_selection, 0, sizeof(stats_selection));
nr = 0;
- for (i = 0; (dive = get_dive(i)) != NULL; ++i) {
+ for_each_dive(i, dive) {
if (dive->selected) {
process_dive(dive, &stats_selection);
nr++;