LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2908|回复: 23

成功移植Fcitx2.0.1到Mac OSX (贴图)

[复制链接]
发表于 2004-1-10 11:45:08 | 显示全部楼层 |阅读模式
经过几天鏖战,Fcitx被成功的移植到了MAC OSX上,成为目前osx上唯一的X11中文输入法。虽然国内MAC的用户少,但是毕竟osx是世界上用的最多unix系统(这是根据APPLE.COM自己说的,有5000万用户)。

最难的过程是数的转换,INTEL-PC 用的是 little-endian , mac 用的是 big-endian 。这样的话,数 257 在 intel-pc 中储存的是 0x01020000 ,但在 mac-osx 中是 0x00000201 。在 fcitx 中  py.c  读取的码表文件中有integer 索引,这样在PC产生的码表自己读没有问题,但是在mac上就会core-dump拉。

另外 macosx 是基于freebsd的,一些头文件和 signal 的定义和 linux 也不同。

付上 patch.mac 文件,表示对 fcitx  的感谢。

diff -r fcitx-2.0.1/IMdkit/lib/IMConn.c fcitx-2.0.1-osx-hack/IMdkit/lib/IMConn.c
33c33
< #include <malloc.h>
---
> #include <sys/malloc.h>
diff -r fcitx-2.0.1/Makefile fcitx-2.0.1-osx-hack/Makefile
16c16
<       $(CC) $(CFLAGS) $(LIB) $(OBJ) IMdkit/lib/libXimd.a -o fcitx
---
>       $(CC) $(CFLAGS) $(LIB) $(OBJ) -liconv IMdkit/lib/libXimd.a -o fcitx
diff -r fcitx-2.0.1/Makefile.noxft fcitx-2.0.1-osx-hack/Makefile.noxft
16c16
<       $(CC) $(CFLAGS) $(LIB) $(OBJ) IMdkit/lib/libXimd.a -o fcitx
---
>       $(CC) $(CFLAGS) $(LIB) $(OBJ) IMdkit/lib/libXimd.a -liconv -o fcitx
diff -r fcitx-2.0.1/MyErrorsHandlers.c fcitx-2.0.1-osx-hack/MyErrorsHandlers.c
6c6
< #include <wait.h>
---
> #include <sys/wait.h>
9a10,11
>
> #define SIGUNUSED 32
diff -r fcitx-2.0.1/py.c fcitx-2.0.1-osx-hack/py.c
91a92,102
> // function to reverse byte order for integer
> // this is required for Mac machine
> int ReverseInt(unsigned int pc_int)
> {
>     int mac_int = pc_int;
>     unsigned char * p = (unsigned char*) &pc_int;
>     mac_int = (p[3] << 24) + (p[2] << 16) + (p[1] << 8) + p[0];
>     return mac_int;
> }
> // end of mod
>
96c107
<     int             i, j, iLen;
---
>     unsigned int    i, j, iLen;
109a121
>       iPYFACount = ReverseInt(iPYFACount);
117a130
>       PYFAList.iBase = ReverseInt(PYFAList.iBase);
122a136
>               iLen = ReverseInt(iLen);
171a186
>               i = ReverseInt(i);
177c192
<
---
>               k = ReverseInt(k);
diff -r fcitx-2.0.1/ui.c fcitx-2.0.1-osx-hack/ui.c
8c8
< #include <malloc.h>
---
> #include <sys/malloc.h>

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
发表于 2004-1-10 12:42:15 | 显示全部楼层
弓虽!
发表于 2004-4-14 07:17:35 | 显示全部楼层
hoho, I reported this little-endian/big-endian issue and sent a priliminary patch to the author, but he seemed to not be interested in it. I think this patch is important since some people may want to use fcitx for big-endian RISC machines, e.g., SPARC, SGI, PowerPC.
发表于 2004-4-14 08:53:07 | 显示全部楼层
最初由 terminator 发表
hoho, I reported this little-endian/big-endian issue and sent a priliminary patch to the author, but he seemed to not be interested in it. I think this patch is important since some people may want to use fcitx for big-endian RISC machines, e.g., SPARC, SGI, PowerPC.

