Subversion Repositories Kolibri OS

Rev

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