Android: update makefile and backport language fix from master
authorLoic Blot <loic.blot@unix-experience.fr>
Sun, 15 Mar 2015 10:01:15 +0000 (11:01 +0100)
committerLoic Blot <loic.blot@unix-experience.fr>
Sun, 15 Mar 2015 10:01:39 +0000 (11:01 +0100)
build/android/Makefile
src/game.cpp
src/gettext.h
src/util/string.cpp
src/util/string.h

index ef9376df34d2ba61acbfcc95bbf710f52bffe6ed..f53f7f9f555454ad2981bc4ba548d271eeb0c1cc 100644 (file)
@@ -26,7 +26,8 @@ GAMES_TO_COPY = minetest_game
 # Android Version code
 # Increase for each build!
 ################################################################################
-ANDROID_VERSION_CODE = 10
+# Play Store actual version (15/03/15): 10
+ANDROID_VERSION_CODE = 11
 
 ################################################################################
 # toolchain config for arm old processors
@@ -743,9 +744,13 @@ $(ROOT)/jni/src/android_version.h :
        >> ${ROOT}/jni/src/android_version.h;                                      \
        export GITHASH=$$(git rev-parse --short=8 HEAD);                           \
        if [ "x$$GITHASH" = "x" ] ; then                                           \
-               export GITHASH=gUnknown;                                               \
+               export GITHASH="";                                                 \
        fi;                                                                        \
-       echo "#define CMAKE_VERSION_GITHASH \"$$GITHASH\""                         \
+       export GITTAG=$$(git describe --abbrev=0 --tags);                          \
+       if [ "x$$GITTAG" = "x" ] ; then                                            \
+               export GITTAG="";                                                  \
+       fi;                                                                        \
+       echo "#define CMAKE_VERSION_GITHASH \"$$GITTAG-$$GITHASH-Android\""        \
        >> ${ROOT}/jni/src/android_version.h;                                      \
        echo "#define CMAKE_VERSION_STRING STR(VERSION_MAJOR)\".\"STR(VERSION_MINOR)\
        \".\"STR(VERSION_PATCH)"                                                   \
index 8e88fbc8fa4a9a0ad27ae2db15e2507fbe7c4ba1..7fb99ef3e14e5cac61e1e81866c83d27b9992fab 100644 (file)
@@ -4117,7 +4117,9 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
        fps_timings->last_time = time;
 }
 