呵呵,不是我不感兴趣。主要是我本人对不同平台的情况不清楚,而且对autoconf等自动配置工具也不太了解,因此不清楚如何设置配置脚本来根据硬件平台选择合适的编译命令。
总之,谢谢二位啦……
发表于 2004-4-14 09:32:21 | 显示全部楼层
我会试试把这段代码加入cvs中,并在autoconf中加入相应的编译控制。但我没有环境,所以到时候还要请 puzzlebird 和其他有 osx 的兄弟们帮忙测试,谢谢!
发表于 2004-4-14 10:52:13 | 显示全部楼层
to puzzlebird:
你的这个patch不太规范,在执行diff时没有用-u参数加上修改代码的上下文,再加上你贴到直接贴到论坛里的网页上,许多对齐的空格和tab在html里都消失了,这让我费了不少工夫手工把他们patch到源代码里。我一般用 diff -uNr 来生成代码的patch,下面是我手工patch之后的结果,请 puzzlebird 看看是不是这个效果:

  1. diff -uNr fcitx-2.0.1/IMdkit/lib/IMConn.c fcitx-2.0.1-osx/IMdkit/lib/IMConn.c
  2. --- fcitx-2.0.1/IMdkit/lib/IMConn.c     2003-12-29 09:10:25.000000000 +0800
  3. +++ fcitx-2.0.1-osx/IMdkit/lib/IMConn.c 2004-04-14 10:28:26.000000000 +0800
  4. @@ -30,7 +30,7 @@
  5. ******************************************************************/

  6. #include <X11/Xlib.h>
  7. -#include <malloc.h>
  8. +#include <sys/malloc.h>
  9. #include <string.h>
  10. #include "IMdkit.h"
  11. #include <stdarg.h>
  12. diff -uNr fcitx-2.0.1/MyErrorsHandlers.c fcitx-2.0.1-osx/MyErrorsHandlers.c
  13. --- fcitx-2.0.1/MyErrorsHandlers.c      2004-01-07 11:29:34.000000000 +0800
  14. +++ fcitx-2.0.1-osx/MyErrorsHandlers.c  2004-04-14 10:33:08.000000000 +0800
  15. @@ -3,11 +3,13 @@
  16. #include <stdio.h>
  17. #include <signal.h>
  18. #include <stdlib.h>
  19. -#include <wait.h>
  20. +#include <sys/wait.h>

  21. #include "wbx.h"
  22. #include "py.h"

  23. +#define SIGUNUSED 32
  24. +
  25. XErrorHandler   oldXErrorHandler;

  26. extern BYTE     iWBChanged;
  27. diff -uNr fcitx-2.0.1/py.c fcitx-2.0.1-osx/py.c
  28. --- fcitx-2.0.1/py.c    2004-01-08 17:45:51.000000000 +0800
  29. +++ fcitx-2.0.1-osx/py.c        2004-04-14 10:42:57.000000000 +0800
  30. @@ -89,11 +89,22 @@
  31. extern int      iCurrentLegendCandPage;
  32. extern Bool     bDisablePagingInLegend;

  33. +
  34. +/* function to reverse byte order for integer
  35. +this is required for Mac machine */
  36. +int ReverseInt(unsigned int pc_int)
  37. +{
  38. +    int mac_int = pc_int;
  39. +    unsigned char * p = (unsigned char*) &pc_int;
  40. +    mac_int = (p[3] << 24) + (p[2] << 16) + (p[1] << 8) + p[0];
  41. +    return mac_int;
  42. +}
  43. +
  44. Bool LoadPYBaseDict (void)
  45. {
  46.      FILE           *fp;
  47.      char            strPath[PATH_MAX];
  48. -    int             i, j, iLen;
  49. +    unsigned int    i, j, iLen;

  50.      if (bRunLocal) {
  51.         strcpy (strPath, (char *) getenv ("HOME"));
  52. @@ -107,6 +118,7 @@
  53.         return False;

  54.      fread (&iPYFACount, sizeof (int), 1, fp);
  55. +    iPYFACount = ReverseInt(iPYFACount);
  56.      PYFAList = (PYFA *) malloc (sizeof (PYFA) * iPYFACount);
  57.      if (!PYFAList)
  58.         return False;
  59. @@ -115,11 +127,13 @@
  60.         fread (PYFAList[i].strMap, sizeof (char) * 2, 1, fp);
  61.         PYFAList[i].strMap[2] = '\0';
  62.         fread (&(PYFAList[i].iBase), sizeof (int), 1, fp);
  63. +       PYFAList[i].iBase = ReverseInt(PYFAList[i].iBase);
  64.         PYFAList[i].pyBase = (PyBase *) malloc (sizeof (PyBase) * PYFAList[i].iBase);
  65.         for (j = 0; j < PYFAList[i].iBase; j++) {
  66.             fread (PYFAList[i].pyBase[j].strHZ, sizeof (char) * 2, 1, fp);
  67.             PYFAList[i].pyBase[j].strHZ[2] = '\0';
  68.             fread (&iLen, sizeof (int), 1, fp);
  69. +           iLen = ReverseInt(iLen);
  70.             PYFAList[i].pyBase[j].iIndex = iLen;
  71.             PYFAList[i].pyBase[j].iHit = 0;
  72.             PYFAList[i].pyBase[j].flag = 0;
  73. @@ -169,12 +183,13 @@
  74.         while (!feof (fp)) {
  75.             if (!fread (&i, sizeof (int), 1, fp))
  76.                 break;
  77. +               i = ReverseInt(i);
  78.             if (!fread (strBase, sizeof (char) * 2, 1, fp))
  79.                 break;
  80.             strBase[2] = '\0';
  81.             if (!fread (&k, sizeof (int), 1, fp))
  82.                 break;
  83. -
  84. +               k = ReverseInt(k);
  85.             j = GetBaseIndex (i, strBase);

  86.             PYFAList[i].pyBase[j].iPhrase = k;
  87. diff -uNr fcitx-2.0.1/ui.c fcitx-2.0.1-osx/ui.c
  88. --- fcitx-2.0.1/ui.c    2004-01-04 15:42:01.000000000 +0800
  89. +++ fcitx-2.0.1-osx/ui.c        2004-04-14 10:41:21.000000000 +0800
  90. @@ -5,7 +5,7 @@
  91. #include <stdio.h>
  92. #include <stdlib.h>
  93. #include <string.h>
  94. -#include <malloc.h>
  95. +#include <sys/malloc.h>
  96. #include <iconv.h>

  97. #ifdef _USE_XFT
复制代码

我把它贴出来是因为其中有问题我不太确定:i = ReverseInt(i);和 reverse k 的这两行按照你的patch里的行号似乎就是在这里,但我对他们的位置很迷惑,他们真的是在这里吗?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
发表于 2004-4-14 12:30:51 | 显示全部楼层

为自己的喜欢的软件提交patch而被接受,是一件相当美妙的事情。

总需要有志愿者去做这些进一步完善的工作。
感谢各位的自由协作给我们带来了Fcitx
发表于 2004-4-14 13:48:26 | 显示全部楼层
加入了 puzzlebird 的代码,前面我觉得有疑问的地方是这样该的,不知道位置对不对:

  1. @@ -157,11 +176,17 @@
  2.      else {
  3.         while (!feof (fp)) {
  4.             if (!fread (&i, sizeof (int), 1, fp))
  5. +               #if defined(DARWIN)
  6. +               i = ReverseInt(i);
  7. +               #endif
  8.                 break;
  9.             if (!fread (strBase, sizeof (char) * 2, 1, fp))
  10.                 break;
  11.             strBase[2] = '\0';
  12.             if (!fread (&k, sizeof (int), 1, fp))
  13. +               #if defined(DARWIN)
  14. +               k = ReverseInt(k);
  15. +               #endif
  16.                 break;
复制代码

请有osx的兄弟们从cvs下载源代码,帮忙测试一下是不是可以执行。方法如下:

  1. cvs -d:pserver:anonymous@cvs.cosoft.org.cn:/sfroot/cvs/fcitx login
  2. cvs -z3 -d:pserver:anonymous@cvs.cosoft.org.cn:/sfroot/cvs/fcitx co -r v2_0_1_2-branch-osx fcitx
  3. cd fcitx/
  4. ./configure && make
复制代码

(login提示密码时直接回车)。如果整个编译过程顺序,就可以用 make install 安装了。
发表于 2004-4-16 03:17:22 | 显示全部楼层
开放源码真是爽,高手经常把一个软件移植到另一种千奇百怪机器上。
发表于 2004-4-16 07:41:21 | 显示全部楼层
测试结果(on OS X 10.3.3 (Panther), Darwin 7.3.0, X11 1.0(2004-03-20)):

./configure 正常,make 时出现错误:

  1. $ make
  2. cd . && /bin/sh /Users/minghua/Desktop/work/fcitx/missing --run aclocal-1.6
  3. cd . && \
  4.   /bin/sh /Users/minghua/Desktop/work/fcitx/missing --run automake-1.6 --foreign  Makefile
  5. cd . && /bin/sh /Users/minghua/Desktop/work/fcitx/missing --run autoconf
  6. /bin/sh ./config.status --recheck
  7. running /bin/sh ./configure   --no-create --no-recursion
  8. checking for a BSD-compatible install... /usr/bin/install -c
  9. checking whether build environment is sane... yes
  10. ... (snipped)
  11. checking sys/param.h presence... yes
  12. checking for sys/param.h... yes
  13. checking for unistd.h... (cached) yes
  14. checking for X... libraries /usr/X11R6/lib, headers
  15. ./configure: line 3848: syntax error near unexpected token `XFT,'
  16. ./configure: line 3848: `  PKG_CHECK_MODULES(XFT, xft >= 0.0.0, have_xft=true, :)'
  17. make: *** [config.status] Error 2
复制代码

然后再重新运行 ./configure 出现同样的错误,make clean 也是同样的过程和错误。

感谢 puzzlebird 和 idkey 为 porting 所做的工作。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表