From: Linus Torvalds Date: Wed, 31 Aug 2011 23:33:20 +0000 (-0700) Subject: Start cleaning up dive accessors X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=00d798854aa2594b819f50dc135efca96a93adb9;p=ext%2Fsubsurface.git Start cleaning up dive accessors I'm going to add a menu to import (and eventually export) dives, and so we'd like to be able to start out with no dives at all. Right now we croak if that happens - it's not like the code has been written with actual end users in mind. So start cleaning things up. First make the 'current_dive' macro work right even for invalid dives. Signed-off-by: Linus Torvalds --- diff --git a/display.h b/display.h index b9de932..8f972e3 100644 --- a/display.h +++ b/display.h @@ -6,12 +6,12 @@ #include extern int selected_dive; +#define current_dive (get_dive(selected_dive)) + extern GtkWidget *dive_profile_frame(void); extern GtkWidget *dive_info_frame(void); extern GtkWidget *create_dive_list(void); extern void update_dive_info(struct dive *dive); extern void repaint_dive(void); -#define current_dive (dive_table.dives[selected_dive]) - #endif diff --git a/dive.h b/dive.h index a8e3c31..23e2f54 100644 --- a/dive.h +++ b/dive.h @@ -121,6 +121,13 @@ struct dive_table { extern struct dive_table dive_table; +static inline struct dive *get_dive(unsigned int nr) +{ + if (nr >= dive_table.nr) + return NULL; + return dive_table.dives[nr]; +} + extern void parse_xml_init(void); extern void parse_xml_file(const char *filename);