Patch libprojectM to make it ignore the decimal-point locale setting when parsing Milkdrop presets. Fixes issue #455

This commit is contained in:
David Sansome 2010-07-24 12:26:28 +00:00
parent dd3182ad70
commit e3f54b745b
2 changed files with 88 additions and 39 deletions

View File

@ -1269,28 +1269,13 @@ int Parser::parse_int(std::istream & fs, int * int_ptr)
/* Parses a floating point number */
int Parser::string_to_float(char * string, float * float_ptr)
{
std::istringstream stream(string);
stream >> *float_ptr;
char ** error_ptr;
if (*string == 0)
if (stream.fail())
return PROJECTM_PARSE_ERROR;
error_ptr = (char**)wipemalloc(sizeof(char**));
(*float_ptr) = strtod(string, error_ptr);
/* These imply a succesful parse of the string */
if ((**error_ptr == '\0') || (**error_ptr == '\r'))
{
free(error_ptr);
error_ptr = NULL;
return PROJECTM_SUCCESS;
}
(*float_ptr) = 0;
free(error_ptr);
error_ptr = NULL;
return PROJECTM_PARSE_ERROR;
return PROJECTM_SUCCESS;
}
/* Parses a floating point number */
@ -1298,11 +1283,9 @@ int Parser::parse_float(std::istream & fs, float * float_ptr)
{
char string[MAX_TOKEN_SIZE];
char ** error_ptr;
token_t token;
int sign;
error_ptr =(char**) wipemalloc(sizeof(char**));
token = parseToken(fs, string);
@ -1322,28 +1305,13 @@ int Parser::parse_float(std::istream & fs, float * float_ptr)
if (string[0] == 0)
{
free(error_ptr);
error_ptr = NULL;
return PROJECTM_PARSE_ERROR;
}
(*float_ptr) = sign*strtod(string, error_ptr);
/* No conversion was performed */
if ((**error_ptr == '\0') || (**error_ptr == '\r'))
{
free(error_ptr);
error_ptr = NULL;
return PROJECTM_SUCCESS;
}
if (PARSE_DEBUG) printf("parse_float: float conversion failed for string \"%s\"\n", string);
(*float_ptr) = 0;
free(error_ptr);
error_ptr = NULL;
return PROJECTM_PARSE_ERROR;
std::istringstream stream(string);
stream >> *float_ptr;
return PROJECTM_SUCCESS;
}
/* Parses a per frame equation. That is, interprets a stream of data as a per frame equation */

View File

@ -0,0 +1,81 @@
Index: MilkdropPresetFactory/Parser.cpp
===================================================================
--- MilkdropPresetFactory/Parser.cpp (revision 1510)
+++ MilkdropPresetFactory/Parser.cpp (working copy)
@@ -1269,28 +1269,13 @@
/* Parses a floating point number */
int Parser::string_to_float(char * string, float * float_ptr)
{
+ std::istringstream stream(string);
+ stream >> *float_ptr;
- char ** error_ptr;
-
- if (*string == 0)
+ if (stream.fail())
return PROJECTM_PARSE_ERROR;
- error_ptr = (char**)wipemalloc(sizeof(char**));
-
- (*float_ptr) = strtod(string, error_ptr);
-
- /* These imply a succesful parse of the string */
- if ((**error_ptr == '\0') || (**error_ptr == '\r'))
- {
- free(error_ptr);
- error_ptr = NULL;
- return PROJECTM_SUCCESS;
- }
-
- (*float_ptr) = 0;
- free(error_ptr);
- error_ptr = NULL;
- return PROJECTM_PARSE_ERROR;
+ return PROJECTM_SUCCESS;
}
/* Parses a floating point number */
@@ -1298,11 +1283,9 @@
{
char string[MAX_TOKEN_SIZE];
- char ** error_ptr;
token_t token;
int sign;
- error_ptr =(char**) wipemalloc(sizeof(char**));
token = parseToken(fs, string);
@@ -1322,28 +1305,13 @@
if (string[0] == 0)
{
- free(error_ptr);
- error_ptr = NULL;
return PROJECTM_PARSE_ERROR;
}
- (*float_ptr) = sign*strtod(string, error_ptr);
+ std::istringstream stream(string);
+ stream >> *float_ptr;
- /* No conversion was performed */
- if ((**error_ptr == '\0') || (**error_ptr == '\r'))
- {
- free(error_ptr);
- error_ptr = NULL;
- return PROJECTM_SUCCESS;
- }
-
- if (PARSE_DEBUG) printf("parse_float: float conversion failed for string \"%s\"\n", string);
-
- (*float_ptr) = 0;
- free(error_ptr);
- error_ptr = NULL;
- return PROJECTM_PARSE_ERROR;
-
+ return PROJECTM_SUCCESS;
}
/* Parses a per frame equation. That is, interprets a stream of data as a per frame equation */