7 #include <gconf/gconf-client.h>
13 struct units output_units;
15 #define GCONF_NAME(x) "/apps/subsurface/" #x
17 /* random helper functions, used here or elsewhere */
18 static int sortfn(const void *_a, const void *_b)
20 const struct dive *a = *(void **)_a;
21 const struct dive *b = *(void **)_b;
23 if (a->when < b->when)
25 if (a->when > b->when)
30 const char *weekday(int wday)
32 static const char wday_array[7][4] = {
33 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
35 return wday_array[wday];
38 const char *monthname(int mon)
40 static const char month_array[12][4] = {
41 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
42 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
44 return month_array[mon];
48 * This doesn't really report anything at all. We just sort the
49 * dives, the GUI does the reporting
51 void report_dives(void)
55 qsort(dive_table.dives, dive_table.nr, sizeof(struct dive *), sortfn);
57 for (i = 1; i < dive_table.nr; i++) {
58 struct dive **pp = &dive_table.dives[i-1];
59 struct dive *prev = pp[0];
60 struct dive *dive = pp[1];
63 if (prev->when + prev->duration.seconds < dive->when)
66 merged = try_to_merge(prev, dive);
74 memmove(pp+1, pp+2, sizeof(*pp)*(dive_table.nr - i));
76 /* Redo the new 'i'th dive */
81 static void parse_argument(const char *arg)
83 const char *p = arg+1;
91 fprintf(stderr, "Bad argument '%s'\n", arg);
97 void update_dive(struct dive *new_dive)
99 static struct dive *buffered_dive;
100 struct dive *old_dive = buffered_dive;
103 flush_dive_info_changes(old_dive);
104 flush_dive_equipment_changes(old_dive);
105 flush_divelist(old_dive);
108 show_dive_info(new_dive);
109 show_dive_equipment(new_dive);
111 buffered_dive = new_dive;
114 void renumber_dives(int nr)
118 for (i = 0; i < dive_table.nr; i++) {
119 struct dive *dive = dive_table.dives[i];
120 dive->number = nr + i;
124 int main(int argc, char **argv)
128 output_units = SI_units;
134 for (i = 1; i < argc; i++) {
135 const char *a = argv[i];
141 GError *error = NULL;
142 parse_xml_file(a, &error);
153 dive_list_update_dives();