[Skencil-commits] r513 - in skencil/trunk: . Sketch/Modules
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Sun Jan 29 02:33:55 CET 2006
Author: bh
Date: 2006-01-29 02:33:55 +0100 (Sun, 29 Jan 2006)
New Revision: 513
Modified:
skencil/trunk/ChangeLog
skencil/trunk/Sketch/Modules/curveobject.c
skencil/trunk/Sketch/Modules/pstokenize.c
skencil/trunk/Sketch/Modules/skreadmodule.c
Log:
* Sketch/Modules/curveobject.c (curve_parse_string_append),
Sketch/Modules/skreadmodule.c (sklex),
Sketch/Modules/pstokenize.c (read_name_or_number): Set LC_NUMERIC
locale to "C" to make sure the C format for floats is recognized
instead of any locale specific format.
Modified: skencil/trunk/ChangeLog
===================================================================
--- skencil/trunk/ChangeLog 2006-01-21 19:45:28 UTC (rev 512)
+++ skencil/trunk/ChangeLog 2006-01-29 01:33:55 UTC (rev 513)
@@ -1,3 +1,11 @@
+2006-01-29 Bernhard Herzog <bh at intevation.de>
+
+ * Sketch/Modules/curveobject.c (curve_parse_string_append),
+ Sketch/Modules/skreadmodule.c (sklex),
+ Sketch/Modules/pstokenize.c (read_name_or_number): Set LC_NUMERIC
+ locale to "C" to make sure the C format for floats is recognized
+ instead of any locale specific format.
+
2005-12-18 Bernhard Herzog <bh at intevation.de>
Change which objects manage which tool is active. Previously it
Modified: skencil/trunk/Sketch/Modules/curveobject.c
===================================================================
--- skencil/trunk/Sketch/Modules/curveobject.c 2006-01-21 19:45:28 UTC (rev 512)
+++ skencil/trunk/Sketch/Modules/curveobject.c 2006-01-29 01:33:55 UTC (rev 513)
@@ -1,5 +1,5 @@
/* Sketch - A Python-based interactive drawing program
- * Copyright (C) 1997, 1998, 1999, 2000, 2003, 2005 by Bernhard Herzog
+ * Copyright (C) 1997, 1998, 1999, 2000, 2003, 2005, 2006 by Bernhard Herzog
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -19,6 +19,8 @@
/* a poly bezier object */
#include <math.h>
+#include <string.h>
+#include <locale.h>
#include <Python.h>
#include <structmember.h>
@@ -1441,6 +1443,10 @@
curve_parse_string_append(SKCurveObject * self, const char * string)
{
CurveSegment segment;
+ char * old_locale;
+
+ old_locale = strdup(setlocale(LC_NUMERIC, NULL));
+ setlocale(LC_NUMERIC, "C");
if (string[1] == 'c')
{
@@ -1452,7 +1458,7 @@
&x1, &y1, &x2, &y2, &x, &y, &cont) != 7)
{
PyErr_SetString(PyExc_ValueError, "cannot parse string");
- return 0;
+ goto fail;
}
segment.cont = cont;
@@ -1461,7 +1467,7 @@
segment.x2 = x2; segment.y2 = y2;
if (!SKCurve_AppendSegment(self, &segment))
- return 0;
+ goto fail;
}
else if (string[1] == 's')
{
@@ -1472,23 +1478,28 @@
if (sscanf(string, "bs%*[ (]%lf,%lf,%d", &x, &y, &cont) != 3)
{
PyErr_SetString(PyExc_ValueError, "cannot parse string");
- return 0;
+ goto fail;
}
segment.cont = cont;
segment.x = x; segment.y = y;
if (!SKCurve_AppendSegment(self, &segment))
- return 0;
+ goto fail;
}
else
{
PyErr_SetString(PyExc_ValueError,
"string must begin with 'bc' or 'bs'");
- return 0;
+ goto fail;
}
return 1;
+
+fail:
+ setlocale(LC_NUMERIC, old_locale);
+ free(old_locale);
+ return 0;
}
static PyObject *
Modified: skencil/trunk/Sketch/Modules/pstokenize.c
===================================================================
--- skencil/trunk/Sketch/Modules/pstokenize.c 2006-01-21 19:45:28 UTC (rev 512)
+++ skencil/trunk/Sketch/Modules/pstokenize.c 2006-01-29 01:33:55 UTC (rev 513)
@@ -1,5 +1,5 @@
/* Sketch - A Python-based interactive drawing program
- * Copyright (C) 1998, 1999, 2000, 2001, 2003 by Bernhard Herzog
+ * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2006 by Bernhard Herzog
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -20,6 +20,7 @@
* Functions to tokenize PostScript-files.
*/
+#include <locale.h>
#include <Python.h>
#include <structmember.h>
#include <filterobj.h>
@@ -486,7 +487,17 @@
p += 1;
if (char_types[(int)*p] & FLOATCHAR)
{
- double result = strtod(start, &numend);
+ char * old_locale;
+ double result;
+
+ /* Change LC_NUMERIC locale to "C" around the strtod
+ * call so that it parses the number correctly. */
+ old_locale = strdup(setlocale(LC_NUMERIC, NULL));
+ setlocale(LC_NUMERIC, "C");
+ result = strtod(start, &numend);
+ setlocale(LC_NUMERIC, old_locale);
+ free(old_locale);
+
if (numend == buf)
{
Py_DECREF(value);
Modified: skencil/trunk/Sketch/Modules/skreadmodule.c
===================================================================
--- skencil/trunk/Sketch/Modules/skreadmodule.c 2006-01-21 19:45:28 UTC (rev 512)
+++ skencil/trunk/Sketch/Modules/skreadmodule.c 2006-01-29 01:33:55 UTC (rev 513)
@@ -1,5 +1,5 @@
/* Sketch - A Python-based interactive drawing program
- * Copyright (C) 1998, 1999, 2000, 2001 by Bernhard Herzog
+ * Copyright (C) 1998, 1999, 2000, 2001, 2006 by Bernhard Herzog
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -27,6 +27,8 @@
*/
#include <ctype.h>
+#include <locale.h>
+#include <string.h>
#include <Python.h>
typedef struct {
@@ -208,7 +210,19 @@
p += 1;
if (*p == '.' || *p == 'e' || *p == 'E')
{
- double result = strtod(buffer->buffer - 1, &(buffer->buffer));
+ char * old_locale;
+ double result;
+
+ /* Change LC_NUMERIC locale to "C" around the strtod
+ * call so that it parses the number correctly. */
+ old_locale = strdup(setlocale(LC_NUMERIC, NULL));
+ setlocale(LC_NUMERIC, "C");
+
+ result = strtod(buffer->buffer - 1, &(buffer->buffer));
+
+ setlocale(LC_NUMERIC, old_locale);
+ free(old_locale);
+
*lval = PyFloat_FromDouble(result);
return FLOAT;
}
More information about the Skencil-commits
mailing list