+/**
+ * Run a function on all file formats supporting a given mode.
+ */
+void a_babel_foreach_file_with_mode (BabelMode mode, GFunc func, gpointer user_data)
+{
+ GList *current;
+ for ( current = g_list_first (a_babel_file_list) ;
+ current != NULL ;
+ current = g_list_next (current) )
+ {
+ BabelFile *currentFile = current->data;
+ /* Check compatibility of modes */
+ gboolean compat = TRUE;
+ if (mode.waypointsRead && ! currentFile->mode.waypointsRead) compat = FALSE;
+ if (mode.waypointsWrite && ! currentFile->mode.waypointsWrite) compat = FALSE;
+ if (mode.tracksRead && ! currentFile->mode.tracksRead) compat = FALSE;
+ if (mode.tracksWrite && ! currentFile->mode.tracksWrite) compat = FALSE;
+ if (mode.routesRead && ! currentFile->mode.routesRead) compat = FALSE;
+ if (mode.routesWrite && ! currentFile->mode.routesWrite) compat = FALSE;
+ /* Do call */
+ if (compat)
+ func (currentFile, user_data);
+ }
+}
+
+/**
+ * a_babel_foreach_file_read_any:
+ * @func: The function to be called on any file format with a read method
+ * @user_data: Data passed into the function
+ *
+ * Run a function on all file formats with any kind of read method
+ * (which is almost all but not quite - e.g. with GPSBabel v1.4.4 - PalmDoc is write only waypoints)
+ */
+void a_babel_foreach_file_read_any (GFunc func, gpointer user_data)
+{
+ GList *current;
+ for ( current = g_list_first (a_babel_file_list) ;
+ current != NULL ;
+ current = g_list_next (current) )
+ {
+ BabelFile *currentFile = current->data;
+ // Call function when any read mode found
+ if ( currentFile->mode.waypointsRead ||
+ currentFile->mode.tracksRead ||
+ currentFile->mode.routesRead)
+ func (currentFile, user_data);
+ }
+}
+