From c48ff3bc89afa281f0383fcb0aa91f3d337f38fa Mon Sep 17 00:00:00 2001 From: jagt Date: Wed, 18 Sep 2013 02:19:02 +0800 Subject: [PATCH] hackaround the gbk char and space char in path; article fix intergrate --- .gitignore | 2 +- Makefile.windows | 1 + src/brogue/Items.c | 9 +-- src/platform/sdl-platform.c | 22 +++++- windeps/include/iconv.h | 134 ++++++++++++++++++++++++++++++++++++ windeps/lib/iconv.lib | Bin 0 -> 3090 bytes 6 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 windeps/include/iconv.h create mode 100644 windeps/lib/iconv.lib diff --git a/.gitignore b/.gitignore index cd8b024..b98c37c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .DS_Store -winbuild \ No newline at end of file +winbuild diff --git a/Makefile.windows b/Makefile.windows index 9035df9..94f1302 100644 --- a/Makefile.windows +++ b/Makefile.windows @@ -70,6 +70,7 @@ WIN32_LIB = \ -lgobject-2.0 \ -lglib-2.0 \ -lSDL \ + -liconv \ ${WIN32_SDL_TTF}/lib/x86/SDL_ttf.dll WIN32_DLL = \ diff --git a/src/brogue/Items.c b/src/brogue/Items.c index 12ab858..88e4b8d 100644 --- a/src/brogue/Items.c +++ b/src/brogue/Items.c @@ -1075,8 +1075,8 @@ void itemName(item *theItem, char *root, boolean includeDetails, boolean include sprintf(root, "芒果"); } else { if (theItem->quantity == 1) { - sprintf(article, "一份"); - sprintf(root, "食物"); + // sprintf(article, "一份"); + sprintf(root, "粮食"); } else { sprintf(root, "粮食"); } @@ -1313,7 +1313,7 @@ void itemName(item *theItem, char *root, boolean includeDetails, boolean include sprintf(article, "%i", theItem->quantity); } else if (theItem->category & AMULET) { sprintf(article, ""); - } else if (!(theItem->category & ARMOR) && !(theItem->category & FOOD && theItem->kind == RATION)) { + } else if (!(theItem->category & ARMOR)) { // otherwise prepend a/an if the item is not armor and not a ration of food; // armor gets no article, and "some food" was taken care of above. sprintf(article, "一"); @@ -1334,8 +1334,9 @@ void itemName(item *theItem, char *root, boolean includeDetails, boolean include strcat(article, "只"); break; case CHARM: strcat(article, "件"); break; - case GOLD: case FOOD: + strcat(article, "份"); break; + case GOLD: strcat(article, "个"); break; case KEY: strcat(article, "把"); break; diff --git a/src/platform/sdl-platform.c b/src/platform/sdl-platform.c index d386155..c8fe42a 100644 --- a/src/platform/sdl-platform.c +++ b/src/platform/sdl-platform.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "platform.h" #include "IncludeGlobals.h" @@ -113,7 +115,7 @@ static SDL_CONSOLE console; relative paths. */ char *SdlConsole_getAppPath(const char *file) { - char *path = malloc(strlen(file) + strlen(console.app_path) + 2); + char *path = malloc(strlen(file) + strlen(console.app_path) + 16); // add more padding just for safety if (path == NULL) { return NULL; @@ -985,7 +987,14 @@ void SdlConsole_remap(const char *input_name, const char *output_name) /* Allocate the structures to be used by the console. */ void SdlConsole_allocate(void) { + char app_dir[1024]; +#ifdef _WIN32 + char utf8_dir[1024]; + size_t outbytesleft, inbytesleft, conv_ret; + const char *tin = app_dir; + char *tout = utf8_dir; +#endif if (getcwd(app_dir, 1024) == NULL) { @@ -993,6 +1002,17 @@ void SdlConsole_allocate(void) exit(1); } +#ifdef _WIN32 + // since we're targetting chs user, convert from gbk anyway + // if all are ascii then nothing happens really + inbytesleft = strlen(app_dir) + 1; + outbytesleft = 1024; + iconv_t cd = iconv_open("UTF-8", "GBK"); + conv_ret = iconv(cd, &tin, &inbytesleft, &tout, &outbytesleft); + iconv_close(cd); + memcpy(app_dir, utf8_dir, sizeof(char)*1024); +#endif + console.app_path = malloc(strlen(app_dir) + 1); strcpy(console.app_path, app_dir); diff --git a/windeps/include/iconv.h b/windeps/include/iconv.h new file mode 100644 index 0000000..d484fc8 --- /dev/null +++ b/windeps/include/iconv.h @@ -0,0 +1,134 @@ +/* Copyright (C) 1999-2003 Free Software Foundation, Inc. + This file is part of the GNU LIBICONV Library. + + The GNU LIBICONV Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + The GNU LIBICONV Library is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU LIBICONV Library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, Inc., 59 Temple Place - + Suite 330, Boston, MA 02111-1307, USA. */ + +/* When installed, this file is called "iconv.h". */ + +#ifndef _LIBICONV_H +#define _LIBICONV_H + +#define _LIBICONV_VERSION 0x0109 /* version number: (major<<8) + minor */ +extern int _libiconv_version; /* Likewise */ + +/* We would like to #include any system header file which could define + iconv_t, 1. in order to eliminate the risk that the user gets compilation + errors because some other system header file includes /usr/include/iconv.h + which defines iconv_t or declares iconv after this file, 2. when compiling + for LIBICONV_PLUG, we need the proper iconv_t type in order to produce + binary compatible code. + But gcc's #include_next is not portable. Thus, once libiconv's iconv.h + has been installed in /usr/local/include, there is no way any more to + include the original /usr/include/iconv.h. We simply have to get away + without it. + Ad 1. The risk that a system header file does + #include "iconv.h" or #include_next "iconv.h" + is small. They all do #include . + Ad 2. The iconv_t type is a pointer type in all cases I have seen. (It + has to be a scalar type because (iconv_t)(-1) is a possible return value + from iconv_open().) */ + +/* Define iconv_t ourselves. */ +#undef iconv_t +#define iconv_t libiconv_t +typedef void* iconv_t; + +/* Get size_t declaration. */ +#include + +/* Get errno declaration and values. */ +#include +/* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS, + have EILSEQ in a different header. On these systems, define EILSEQ + ourselves. */ +#ifndef EILSEQ +/* Igor: called upon EILSEQ from glibc, since autogeneration of this header + on Windows didn't do the job. */ +/* #define EILSEQ @EILSEQ@ */ +#define EILSEQ 84 +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Allocates descriptor for code conversion from encoding `fromcode' to + encoding `tocode'. */ +#ifndef LIBICONV_PLUG +#define iconv_open libiconv_open +#endif +extern iconv_t iconv_open (const char* tocode, const char* fromcode); + +/* Converts, using conversion descriptor `cd', at most `*inbytesleft' bytes + starting at `*inbuf', writing at most `*outbytesleft' bytes starting at + `*outbuf'. + Decrements `*inbytesleft' and increments `*inbuf' by the same amount. + Decrements `*outbytesleft' and increments `*outbuf' by the same amount. */ +#ifndef LIBICONV_PLUG +#define iconv libiconv +#endif +extern size_t iconv (iconv_t cd, const char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft); + +/* Frees resources allocated for conversion descriptor `cd'. */ +#ifndef LIBICONV_PLUG +#define iconv_close libiconv_close +#endif +extern int iconv_close (iconv_t cd); + + +#ifndef LIBICONV_PLUG + +/* Nonstandard extensions. */ + +/* Control of attributes. */ +#define iconvctl libiconvctl +extern int iconvctl (iconv_t cd, int request, void* argument); + +/* Requests for iconvctl. */ +#define ICONV_TRIVIALP 0 /* int *argument */ +#define ICONV_GET_TRANSLITERATE 1 /* int *argument */ +#define ICONV_SET_TRANSLITERATE 2 /* const int *argument */ +#define ICONV_GET_DISCARD_ILSEQ 3 /* int *argument */ +#define ICONV_SET_DISCARD_ILSEQ 4 /* const int *argument */ + +/* Listing of locale independent encodings. */ +#define iconvlist libiconvlist +extern void iconvlist (int (*do_one) (unsigned int namescount, + const char * const * names, + void* data), + void* data); + +/* Support for relocatable packages. */ + +/* Sets the original and the current installation prefix of the package. + Relocation simply replaces a pathname starting with the original prefix + by the corresponding pathname with the current prefix instead. Both + prefixes should be directory names without trailing slash (i.e. use "" + instead of "/"). */ +extern void libiconv_set_relocation_prefix (const char *orig_prefix, + const char *curr_prefix); + +#endif + + +#ifdef __cplusplus +} +#endif + + +#endif /* _LIBICONV_H */ diff --git a/windeps/lib/iconv.lib b/windeps/lib/iconv.lib new file mode 100644 index 0000000000000000000000000000000000000000..4a49795e2d4e3e985b18804d6b7bb689f2a97182 GIT binary patch literal 3090 zcmcImOHbQC5T3jfheJdw^`%y+gb?i^h2R7#RaI!IR740UghLNy365zj85|`k>aBOw zpV0$9fg?YlhaP(1$dBM$I%DsyABm}h+Lgw;^YDJ&oo{FT^i{jBbzdtlivG5+pjNBP z)pDikx6gA`RbTSao&o^V0LcPCx(tx%0%Xqsa#vhtu_rlkM7aPU$=A4?VvnNik}$Tm zv9;N3vDJ6mZ<}jdt<5GgH0$UX7;Eg*>!WV?YWp2;>-|n+ovp64RxsW;>@mhnW8Vol z*82m)IuZ_Pw|Y7n1FG|~FuLxMw>8rm=&qk}-T%HeG~Eze@%v3xa|sV)p~((orFSeGTT%d0ds7 zkv9OpQ7(l6`x+F_%6T=QA6zSdYL z=SZ7E3w;O8fc4HEVbMbllTCs^O|uSr_@Sw(k8pi0&?uf7eOVmDdTRjow|0faUKybz zghizoG=Pk$xE8WMp$Bg?JHQgxsEb1bpSL(oArz78jL49(=ccH~;x0Ei6=Ul16PH{hl!ux-@yHR%Z5#olBaN_-xBrMYZ3Z2S&jA|8S4J!m@PSj2&{u3n8 zVRAI_n-oAJ&c?7dN-$5=kZ=*tl`0Bv0OKKI#Jw2&E|K%Qm{E}g6$3~Q5Gmn9vTrFD zXySdVmO1GINY4=|=|dWS0lLs~6m^Y@|QLSF4=-7R*q`