[Scummvm-cvs-logs] scummvm master -> f6b3b72eae246479d730bb8f61a4169a7da8b6d1

eriktorbjorn eriktorbjorn at telia.com
Fri May 20 18:36:33 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f6b3b72eae SWORD25: Don't assume that all locales use decimal point


Commit: f6b3b72eae246479d730bb8f61a4169a7da8b6d1
    https://github.com/scummvm/scummvm/commit/f6b3b72eae246479d730bb8f61a4169a7da8b6d1
Author: eriktorbjorn (eriktorbjorn at users.sourceforge.net)
Date: 2011-05-20T09:34:42-07:00

Commit Message:
SWORD25: Don't assume that all locales use decimal point

The trydecpoint() function *is* used, though probably only in
countries which don't use a decimal point. We can't use the ISO C
locale functions here because they're not fully implemented on
some platforms, e.g. Android. Hopefully this method will work.

Changed paths:
    engines/sword25/util/lua/llex.cpp



diff --git a/engines/sword25/util/lua/llex.cpp b/engines/sword25/util/lua/llex.cpp
index 87eafea..4d73a6a 100644
--- a/engines/sword25/util/lua/llex.cpp
+++ b/engines/sword25/util/lua/llex.cpp
@@ -6,6 +6,7 @@
 
 
 #include <ctype.h>
+#include <stdio.h>
 #include <string.h>
 
 #define llex_c
@@ -175,11 +176,23 @@ static void buffreplace (LexState *ls, char from, char to) {
 
 static void trydecpoint (LexState *ls, SemInfo *seminfo) {
   /* format error: try to update decimal point separator */
-  // Non-portable call to update the decimal point separator.
-  // It has been simplified in ScummVM to not use any system locale
-  // information, as it's not used in sword25.
+  // Normally we'd use localeconv() to get the decimal point separator, but
+  // annoyingly that is not available on some platforms, e.g. Android. Figure
+  // it out by formatting a known value and extract the separator from that
+  // instead. The result could be cached, but considering the game I doubt
+  // this will ever be a bottleneck. Note that the separator is assumed to fit
+  // in a char, but that was a limitation in the original code as well.
   char old = ls->decpoint;
+  char buf[5];
+  int i;
+  sprintf(buf, "%.1f", 1.0);
   ls->decpoint = '.';
+  for (i = 0; buf[i]; i++) {
+    if (!isspace(buf[i]) && !isdigit(buf[i])) {
+      ls->decpoint = buf[i];
+      break;
+    }
+  }
   buffreplace(ls, old, ls->decpoint);  /* try updated decimal separator */
   if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) {
     /* format error with correct decimal point: no more options */






More information about the Scummvm-git-logs mailing list