From 1ef1a0a3a023dab2ca8b2fd382ed29582c7585f9 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Thu, 6 Aug 2015 22:37:34 +0000 Subject: [PATCH] CMM: 1. remove /lib/encoding.h and use iconv library instead, as a result next point 2. better encoding in WebBrowser 3. fix error_init() in lib/dll.h git-svn-id: svn://kolibrios.org@5690 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/TWB/TWB.c | 22 +++- programs/cmm/browser/WebView.c | 17 +-- programs/cmm/downloader/Downloader.c | 1 - programs/cmm/lib/dll.h | 2 +- programs/cmm/lib/encoding.h | 175 --------------------------- programs/cmm/lib/obj/iconv.h | 4 +- programs/cmm/lib/strings.h | 2 +- programs/cmm/liza/liza.c | 3 +- programs/cmm/liza/parselist.c | 31 ++--- programs/cmm/liza/settings.c | 10 -- programs/cmm/tmpdisk/t_gui.c | 2 +- 11 files changed, 45 insertions(+), 224 deletions(-) delete mode 100644 programs/cmm/lib/encoding.h diff --git a/programs/cmm/TWB/TWB.c b/programs/cmm/TWB/TWB.c index 3bf6fb8faa..bc6e8035e6 100644 --- a/programs/cmm/TWB/TWB.c +++ b/programs/cmm/TWB/TWB.c @@ -113,9 +113,9 @@ void BufEncode(int set_new_encoding) { strcpy(bufpointer, o_bufpointer); } - if (set_new_encoding==_WIN) wintodos(bufpointer); - if (set_new_encoding==_UTF) utf8rutodos(bufpointer); - if (set_new_encoding==_KOI) koitodos(bufpointer); + if (set_new_encoding==_WIN) bufpointer = ChangeCharset("CP1251", "CP866", bufpointer); + if (set_new_encoding==_UTF) bufpointer = ChangeCharset("UTF-8", "CP866", bufpointer); + if (set_new_encoding==_KOI) bufpointer = ChangeCharset("KOI8-RU", "CP866", bufpointer); } void TWebBrowser::Prepare(dword bufpos, in_filesize){ @@ -653,3 +653,19 @@ int isTag(dword text) } +:dword Hex2Symb(char* htmlcolor) +{ + dword j=0, symbol=0; + char ch=0x00; + for (;j<2;j++) + { + ch=ESBYTE[htmlcolor+j]; + if (ch==0x0d) || (ch=='\9') RETURN 0; + if ((ch>='0') && (ch<='9')) ch -= '0'; + if ((ch>='A') && (ch<='F')) ch -= 'A'-10; + if ((ch>='a') && (ch<='f')) ch -= 'a'-10; + symbol = symbol*0x10 + ch; + } + AL=symbol; +} + diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index 80489a4d45..318ac9fd93 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -11,7 +11,6 @@ #define MEMSIZE 0x100000 #include "..\lib\strings.h" #include "..\lib\gui.h" -#include "..\lib\encoding.h" #include "..\lib\file_system.h" #include "..\lib\mem.h" #include "..\lib\draw_buf.h" @@ -23,6 +22,7 @@ #include "..\lib\obj\libio_lib.h" #include "..\lib\obj\libimg_lib.h" #include "..\lib\obj\http.h" +#include "..\lib\obj\iconv.h" //useful patterns #include "..\lib\patterns\libimg_load_skin.h" @@ -30,14 +30,14 @@ char homepage[] = FROM "html\\homepage.htm"; #ifdef LANG_RUS - char version[]=" Текстовый браузер 1.15"; + char version[]=" Текстовый браузер 1.16"; ?define IMAGES_CACHE_CLEARED "Кэш картинок очищен" ?define T_LAST_SLIDE "Это последний слайд" char loading[] = "Загрузка страницы...
"; char page_not_found[] = FROM "html\page_not_found_ru.htm"; char accept_language[]= "Accept-Language: ru\n"; #else - char version[]=" Text-based Browser 1.15"; + char version[]=" Text-based Browser 1.16"; ?define IMAGES_CACHE_CLEARED "Images cache cleared" ?define T_LAST_SLIDE "This slide is the last" char loading[] = "Loading...
"; @@ -128,6 +128,7 @@ void main() load_dll(libio, #libio_init,1); load_dll(libimg, #libimg_init,1); load_dll(libHTTP, #http_lib_init,1); + load_dll(iconv_lib, #iconv_open,0); Libimg_LoadImage(#skin, abspath("wv_skin.png")); SetSkinColors(); @@ -332,7 +333,7 @@ void Draw_Window() } -void ChangeCharset(byte new_charset) +void ChangeCharset1(byte new_charset) { BufEncode(new_charset); WB1.Parse(); @@ -349,19 +350,19 @@ void Scan(int id) switch (id) { case 011: //Ctrk+K - ChangeCharset(_KOI); + ChangeCharset1(_KOI); return; case 021: //Ctrl+U - ChangeCharset(_UTF); + ChangeCharset1(_UTF); return; case 004: //Ctrl+D - ChangeCharset(_DOS); + ChangeCharset1(_DOS); return; case 005: //Win encoding - ChangeCharset(_WIN); + ChangeCharset1(_WIN); return; case 009: //free img cache diff --git a/programs/cmm/downloader/Downloader.c b/programs/cmm/downloader/Downloader.c index 188fab2aac..8c38252bea 100644 --- a/programs/cmm/downloader/Downloader.c +++ b/programs/cmm/downloader/Downloader.c @@ -3,7 +3,6 @@ #include "..\lib\kolibri.h" #include "..\lib\strings.h" #include "..\lib\gui.h" -#include "..\lib\encoding.h" #include "..\lib\draw_buf.h" #include "..\lib\file_system.h" #include "..\lib\mem.h" diff --git a/programs/cmm/lib/dll.h b/programs/cmm/lib/dll.h index b4dc975d6f..d2455de681 100644 --- a/programs/cmm/lib/dll.h +++ b/programs/cmm/lib/dll.h @@ -19,7 +19,7 @@ char a_libdir[43] = "/sys/lib/\0"; :inline void error_init(dword text) { dword TEXT_ERROR = malloc(1024); - sprintf("%s `%s`' -E",_TEXT_ERROR_ADD,text); + sprintf(TEXT_ERROR, "%s `%s`' -E",_TEXT_ERROR_ADD,text); notify(TEXT_ERROR); free(TEXT_ERROR); } diff --git a/programs/cmm/lib/encoding.h b/programs/cmm/lib/encoding.h deleted file mode 100644 index 8c101576a1..0000000000 --- a/programs/cmm/lib/encoding.h +++ /dev/null @@ -1,175 +0,0 @@ -#ifndef INCLUDE_ENCODING_H -#define INCLUDE_ENCODING_H -#print "[include ]\n" - -#ifndef INCLUDE_KOLIBRI_H -#include "../lib/kolibri.h" -#endif - -inline fastcall void wintodos( ESI) -{ - while (BL=ESBYTE[ESI]) - { - if (BL>=192) - { - if (BL>=240) ESBYTE[ESI] = BL - 16; - else ESBYTE[ESI] = BL - 64; - } - else - { - if (BL==178) ESBYTE[ESI] = 73; //I - if (BL==179) ESBYTE[ESI] = 105; //i - if (BL==175) ESBYTE[ESI] = 244; //J - if (BL==191) ESBYTE[ESI] = 245; //j - if (BL==170) ESBYTE[ESI] = 242; //E - if (BL==186) ESBYTE[ESI] = 243; //e - if (BL==168) ESBYTE[ESI] = 240; //Ё - if (BL==184) ESBYTE[ESI] = 'e'; //e - if (BL==180) ESBYTE[ESI] = 254; //у - if ((BL==147) || (BL==148) || (BL==171) || (BL==187)) ESBYTE[ESI] = 34; - if ((BL==150) || (BL==151)) ESBYTE[ESI] = 45; - } - ESI++; - } -} - - -byte mas[66] = "юабцдефгхийклмнопярстужвьызшэщчъЮАБЦДЕФГХИЙКЛМНОПЯРСТУЖВЬЫЗШЭЩЧЪ"; -inline fastcall void koitodos( EDI) -{ - while (BL=ESBYTE[EDI]) - { - if (BL >= 0xC0) - { - BL -= 0xC0; - ESBYTE[EDI] = mas[BL]; - } - //if (ESBYTE[EDI]=='\244') ESBYTE[EDI]='i'; - EDI++; - } -} - -//Asper, lev -//uncomplete -inline fastcall void utf8rutodos( ESI) -{ - EDI=ESI; - while (BL=ESBYTE[ESI]) - { - if (BL == 0xD0) || (BL == 0xD1) EDI--; - else if (BL == 0x81) && (ESBYTE[ESI-1]==0xD0) ESBYTE[EDI] = 0xF0; //° - else if (BL == 0x91) && (ESBYTE[ESI-1]==0xD1) ESBYTE[EDI] = 0xF1; //ь - //0xE2 0x80 - ёуЁєяяшЁютрЄ№ - else if (BL == 0xE2) && (ESBYTE[ESI+1]==0x80) - switch (ESBYTE[ESI+2]) - { - case 0x93: //long defis - case 0x94: - { - ESBYTE[EDI] = '-'; - ESI+=2; - break; - } - case 0xA2: //central point - { - ESBYTE[EDI] = '*'; - ESI+=2; - break; - } - case 0xA6: //ьэюуюЄюўшх - { - ESBYTE[EDI] = ESBYTE[EDI+1] = ESBYTE[EDI+2] = '.'; - EDI+=2; - ESI+=2; - break; - } - } - - else if (BL == 0xC2) //ЄрсышЎє яхЁхъюфшЁютюъ? - switch(ESBYTE[ESI+1]) { - case 0xAB: //" - case 0xBB: //" - { - ESBYTE[EDI] = '\"'; - ESI++; - break; - } - case 0xB7: // _ - { - ESBYTE[EDI] = '_'; - ESI++; - break; - } - case 0xA0: // Alt+160 - эхЁрчсштр■∙шщ яЁюсхы - { - ESBYTE[EDI] = ' '; - ESI++; - break; - } - case 0xB0: // уЁрфєё - { - ESBYTE[EDI] = '\29'; - ESI++; - break; - } - case 0xA9: // (c) --- т√ыхЄ ╬_ю - { - ESBYTE[EDI] = 'c'; - ESI++; - break; - } - case 0xAE: // (r) - { - ESBYTE[EDI] = 'r'; - ESI++; - break; - } - } - - else if (BL >= 0x90) && (BL <= 0xAF) - { - BL -= 0x10; - ESBYTE[EDI] = BL; - } - else if (BL >= 0x80) && (BL <= 0x8F) - { - BL += 0x60; - ESBYTE[EDI] = BL; - } - else if (BL >= 0xB0) && (BL <= 0xBF) - { - BL -= 0x10; - ESBYTE[EDI] = BL; - } - else ESBYTE[EDI] = BL; - ESI++; - EDI++; - } - while (EDI='0') && (ch<='9')) ch -= '0'; - if ((ch>='A') && (ch<='F')) ch -= 'A'-10; - if ((ch>='a') && (ch<='f')) ch -= 'a'-10; - symbol = symbol*0x10 + ch; - } - wintodos(#symbol); - AL=symbol; -} - - -#endif \ No newline at end of file diff --git a/programs/cmm/lib/obj/iconv.h b/programs/cmm/lib/obj/iconv.h index 602c499b2e..f107e4fd8f 100644 --- a/programs/cmm/lib/obj/iconv.h +++ b/programs/cmm/lib/obj/iconv.h @@ -57,8 +57,8 @@ dword ChangeCharset(dword from_chs, to_chs, conv_buf) } -char *charsets[] = { " ", "UTF-8", "KOI8-RU", "CP1251", "CP1252", "ISO8859-5", "CP866"}; -int cur_charset; +:char *charsets[] = { " ", "UTF-8", "KOI8-RU", "CP1251", "CP1252", "ISO8859-5", "CP866"}; +:int cur_charset; enum { CH_NULL, CH_UTF8, diff --git a/programs/cmm/lib/strings.h b/programs/cmm/lib/strings.h index 61f5066e39..edb4b36cbf 100644 --- a/programs/cmm/lib/strings.h +++ b/programs/cmm/lib/strings.h @@ -21,7 +21,7 @@ // itoa(signed long number) --- convert the number as a string // atoi(dword text) --- convert a string as a number // strupr( ESI) -// strlwr( ESI) --- kyrillic symbols may not work +// strlwr( ESI) --- Cyrillic symbols may not work // strttl( EDX) // strtok( ESI) // strltrim(dword text) --- removes "blank" characters on the left (\r, \n and space) diff --git a/programs/cmm/liza/liza.c b/programs/cmm/liza/liza.c index b6d5d020c0..7f9aa73288 100644 --- a/programs/cmm/liza/liza.c +++ b/programs/cmm/liza/liza.c @@ -6,7 +6,6 @@ #include "../lib/strings.h" #include "../lib/mem.h" #include "../lib/dll.h" -#include "../lib/encoding.h" #include "../lib/gui.h" #include "../lib/file_system.h" #include "../lib/list_box.h" @@ -106,7 +105,7 @@ void main() { load_dll(netcode_lib, #base64_encode,0); load_dll(libio, #libio_init,1); load_dll(libimg, #libimg_init,1); - if (load_dll2(iconv_lib, #iconv_open,0)!=0) { notify("Error while loading library - iconv.obj"); use_iconv=2; } + load_dll(iconv_lib, #iconv_open,0); OpenMailDat(); SetEventMask(0x27); LoginBoxLoop(); diff --git a/programs/cmm/liza/parselist.c b/programs/cmm/liza/parselist.c index 33be8779da..f318b9258b 100644 --- a/programs/cmm/liza/parselist.c +++ b/programs/cmm/liza/parselist.c @@ -52,26 +52,17 @@ void ParseMail() void ConvertToDOS(dword inbuf, searchin) { dword dos_buf=0; - if (use_iconv==1) - { - cur_charset = CH_CP866; - if (strstri(searchin, "windows-1251")!=0) || (strstri(searchin, "windows1251")!=0) - { dos_buf = ChangeCharset("CP1251", "CP866", inbuf); cur_charset = CH_CP1251;} - else if (strstri(searchin, "koi8-")!=0) - { dos_buf = ChangeCharset("KOI8-RU", "CP866", inbuf); cur_charset = CH_KOI8;} - else if (strstri(searchin, "utf-8")!=0) || (strstri(searchin, "utf8")!=0) - { dos_buf = ChangeCharset("UTF-8", "CP866", inbuf); cur_charset = CH_UTF8;} - else if (strstri(searchin, "iso8859-5")!=0) || (strstri(searchin, "iso-8859-5")!=0) - { dos_buf = ChangeCharset("ISO8859-5", "CP866", inbuf); cur_charset = CH_ISO8859_5;} - else if (strstri(searchin, "windows-1252")!=0) || (strstri(searchin, "windows1252")!=0) - { dos_buf = ChangeCharset("CP1252", "CP866", inbuf); cur_charset = CH_CP1252;} - } - else - { - if (strstri(searchin, "windows-1251")!=0) wintodos( inbuf); else - if (strstri(searchin, "koi8-")!=0) koitodos( inbuf); else - if (strstri(searchin, "utf-8")!=0) utf8rutodos( inbuf); - } + cur_charset = CH_CP866; + if (strstri(searchin, "windows-1251")!=0) || (strstri(searchin, "windows1251")!=0) + { dos_buf = ChangeCharset("CP1251", "CP866", inbuf); cur_charset = CH_CP1251;} + else if (strstri(searchin, "koi8-")!=0) + { dos_buf = ChangeCharset("KOI8-RU", "CP866", inbuf); cur_charset = CH_KOI8;} + else if (strstri(searchin, "utf-8")!=0) || (strstri(searchin, "utf8")!=0) + { dos_buf = ChangeCharset("UTF-8", "CP866", inbuf); cur_charset = CH_UTF8;} + else if (strstri(searchin, "iso8859-5")!=0) || (strstri(searchin, "iso-8859-5")!=0) + { dos_buf = ChangeCharset("ISO8859-5", "CP866", inbuf); cur_charset = CH_ISO8859_5;} + else if (strstri(searchin, "windows-1252")!=0) || (strstri(searchin, "windows1252")!=0) + { dos_buf = ChangeCharset("CP1252", "CP866", inbuf); cur_charset = CH_CP1252;} } diff --git a/programs/cmm/liza/settings.c b/programs/cmm/liza/settings.c index b588b09b9f..00b424a1a3 100644 --- a/programs/cmm/liza/settings.c +++ b/programs/cmm/liza/settings.c @@ -3,7 +3,6 @@ #define CUSTOM 0 #define MANUAL 1 char checked[3] = { 1, 0 }; -int use_iconv = 1; char *text1[] = {"POP server adress:", "POP server port:", "SMTP server adress:", "SMTP server port:", '\0'}; @@ -62,12 +61,6 @@ void SettingsDialog() } OptionsWindow(); } - if (id==20) - { - if (use_iconv==2) break; - if (use_iconv==1) use_iconv=0; else use_iconv=1; - OptionsWindow(); - } break; case evKey: @@ -120,7 +113,4 @@ void OptionsWindow() edit_box_draw stdcall(#POP_server_port_box); edit_box_draw stdcall(#SMTP_server_box); edit_box_draw stdcall(#SMTP_server_port_box); - - WriteTextB(ELEM_X, 205, 0x90, system.color.work_text, "MailBox settings"); - CheckBox(ELEM_X, 230,12, 12, 20, "Use iconv library for converting text charsets", system.color.work_graph, system.color.work_text, use_iconv); } \ No newline at end of file diff --git a/programs/cmm/tmpdisk/t_gui.c b/programs/cmm/tmpdisk/t_gui.c index 3be2fe1113..ccf52da16d 100644 --- a/programs/cmm/tmpdisk/t_gui.c +++ b/programs/cmm/tmpdisk/t_gui.c @@ -227,7 +227,7 @@ void DrawTmpDisks() for (i=0; i