+++ /dev/null
-diff -Nur old/dillorc new/dillorc
---- old/dillorc 2004-01-25 16:18:12.000000000 +0100
-+++ new/dillorc 2004-03-07 17:42:28.000000000 +0100
-@@ -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 tooltip popup for images?
- # Note: We use the "title" attribute and not "alt".
- # More info at: http://bugzilla.mozilla.org/show_bug.cgi?id=25537
-diff -Nur old/encodings new/encodings
---- old/encodings 1970-01-01 01:00:00.000000000 +0100
-+++ new/encodings 2004-03-07 17:32:50.000000000 +0100
-@@ -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 -Nur old/src/browser.h new/src/browser.h
---- old/src/browser.h 2004-02-03 20:03:28.000000000 +0100
-+++ new/src/browser.h 2004-03-07 17:45:51.000000000 +0100
-@@ -4,9 +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;
-@@ -65,6 +64,9 @@
- /* Popup menu for this BrowserWindow */
- DilloMenuPopup menu_popup;
-
-+ /* The encoding menu */
-+ GtkWidget *enc_menu;
-+
- /* The "Headings" and "Anchors" menus */
- GtkWidget *pagemarks_menuitem;
- GtkWidget *pagemarks_menu;
-@@ -132,6 +134,10 @@
-
- /* The id for the idle function that sets button sensitivity. */
- guint sens_idle_id;
-+
-+ /* encodings variable */
-+ gchar* encoding; /* the selected character set (pointer to static content -don't free it*/
-+ deConversion dcv; /* handle for character set conversion */
- };
-
-
-diff -Nur old/src/dillo.c new/src/dillo.c
---- old/src/dillo.c 2004-02-06 16:53:59.000000000 +0100
-+++ new/src/dillo.c 2004-03-07 19:43:48.000000000 +0100
-@@ -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>
-@@ -41,6 +48,7 @@
- #include "nav.h"
- #include "history.h"
- #include "bookmark.h"
-+#include "encodings.h"
- #include "dicache.h"
- #include "dns.h"
- #include "IO/mime.h"
-@@ -198,7 +206,7 @@
- */
- gint main(int argc, char *argv[])
- {
-- gchar *dir, *curr_locale;
-+ gchar *dir, *loctmp;
- DilloUrl *start_url;
- BrowserWindow *bw;
- guint32 xid = 0;
-@@ -210,9 +218,6 @@
- gint xpos = D_GEOMETRY_DEFAULT_XPOS, ypos = D_GEOMETRY_DEFAULT_YPOS;
- gint width = D_GEOMETRY_DEFAULT_WIDTH, height = D_GEOMETRY_DEFAULT_HEIGHT;
-
-- /* set locale */
-- curr_locale = g_strdup(setlocale(LC_ALL, NULL));
-- gtk_set_locale();
- /* Initialize GUI and parse GTK related args */
- gtk_init(&argc, &argv);
- gdk_rgb_init();
-@@ -254,9 +259,21 @@
- }
- }
-
-- /* Send a delayed locale-related message */
-- MSG("Setting locale to %s...\n", curr_locale);
-- g_free(curr_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);
-
- /* This lets threads in the file module end peacefully when aborted
- * todo: implement a cleaner mechanism (in file.c) */
-@@ -300,6 +317,7 @@
- gtk_widget_set_uposition(bw->main_window, prefs.xpos, prefs.ypos);
-
- a_Bookmarks_init();
-+ a_Encodings_init();
-
- /* Send dillo startup screen */
- start_url = a_Url_new("splash", "about:", 0, 0, 0);
-diff -Nur old/src/dillo.h new/src/dillo.h
---- old/src/dillo.h 2003-09-05 14:07:06.000000000 +0200
-+++ new/src/dillo.h 2004-03-07 19:26:40.000000000 +0100
-@@ -4,6 +4,7 @@
- #include "browser.h"
- #include "web.h"
-
-+char* curr_locale;
- extern gboolean dillo_dbg_rendering;
-
- #endif /* __DILLO_H__ */
-diff -Nur old/src/dw_style.c new/src/dw_style.c
---- old/src/dw_style.c 2003-11-15 22:57:53.000000000 +0100
-+++ new/src/dw_style.c 2004-03-07 19:34:53.000000000 +0100
-@@ -11,6 +11,7 @@
-
- #include "dw_style.h"
- #include "dw_widget.h"
-+#include "prefs.h"
-
- #include <gdk/gdk.h>
- #include <stdio.h>
-@@ -300,40 +301,37 @@
- break;
- }
-
-- sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-iso8859-1",
-+ sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-%s",
- font->name,
- (font->weight >= 500) ? "bold" : "medium",
-- style_char_1, font->size);
-+ style_char_1, font->size, prefs.font_charset);
- font->font = gdk_font_load (fontname);
-
- if (font->font == NULL && font->style != DW_STYLE_FONT_STYLE_NORMAL) {
-- sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-iso8859-1",
-+ sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-%s",
- font->name,
- (font->weight >= 500) ? "bold" : "medium",
-- style_char_2, font->size);
-+ style_char_2, 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. */
-- font->font =
-- gdk_font_load
-- ("-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-iso8859-1");
-+ 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) */
-- font->font =
-- gdk_font_load
-- ("-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-1");
-+ 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 ISO8859-1 font!?! :(");
-- font->font =
-- gdk_font_load ("-adobe-helvetica-*-*-*--*-*-*-*-*-*-*-*");
-+ g_warning ("Can't load any font with charset '%s'!?! :(",prefs.font_charset);
-+ font->font = gdk_fontset_load("-adobe-helvetica-*-*-*--*-*-*-*-*-*-*-*,-misc-fixed-*,*");
- }
- }
-
-diff -Nur old/src/encodings.c new/src/encodings.c
---- old/src/encodings.c 1970-01-01 01:00:00.000000000 +0100
-+++ new/src/encodings.c 2004-03-07 17:32:50.000000000 +0100
-@@ -0,0 +1,383 @@
-+/* 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 <unistd.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);
-+
-+extern BrowserWindow **browser_window;
-+
-+/*
-+ * 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");
-+ if (access(file, R_OK))
-+ Encodings_file_op(LOAD_ENCODINGS, "/etc/dillo/encodings", NULL);
-+ else
-+ 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) {
-+ /* SAVE_ENCODINGS is broken anyway, better make use of /etc/dillo/encodings */
-+ if ((fp = fopen(title, "r")) == 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 -Nur old/src/encodings.h new/src/encodings.h
---- old/src/encodings.h 1970-01-01 01:00:00.000000000 +0100
-+++ new/src/encodings.h 2004-03-07 17:32:50.000000000 +0100
-@@ -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 -Nur old/src/encodings-types.h new/src/encodings-types.h
---- old/src/encodings-types.h 1970-01-01 01:00:00.000000000 +0100
-+++ new/src/encodings-types.h 2004-03-07 17:32:50.000000000 +0100
-@@ -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 -Nur old/src/html.c new/src/html.c
---- old/src/html.c 2004-02-07 00:10:45.000000000 +0100
-+++ new/src/html.c 2004-03-07 18:21:23.000000000 +0100
-@@ -51,6 +52,7 @@
- #include "progressbar.h"
- #include "prefs.h"
- #include "misc.h"
-+#include "encodings.h"
- #include "capi.h"
- #include "html.h"
-
-@@ -3140,7 +3142,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++) {
-@@ -3204,6 +3206,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);
-@@ -4374,6 +4382,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.
- * Return value: number of bytes parsed
-@@ -4511,8 +4535,12 @@
-
- g_return_if_fail ( (page = DW_PAGE (html->dw)) != NULL );
-
-+ Html_set_encoding(html, buf, bufsize);
-+ buf = Html_translate_encoding(html, buf, bufsize);
-+
- html->Start_Buf = Buf;
- token_start = Html_write_raw(html, buf, bufsize, Eof);
-+ g_free(buf);
- html->Start_Ofs += token_start;
-
- if ( html->bw ) {
-diff -Nur old/src/interface.c new/src/interface.c
---- old/src/interface.c 2004-02-03 20:10:42.000000000 +0100
-+++ new/src/interface.c 2004-03-07 18:22:51.000000000 +0100
-@@ -55,7 +55,7 @@
- */
- /* BrowserWindow holds all the widgets (and perhaps more)
- * for each new_browser.*/
--static BrowserWindow **browser_window;
-+BrowserWindow **browser_window;
- static gint num_bw, num_bw_max;
-
- /* We need only one of them. */
-@@ -969,6 +969,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_to = (iconv_t)-1;
- bw->pagebugs_window = NULL;
-
- /* now that the bw is made, let's customize it.. */
-diff -Nur old/src/Makefile.am new/src/Makefile.am
---- old/src/Makefile.am 2004-01-29 21:34:05.000000000 +0100
-+++ new/src/Makefile.am 2004-03-07 18:32:22.000000000 +0100
-@@ -63,6 +63,9 @@
- dw_tooltip.h \
- dw_widget.c \
- dw_widget.h \
-+ encodings.c \
-+ encodings.h \
-+ encoding-types.h \
- findtext.c \
- findtext.h \
- selection.c \
-diff -Nur old/src/menu.c new/src/menu.c
---- old/src/menu.c 2004-02-03 20:03:11.000000000 +0100
-+++ new/src/menu.c 2004-03-07 18:26:30.000000000 +0100
-@@ -33,6 +33,7 @@
- #include "bookmark.h"
- #include "interface.h"
- #include "menu.h"
-+#include "encodings.h"
- #include "selection.h"
-
- /*
-@@ -141,6 +142,7 @@
- GtkWidget *menubar;
- GtkWidget *file_menu;
- /* GtkWidget *help_menu; */
-+ GtkWidget *enc_menu;
-
- bw->menubar = menubar = gtk_menu_bar_new();
-
-@@ -167,6 +169,10 @@
- Menu_add(help_menu, "Dillo _Home", NULL, bw,
- a_Commands_helphome_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;
- }
-
-diff -Nur old/src/prefs.c new/src/prefs.c
---- old/src/prefs.c 2004-01-25 16:17:53.000000000 +0100
-+++ new/src/prefs.c 2004-03-07 18:30:13.000000000 +0100
-@@ -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;
-@@ -363,6 +368,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;
-@@ -405,6 +411,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 -Nur old/src/prefs.h new/src/prefs.h
---- old/src/prefs.h 2004-01-25 16:17:37.000000000 +0100
-+++ new/src/prefs.h 2004-03-07 18:31:25.000000000 +0100
-@@ -43,6 +43,7 @@
- DRC_TOKEN_PANEL_SIZE,
- DRC_TOKEN_SMALL_ICONS,
- DRC_TOKEN_FONT_FACTOR,
-+ DRC_TOKEN_FONT_CHARSET,
- DRC_TOKEN_SHOW_TOOLTIP,
- DRC_TOKEN_LIMIT_TEXT_WIDTH,
- DRC_TOKEN_USE_DICACHE,
-@@ -95,6 +96,7 @@
- gboolean small_icons;
- gboolean limit_text_width;
- gdouble font_factor;
-+ char *font_charset;
- gboolean use_dicache;
- gboolean show_back;
- gboolean show_forw;
+++ /dev/null
-diff -urN dillo-0.8.6.orig/dpi/file.c dillo-0.8.6/dpi/file.c
---- dillo-0.8.6.orig/dpi/file.c 2006-04-11 19:50:23.000000000 +0200
-+++ dillo-0.8.6/dpi/file.c 2006-08-20 20:27:22.392356500 +0200
-@@ -15,6 +15,7 @@
- * With new HTML layout.
- */
-
-+#define _GNU_SOURCE
- #include <pthread.h>
-
- #include <ctype.h> /* for tolower */
-@@ -33,6 +34,7 @@
- #include <time.h>
- #include <signal.h>
- #include <glib.h>
-+#include <zlib.h>
-
- #include "../dpip/dpip.h"
- #include "dpiutil.h"
-@@ -73,7 +75,7 @@
- /*
- * Forward references
- */
--static const char *File_content_type(const char *filename);
-+static const char *File_content_type(const char *filename, int *gzipped);
- static gint File_get_file(ClientInfo *Client,
- const gchar *filename,
- struct stat *sb,
-@@ -343,7 +345,7 @@
- } else if (finfo->mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
- filecont = "Executable";
- } else {
-- filecont = File_content_type(finfo->full_path);
-+ filecont = File_content_type(finfo->full_path, NULL);
- if (!filecont || !strcmp(filecont, "application/octet-stream"))
- filecont = "unknown";
- }
-@@ -468,13 +470,24 @@
- /*
- * Return a content type based on the extension of the filename.
- */
--static const char *File_ext(const char *filename)
-+static const char *File_ext(const char *filename, int *gzipped)
- {
-- char *e;
-+ char *e, *e2;
-
- if ( !(e = strrchr(filename, '.')) )
- return NULL;
-
-+ if ((e > filename) && !strcasecmp(e+1, "gz") &&
-+ ((e2 = memrchr(filename, '.', e-filename)) != NULL)) {
-+ e2++;
-+ if (!strncasecmp(e2, "html.", 5) ||
-+ !strncasecmp(e2, "htm.", 4) ||
-+ !strncasecmp(e2, "shtml.", 6)) {
-+ if(gzipped != NULL)
-+ *gzipped = 1;
-+ return "text/html";
-+ }
-+ }
- e++;
-
- if (!strcasecmp(e, "gif")) {
-@@ -497,7 +510,7 @@
- * Based on the extension, return the content_type for the file.
- * (if there's no extension, analyze the data and try to figure it out)
- */
--static const char *File_content_type(const char *filename)
-+static const char *File_content_type(const char *filename, int *gzipped)
- {
- gint fd;
- struct stat sb;
-@@ -505,7 +518,7 @@
- gchar buf[256];
- ssize_t buf_size;
-
-- if (!(ct = File_ext(filename))) {
-+ if (!(ct = File_ext(filename, gzipped))) {
- /* everything failed, let's analyze the data... */
- if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) != -1) {
- if ((buf_size = read(fd, buf, 256)) == 256 ) {
-@@ -531,25 +544,39 @@
- int res;
- struct stat sb;
- char *msg = NULL, *d_cmd;
-+ char *tmp_filename = (char*)filename, *p;
-
- if (stat(filename, &sb) != 0) {
-+ char *e = strrchr(filename, '.');
-+ if ((e == NULL) || strcasecmp(e + 1, "gz")) {
-+ if ((p = malloc(strlen(filename) + 4)) != NULL) {
-+ tmp_filename = p;
-+ strcpy(tmp_filename, filename);
-+ strcat(tmp_filename, ".gz");
-+ filename = tmp_filename;
-+ }
-+ }
-+ }
-+ if (stat(tmp_filename, &sb) != 0) {
- /* stat failed, prepare a file-not-found error. */
- res = FILE_NOT_FOUND;
- } else if (S_ISDIR(sb.st_mode)) {
- /* set up for reading directory */
-- res = File_get_dir(Client, filename, orig_url);
-+ res = File_get_dir(Client, tmp_filename, orig_url);
- } else {
- /* set up for reading a file */
-- res = File_get_file(Client, filename, &sb, orig_url);
-+ res = File_get_file(Client, tmp_filename, &sb, orig_url);
- }
-
- if (res == FILE_NOT_FOUND) {
- msg = g_strdup_printf("%s Not Found: %s",
-- S_ISDIR(sb.st_mode) ? "Directory" : "File", filename);
-+ S_ISDIR(sb.st_mode) ? "Directory" : "File", tmp_filename);
- } else if (res == FILE_NO_ACCESS) {
- msg = g_strdup_printf("Access denied to %s: %s",
-- S_ISDIR(sb.st_mode) ? "Directory" : "File", filename);
-+ S_ISDIR(sb.st_mode) ? "Directory" : "File", tmp_filename);
- }
-+ if(tmp_filename != filename)
-+ free(tmp_filename);
- if (msg) {
- d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "send_status_message", msg);
- sock_handler_write_str(Client->sh, d_cmd, 1);
-@@ -596,6 +623,8 @@
- const gchar *ct;
- char buf[LBUF], *d_cmd;
- gint fd, st;
-+ int gzipped = 0;
-+ gzFile gzdata;
-
- if ( (fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0)
- return FILE_NO_ACCESS;
-@@ -604,7 +633,7 @@
- * known extension, then we do data sniffing. If this doesn't lead
- * to a conclusion, "application/octet-stream" is sent.
- */
-- if (!(ct = File_content_type(filename)))
-+ ct = File_content_type(filename, &gzipped);
- ct = "application/octet-stream";
-
- /* Send DPI command */
-@@ -612,6 +641,24 @@
- sock_handler_write_str(Client->sh, d_cmd, 1);
- g_free(d_cmd);
-
-+ if (gzipped) {
-+ /* Send HTTP stream */
-+ sock_handler_printf(Client->sh, 0,
-+ "Content-Type: %s\n\n", ct);
-+
-+ gzdata = gzdopen(fd, "r");
-+ do {
-+ if ((st = gzread(gzdata, buf, LBUF)) > 0) {
-+ if (sock_handler_write(Client->sh, buf, st, 0) != 0)
-+ break;
-+ } else if (st < 0) {
-+ perror("[read]");
-+ if (errno == EINTR || errno == EAGAIN)
-+ continue;
-+ }
-+ } while (st > 0);
-+ gzclose(gzdata);
-+ } else {
- /* Send HTTP stream */
- sock_handler_printf(Client->sh, 0,
- "Content-Type: %s\n"
-@@ -629,6 +676,7 @@
- continue;
- }
- } while (st > 0);
-+ }
-
- /* todo: It may be better to send an error report to dillo instead of
- * calling abort from g_error() */
-diff -urN dillo-0.8.6.orig/dpi/Makefile.am dillo-0.8.6/dpi/Makefile.am
---- dillo-0.8.6.orig/dpi/Makefile.am 2006-01-03 21:16:10.000000000 +0100
-+++ dillo-0.8.6/dpi/Makefile.am 2006-08-20 20:10:16.412236750 +0200
-@@ -27,7 +27,7 @@
- ftp_filter_dpi_LDADD = @GLIB_LIBS@ ../dpip/libDpip.a
- https_filter_dpi_LDADD = @GLIB_LIBS@ @LIBSSL_LIBS@ ../dpip/libDpip.a
- hello_filter_dpi_LDADD = @GLIB_LIBS@ ../dpip/libDpip.a
--file_dpi_LDADD = @GLIB_LIBS@ @LIBPTHREAD_LIBS@ ../dpip/libDpip.a
-+file_dpi_LDADD = @GLIB_LIBS@ @LIBPTHREAD_LIBS@ ../dpip/libDpip.a -lz
- cookies_dpi_LDADD = @GLIB_LIBS@ ../dpip/libDpip.a
- datauri_filter_dpi_LDADD = @GLIB_LIBS@ ../dpip/libDpip.a
-