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 */
80 dive_list_update_dives();
83 static void parse_argument(const char *arg)
85 const char *p = arg+1;
93 fprintf(stderr, "Bad argument '%s'\n", arg);
99 void update_dive(struct dive *new_dive)
101 static struct dive *buffered_dive;
102 struct dive *old_dive = buffered_dive;
105 flush_dive_info_changes(old_dive);
106 flush_dive_equipment_changes(old_dive);
107 flush_divelist(old_dive);
110 show_dive_info(new_dive);
111 show_dive_equipment(new_dive);
113 buffered_dive = new_dive;
116 void renumber_dives(int nr)
120 for (i = 0; i < dive_table.nr; i++) {
121 struct dive *dive = dive_table.dives[i];
122 dive->number = nr + i;
126 int main(int argc, char **argv)
130 output_units = SI_units;
136 for (i = 1; i < argc; i++) {
137 const char *a = argv[i];
143 GError *error = NULL;
144 parse_xml_file(a, &error);