Hi, Thanks for trying to solve this bug.
I prefer to avoid, as far as possible, any detection based over filename extension: this is not really UNIX-friendly. As far as I know, the matter concern the BOM, ie some extra bytes added at the begining of the XML file. So, a probably easy way to solve the matter is to add a "tolerance" in the search process. For example, try to locate the MAGIC at the begining, or somewhere ignoring the 2~3 first characters. An other more evolved solution can be to use a mime-type framework. Glib/Gtk/Gnome certainly has one. 2009/5/3 Tal <tal....@gmail.com>: > Hi, > > I hope the following is a reasonable solution for bug 2163652 (GPX > file with byte order mark not parsed). > It simply treats files with ".gpx" extention as gpx files. All other > files, including gpx files without gpx extentions, receive the same > treatment as before. > > > > >From 618510b95c77a6026173b4e6e19196b17ec986dd Mon Sep 17 00:00:00 2001 > From: Tal B <tal....@gmail.com> > Date: Sun, 3 May 2009 19:32:35 +0300 > Subject: [PATCH] viking bug 2163652 gpx with bom > when loading a file, first check for gpx extention. if no gpx file > extention, follow the previous method of magic numbers. > > --- > src/file.c | 23 +++++++++++++++++++++-- > src/file.h | 1 + > 2 files changed, 22 insertions(+), 2 deletions(-) > > diff --git a/src/file.c b/src/file.c > index 9978f81..2075de9 100644 > --- a/src/file.c > +++ b/src/file.c > @@ -564,6 +564,7 @@ static void xfclose ( FILE *f ) > /* 0 on failure, 1 on success (vik file) 2 on success (other file) */ > gshort a_file_load ( VikAggregateLayer *top, VikViewport *vp, const gchar > *filename ) > { > + gboolean is_gpx_file = check_file_ext ( filename, ".gpx" ); > FILE *f = xfopen ( filename, "r" ); > > g_assert ( vp ); > @@ -571,7 +572,7 @@ gshort a_file_load ( VikAggregateLayer *top, > VikViewport *vp, const gchar *filen > if ( ! f ) > return 0; > > - if ( check_magic ( f, VIK_MAGIC ) ) > + if ( !is_gpx_file && check_magic ( f, VIK_MAGIC ) ) > { > file_read ( top, f, vp ); > if ( f != stdin ) > @@ -584,7 +585,7 @@ gshort a_file_load ( VikAggregateLayer *top, > VikViewport *vp, const gchar *filen > VikLayer *vtl = vik_layer_create ( VIK_LAYER_TRW, vp, NULL, FALSE ); > vik_layer_rename ( vtl, a_file_basename ( filename ) ); > > - if ( check_magic ( f, GPX_MAGIC ) ) > + if ( is_gpx_file || check_magic ( f, GPX_MAGIC ) ) > a_gpx_read_file ( VIK_TRW_LAYER(vtl), f ); > else > a_gpspoint_read_file ( VIK_TRW_LAYER(vtl), f ); > @@ -627,6 +628,24 @@ const gchar *a_file_basename ( const gchar *filename > ) > return filename; > } > > +/* example: > + gboolean is_gpx = check_file_ext ( "a/b/c.gpx", ".gpx" ); > +*/ > +gboolean check_file_ext ( const gchar *filename, const gchar *fileext ) > +{ > + const gchar *basename = a_file_basename(filename); > + g_assert( filename ); > + g_assert( fileext && fileext[0]=='.' ); > + if (!basename) > + return FALSE; > + > + const char * dot = strrchr(basename, '.'); > + if (dot && !strcmp(dot, fileext)) > + return TRUE; > + > + return FALSE; > +} > + > gboolean a_file_export ( VikTrwLayer *vtl, const gchar *filename, gshort > file_type ) > { > FILE *f = g_fopen ( filename, "w" ); > diff --git a/src/file.h b/src/file.h > index 5c06c4a..bbaf230 100644 > --- a/src/file.h > +++ b/src/file.h > @@ -33,6 +33,7 @@ > #define FILE_TYPE_GPX 3 > > const gchar *a_file_basename ( const gchar *filename ); > +gboolean check_file_ext ( const gchar *filename, const gchar *fileext ); > > /* 0 on failure, 1 on success (vik file) 2 on success (other file) */ > gshort a_file_load ( VikAggregateLayer *top, VikViewport *vp, const gchar > *filename ); > -- > 1.6.0.4 > > ------------------------------------------------------------------------------ > Register Now & Save for Velocity, the Web Performance & Operations > Conference from O'Reilly Media. Velocity features a full day of > expert-led, hands-on workshops and two days of sessions from industry > leaders in dedicated Performance & Operations tracks. Use code vel09scf > and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf > _______________________________________________ > Viking-devel mailing list > Viking-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/viking-devel > Viking home page: http://viking.sf.net/ > -- Guilhem BONNEFILLE -=- JID: gu...@im.apinc.org MSN: guilhem_bonnefi...@hotmail.com -=- mailto:guilhem.bonnefi...@gmail.com -=- http://nathguil.free.fr/ ------------------------------------------------------------------------------ Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf _______________________________________________ Viking-devel mailing list Viking-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/viking-devel Viking home page: http://viking.sf.net/