int main(int argc, char **argv) { int i; output_units = SI_units; parse_xml_init(); init_ui(argc, argv); for (i = 1; i < argc; i++) { const char *a = argv[i]; if (a[0] == '-') { parse_argument(a); continue; } GError *error = NULL; parse_xml_file(a, &error); if (error != NULL) { report_error(error); g_error_free(error); error = NULL; } } report_dives(); dive_list_update_dives(); run_ui(); return 0; }
/* * This doesn't really report anything at all. We just sort the * dives, the GUI does the reporting */ void report_dives(gboolean imported) { int i; int preexisting = dive_table.preexisting; struct dive *last; /* This does the right thing for -1: NULL */ last = get_dive(preexisting-1); qsort(dive_table.dives, dive_table.nr, sizeof(struct dive *), sortfn); for (i = 1; i < dive_table.nr; i++) { struct dive **pp = &dive_table.dives[i-1]; struct dive *prev = pp[0]; struct dive *dive = pp[1]; struct dive *merged; if (prev->when + prev->duration.seconds < dive->when) continue; merged = try_to_merge(prev, dive); if (!merged) continue; free(prev); free(dive); *pp = merged; dive_table.nr--; memmove(pp+1, pp+2, sizeof(*pp)*(dive_table.nr - i)); /* Redo the new 'i'th dive */ i--; } if (imported) { /* Was the previous dive table state numbered? */ if (last && last->number) try_to_renumber(last, preexisting); /* did we have dives in the table and added more? */ if (last && preexisting != dive_table.nr) mark_divelist_changed(TRUE); } dive_table.preexisting = dive_table.nr; dive_list_update_dives(); }
/* * This doesn't really report anything at all. We just sort the * dives, the GUI does the reporting */ void report_dives(gboolean is_imported, gboolean prefer_imported) { int i; int preexisting = dive_table.preexisting; struct dive *last; /* check if we need a nickname for the divecomputer for newly downloaded dives; * since we know they all came from the same divecomputer we just check for the * first one */ if (preexisting < dive_table.nr && dive_table.dives[preexisting]->downloaded) set_dc_nickname(dive_table.dives[preexisting]); else /* they aren't downloaded, so record / check all new ones */ for (i = preexisting; i < dive_table.nr; i++) set_dc_nickname(dive_table.dives[i]); /* This does the right thing for -1: NULL */ last = get_dive(preexisting-1); sort_table(&dive_table); for (i = 1; i < dive_table.nr; i++) { struct dive **pp = &dive_table.dives[i-1]; struct dive *prev = pp[0]; struct dive *dive = pp[1]; struct dive *merged; /* only try to merge overlapping dives - or if one of the dives has * zero duration (that might be a gps marker from the webservice) */ if (prev->duration.seconds && dive->duration.seconds && prev->when + prev->duration.seconds < dive->when) continue; merged = try_to_merge(prev, dive, prefer_imported); if (!merged) continue; /* careful - we might free the dive that last points to. Oops... */ if (last == prev || last == dive) last = merged; /* Redo the new 'i'th dive */ i--; add_single_dive(i, merged); delete_single_dive(i+1); delete_single_dive(i+1); } /* make sure no dives are still marked as downloaded */ for (i = 1; i < dive_table.nr; i++) dive_table.dives[i]->downloaded = FALSE; if (is_imported) { /* If there are dives in the table, are they numbered */ if (!last || last->number) try_to_renumber(last, preexisting); /* did we add dives to the dive table? */ if (preexisting != dive_table.nr) mark_divelist_changed(TRUE); } dive_list_update_dives(); }