]> git.pld-linux.org Git - packages/dillo.git/blob - dillo-0.7.0-alt-asp-charset-encodings-sysconfdir.patch
- patch by Alexey Tourbin
[packages/dillo.git] / dillo-0.7.0-alt-asp-charset-encodings-sysconfdir.patch
1 --- dillo-0.7.0~/dillorc        2003-02-13 23:59:30 +0300
2 +++ dillo-0.7.0/dillorc 2003-02-21 03:15:45 +0300
3 @@ -35,6 +35,9 @@
4  # If you prefer oblique over italic fonts, uncoment next line
5  #use_oblique=YES
6  
7 +# Use this value as charset part of font for loading. (default is iso8859-1)
8 +# font_charset=iso8859-5
9 +
10  # Show tooltip popup for images?
11  # Note: We use the "title" attribute and not "alt".
12  #       More info at: http://bugzilla.mozilla.org/show_bug.cgi?id=25537
13 --- dillo-0.7.0~/encodings      1970-01-01 03:00:00 +0300
14 +++ dillo-0.7.0/encodings       2003-02-21 03:15:46 +0300
15 @@ -0,0 +1,18 @@
16 +<enc value="ASCII">7-bit ASCII</enc>
17 +<enc value="ISO8859-1">Western European (ISO 8859-1)</enc>
18 +<enc value="ISO8859-15">Western European (ISO 8859-15)</enc>
19 +<enc value="CP1252">Western European (CodePage1252)</enc>
20 +<enc value="ISO8859-2">Central European (ISO 8859-2)</enc>
21 +<enc value="CP1250">Central European (CodePage1250)</enc>
22 +<enc value="ISO8859-3">Southern European (ISO 8859-3)</enc>
23 +<enc value="KOI8-R">Cyrillic (KOI8-R)</enc>
24 +<enc value="CP1251">Cyrillic (CodePage1251)</enc>
25 +<enc value="IBM866">Cyrillic (IBM866)</enc>
26 +<enc value="ISO8859-13">Baltic (ISO 8859-13)</enc>
27 +<enc value="ISO8859-4">Baltic (ISO 8859-4)</enc>
28 +<enc value="CP1257">Baltic (CodePage1257)</enc>
29 +<enc value="ISO8859-10">Nordic (ISO 8859-10)</enc>
30 +<enc value="ISO8859-14">Celtic (ISO 8859-14)</enc>
31 +<enc value="KOI8-U">Ukraine (KOI8-U)</enc>
32 +<enc value="UTF-8">Unicode (UTF-8)</enc>
33 +<enc value="UTF-16">Unicode (UTF-16)</enc>
34 --- dillo-0.7.0~/Makefile.am    2003-02-13 23:56:11 +0300
35 +++ dillo-0.7.0/Makefile.am     2003-02-21 03:15:46 +0300
36 @@ -1,17 +1,21 @@
37  SUBDIRS = doc src dpi
38    
39 -EXTRA_DIST = ChangeLog.old dillorc
40 +EXTRA_DIST = ChangeLog.old dillorc encodings
41  
42  install-data-local: dillorc
43         -if [ -d $(DESTDIR)$(sysconfdir) ]; then \
44                 $(INSTALL_DATA) -b $(srcdir)/dillorc $(DESTDIR)$(sysconfdir)/; \
45 +               $(INSTALL_DATA) --backup=t $(srcdir)/encodings $(DESTDIR)$(sysconfdir)/; \
46         elif [ -d /etc/ ]; then \
47                 $(INSTALL_DATA) -b $(srcdir)/dillorc /etc/; \
48 +               $(INSTALL_DATA) --backup=t $(srcdir)/encodings /etc/; \
49         fi
50  
51  uninstall-local:
52         -if [ -d $(DESTDIR)$(sysconfdir) ]; then \
53                 rm -f $(DESTDIR)$(sysconfdir)/dillorc*; \
54 +               rm -f $(DESTDIR)$(sysconfdir)/encodings*; \
55         elif [ -d /etc/ ]; then \
56                 rm -f /etc/dillorc*; \
57 +               rm -f /etc/encodings* ;\
58         fi
59 --- dillo-0.7.0~/src/browser.h  2003-02-10 16:10:30 +0300
60 +++ dillo-0.7.0/src/browser.h   2003-02-21 03:15:46 +0300
61 @@ -4,10 +4,8 @@
62  #include <sys/types.h>
63  #include <gdk/gdk.h>
64  #include <gtk/gtk.h>
65 -
66  #include "url.h"     /* for DilloUrl */
67 -
68 -
69 +#include "encodings-types.h"
70  typedef struct _BrowserWindow BrowserWindow;
71  typedef struct _DilloMenuPopup DilloMenuPopup;
72  
73 @@ -61,6 +59,9 @@
74     /* The bookmarks menu so that we can add things to it. */
75     GtkWidget *bookmarks_menu;
76  
77 +   /* The encoding menu */
78 +   GtkWidget *enc_menu;
79 +
80     /* The "Headings" and "Anchors" menus */
81     GtkWidget *pagemarks_menuitem;
82     GtkWidget *pagemarks_menu;
83 @@ -121,6 +122,10 @@
84  
85     /* The tag for the idle function that sets button sensitivity. */
86     guint sens_idle_tag;
87 +
88 +   /* encodings variable */
89 +   gchar*   encoding;     /* the selected character set (pointer to static content -don't free it*/
90 +   deConversion dcv;      /* handle for character set conversion */
91  };
92  
93  
94 --- dillo-0.7.0~/src/dillo.c    2003-02-09 03:22:14 +0300
95 +++ dillo-0.7.0/src/dillo.c     2003-02-21 03:15:46 +0300
96 @@ -22,6 +22,13 @@
97  #include <stdio.h>
98  #include <gtk/gtk.h>
99  
100 +#ifdef HAVE_LANGINFO
101 +#include <langinfo.h>
102 +#if ! defined(CODESET) && defined (_NL_CTYPE_CODESET_NAME)
103 +#define CODESET _NL_CTYPE_CODESET_NAME
104 +#endif
105 +#endif
106 +
107  #include <sys/types.h>
108  #include <sys/stat.h>
109  #include <string.h>
110 @@ -39,6 +46,7 @@
111  #include "nav.h"
112  #include "history.h"
113  #include "bookmark.h"
114 +#include "encodings.h"
115  #include "dicache.h"
116  #include "dns.h"
117  #include "IO/mime.h"
118 @@ -171,7 +179,7 @@
119   */
120  gint main(int argc, char *argv[])
121  {
122 -   gchar *file, *curr_locale;
123 +   gchar *file, *loctmp;
124     DilloUrl *start_url;
125     BrowserWindow *bw;
126     guint32 xid = 0;
127 @@ -181,9 +189,6 @@
128     gint i;
129     char **opt_argv = NULL;
130  
131 -   /* set locale */
132 -   curr_locale = g_strdup(setlocale(LC_ALL, NULL));
133 -   gtk_set_locale();
134     /* Initialize GUI and parse GTK related args */
135     gtk_init(&argc, &argv);
136     gdk_rgb_init();
137 @@ -219,9 +224,21 @@
138       }
139     }
140  
141 -   /* Send a delayed locale-related message */
142 -   g_print("Setting locale to %s...\n", curr_locale);
143 -   g_free(curr_locale);
144 +   curr_locale=gtk_set_locale();
145 +#ifdef HAVE_LANGINFO
146 +   curr_locale = nl_langinfo(CODESET);
147 +#else
148 +    loctmp = strchr(curr_locale, '.');
149 +    if (loctmp != NULL) {
150 +        gchar** trk = g_strsplit(++loctmp, ";", 1);
151 +        curr_locale = g_strdup(trk[0]);
152 +        g_strfreev(trk);
153 +    } else {
154 +        curr_locale = "ASCII";
155 +    }
156 +#endif
157 +
158 +   g_print("Setting locale to %s\n",curr_locale);
159  
160     /* This lets threads in the file module end peacefully when aborted
161      * todo: implement a cleaner mechanism (in file.c) */
162 @@ -255,6 +272,7 @@
163     bw = a_Interface_browser_window_new(prefs.width, prefs.height, xid);
164  
165     a_Bookmarks_init();
166 +   a_Encodings_init();
167  
168     /* Send dillo startup screen */
169     start_url = a_Url_new("splash", "about:", 0, 0);
170 --- dillo-0.7.0~/src/dillo.h    2002-11-28 19:42:22 +0300
171 +++ dillo-0.7.0/src/dillo.h     2003-02-21 03:15:46 +0300
172 @@ -4,4 +4,5 @@
173  #include "browser.h"
174  #include "web.h"
175  
176 +char* curr_locale;
177  #endif /* __DILLO_H__ */
178 diff -ubBdr -N dillo-0.7.0~/src/dillo.h.orig dillo-0.7.0/src/dillo.h.orig
179 --- dillo-0.7.0~/src/dw_style.c 2003-01-05 22:24:06 +0300
180 +++ dillo-0.7.0/src/dw_style.c  2003-02-21 03:15:45 +0300
181 @@ -245,42 +245,39 @@
182     char fontname[256], *ItalicChar;
183  
184     ItalicChar = prefs.use_oblique ? "o" : "i";
185 -   sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-iso8859-1",
186 +   sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-%s",
187              font->name,
188              font->bold ? "bold" : "medium",
189              font->italic ? ItalicChar : "r",
190 -            font->size);
191 +            font->size,prefs.font_charset);
192     font->font = gdk_font_load (fontname);
193  
194     if (font->font == NULL && font->italic) {
195 -      sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-iso8859-1",
196 +      sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-%s",
197                 font->name,
198                 font->bold ? "bold" : "medium",
199                 (*ItalicChar == 'o') ? "i" : "o",
200 -               font->size);
201 +               font->size,prefs.font_charset);
202        font->font = gdk_font_load (fontname);
203     }
204  
205     if (try_all) {
206        if (font->font == NULL) {
207           /* Can't load the font - substitute the default instead. */
208 -         font->font =
209 -            gdk_font_load
210 -            ("-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-iso8859-1");
211 +         sprintf(fontname,"-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-%s",prefs.font_charset);
212 +         font->font = gdk_font_load (fontname);
213        }
214  
215        if (font->font == NULL) {
216           /* Try another platform-font that should be available. (iPaq) */
217 -         font->font =
218 -            gdk_font_load
219 -            ("-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-1");
220 +         sprintf(fontname,"-misc-fixed-medium-r-normal--13-120-75-75-c-80-%s",prefs.font_charset);
221 +         font->font = gdk_font_load (fontname);
222        }
223  
224        if (font->font == NULL) {
225           /* Can't load any suitable font!  */
226 -         g_warning ("Can't load any ISO8859-1 font!?! :(");
227 -         font->font =
228 -            gdk_font_load ("-adobe-helvetica-*-*-*--*-*-*-*-*-*-*-*");
229 +         g_warning ("Can't load any font with charset '%s'!?! :(",prefs.font_charset);
230 +         font->font = gdk_fontset_load("-adobe-helvetica-*-*-*--*-*-*-*-*-*-*-*,-misc-fixed-*,*");
231        }
232     }
233  
234 --- dillo-0.7.0~/src/encodings.c        1970-01-01 03:00:00 +0300
235 +++ dillo-0.7.0/src/encodings.c 2003-02-21 03:15:46 +0300
236 @@ -0,0 +1,383 @@
237 +/* cruelty :) */
238 +
239 +/* Copyright (C) 2002 Grigory Bakunov <black@asplinux.ru> */
240 +
241 +/* Copyright (C) 1997 Ian Main
242 + *
243 + * This program is free software; you can redistribute it and/or modify
244 + * it under the terms of the GNU General Public License as published by
245 + * the Free Software Foundation; either version 2 of the License, or
246 + * (at your option) any later version.
247 + *
248 + * This program is distributed in the hope that it will be useful,
249 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
250 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
251 + * GNU General Public License for more details.
252 + *
253 + * You should have received a copy of the GNU General Public License
254 + * along with this program; if not, write to the Free Software
255 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
256 + */
257 +
258 +#include <gtk/gtk.h>
259 +
260 +#include <errno.h>
261 +#include <stdio.h>
262 +#include <unistd.h>
263 +#include <stdlib.h>
264 +#include <string.h>
265 +
266 +#include "list.h"
267 +#include "interface.h"
268 +#include "dillo.h"
269 +#include "nav.h"
270 +#include "browser.h"
271 +#include "menu.h"
272 +#include "misc.h"
273 +#include "url.h"
274 +
275 +#define LOAD_ENCODINGS 1
276 +#define SAVE_ENCODING 2
277 +#define CLOSE_ENCODINGS 3
278 +
279 +/* this #define will cut page title if > 39 chars */
280 +#define TITLE39
281 +
282 +/* double quote */
283 +#define D_QUOTE 0x22
284 +
285 +/* Data types */
286 +
287 +typedef struct _Encoding Encoding;
288 +typedef struct _CallbackInfo CallbackInfo;
289 +
290 +struct _Encoding {
291 +   char *title;
292 +   char *iconv_name;
293 +   GtkWidget *menuitem;
294 +};
295 +
296 +struct _CallbackInfo {
297 +   BrowserWindow *bw;
298 +   guint index;
299 +};
300 +
301 +/*
302 + * Forward declarations
303 + */
304 +static void
305 +   Encodings_load_to_menu(FILE *fp),
306 +   Encodings_file_op(gint operation, const char *title, const char *iconv_name),
307 +   Encodings_save_to_file(FILE *fp, const char *title,  const char *iconv_name);
308 +
309 +static char*
310 +   Encodings_search_line(char *line, char *start_text, char *end_text);
311 +
312 +extern BrowserWindow **browser_window;
313 +
314 +/*
315 + * Local data
316 + */
317 +static Encoding *encodings = NULL;
318 +static gint num_encodings = 0;
319 +static gint num_encodings_max = 16;
320 +
321 +
322 +/*
323 + * Allocate memory and load the encodings list
324 + */
325 +void a_Encodings_init(void)
326 +{
327 +   gchar *file;
328 +
329 +   /* Here we load and set the encodings */
330 +   file = a_Misc_prepend_user_home(".dillo/encodings");
331 +   if (access(file, R_OK))
332 +       Encodings_file_op(LOAD_ENCODINGS, "/etc/dillo/encodings", NULL);
333 +   else
334 +   Encodings_file_op(LOAD_ENCODINGS, file, NULL);
335 +   g_free(file);
336 +}
337 +
338 +/*
339 + * ?
340 + */
341 +void Encodings_set_encoding(GtkWidget *widget, CallbackInfo *CbInfo)
342 +{
343 +   if (CbInfo->index >= num_encodings) {
344 +      g_warning("encoding not found!\n");
345 +      return;
346 +   }
347 +   g_print("Selected encoding: %s\n",encodings[CbInfo->index].iconv_name);
348 +   CbInfo->bw->encoding=encodings[CbInfo->index].iconv_name;
349 +   a_Nav_reload(CbInfo->bw);
350 +   /*HERE!!! LOOKOUT!!!! */
351 +}
352 +
353 +/*
354 + * Add a encoding to the encodings menu of a particular browser window
355 + */
356 +void Encodings_add_to_menu(BrowserWindow *bw, GtkWidget *menuitem, guint index)
357 +{
358 +   CallbackInfo *CbInfo;
359 +
360 +   gtk_menu_append(GTK_MENU(bw->enc_menu), menuitem);
361 +
362 +   CbInfo = g_new(CallbackInfo, 1);
363 +   CbInfo->bw = bw;
364 +   CbInfo->index = index;
365 +
366 +   /* accelerator goes here */
367 +   gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
368 +                      (GtkSignalFunc)Encodings_set_encoding, CbInfo);
369 +}
370 +
371 +/*
372 + * ?
373 + */
374 +static GtkWidget *Encodings_insert(const char *title, const char *iconv_name)
375 +{
376 +   GtkWidget *menuitem;
377 +
378 +   menuitem = gtk_menu_item_new_with_label(title);
379 +   gtk_widget_show(menuitem);
380 +
381 +   a_List_add(encodings, num_encodings, num_encodings_max);
382 +   encodings[num_encodings].title = g_strdup(title);
383 +   encodings[num_encodings].iconv_name = g_strdup(iconv_name);
384 +   encodings[num_encodings].menuitem = menuitem;
385 +   num_encodings++;
386 +   return menuitem;
387 +}
388 +
389 +/*
390 + * Add the new encoding to encodings menu of _all_ browser windows and then
391 + * write the new encoding to file
392 + */
393 +/*
394 +void a_Encodings_add(GtkWidget *widget, gpointer client_data)
395 +{
396 +   BrowserWindow *bw = (BrowserWindow *)client_data;
397 +   gint i;
398 +#ifdef TITLE39
399 +   gboolean allocated = FALSE;
400 +#endif
401 +   char *title;
402 +   char *iconv_name;
403 +   GtkWidget *menuitem;
404 +
405 +   title = bw->menu_popup.info.title;
406 +   iconv_name = bw->menu_popup.info.iconv_name;
407 +
408 +#ifdef TITLE39
409 +   if (strlen (title) > 39) {
410 +      char buf1[20];
411 +      char buf2[20];
412 +
413 +      memcpy (buf1, title, 18);
414 +      buf1[18] = '\0';
415 +      strcpy (buf2, title + strlen (title) - 18);
416 +      buf2[18] = '\0';
417 +      title = g_strconcat (buf1, "...", buf2, NULL);
418 +      allocated = TRUE;
419 +   }
420 +#endif
421 +
422 +   menuitem = Encodings_insert(title, iconv_name);
423 +   Encodings_add_to_menu(browser_window[0], menuitem, num_encodings-1);
424 +   for (i = 1; i < num_bw; i++) {
425 +      menuitem= gtk_menu_item_new_with_label(encodings[num_encodings-1].title);
426 +      gtk_widget_show(menuitem);
427 +      Encodings_add_to_menu(browser_window[i], menuitem, num_encodings-1);
428 +   }
429 +
430 +   Encodings_file_op(SAVE_ENCODING, title, iconv_name);
431 +
432 +#ifdef TITLE39
433 +   if (allocated)
434 +      g_free (title);
435 +#endif
436 +}
437 +*/
438 +/*
439 + * Never called (the file remains open all the time)  --Jcid
440 + */
441 +void Encodings_close(void)
442 +{
443 +   Encodings_file_op(CLOSE_ENCODINGS, NULL, NULL);
444 +}
445 +
446 +/*
447 + * Performs operations on the encoding file..
448 + * for first call, title is the filename
449 + */
450 +static void
451 + Encodings_file_op(gint operation, const char *title, const char *iconv_name)
452 +{
453 +   static FILE *fp;
454 +   static gint initialized = 0;
455 +
456 +   if (!initialized) {
457 +      if (operation == LOAD_ENCODINGS) {
458 +         /* SAVE_ENCODINGS is broken anyway, better make use of /etc/dillo/encodings */
459 +         if ((fp = fopen(title, "r")) == NULL)
460 +            g_print("dillo: opening encoding file %s: %s\n",
461 +                    title, strerror(errno));
462 +         else
463 +            initialized = 1;
464 +      } else
465 +         g_print("Error: invalid call to Encodings_file_op.\n");
466 +   }
467 +
468 +   g_return_if_fail( initialized );
469 +
470 +   switch (operation) {
471 +   case LOAD_ENCODINGS:
472 +      Encodings_load_to_menu(fp);
473 +      break;
474 +
475 +   case SAVE_ENCODING:
476 +      Encodings_save_to_file(fp, title, iconv_name);
477 +      break;
478 +
479 +   case CLOSE_ENCODINGS:
480 +      fclose(fp);
481 +      break;
482 +
483 +   default:
484 +      break;
485 +   }
486 +}
487 +
488 +/*
489 + * Save encodings to ~/.dillo/encodings
490 + */
491 +static void
492 + Encodings_save_to_file(FILE *fp, const char *title, const char* iconv_name)
493 +{
494 +   fseek(fp, 0L, SEEK_END);
495 +   fprintf(fp, "<enc value=\"%s\">%s</a>\n", iconv_name,title);
496 +   fflush(fp);
497 +}
498 +
499 +/*
500 + * Load encodings
501 + */
502 +static void Encodings_load_to_menu(FILE *fp)
503 +{
504 +   gchar *title=NULL;
505 +   gchar *iconv_name=NULL;
506 +   char buf[4096];
507 +   gint i = 0;
508 +   GtkWidget *menuitem;
509 +
510 +   rewind(fp);
511 +
512 +   g_print("Loading encodings...\n");
513 +   while (1) {
514 +      /* Read a whole line from the file */
515 +      if ((fgets(buf, 4096, fp)) == NULL)
516 +          break;
517 +
518 +      /* get url from line */
519 +      if ( !(iconv_name = Encodings_search_line(buf, "=\"", "\">")) )
520 +         continue;
521 +
522 +      /* get title from line */
523 +      if ( !(title = Encodings_search_line(buf, "\">", "</")) ){
524 +         g_free(iconv_name);
525 +         continue;
526 +      }
527 +      printf("%s = %s\n",title,iconv_name);
528 +      menuitem = Encodings_insert(title, iconv_name);
529 +      Encodings_add_to_menu(browser_window[0], menuitem, i);
530 +      g_free(iconv_name);
531 +      g_free(title);
532 +      i++;
533 +   }
534 +}
535 +
536 +/*
537 + * Copy encodings when new browser windows are opened.
538 + * Called by 'a_Menu_mainbar_new()'
539 + */
540 +void a_Encodings_fill_new_menu(BrowserWindow *bw)
541 +{
542 +   gint i;
543 +   GtkWidget *menuitem;
544 +
545 +   for (i = 0; i < num_encodings; i++) {
546 +     menuitem = gtk_menu_item_new_with_label(encodings[i].title);
547 +     gtk_widget_show(menuitem);
548 +     Encodings_add_to_menu(bw, menuitem, i);
549 +   }
550 +}
551 +
552 +static char *
553 + Encodings_search_line(char *line, char *start_text, char *end_text) {
554 +   gint segment_length;
555 +   char *start_index, *end_index;
556 +
557 +   /* if string is not found, return NULL */
558 +   if ((start_index = strstr(line, start_text)) == NULL)
559 +      return (NULL);
560 +   if ((end_index = strstr(line, end_text)) == NULL)
561 +      return (NULL);
562 +
563 +   /* adjustment cause strstr returns the start of the text */
564 +   start_index += strlen(start_text);
565 +
566 +   /* find length of text segment */
567 +   segment_length = end_index - start_index;
568 +   return g_strndup(start_index, segment_length);
569 +};
570 +
571 +void   a_Encoding_get_conversion(BrowserWindow *bw, char* charset) {
572 +    bw->dcv.c_from=iconv_open(curr_locale,charset);
573 +    bw->dcv.c_to=iconv_open(charset,curr_locale);
574 +    if (bw->dcv.c_from == (iconv_t)-1 || bw->dcv.c_to == (iconv_t)-1)
575 +       g_warning ("could not allocate character encoding converter.");
576 +    return;
577 +};
578 +
579 +#define MAX_CHAR_SIZE 4
580 +gchar *a_Encoding_translate_encoding(deConversion dcv, gchar *buf, gint bufsize,deDirection dir) {
581 +    char *result, *source, *dest; 
582 +    size_t s_left, d_left;
583 +    iconv_t conversion;
584 +    if (dir==DE_DECODE)
585 +       conversion=dcv.c_from;
586 +    else 
587 +       conversion=dcv.c_to;
588 +    /* no conversion is needed, or none is available */
589 +    if (conversion == (iconv_t)-1)
590 +       return g_strndup(buf, bufsize);
591 +
592 +    /* Note that for some conversions, the translated buffer can be larger
593 +     * than the input buffer. This is particularly important for conversions
594 +     * to UTF8 (check the unicode standard to find out the scale factor). */
595 +    result = g_malloc((bufsize + 1)*MAX_CHAR_SIZE);
596 +    
597 +    source = buf;
598 +    dest = result;
599 +    s_left =  bufsize;
600 +    d_left = bufsize*MAX_CHAR_SIZE;
601 +    if (iconv(conversion, &source, &s_left, &dest, &d_left)
602 +       == (size_t)-1) {
603 +       g_warning ("unable to fully convert page to native character set");
604 +       /* This just skips past unconvertable characters, putting "?" in the
605 +        * output, then retries the conversion. This is a hack, but it seems
606 +        * like the best course of action in the circumstances. */
607 +       while (s_left > 0 && d_left > 0 && errno == EILSEQ) {
608 +           source++;
609 +           s_left--;
610 +           *dest = '?';
611 +           dest++;
612 +           d_left--;
613 +           if (s_left > 0 && d_left > 0)
614 +               iconv(conversion, &source, &s_left, &dest, &d_left);
615 +       }
616 +    }
617 +    *dest = 0; /* terminate the string */
618 +    return result;
619 +}
620 --- dillo-0.7.0~/src/encodings.h        1970-01-01 03:00:00 +0300
621 +++ dillo-0.7.0/src/encodings.h 2003-02-21 03:15:46 +0300
622 @@ -0,0 +1,18 @@
623 +#ifndef __DILLO_ENCODING_H__
624 +#define __DILLO_ENCODING_H__
625 +#include <gtk/gtk.h>
626 +#include <iconv.h>
627 +#include "browser.h"
628 +#include "encodings-types.h"
629 +
630 +
631 +/* Copyright (C) 2002 Grigory Bakunov <black@asplinux.ru> */
632 +
633 +void   a_Encodings_init();
634 +void   a_Encodings_add(GtkWidget *widget, gpointer client_data);
635 +void   a_Encodings_fill_new_menu(BrowserWindow *bw);
636 +void   a_Encoding_get_conversion(BrowserWindow *bw, char* charset);
637 +char   *a_Encoding_translate_encoding(deConversion dcv, char *buf, 
638 +                                    gint bufsize,deDirection dir);
639 +
640 +#endif /* __DILLO_ENCODING_H__ */
641 diff -ubBdr -N dillo-0.7.0~/src/encodings-types.h dillo-0.7.0/src/encodings-types.h
642 --- dillo-0.7.0~/src/encodings-types.h  1970-01-01 03:00:00 +0300
643 +++ dillo-0.7.0/src/encodings-types.h   2003-02-21 03:15:46 +0300
644 @@ -0,0 +1,19 @@
645 +#ifndef __DILLO_ENCODING_TYPES_H__
646 +#define __DILLO_ENCODING_TYPES_H__
647 +#include <iconv.h>
648 +/* Copyright (C) 2002 Grigory Bakunov <black@asplinux.ru> */
649 +
650 +typedef struct _deConversion deConversion;
651 +
652 +struct _deConversion {
653 +    iconv_t c_from;
654 +    iconv_t c_to;
655 +};
656 +
657 +
658 +typedef enum {
659 +    DE_DECODE,
660 +    DE_ENCODE
661 +} deDirection;
662 +
663 +#endif /*  __DILLO_ENCODING_TYPES_H__ */
664 diff -ubBdr -N dillo-0.7.0~/src/html.c dillo-0.7.0/src/html.c
665 --- dillo-0.7.0~/src/html.c     2003-02-14 00:01:02 +0300
666 +++ dillo-0.7.0/src/html.c      2003-02-21 03:15:46 +0300
667 @@ -21,6 +21,7 @@
668  #include <stdlib.h>
669  #include <stdio.h>      /* for sprintf */
670  #include <math.h>      /* for rint */
671 +#include <errno.h>      /* for iconv error codes */
672  
673  #include <gtk/gtk.h>
674  
675 @@ -48,6 +49,7 @@
676  #include "progressbar.h"
677  #include "prefs.h"
678  #include "misc.h"
679 +#include "encodings.h"
680  #include "capi.h"
681  #include "html.h"
682  
683 @@ -2847,7 +2849,7 @@
684     if ((form->method == DILLO_HTML_METHOD_GET) ||
685         (form->method == DILLO_HTML_METHOD_POST)) {
686        GString *DataStr = g_string_sized_new(4096);
687 -
688 +      GString *DataStrEnc;
689        DEBUG_MSG(3,"Html_submit_form form->action=%s\n",URL_STR_(form->action));
690  
691        for (input_index = 0; input_index < form->num_inputs; input_index++) {
692 @@ -2911,6 +2913,12 @@
693              break;
694           } /* switch */
695        } /* for (inputs) */
696 +      DataStrEnc = g_string_new(a_Encoding_translate_encoding(html_lb->bw->dcv,
697 +                                                                DataStr -> str,
698 +                                                                DataStr -> len,
699 +                                                                DE_ENCODE));
700 +      g_string_free(DataStr,TRUE);
701 +      DataStr = DataStrEnc;
702  
703        if ( DataStr->str[DataStr->len - 1] == '&' )
704           g_string_truncate(DataStr, DataStr->len - 1);
705 @@ -3992,6 +4000,22 @@
706        Html_write(Client->CbData, Client->Buf, Client->BufSize, 0);
707  }
708  
709 +static void Html_set_encoding(DilloHtml *html, char *buf, gint bufsize) {
710 +   /* only do _anything_ if told so */
711 +   if (html->bw->encoding != NULL)
712 +       a_Encoding_get_conversion(html->bw, html->bw->encoding);
713 +   return;
714 +}
715 +
716 +static char *Html_translate_encoding(DilloHtml *html, char *buf,
717 +                                   gint bufsize) {
718 +    char* result=a_Encoding_translate_encoding(html->bw->dcv,
719 +                                              buf, bufsize,
720 +                                              DE_DECODE);
721 +    return result;
722 +
723 +}
724 +
725  /*
726   * Here's where we parse the html and put it into the page structure.
727   * Return value: number of bytes parsed
728 @@ -4147,7 +4147,11 @@
729  
730     g_return_if_fail ( (page = DW_PAGE (html->dw)) != NULL );
731  
732 +   Html_set_encoding(html, buf, bufsize);
733 +   buf = Html_translate_encoding(html, buf, bufsize);
734 +
735     token_start = Html_write_raw(html, buf, bufsize, Eof);
736 +   g_free(buf);
737     html->Start_Ofs += token_start;
738  
739     if ( html->bw ) {
740 --- dillo-0.7.0~/src/interface.c        2003-02-11 04:09:59 +0300
741 +++ dillo-0.7.0/src/interface.c 2003-02-21 03:15:46 +0300
742 @@ -19,6 +19,7 @@
743  #include <sys/stat.h>
744  #include <sys/time.h>
745  #include <fcntl.h>
746 +#include <iconv.h>
747  
748  #include "list.h"
749  #include "misc.h"
750 @@ -54,7 +55,7 @@
751   */
752  /* BrowserWindow holds all the widgets (and perhaps more)
753   * for each new_browser.*/
754 -static BrowserWindow **browser_window;
755 +BrowserWindow **browser_window;
756  static gint num_bw, num_bw_max;
757  
758  
759 @@ -822,6 +823,9 @@
760     bw->question_dialog_window = NULL;
761     bw->question_dialog_data = NULL;
762     bw->viewsource_window = NULL;
763 +   bw->encoding=NULL;
764 +   bw->dcv.c_from  = (iconv_t)-1; /* no conversion yet */
765 +   bw->dcv.c_to  = (iconv_t)-1;
766  
767     /* now that the bw is made, let's customize it.. */
768     Interface_browser_window_customize(bw);
769 --- dillo-0.7.0~/src/Makefile.am        2003-01-05 22:24:06 +0300
770 +++ dillo-0.7.0/src/Makefile.am 2003-02-21 03:15:46 +0300
771 @@ -57,6 +57,9 @@
772         dw_tooltip.h \
773         dw_widget.c \
774         dw_widget.h \
775 +       encodings.c \
776 +       encodings.h \
777 +       encoding-types.h \
778         findtext.c \
779         findtext.h \
780         web.c   \
781 diff -ubBdr -N dillo-0.7.0~/src/Makefile.am.orig dillo-0.7.0/src/Makefile.am.orig
782 --- dillo-0.7.0~/src/menu.c     2003-02-11 00:30:13 +0300
783 +++ dillo-0.7.0/src/menu.c      2003-02-21 03:15:46 +0300
784 @@ -33,6 +33,7 @@
785  #include "bookmark.h"
786  #include "interface.h"
787  #include "menu.h"
788 +#include "encodings.h"
789  
790  /*
791   * Forward declarations
792 @@ -124,6 +125,7 @@
793     GtkWidget *file_menu;
794     /* GtkWidget *bookmarks_menu; */
795     /* GtkWidget *help_menu; */
796 +   GtkWidget *enc_menu;
797  
798     bw->menubar = menubar = gtk_menu_bar_new();
799  
800 @@ -160,6 +162,10 @@
801     Menu_add(help_menu, "Dillo _Manual", NULL, bw,
802              a_Commands_manual_callback, bw);
803     */
804 +   enc_menu = Menu_new(menubar, tiny ? "_E" : "_Encodings", FALSE, bw);
805 +   bw->enc_menu = enc_menu;
806 +   a_Encodings_fill_new_menu(bw);
807 +
808     return menubar;
809  }
810  
811 --- dillo-0.7.0~/src/prefs.c    2003-02-11 00:40:13 +0300
812 +++ dillo-0.7.0/src/prefs.c     2003-02-21 03:15:46 +0300
813 @@ -51,6 +51,7 @@
814     { "small_icons", DRC_TOKEN_SMALL_ICONS },
815     { "limit_text_width", DRC_TOKEN_LIMIT_TEXT_WIDTH },
816     { "font_factor", DRC_TOKEN_FONT_FACTOR },
817 +   { "font_charset", DRC_TOKEN_FONT_CHARSET },
818     { "use_dicache", DRC_TOKEN_USE_DICACHE },
819     { "show_back", DRC_TOKEN_SHOW_BACK },
820     { "show_forw", DRC_TOKEN_SHOW_FORW },
821 @@ -173,6 +174,10 @@
822     case DRC_TOKEN_FONT_FACTOR:
823        prefs.font_factor = strtod(scanner->value.v_string, NULL);
824        break;
825 +   case DRC_TOKEN_FONT_CHARSET:
826 +       if (prefs.font_charset) g_free(prefs.font_charset);
827 +       prefs.font_charset = g_strdup(scanner->value.v_string);
828 +      break;
829     case DRC_TOKEN_LIMIT_TEXT_WIDTH:
830        prefs.limit_text_width = (strcmp(scanner->value.v_string, "YES") == 0);
831        break;
832 @@ -250,7 +255,7 @@
833     file = a_Misc_prepend_user_home(".dillo/dillorc");
834     fd = open(file, O_RDONLY);
835     g_free(file);
836 -   if (fd < 0 && (fd = open("/etc/dillorc", O_RDONLY)) < 0)
837 +   if (fd < 0 && (fd = open("/etc/dillo/dillorc", O_RDONLY)) < 0)
838        if ((fd = open("/usr/local/etc/dillorc", O_RDONLY)) < 0)
839           return FILE_NOT_FOUND;
840  
841 @@ -347,6 +352,7 @@
842     prefs.small_icons = FALSE;
843     prefs.limit_text_width = FALSE;
844     prefs.font_factor = 1.0;
845 +   prefs.font_charset = g_strdup("iso8859-1");
846     prefs.use_dicache = FALSE;
847     prefs.show_back=TRUE;
848     prefs.show_forw=TRUE;
849 @@ -385,6 +391,8 @@
850     g_free(prefs.no_proxy);
851     if (prefs.no_proxy_vec)
852        g_strfreev(prefs.no_proxy_vec);
853 +   if (prefs.font_charset)
854 +      g_free (prefs.font_charset);
855     a_Url_free(prefs.http_proxy);
856     g_free(prefs.fw_fontname);
857     g_free(prefs.vw_fontname);
858 --- dillo-0.7.0~/src/prefs.h    2003-02-11 00:42:09 +0300
859 +++ dillo-0.7.0/src/prefs.h     2003-02-21 03:15:45 +0300
860 @@ -41,6 +41,7 @@
861     DRC_TOKEN_PANEL_SIZE,
862     DRC_TOKEN_SMALL_ICONS,
863     DRC_TOKEN_FONT_FACTOR,
864 +   DRC_TOKEN_FONT_CHARSET,
865     DRC_TOKEN_SHOW_TOOLTIP,
866     DRC_TOKEN_LIMIT_TEXT_WIDTH,
867     DRC_TOKEN_USE_DICACHE,
868 @@ -87,6 +88,7 @@
869     gboolean small_icons;
870     gboolean limit_text_width;
871     gdouble font_factor;
872 +   char *font_charset;
873     gboolean use_dicache;
874     gboolean show_back;
875     gboolean show_forw;
This page took 0.121395 seconds and 4 git commands to generate.