-
+// Note: This will free (using delete[])! \p msg. If you want to use it later,
+// pass a copy of it to this function
+// Note: \p msg must be allocated using new (not malloc())
 void Game::showOverlayMessage(const wchar_t *msg, float dtime,
                int percent, bool draw_clouds)
 {
index dce45fa3aafd3b339bbf843cbcb6fc5ab3b53c5b..8235efa8ac0b3ef7f998d7dd364860610810060c 100644 (file)
@@ -23,31 +23,31 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "config.h" // for USE_GETTEXT
 
 #if USE_GETTEXT
-#include <libintl.h>
+       #include <libintl.h>
 #else
-#define gettext(String) String
+       #define gettext(String) String
 #endif
 
 #define _(String) gettext(String)
-#define gettext_noop(String) String
-#define N_(String) gettext_noop (String)
+#define gettext_noop(String) (String)
+#define N_(String) gettext_noop((String))
 
 #ifdef _MSC_VER
-void init_gettext(const char *path, const std::string &configured_language, int argc, char** argv);
+void init_gettext(const char *path, const std::string &configured_language,
+               int argc, char** argv);
 #else
 void init_gettext(const char *path, const std::string &configured_language);
 #endif
 
-extern const wchar_t *narrow_to_wide_c(const char *mbs);
-extern std::wstring narrow_to_wide(const std::string &mbs);
+extern wchar_t *narrow_to_wide_c(const char *str);
 
 // You must free the returned string!
+// The returned string is allocated using new
 inline const wchar_t *wgettext(const char *str)
 {
        return narrow_to_wide_c(gettext(str));
 }
 
-// Gettext under MSVC needs this strange way. Just don't ask...
 inline std::wstring wstrgettext(const std::string &text)
 {
        const wchar_t *tmp = wgettext(text.c_str());
index a29bce94bf7e4913c320944a65e17668b7666562..956a1ac44fbeaae47035bf42e8919938660ff18b 100644 (file)
@@ -22,9 +22,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "numeric.h"
 #include "log.h"
 
-#include "../sha1.h"
-#include "../base64.h"
-#include "../hex.h"
+#include "sha1.h"
+#include "base64.h"
+#include "hex.h"
 #include "../porting.h"
 
 #include <algorithm>
@@ -32,12 +32,35 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <iomanip>
 #include <map>
 
+static bool parseHexColorString(const std::string &value, video::SColor &color);
+static bool parseNamedColorString(const std::string &value, video::SColor &color);
+
+
+// You must free the returned string!
+// The returned string is allocated using new
+wchar_t *narrow_to_wide_c(const char *str)
+{
+       wchar_t* nstr = 0;
 #if defined(_WIN32)
-#include <windows.h>  // MultiByteToWideChar
+       int nResult = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR) str, -1, 0, 0);
+       if (nResult == 0) {
+               errorstream<<"gettext: MultiByteToWideChar returned null"<<std::endl;
+       } else {
+               nstr = new wchar_t[nResult];
+               MultiByteToWideChar(CP_UTF8, 0, (LPCSTR) str, -1, (WCHAR *) nstr, nResult);
+       }
+#else
+       size_t len = strlen(str);
+       nstr = new wchar_t[len+1];
+
+       std::wstring intermediate = narrow_to_wide(str);
+       memset(nstr, 0, (len + 1) * sizeof(wchar_t));
+       memcpy(nstr, intermediate.c_str(), len * sizeof(wchar_t));
 #endif
 
-static bool parseHexColorString(const std::string &value, video::SColor &color);
-static bool parseNamedColorString(const std::string &value, video::SColor &color);
+       return nstr;
+}
+
 
 #ifdef __ANDROID__
 const wchar_t* wide_chars =
