[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Patch] unicode work with gnokii.
From: |
Hu Gang |
Subject: |
Re: [Patch] unicode work with gnokii. |
Date: |
Wed, 29 May 2002 08:45:37 +0800 |
On Mon, 27 May 2002 14:11:16 +0200
"Pawel Kot" <address@hidden> wrote:
|Why don't you do it in DecodeWithUnicodeAlphabet()?
|
in next patch , i will try it.
? Makefile.global
? config.cache
? config.log
? config.status
? configure
? common/gsm-sms.c.u
? common/vcal.c
? include/config.h
? include/config.h.in
? packaging/RedHat/gnokii.spec
? packaging/Slackware/SlackBuild
? po/Makefile
? po/Makefile.in
? po/gnokii.pot
Index: common/gsm-encoding.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/gsm-encoding.c,v
retrieving revision 1.19
diff -u -r1.19 gsm-encoding.c
--- common/gsm-encoding.c 18 Apr 2002 21:22:50 -0000 1.19
+++ common/gsm-encoding.c 28 May 2002 11:54:30 -0000
@@ -252,30 +252,65 @@
return;
}
-void DecodeUnicode(unsigned char* dest, const unsigned char* src, int len)
+int DecodeUnicode(unsigned char* dest, const unsigned char* src, int len)
{
int i;
- wchar_t wc;
+ unsigned char * d = dest;
- for (i = 0; i < len; i++) {
- wc = src[(2 * i) + 1] | (src[2 * i] << 8);
- dest[i] = DecodeWithUnicodeAlphabet(wc);
+ for (i = 0; i < len;) {
+ wchar_t wc;
+ wc = src[i] << 8 | src[i + 1]; /* convert the stream data to
+ * wide character */
+ switch (wctomb ( d + i, wc)){
+ case 2: /* one wide character converts to two multibyte
+ * data */
+ i += 2;
+ break;
+ default: /* convert one wide character to multibyte
failed
+ * the src[i] is zero in most times,
+ * so copy src[i+1]
+ * d-- is make dest only add on character */
+ d [i]= src [i + 1];
+ d --;
+ i += 2;
+ break;
+ }
}
- dest[len] = 0;
- return;
+
+ return ((d - dest) + len);
+
}
-void EncodeUnicode(unsigned char* dest, const unsigned char* src, int len)
+int EncodeUnicode(unsigned char* dest, const unsigned char* src, int len)
{
int i;
- wchar_t wc;
+ unsigned char * d = dest;
+
+ for (i = 0; i < len; ) {
+ wchar_t wc;
+ switch (mbtowc (&wc, src + i, 2)){
+ case 2: /* convert two multibyte to wide character
passed*/
+ d[i] = wc >> 8 & 0xff;
+ d[i + 1] = wc & 0xff;
+ i += 2;
+ break;
+ case 1: /* convert one multibyte to wide character
passed
+ * it possible is an ACSSII code so let the
first
+ * is zero and copy the mulitibyte to dest */
+ d[i] = 0;
+ d[i + 1] = src[i];
+ i ++;
+ d ++;
+ break;
+ default: /* convert failed and try to recover it so copy
+ * it to dest */
+ d[i] = src[i];
+ i += 1;
+ break;
+ }
+ }
+ return ((d - dest ) + len);
- for (i = 0; i < len; i++) {
- wc = EncodeWithUnicodeAlphabet(src[i]);
- dest[i*2] = (wc >> 8) & 0xff;
- dest[(i*2)+1] = wc & 0xff;
- }
- return;
}
/* Conversion bin -> hex and hex -> bin */
Index: common/gsm-sms.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/gsm-sms.c,v
retrieving revision 1.80
diff -u -r1.80 gsm-sms.c
--- common/gsm-sms.c 27 May 2002 22:56:50 -0000 1.80
+++ common/gsm-sms.c 28 May 2002 11:54:33 -0000
@@ -92,7 +92,7 @@
sms->Validity = 4320; /* 4320 minutes == 72 hours */
sms->DCS.Type = SMS_GeneralDataCoding;
sms->DCS.u.General.Compressed = false;
- sms->DCS.u.General.Alphabet = SMS_DefaultAlphabet;
+ sms->DCS.u.General.Alphabet = SMS_UCS2;
sms->DCS.u.General.Class = 0;
}
@@ -356,7 +356,7 @@
/* Unicode */
if ((dcs.Type & 0x08) == 0x08) {
dprintf("Unicode message\n");
- DecodeUnicode(output, message, length);
+ length = DecodeUnicode(output, message, length);
} else {
/* 8bit SMS */
if ((dcs.Type & 0xf4) == 0xf4) {
Index: include/gsm-encoding.h
===================================================================
RCS file: /cvsroot/gnokii/gnokii/include/gsm-encoding.h,v
retrieving revision 1.9
diff -u -r1.9 gsm-encoding.h
--- include/gsm-encoding.h 4 Apr 2002 22:35:37 -0000 1.9
+++ include/gsm-encoding.h 28 May 2002 11:54:34 -0000
@@ -40,8 +40,8 @@
unsigned char *input, unsigned char *output);
int Pack7BitCharacters(int offset, unsigned char *input, unsigned char
*output);
-void DecodeUnicode (unsigned char* dest, const unsigned char* src, int len);
-void EncodeUnicode (unsigned char* dest, const unsigned char* src, int len);
+int DecodeUnicode (unsigned char* dest, const unsigned char* src, int len);
+int EncodeUnicode (unsigned char* dest, const unsigned char* src, int len);
void DecodeAscii (unsigned char* dest, const unsigned char* src, int len);
void EncodeAscii (unsigned char* dest, const unsigned char* src, int len);
--
thanks with regards!
hugang.
************************************
Beijing Soul Technology Co.,Ltd.
Tel:010-68425741/42/43/44
Fax:010-68425745
email:address@hidden
web:http://www.soul.com.cn
Developer, Debian GNU/Linux
***********************************
1.diff
Description: Text document