Subversion Repositories Kolibri OS

Rev

Rev 7252 | Rev 7759 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //convert text characters
  2. #ifndef INCLUDE_LIBICONV_H
  3. #define INCLUDE_LIBICONV_H
  4.  
  5. #ifndef INCLUDE_KOLIBRI_H
  6. #include "../lib/kolibri.h"
  7. #endif
  8.  
  9. dword iconv_lib = #a_iconv_lib;
  10. char a_iconv_lib[]="/sys/lib/iconv.obj";
  11.  
  12. dword iconv_open     = #aIconv_open;
  13. dword iconv          = #aIconv;
  14. $DD 2 dup 0
  15.  
  16. char aIconv_open[] = "iconv_open";
  17. char aIconv[]       = "iconv";
  18.  
  19.  
  20. dword ChangeCharset(dword from_chs, to_chs, conv_buf)
  21. {
  22.         dword cd, in_len, out_len, new_buf;    
  23.  
  24.         iconv_open stdcall (from_chs, to_chs); //CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5
  25.         if (EAX==-1)
  26.         {
  27.                 debugln(from_chs);
  28.                 debugln(to_chs);
  29.                 debugln("iconv: wrong charset,\nuse only CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5");
  30.                 return 0;
  31.         }
  32.         cd = EAX;
  33.  
  34.         in_len = out_len = strlen(conv_buf)+1;
  35.         new_buf = mem_Alloc(in_len);
  36.         iconv stdcall (cd, #conv_buf, #in_len, #new_buf, #out_len);
  37.         cd = EAX;
  38.         if (cd!=0)
  39.         {
  40.                 debugval("iconv: something is wrong with stdcall iconv()", cd);
  41.                 debugval("in_len", in_len);
  42.                 debugval("out_len", out_len);
  43.                 new_buf = free(new_buf);
  44.                 return 0;
  45.         }
  46.         strcpy(conv_buf, new_buf);
  47.         free(new_buf);
  48.         return conv_buf;
  49. }
  50.  
  51.  
  52. :int cur_charset;
  53. :char *charsets[] = { "UTF-8", "KOI8-RU", "CP1251", "CP1252", "ISO8859-5", "CP866", 0 };
  54. enum { CH_UTF8, CH_KOI8, CH_CP1251, CH_CP1252, CH_ISO8859_5, CH_CP866, CH_NULL };
  55.  
  56. #endif