@@ -62,80 +85,55 @@ int wctomb(char *s, wchar_t wc)
 
 int mbtowc(wchar_t *pwc, const char *s, size_t n)
 {
-       const wchar_t *tmp = narrow_to_wide_c(s);
+       std::wstring intermediate = narrow_to_wide(s);
 
-       if (tmp[0] != '\0') {
-               *pwc = tmp[0];
+       if (intermediate.length() > 0) {
+               *pwc = intermediate[0];
                return 1;
-       } else {
+       }
+       else {
                return -1;
        }
 }
 
-// You must free the returned string!
-const wchar_t *narrow_to_wide_c(const char *mbs)
-{
-       size_t mbl = strlen(mbs);
-       wchar_t *wcs = new wchar_t[mbl + 1];
-
-       size_t i, dest_i = 0;
-       for (i = 0; i < mbl; i++) {
-               if (((unsigned char) mbs[i] > 31) &&
-                               ((unsigned char) mbs[i] < 127)) {
-                       wcs[dest_i++] = wide_chars[(unsigned char) mbs[i] - 32];
+std::wstring narrow_to_wide(const std::string &mbs) {
+       size_t wcl = mbs.size();
+
+       std::wstring retval = L"";
+
+       for (unsigned int i = 0; i < wcl; i++) {
+               if (((unsigned char) mbs[i] >31) &&
+                ((unsigned char) mbs[i] < 127)) {
+
+                       retval += wide_chars[(unsigned char) mbs[i] -32];
                }
                //handle newline
                else if (mbs[i] == '\n') {
-                       wcs[dest_i++] = L'\n';
+                       retval += L'\n';
                }
        }
-       wcs[dest_i] = '\0';
 
-       return wcs;
-}
-
-#else
-
-// You must free the returned string!
-const wchar_t *narrow_to_wide_c(const char *mbs)
-{
-       wchar_t *wcs = NULL;
-#if defined(_WIN32)
-       int nResult = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR) mbs, -1, 0, 0);
-       if (nResult == 0) {
-               errorstream << "gettext: MultiByteToWideChar returned null" << std::endl;
-       } else {
-               wcs = new wchar_t[nResult];
-               MultiByteToWideChar(CP_UTF8, 0, (LPCSTR) mbs, -1, (WCHAR *) wcs, nResult);
-       }
-#else
-       size_t wcl = mbstowcs(NULL, mbs, 0);
-       if (wcl == (size_t) -1)
-               return NULL;
-       wcs = new wchar_t[wcl + 1];
-       size_t l = mbstowcs(wcs, mbs, wcl);
-       assert(l != (size_t) -1); // Should never happen if the last call worked
-       wcs[l] = '\0';
-#endif
-
-       return wcs;
+       return retval;
 }
 
-#endif
+#else // not Android
 
-std::wstring narrow_to_wide(const std::stringmbs)
+std::wstring narrow_to_wide(const std::string &mbs)
 {
        size_t wcl = mbs.size();
        Buffer<wchar_t> wcs(wcl + 1);
-       size_t l = mbstowcs(*wcs, mbs.c_str(), wcl);
-       if (l == (size_t)(-1))
+       size_t len = mbstowcs(*wcs, mbs.c_str(), wcl);
+       if (len == (size_t)(-1))
                return L"<invalid multibyte string>";
-       wcs[l] = 0;
+       wcs[len] = 0;
        return *wcs;
 }
 
+#endif
+
 #ifdef __ANDROID__
-std::string wide_to_narrow(const std::wstring& wcs) {
+
+std::string wide_to_narrow(const std::wstring &wcs) {
        size_t mbl = wcs.size()*4;
 
        std::string retval = "";
@@ -160,17 +158,18 @@ std::string wide_to_narrow(const std::wstring& wcs) {
 
        return retval;
 }
-#else
-std::string wide_to_narrow(const std::wstring& wcs)
+
+#else // not Android
+
+std::string wide_to_narrow(const std::wstring &wcs)
 {
-       size_t mbl = wcs.size()*4;
+       size_t mbl = wcs.size() * 4;
        SharedBuffer<char> mbs(mbl+1);
-       size_t l = wcstombs(*mbs, wcs.c_str(), mbl);
-       if(l == (size_t)(-1)) {
+       size_t len = wcstombs(*mbs, wcs.c_str(), mbl);
+       if (len == (size_t)(-1))
                return "Character conversion failed!";
-       }
        else
-               mbs[l] = 0;
+               mbs[len] = 0;
        return *mbs;
 }
 
@@ -183,7 +182,7 @@ std::string wide_to_narrow(const std::wstring& wcs)
 // compatibility with password-less players).
 std::string translatePassword(std::string playername, std::wstring password)
 {
-       if(password.length() == 0)
+       if (password.length() == 0)
                return "";
 
        std::string slt = playername + wide_to_narrow(password);
index 388184ca49a645cdd480ebd042892f97763ce7a7..dc520e3a8947c91e8183873b68fe1d0bb611ccd5 100644 (file)
@@ -36,11 +36,13 @@ struct FlagDesc {
        u32 flag;
 };
 
+
 // You must free the returned string!
-const wchar_t *narrow_to_wide_c(const char *mbs);
+// The returned string is allocated using new
+wchar_t *narrow_to_wide_c(const char *str);
 
-std::wstring narrow_to_wide(const std::stringmbs);
-std::string wide_to_narrow(const std::wstringwcs);
+std::wstring narrow_to_wide(const std::string &mbs);
+std::string wide_to_narrow(const std::wstring &wcs);
 std::string translatePassword(std::string playername, std::wstring password);
 std::string urlencode(std::string str);
 std::string urldecode(std::string str);