gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Patch] unicode work with gnokii.


From: Pavel Machek
Subject: Re: [Patch] unicode work with gnokii.
Date: Sat, 18 May 2002 00:51:47 +0200
User-agent: Mutt/1.3.28i

Hi!

> here is the patch for cvs. it works in my computer with nokia 6150.I 'm in 
> china , it can send and read the chinese charset.please test it.
> 

> 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     17 May 2002 09:48:31 -0000
> @@ -31,6 +31,7 @@
>  #include <stdlib.h>
>  #include <stdio.h>
>  #include <string.h>
> +#include <wchar.h>
>  
>  #include "misc.h"
>  #include "gsm-common.h"

Is wchar.h available on all systems?

> @@ -252,30 +253,54 @@
>       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; ) {
> +             mbstate_t state;
> +             memset(&state , '\0', sizeof(mbstate_t));
> +             
> +             switch (wctomb ( d + i, (*(src + i) << 8 | * (src +i + 1 )))){
> +             case 2:         /* mulit char  */
> +                     i += 2;
> +                     break;
> +             default:        /* pass the old char */
> +                     *(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; i++) {
> -             wc = EncodeWithUnicodeAlphabet(src[i]);
> -             dest[i*2] = (wc >> 8) & 0xff;
> -             dest[(i*2)+1] = wc & 0xff;
> -     }
> -     return;
> +     for (i = 0; i < len; ) {
> +             mbstate_t state;
> +             wchar_t   wc;
> +             memset(&state , '\0', sizeof(mbstate_t));
> +             
> +             switch (mbtowc (&wc, src + i, 2)){
> +             case 2:         /* mulit char  */
> +                     *(d + i)     =  wc >> 8 & 0xFF;
> +                     *(d + i + 1) =  wc & 0xFF;
> +                     i += 2;
> +                     break;
> +             case 1:         /* ASCII char */
> +                     *(d + i) = 0;
> +                     d ++;
> +             default:        /* pass old char */
> +                     d[i] = *(src + i);
> +                     i += 1;
> +             }
> +        }
> +     return ( (d - dest ) + len);
>  }
>  
>  /* Conversion bin -> hex and hex -> bin */
> Index: common/gsm-sms.c
> ===================================================================
> RCS file: /cvsroot/gnokii/gnokii/common/gsm-sms.c,v
> retrieving revision 1.59
> diff -u -r1.59 gsm-sms.c
> --- common/gsm-sms.c  17 May 2002 00:22:09 -0000      1.59
> +++ common/gsm-sms.c  17 May 2002 09:48:34 -0000
> @@ -91,7 +91,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;
>  }
>  

Is this good idea?

Rest looks okay...

> @@ -355,7 +355,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    17 May 2002 09:48:35 -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);
> 
> 


-- 
I'm address@hidden "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents at address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]