force "C" locale with atof() in order to always consider the decimal delimiter as [.]; fix bug on the ratio with the MPlayer wrapper and fr_FR locale where the delimiter is [,]
authorMathieu Schroeter <mathieu.schroeter@mycable.ch>
Thu Jul 16 20:32:11 2009 +0200 (6 months ago)
changeset 1149398947e251f0
parent 1148203a82268910
child 1150d1b7e7b79258
force "C" locale with atof() in order to always consider the decimal delimiter as [.]; fix bug on the ratio with the MPlayer wrapper and fr_FR locale where the delimiter is [,]
src/parse_utils.c
src/parse_utils.h
src/wrapper_mplayer.c
src/wrapper_vlc.c
       1 --- a/src/parse_utils.c	Tue Jul 14 15:39:23 2009 +0200
       2 +++ b/src/parse_utils.c	Thu Jul 16 20:32:11 2009 +0200
       3 @@ -19,6 +19,9 @@
       4   * Foundation, Inc, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
       5   */
       6  
       7 +#define _GNU_SOURCE
       8 +#include <stdlib.h>
       9 +#include <locale.h>
      10  #include <string.h>
      11  
      12  #include "parse_utils.h"
      13 @@ -69,3 +72,18 @@
      14  
      15    return res;
      16  }
      17 +
      18 +double
      19 +my_atof (const char *nptr)
      20 +{
      21 +  double res;
      22 +  locale_t new_locale, prev_locale;
      23 +
      24 +  new_locale = newlocale (LC_NUMERIC_MASK, "C", NULL);
      25 +  prev_locale = uselocale (new_locale);
      26 +  res = atof (nptr);
      27 +  uselocale (prev_locale);
      28 +  freelocale (new_locale);
      29 +
      30 +  return res;
      31 +}
     1.1 --- a/src/parse_utils.h	Tue Jul 14 15:39:23 2009 +0200
     1.2 +++ b/src/parse_utils.h	Thu Jul 16 20:32:11 2009 +0200
     1.3 @@ -25,5 +25,6 @@
     1.4  char *trim_whitespaces (char *str);
     1.5  int count_nb_dec (int dec);
     1.6  char *my_strrstr (const char *buf, const char *str);
     1.7 +double my_atof (const char *nptr);
     1.8  
     1.9  #endif /* PARSE_UTILS_H */
     2.1 --- a/src/wrapper_mplayer.c	Tue Jul 14 15:39:23 2009 +0200
     2.2 +++ b/src/wrapper_mplayer.c	Thu Jul 16 20:32:11 2009 +0200
     2.3 @@ -971,7 +971,7 @@
     2.4  
     2.5    if (result)
     2.6    {
     2.7 -    value = (int) rintf (atof (result));
     2.8 +    value = (int) rintf (my_atof (result));
     2.9      free (result);
    2.10    }
    2.11  
    2.12 @@ -988,7 +988,7 @@
    2.13  
    2.14    if (result)
    2.15    {
    2.16 -    value = atof (result);
    2.17 +    value = my_atof (result);
    2.18      free (result);
    2.19    }
    2.20  
    2.21 @@ -1854,7 +1854,7 @@
    2.22      else if (strstr (val, "ANGLES") == val)
    2.23        title->angles = atoi (parse_field (val));
    2.24      else if (strstr (val, "LENGTH") == val)
    2.25 -      title->length = (uint32_t) (atof (parse_field (val)) * 1000.0);
    2.26 +      title->length = (uint32_t) (my_atof (parse_field (val)) * 1000.0);
    2.27      return 1;
    2.28    }
    2.29  
    2.30 @@ -2085,7 +2085,7 @@
    2.31    it = strstr (buffer, "ID_VIDEO_ASPECT=");
    2.32    if (it == buffer)
    2.33    {
    2.34 -    video->aspect = (uint32_t) (atof (parse_field (it))
    2.35 +    video->aspect = (uint32_t) (my_atof (parse_field (it))
    2.36                                  * PLAYER_VIDEO_ASPECT_RATIO_MULT);
    2.37      return 1;
    2.38    }
    2.39 @@ -2093,7 +2093,7 @@
    2.40    it = strstr (buffer, "ID_VIDEO_FPS=");
    2.41    if (it == buffer)
    2.42    {
    2.43 -    val = atof (parse_field (it));
    2.44 +    val = my_atof (parse_field (it));
    2.45      video->frameduration =
    2.46        (uint32_t) (val ? PLAYER_VIDEO_FRAMEDURATION_RATIO_DIV / val : 0);
    2.47      return 1;
    2.48 @@ -2146,7 +2146,7 @@
    2.49      it = strstr (buffer, "ID_DVD_TITLE_");
    2.50      if (it == buffer && strstr (buffer, "_LENGTH="))
    2.51      {
    2.52 -      mrl->prop->length += (uint32_t) (atof (parse_field (it)) * 1000.0);
    2.53 +      mrl->prop->length += (uint32_t) (my_atof (parse_field (it)) * 1000.0);
    2.54        return 1;
    2.55      }
    2.56      break;
    2.57 @@ -2155,7 +2155,7 @@
    2.58      it = strstr (buffer, "ID_LENGTH=");
    2.59      if (it == buffer)
    2.60      {
    2.61 -      mrl->prop->length = (uint32_t) (atof (parse_field (it)) * 1000.0);
    2.62 +      mrl->prop->length = (uint32_t) (my_atof (parse_field (it)) * 1000.0);
    2.63        return 1;
    2.64      }
    2.65      break;
     3.1 --- a/src/wrapper_vlc.c	Tue Jul 14 15:39:23 2009 +0200
     3.2 +++ b/src/wrapper_vlc.c	Thu Jul 16 20:32:11 2009 +0200
     3.3 @@ -31,6 +31,7 @@
     3.4  #include "logs.h"
     3.5  #include "playlist.h"
     3.6  #include "fs_utils.h"
     3.7 +#include "parse_utils.h"
     3.8  #include "wrapper_vlc.h"
     3.9  
    3.10  #define MODULE_NAME "vlc"
    3.11 @@ -241,7 +242,7 @@
    3.12  
    3.13    video->width = libvlc_video_get_width (mp, ex);
    3.14    video->height = libvlc_video_get_height (mp, ex);
    3.15 -  video->aspect = (uint32_t) (atof (libvlc_video_get_aspect_ratio (mp, ex))
    3.16 +  video->aspect = (uint32_t) (my_atof (libvlc_video_get_aspect_ratio (mp, ex))
    3.17                                * PLAYER_VIDEO_ASPECT_RATIO_MULT);
    3.18  
    3.19    val = libvlc_media_player_get_fps (mp, ex);