The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

Установка браузера Dillo с поддержкой кириллицы. (linux browser web rus charset patch)


<< Предыдущая ИНДЕКС Правка src / Печать Следующая >>
Ключевые слова: linux, browser, web, rus, charset, patch,  (найти похожие документы)
From: Шевченко Александр <pzp-5@ukr.net.> Newsgroups: email Date: Mon, 20 Feb 2006 14:31:37 +0000 (UTC) Subject: Установка браузера Dillo с поддержкой кириллицы. Я поборол поставленную перед собой задачу - поднять "Дилло" на слабом компьютере.Гугл прямого решения не дал, поэтому делюсь с сообществом собственным опытом установки сверхлегкого браузера (пусть его версия устаревшая, но, - работает) на слабую машинку. Основная ссылка: http://bobuk.ipost.ru/packages/dillo/ Остальное - гугл. Собираем из исходных текстов с патчами для русификации: (Патчи - http://bobuk.ipost.ru/packages/dillo/) tar xzvf dillo-0.6.6.tar.gz cp dillo-0.6.6-*.patch dillo-0.6.6/ cd dillo-0.6.6 patch -p0 < dillo-0.6.6-encodings.patch patch -p0 < dillo-0.6.6-fontset.patch aclocal autoconf ./configure make make install Копируем файлы необходимые для перекодирования: mkdir ~/.dillo cp dillorc encodings ~/.dillo/ Или ставим бинарную версию из комплекта ASPLinux. У меня система - Дип-1.0/Слака-10.0): 1) Качаем это: bobuk.ipost.ru/packages/dillo/files...-5.asp.i386.rpm 2) Делаем (под рутом) rpm -i --nodeps /путь_к_нашему_РПМ/dillo-0.6.6-5.asp.i386.rpm Пытался запустить (естественно от юзера и из консоли) - выругалось на отсутствие библиотеки libpng.so.2 3) Качаем нужную библиотеку (я это сделал отсюда): ftp://ftp.fact400.ru/pub/Linux/redhat-6.2...lib/libpng.so.2 4) Копируем (или перемещаем) ее под рутом в /usr/lib/ 5) Чтобы новая библиотека "зарисовалась" в компе, делаем: # ldconfig 6) Запускаем dillo из командной строки и выходим - это, чтобы образовалось ~./dillo/* 7) Копируем/перезаписываем (под рутом, наверное, но не забываем дать права на чтение/запись юзверю) содержимое /etc/skel/.dillo/* в ~./dillo/* 8) Редактируем файл ~./dillo/dillorc ( параметры, что менял я, к примеру): geometry=800x600 # это чтобы у меня на полный экран запускалось vw_fontname=helvetica # шрифта lucida у меня нет, поэтому поставил наобум другое http_proxy=http://192.168.0.1:3128 # это мой прокси-сервер font_charset=koi8-r 9) Наслаждаемся работой браузера быстрого, как свет.
dillo-0.6.6-charset.patch Оригинал статьи diff -BurN dillo-0.6.6.old/dillorc dillo-0.6.6/dillorc --- dillo-0.6.6.old/dillorc Thu May 30 01:36:08 2002 + dillo-0.6.6/dillorc Sat Jun 1 17:31:30 2002 @@ -35,6 +35,9 @@ # If you prefer oblique over italic fonts, uncoment next line #use_oblique=YES +# Use this value as charset part of font for loading. (default is iso8859-1) +# font_charset=iso8859-5 + # Show ALT popup for images? show_alt=YES diff -BurN dillo-0.6.6.old/src/dw_style.c dillo-0.6.6/src/dw_style.c --- dillo-0.6.6.old/src/dw_style.c Tue May 28 05:14:03 2002 + dillo-0.6.6/src/dw_style.c Sat Jun 1 17:31:30 2002 @@ -243,45 +243,44 @@ { char fontname[256], *ItalicChar; - ItalicChar = prefs.use_oblique ? "o" : "i"; - sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-iso8859-1", - font->name, - font->bold ? "bold" : "medium", - font->italic ? ItalicChar : "r", - font->size); - font->font = gdk_font_load(fontname); - - if (font->font == NULL && font->italic) { - sprintf(fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-iso8859-1", + ItalicChar = prefs.use_oblique ? "o" : "i"; + sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-%s", font->name, font->bold ? "bold" : "medium", - (*ItalicChar == 'o') ? "i" : "o", - font->size); - font->font = gdk_font_load(fontname); - } - - if (try_all) { - if (font->font == NULL) { - /* Can't load the font - substitute the default instead. */ - font->font = - gdk_font_load - ("-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-iso8859-1"); - } - - if (font->font == NULL) { - /* Try another platform-font that should be available. (iPaq) */ - font->font = - gdk_font_load - ("-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-1"); - } - - if (font->font == NULL) { - /* Can't load any suitable font! */ - g_warning ("Can't load any ISO8859-1 font!?! :("); - font->font = - gdk_font_load("-adobe-helvetica-*-*-*--*-*-*-*-*-*-*-*"); - } - } + font->italic ? ItalicChar : "r", + font->size, + prefs.font_charset); + font->font = gdk_font_load(fontname); + + if (font->font == NULL && font->italic) { + sprintf(fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-%s", + font->name, + font->bold ? "bold" : "medium", + (*ItalicChar == 'o') ? "i" : "o", + font->size, + prefs.font_charset); + font->font = gdk_font_load(fontname); + } + + if (try_all) { + if (font->font == NULL) { + /* Can't load the font - substitute the default instead. */ + sprintf(fontname,"-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-%s",prefs.font_charset); + font->font = gdk_font_load (fontname); + } + + if (font->font == NULL) { + /* Try another platform-font that should be available. (iPaq) */ + sprintf(fontname,"-misc-fixed-medium-r-normal--13-120-75-75-c-80-%s",prefs.font_charset); + font->font = gdk_font_load (fontname); + } + + if (font->font == NULL) { + /* Can't load any suitable font! */ + g_warning ("Can't load any font with charset '%s'!?! :(",prefs.font_charset); + font->font = gdk_fontset_load("-adobe-helvetica-*-*-*--*-*-*-*-*-*-*-*,-misc-fixed-*,*"); + } + } if (font->font) { font->space_width = gdk_char_width (font->font, ' '); diff -BurN dillo-0.6.6.old/src/prefs.c dillo-0.6.6/src/prefs.c --- dillo-0.6.6.old/src/prefs.c Wed Apr 3 20:31:46 2002 + dillo-0.6.6/src/prefs.c Sat Jun 1 17:31:30 2002 @@ -52,6 +52,7 @@ { "small_icons", DRC_TOKEN_SMALL_ICONS }, { "limit_text_width", DRC_TOKEN_LIMIT_TEXT_WIDTH }, { "font_factor", DRC_TOKEN_FONT_FACTOR }, + { "font_charset", DRC_TOKEN_FONT_CHARSET }, { "use_dicache", DRC_TOKEN_USE_DICACHE }, { "show_back", DRC_TOKEN_SHOW_BACK }, { "show_forw", DRC_TOKEN_SHOW_FORW }, @@ -172,6 +173,10 @@ case DRC_TOKEN_FONT_FACTOR: prefs.font_factor = strtod(scanner->value.v_string, NULL); break; + case DRC_TOKEN_FONT_CHARSET: + if (prefs.font_charset) g_free(prefs.font_charset); + prefs.font_charset = g_strdup(scanner->value.v_string); + break; case DRC_TOKEN_LIMIT_TEXT_WIDTH: prefs.limit_text_width = (strcmp(scanner->value.v_string, "YES") == 0); break; @@ -338,6 +343,7 @@ prefs.small_icons = FALSE; prefs.limit_text_width = FALSE; prefs.font_factor = 1.0; + prefs.font_charset = g_strdup("iso8859-1"); prefs.use_dicache = FALSE; prefs.show_back=TRUE; prefs.show_forw=TRUE; @@ -374,6 +380,8 @@ g_free(prefs.no_proxy); if (prefs.no_proxy_vec) g_strfreev(prefs.no_proxy_vec); + if (prefs.font_charset) + g_free (prefs.font_charset); a_Url_free(prefs.http_proxy); g_free(prefs.fw_fontname); g_free(prefs.vw_fontname); diff -BurN dillo-0.6.6.old/src/prefs.h dillo-0.6.6/src/prefs.h --- dillo-0.6.6.old/src/prefs.h Wed Apr 3 20:31:46 2002 + dillo-0.6.6/src/prefs.h Sat Jun 1 17:31:30 2002 @@ -40,6 +40,7 @@ DRC_TOKEN_PANEL_SIZE, DRC_TOKEN_SMALL_ICONS, DRC_TOKEN_FONT_FACTOR, + DRC_TOKEN_FONT_CHARSET, DRC_TOKEN_SHOW_ALT, DRC_TOKEN_LIMIT_TEXT_WIDTH, DRC_TOKEN_USE_DICACHE, @@ -84,6 +85,7 @@ gboolean small_icons; gboolean limit_text_width; gdouble font_factor; + char *font_charset; gboolean use_dicache; gboolean show_back; gboolean show_forw;
dillo-0.6.6-encodings.patch diff -BurN dillo-0.6.6.old/Makefile.am dillo-0.6.6/Makefile.am --- dillo-0.6.6.old/Makefile.am Sat Jun 1 18:00:09 2002 + dillo-0.6.6/Makefile.am Sat Jun 1 18:02:02 2002 @@ -1,17 +1,21 @@ SUBDIRS = doc src -EXTRA_DIST = ChangeLog dillorc +EXTRA_DIST = ChangeLog dillorc encodings install-data-local: dillorc -if [ -d $(DESTDIR)$(sysconfdir) ]; then \ $(INSTALL_DATA) --backup=t $(srcdir)/dillorc $(DESTDIR)$(sysconfdir)/; \ + $(INSTALL_DATA) --backup=t $(srcdir)/encodings $(DESTDIR)$(sysconfdir)/; \ elif [ -d /etc/ ]; then \ $(INSTALL_DATA) --backup=t $(srcdir)/dillorc /etc/; \ + $(INSTALL_DATA) --backup=t $(srcdir)/encodings /etc/; \ fi uninstall-local: -if [ -d $(DESTDIR)$(sysconfdir) ]; then \ rm -f $(DESTDIR)$(sysconfdir)/dillorc*; \ + rm -f $(DESTDIR)$(sysconfdir)/encodings*; \ elif [ -d /etc/ ]; then \ - rm -f /etc/dillorc* + rm -f /etc/dillorc*; \ + rm -f /etc/encodings* ;\ fi diff -BurN dillo-0.6.6.old/encodings dillo-0.6.6/encodings --- dillo-0.6.6.old/encodings Thu Jan 1 03:00:00 1970 + dillo-0.6.6/encodings Sat Jun 1 18:02:02 2002 @@ -0,0 +1,18 @@ +<enc value="ASCII">7-bit ASCII</enc> +<enc value="ISO8859-1">Western European (ISO 8859-1)</enc> +<enc value="ISO8859-15">Western European (ISO 8859-15)</enc> +<enc value="CP1252">Western European (CodePage1252)</enc> +<enc value="ISO8859-2">Central European (ISO 8859-2)</enc> +<enc value="CP1250">Central European (CodePage1250)</enc> +<enc value="ISO8859-3">Southern European (ISO 8859-3)</enc> +<enc value="KOI8-R">Cyrillic (KOI8-R)</enc> +<enc value="CP1251">Cyrillic (CodePage1251)</enc> +<enc value="IBM866">Cyrillic (IBM866)</enc> +<enc value="ISO8859-13">Baltic (ISO 8859-13)</enc> +<enc value="ISO8859-4">Baltic (ISO 8859-4)</enc> +<enc value="CP1257">Baltic (CodePage1257)</enc> +<enc value="ISO8859-10">Nordic (ISO 8859-10)</enc> +<enc value="ISO8859-14">Celtic (ISO 8859-14)</enc> +<enc value="KOI8-U">Ukraine (KOI8-U)</enc> +<enc value="UTF-8">Unicode (UTF-8)</enc> +<enc value="UTF-16">Unicode (UTF-16)</enc> diff -BurN dillo-0.6.6.old/src/Makefile.am dillo-0.6.6/src/Makefile.am --- dillo-0.6.6.old/src/Makefile.am Sat Jun 1 18:00:09 2002 + dillo-0.6.6/src/Makefile.am Sat Jun 1 18:02:03 2002 @@ -51,6 +51,9 @@ dw_tooltip.h \ dw_widget.c \ dw_widget.h \ + encodings.c \ + encodings.h \ + encoding-types.h \ findtext.c \ findtext.h \ web.c \ diff -BurN dillo-0.6.6.old/src/browser.h dillo-0.6.6/src/browser.h --- dillo-0.6.6.old/src/browser.h Sat Jun 1 18:00:09 2002 + dillo-0.6.6/src/browser.h Sat Jun 1 18:02:03 2002 @@ -4,10 +4,8 @@ #include <sys/types.h> #include <gdk/gdk.h> #include <gtk/gtk.h> - #include "url.h" /* for DilloUrl */ - - +#include "encodings-types.h" typedef struct _BrowserWindow BrowserWindow; typedef struct _DilloMenuPopup DilloMenuPopup; @@ -58,6 +56,9 @@ /* The bookmarks menu so that we can add things to it. */ GtkWidget *bookmarks_menu; + /* The encoding menu */ + GtkWidget *enc_menu; + /* The "Headings" and "Anchors" menus */ GtkWidget *pagemarks_menuitem; GtkWidget *pagemarks_menu; @@ -118,6 +119,10 @@ /* The tag for the idle function that sets button sensitivity. */ gint sens_idle_tag; + + /* encodings variable */ + gchar* encoding; /* the selected character set (pointer to static content -don't free it*/ + deConversion dcv; /* handle for character set conversion */ }; diff -BurN dillo-0.6.6.old/src/dillo.c dillo-0.6.6/src/dillo.c --- dillo-0.6.6.old/src/dillo.c Sat Jun 1 18:00:09 2002 + dillo-0.6.6/src/dillo.c Sat Jun 1 18:02:03 2002 @@ -22,6 +22,13 @@ #include <stdio.h> #include <gtk/gtk.h> +#ifdef HAVE_LANGINFO +#include <langinfo.h> +#if ! defined(CODESET) && defined (_NL_CTYPE_CODESET_NAME) +#define CODESET _NL_CTYPE_CODESET_NAME +#endif +#endif + #include <sys/types.h> #include <sys/stat.h> #include <string.h> @@ -37,6 +44,7 @@ #include "nav.h" #include "history.h" #include "bookmark.h" +#include "encodings.h" #include "dicache.h" #include "dns.h" #include "IO/Url.h" @@ -61,6 +69,7 @@ gint main(int argc, char *argv[]) { gchar *file; + gchar *loctmp; DilloUrl *start_url; BrowserWindow *bw; @@ -68,7 +77,21 @@ * todo: implement a cleaner mechanism (in file.c) */ signal(SIGPIPE, SIG_IGN); - g_print("Setting locale to %s\n", gtk_set_locale()); + curr_locale=gtk_set_locale(); +#ifdef HAVE_LANGINFO + curr_locale = nl_langinfo(CODESET); +#else + loctmp = strchr(curr_locale, '.'); + if (loctmp != NULL) { + gchar** trk = g_strsplit(++loctmp, ";", 1); + curr_locale = g_strdup(trk[0]); + g_strfreev(trk); + } else { + curr_locale = "ASCII"; + } +#endif + + g_print("Setting locale to %s\n",curr_locale); gtk_init(&argc, &argv); gdk_rgb_init(); @@ -92,6 +115,7 @@ bw = a_Interface_browser_window_new(prefs.width, prefs.height); a_Bookmarks_init(); + a_Encodings_init(); /* Send dillo startup screen */ start_url = a_Url_new("splash", "about:", 0, 0); diff -BurN dillo-0.6.6.old/src/dillo.h dillo-0.6.6/src/dillo.h --- dillo-0.6.6.old/src/dillo.h Sat Jun 1 18:00:09 2002 + dillo-0.6.6/src/dillo.h Sat Jun 1 18:02:03 2002 @@ -6,4 +6,5 @@ #define DILLO_HOME "http://dillo.cipsga.org.br/" +char* curr_locale; #endif /* __DILLO_H__ */ diff -BurN dillo-0.6.6.old/src/encodings-types.h dillo-0.6.6/src/encodings-types.h --- dillo-0.6.6.old/src/encodings-types.h Thu Jan 1 03:00:00 1970 + dillo-0.6.6/src/encodings-types.h Sat Jun 1 18:02:03 2002 @@ -0,0 +1,19 @@ +#ifndef __DILLO_ENCODING_TYPES_H__ +#define __DILLO_ENCODING_TYPES_H__ +#include <iconv.h> +/* Copyright (C) 2002 Grigory Bakunov <black@asplinux.ru.> */ + +typedef struct _deConversion deConversion; + +struct _deConversion { + iconv_t c_from; + iconv_t c_to; +}; + + +typedef enum { + DE_DECODE, + DE_ENCODE +} deDirection; + +#endif /* __DILLO_ENCODING_TYPES_H__ */ diff -BurN dillo-0.6.6.old/src/encodings.c dillo-0.6.6/src/encodings.c --- dillo-0.6.6.old/src/encodings.c Thu Jan 1 03:00:00 1970 + dillo-0.6.6/src/encodings.c Sat Jun 1 18:02:03 2002 @@ -0,0 +1,376 @@ +/* cruelty :) */ + +/* Copyright (C) 2002 Grigory Bakunov <black@asplinux.ru.> */ + +/* Copyright (C) 1997 Ian Main + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <gtk/gtk.h> + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "list.h" +#include "interface.h" +#include "dillo.h" +#include "nav.h" +#include "browser.h" +#include "menu.h" +#include "misc.h" +#include "url.h" + +#define LOAD_ENCODINGS 1 +#define SAVE_ENCODING 2 +#define CLOSE_ENCODINGS 3 + +/* this #define will cut page title if > 39 chars */ +#define TITLE39 + +/* double quote */ +#define D_QUOTE 0x22 + +/* Data types */ + +typedef struct _Encoding Encoding; +typedef struct _CallbackInfo CallbackInfo; + +struct _Encoding { + char *title; + char *iconv_name; + GtkWidget *menuitem; +}; + +struct _CallbackInfo { + BrowserWindow *bw; + guint index; +}; + +/* + * Forward declarations + */ +static void + Encodings_load_to_menu(FILE *fp), + Encodings_file_op(gint operation, const char *title, const char *iconv_name), + Encodings_save_to_file(FILE *fp, const char *title, const char *iconv_name); + +static char* + Encodings_search_line(char *line, char *start_text, char *end_text); + +/* + * Local data + */ +static Encoding *encodings = NULL; +static gint num_encodings = 0; +static gint num_encodings_max = 16; + + +/* + * Allocate memory and load the encodings list + */ +void a_Encodings_init(void) +{ + gchar *file; + + /* Here we load and set the encodings */ + file = a_Misc_prepend_user_home(".dillo/encodings"); + Encodings_file_op(LOAD_ENCODINGS, file, NULL); + g_free(file); +} + +/* + * ? + */ +void Encodings_set_encoding(GtkWidget *widget, CallbackInfo *CbInfo) +{ + if (CbInfo->index >= num_encodings) { + g_warning("encoding not found!\n"); + return; + } + g_print("Selected encoding: %s\n",encodings[CbInfo->index].iconv_name); + CbInfo->bw->encoding=encodings[CbInfo->index].iconv_name; + a_Nav_reload(CbInfo->bw); + /*HERE!!! LOOKOUT!!!! */ +} + +/* + * Add a encoding to the encodings menu of a particular browser window + */ +void Encodings_add_to_menu(BrowserWindow *bw, GtkWidget *menuitem, guint index) +{ + CallbackInfo *CbInfo; + + gtk_menu_append(GTK_MENU(bw->enc_menu), menuitem); + + CbInfo = g_new(CallbackInfo, 1); + CbInfo->bw = bw; + CbInfo->index = index; + + /* accelerator goes here */ + gtk_signal_connect(GTK_OBJECT (menuitem), "activate", + (GtkSignalFunc)Encodings_set_encoding, CbInfo); +} + +/* + * ? + */ +static GtkWidget *Encodings_insert(const char *title, const char *iconv_name) +{ + GtkWidget *menuitem; + + menuitem = gtk_menu_item_new_with_label(title); + gtk_widget_show(menuitem); + + a_List_add(encodings, num_encodings, num_encodings_max); + encodings[num_encodings].title = g_strdup(title); + encodings[num_encodings].iconv_name = g_strdup(iconv_name); + encodings[num_encodings].menuitem = menuitem; + num_encodings++; + return menuitem; +} + +/* + * Add the new encoding to encodings menu of _all_ browser windows and then + * write the new encoding to file + */ +/* +void a_Encodings_add(GtkWidget *widget, gpointer client_data) +{ + BrowserWindow *bw = (BrowserWindow *)client_data; + gint i; +#ifdef TITLE39 + gboolean allocated = FALSE; +#endif + char *title; + char *iconv_name; + GtkWidget *menuitem; + + title = bw->menu_popup.info.title; + iconv_name = bw->menu_popup.info.iconv_name; + +#ifdef TITLE39 + if (strlen (title) > 39) { + char buf1[20]; + char buf2[20]; + + memcpy (buf1, title, 18); + buf1[18] = '\0'; + strcpy (buf2, title + strlen (title) - 18); + buf2[18] = '\0'; + title = g_strconcat (buf1, "...", buf2, NULL); + allocated = TRUE; + } +#endif + + menuitem = Encodings_insert(title, iconv_name); + Encodings_add_to_menu(browser_window[0], menuitem, num_encodings-1); + for (i = 1; i < num_bw; i++) { + menuitem= gtk_menu_item_new_with_label(encodings[num_encodings-1].title); + gtk_widget_show(menuitem); + Encodings_add_to_menu(browser_window[i], menuitem, num_encodings-1); + } + + Encodings_file_op(SAVE_ENCODING, title, iconv_name); + +#ifdef TITLE39 + if (allocated) + g_free (title); +#endif +} +*/ +/* + * Never called (the file remains open all the time) --Jcid + */ +void Encodings_close(void) +{ + Encodings_file_op(CLOSE_ENCODINGS, NULL, NULL); +} + +/* + * Performs operations on the encoding file.. + * for first call, title is the filename + */ +static void + Encodings_file_op(gint operation, const char *title, const char *iconv_name) +{ + static FILE *fp; + static gint initialized = 0; + + if (!initialized) { + if (operation == LOAD_ENCODINGS) { + if ((fp = fopen(title, "a+")) == NULL) + g_print("dillo: opening encoding file %s: %s\n", + title, strerror(errno)); + else + initialized = 1; + } else + g_print("Error: invalid call to Encodings_file_op.\n"); + } + + g_return_if_fail( initialized ); + + switch (operation) { + case LOAD_ENCODINGS: + Encodings_load_to_menu(fp); + break; + + case SAVE_ENCODING: + Encodings_save_to_file(fp, title, iconv_name); + break; + + case CLOSE_ENCODINGS: + fclose(fp); + break; + + default: + break; + } +} + +/* + * Save encodings to ~/.dillo/encodings + */ +static void + Encodings_save_to_file(FILE *fp, const char *title, const char* iconv_name) +{ + fseek(fp, 0L, SEEK_END); + fprintf(fp, "<enc value=\"%s\">%s</a>\n", iconv_name,title); + fflush(fp); +} + +/* + * Load encodings + */ +static void Encodings_load_to_menu(FILE *fp) +{ + gchar *title=NULL; + gchar *iconv_name=NULL; + char buf[4096]; + gint i = 0; + GtkWidget *menuitem; + + rewind(fp); + + g_print("Loading encodings...\n"); + while (1) { + /* Read a whole line from the file */ + if ((fgets(buf, 4096, fp)) == NULL) + break; + + /* get url from line */ + if ( !(iconv_name = Encodings_search_line(buf, "=\"", "\">")) ) + continue; + + /* get title from line */ + if ( !(title = Encodings_search_line(buf, "\">", "</")) ){ + g_free(iconv_name); + continue; + } + printf("%s = %s\n",title,iconv_name); + menuitem = Encodings_insert(title, iconv_name); + Encodings_add_to_menu(browser_window[0], menuitem, i); + g_free(iconv_name); + g_free(title); + i++; + } +} + +/* + * Copy encodings when new browser windows are opened. + * Called by 'a_Menu_mainbar_new()' + */ +void a_Encodings_fill_new_menu(BrowserWindow *bw) +{ + gint i; + GtkWidget *menuitem; + + for (i = 0; i < num_encodings; i++) { + menuitem = gtk_menu_item_new_with_label(encodings[i].title); + gtk_widget_show(menuitem); + Encodings_add_to_menu(bw, menuitem, i); + } +} + +static char * + Encodings_search_line(char *line, char *start_text, char *end_text) { + gint segment_length; + char *start_index, *end_index; + + /* if string is not found, return NULL */ + if ((start_index = strstr(line, start_text)) == NULL) + return (NULL); + if ((end_index = strstr(line, end_text)) == NULL) + return (NULL); + + /* adjustment cause strstr returns the start of the text */ + start_index += strlen(start_text); + + /* find length of text segment */ + segment_length = end_index - start_index; + return g_strndup(start_index, segment_length); +}; + +void a_Encoding_get_conversion(BrowserWindow *bw, char* charset) { + bw->dcv.c_from=iconv_open(curr_locale,charset); + bw->dcv.c_to=iconv_open(charset,curr_locale); + if (bw->dcv.c_from == (iconv_t)-1 || bw->dcv.c_to == (iconv_t)-1) + g_warning ("could not allocate character encoding converter."); + return; +}; + +#define MAX_CHAR_SIZE 4 +gchar *a_Encoding_translate_encoding(deConversion dcv, gchar *buf, gint bufsize,deDirection dir) { + char *result, *source, *dest; + size_t s_left, d_left; + iconv_t conversion; + if (dir==DE_DECODE) + conversion=dcv.c_from; + else + conversion=dcv.c_to; + /* no conversion is needed, or none is available */ + if (conversion == (iconv_t)-1) + return g_strndup(buf, bufsize); + + /* Note that for some conversions, the translated buffer can be larger + * than the input buffer. This is particularly important for conversions + * to UTF8 (check the unicode standard to find out the scale factor). */ + result = g_malloc((bufsize + 1)*MAX_CHAR_SIZE); + + source = buf; + dest = result; + s_left = bufsize; + d_left = bufsize*MAX_CHAR_SIZE; + if (iconv(conversion, &source, &s_left, &dest, &d_left) + == (size_t)-1) { + g_warning ("unable to fully convert page to native character set"); + /* This just skips past unconvertable characters, putting "?" in the + * output, then retries the conversion. This is a hack, but it seems + * like the best course of action in the circumstances. */ + while (s_left > 0 && d_left > 0 && errno == EILSEQ) { + source++; + s_left--; + *dest = '?'; + dest++; + d_left--; + if (s_left > 0 && d_left > 0) + iconv(conversion, &source, &s_left, &dest, &d_left); + } + } + *dest = 0; /* terminate the string */ + return result; +} diff -BurN dillo-0.6.6.old/src/encodings.h dillo-0.6.6/src/encodings.h --- dillo-0.6.6.old/src/encodings.h Thu Jan 1 03:00:00 1970 + dillo-0.6.6/src/encodings.h Sat Jun 1 18:02:03 2002 @@ -0,0 +1,18 @@ +#ifndef __DILLO_ENCODING_H__ +#define __DILLO_ENCODING_H__ +#include <gtk/gtk.h> +#include <iconv.h> +#include "browser.h" +#include "encodings-types.h" + + +/* Copyright (C) 2002 Grigory Bakunov <black@asplinux.ru.> */ + +void a_Encodings_init(); +void a_Encodings_add(GtkWidget *widget, gpointer client_data); +void a_Encodings_fill_new_menu(BrowserWindow *bw); +void a_Encoding_get_conversion(BrowserWindow *bw, char* charset); +char *a_Encoding_translate_encoding(deConversion dcv, char *buf, + gint bufsize,deDirection dir); + +#endif /* __DILLO_ENCODING_H__ */ diff -BurN dillo-0.6.6.old/src/html.c dillo-0.6.6/src/html.c --- dillo-0.6.6.old/src/html.c Sat Jun 1 18:00:09 2002 + dillo-0.6.6/src/html.c Sat Jun 1 18:02:03 2002 @@ -21,6 +21,7 @@ #include <stdlib.h> #include <stdio.h> /* for sprintf */ #include <math.h> /* for rint */ +#include <errno.h> /* for iconv error codes */ #include <gtk/gtk.h> @@ -47,6 +48,7 @@ #include "progressbar.h" #include "prefs.h" #include "misc.h" +#include "encodings.h" //#define DEBUG_LEVEL 3 #include "debug.h" @@ -2675,7 +2677,7 @@ if ((form->method == DILLO_HTML_METHOD_GET) || (form->method == DILLO_HTML_METHOD_POST)) { GString *DataStr = g_string_sized_new(4096); - + GString *DataStrEnc; DEBUG_MSG(3,"Html_submit_form form->action=%s\n",URL_STR_(form->action)); for (input_index = 0; input_index < form->num_inputs; input_index++) { @@ -2732,6 +2734,12 @@ break; } /* switch */ } /* for (inputs) */ + DataStrEnc = g_string_new(a_Encoding_translate_encoding(html_lb->bw->dcv, + DataStr -> str, + DataStr -> len, + DE_ENCODE)); + g_string_free(DataStr,TRUE); + DataStr = DataStrEnc; if ( DataStr->str[DataStr->len - 1] == '&' ) g_string_truncate(DataStr, DataStr->len - 1); @@ -3766,6 +3774,22 @@ Html_write(Client->CbData, Client->Buf, Client->BufSize, 0); } +static void Html_set_encoding(DilloHtml *html, char *buf, gint bufsize) { + /* only do _anything_ if told so */ + if (html->bw->encoding != NULL) + a_Encoding_get_conversion(html->bw, html->bw->encoding); + return; +} + +static char *Html_translate_encoding(DilloHtml *html, char *buf, + gint bufsize) { + char* result=a_Encoding_translate_encoding(html->bw->dcv, + buf, bufsize, + DE_DECODE); + return result; + +} + /* * Here's where we parse the html and put it into the page structure. * (This function is called by Html_callback whenever there's new data) @@ -3777,12 +3801,18 @@ char completestr[32]; gint token_start, buf_index; char *buf = Buf + html->Start_Ofs; + char *buf_encoded; gint bufsize = BufSize - html->Start_Ofs; - + g_return_if_fail ( (page = DW_PAGE (html->dw)) != NULL ); buf = g_strndup(buf, bufsize); + Html_set_encoding(html, buf, bufsize); + buf_encoded=buf; + buf = Html_translate_encoding(html, buf, bufsize); + g_free(buf_encoded); + /* Now, 'buf' and 'bufsize' define a buffer aligned to start at a token * boundary. Iterate through tokens until end of buffer is reached. */ buf_index = 0; diff -BurN dillo-0.6.6.old/src/interface.c dillo-0.6.6/src/interface.c --- dillo-0.6.6.old/src/interface.c Sat Jun 1 18:00:09 2002 + dillo-0.6.6/src/interface.c Sat Jun 1 18:02:37 2002 @@ -17,6 +17,7 @@ #include <sys/stat.h> #include <sys/time.h> #include <fcntl.h> +#include <iconv.h> #include "list.h" #include "dillo.h" @@ -765,6 +766,9 @@ bw->question_dialog_window = NULL; bw->question_dialog_data = NULL; bw->viewsource_window = NULL; + bw->encoding=NULL; + bw->dcv.c_from = (iconv_t)-1; /* no conversion yet */ + bw->dcv.c_from = (iconv_t)-1; /* now that the bw is made, let's customize it.. */ Interface_browser_window_customize(bw); diff -BurN dillo-0.6.6.old/src/menu.c dillo-0.6.6/src/menu.c --- dillo-0.6.6.old/src/menu.c Sat Jun 1 18:00:09 2002 + dillo-0.6.6/src/menu.c Sat Jun 1 18:02:03 2002 @@ -31,6 +31,7 @@ #include "dw_page.h" /* for a_Dw_page_add_anchor */ #include "bookmark.h" #include "interface.h" +#include "encodings.h" /* * Forward declarations @@ -121,6 +122,8 @@ GtkWidget *menubar; GtkWidget *file_menu; GtkWidget *bookmarks_menu; + GtkWidget *enc_menu; + /* GtkWidget *help_menu; */ bw->menubar = menubar = gtk_menu_bar_new(); @@ -158,6 +161,10 @@ Menu_add(help_menu, "Dillo _Manual", NULL, bw, a_Commands_manual_callback, bw); */ + enc_menu = Menu_new(menubar, tiny ? "_E" : "_Encodings", FALSE, bw); + bw->enc_menu = enc_menu; + a_Encodings_fill_new_menu(bw); + return menubar; }

<< Предыдущая ИНДЕКС Правка src / Печать Следующая >>

Обсуждение [ RSS ]
  • 1, kostik (??), 00:01, 27/02/2006 [ответить]  
  • +/
    Всё, разумеется, было бы изюмительно будь эти патчи к последней версии 0.8.5, а не древней, как мир, 0.6.6 !
    А юзать браузер с заранее известными дырами мало кто станет...
    Я как-то умудрился пропатчить 0.8.5 до понимания кириллицы, но он периодически падал, видимо где-то у него там накапливается мусор в памяти... Пришлось откатиться на некириллический вариант :(
    Будет время попробую еще раз!
     
  • 2, японец (?), 08:23, 19/04/2006 [ответить]  
  • +/
    ставьте японскую диллу и не парьтесь
     

     Добавить комментарий
    Имя:
    E-Mail:
    Заголовок:
    Текст:




    Партнёры:
    PostgresPro
    Inferno Solutions
    Hosting by Hoster.ru
    Хостинг:

    Закладки на сайте
    Проследить за страницей
    Created 1996-2024 by Maxim Chirkov
    Добавить, Поддержать, Вебмастеру