2009年5月14日 星期四

Dillo JavaScript experiment patch

diff -r 468e535f1435 config.h.in
--- a/config.h.in    Wed May 13 13:31:37 2009 -0400
+++ b/config.h.in    Thu May 14 23:48:02 2009 +0800
@@ -2,6 +2,9 @@
 
 /* Enable GIF images */
 #undef ENABLE_GIF
+
+/* Enable JavaScript */
+#undef ENABLE_JAVASCRIPT
 
 /* Enable JPEG images */
 #undef ENABLE_JPEG
@@ -14,6 +17,24 @@
 
 /* Define to 1 if you have the header file. */
 #undef HAVE_FCNTL_H
+
+/* Define to 1 if you have the `GC_dump' function. */
+#undef HAVE_GC_DUMP
+
+/* Define to 1 if you have the `GC_free' function. */
+#undef HAVE_GC_FREE
+
+/* Define to 1 if you have the `GC_gcollect' function. */
+#undef HAVE_GC_GCOLLECT
+
+/* Define to 1 if you have the header file. */
+#undef HAVE_GC_GC_H
+
+/* Define to 1 if you have the `GC_malloc' function. */
+#undef HAVE_GC_MALLOC
+
+/* Define to 1 if you have the `GC_malloc_atomic' function. */
+#undef HAVE_GC_MALLOC_ATOMIC
 
 /* Define to 1 if you have the `gethostbyname' function. */
 #undef HAVE_GETHOSTBYNAME
@@ -35,6 +56,12 @@
 
 /* Define to 1 if you have the header file. */
 #undef HAVE_PNG_H
+
+/* Define to 1 if you have the header file. */
+#undef HAVE_SEE_H
+
+/* Define to 1 if you have the header file. */
+#undef HAVE_SEE_SEE_H
 
 /* Define to 1 if you have the `setsockopt' function. */
 #undef HAVE_SETSOCKOPT
@@ -102,6 +129,9 @@
 /* Version number of package */
 #undef VERSION
 
+/* Define if you have Boehm GC */
+#undef WITH_BOEHM_GC
+
 /* Use char pointers for newer libiconv */
 #undef inbuf_t
 
diff -r 468e535f1435 configure.in
--- a/configure.in    Wed May 13 13:31:37 2009 -0400
+++ b/configure.in    Thu May 14 23:48:02 2009 +0800
@@ -32,6 +32,8 @@ AC_ARG_ENABLE(jpeg,   [  --disable-jpeg
               enable_jpeg=$enableval, enable_jpeg=yes)
 AC_ARG_ENABLE(gif,    [  --disable-gif           Disable support for GIF images],
               enable_gif=$enableval, enable_gif=yes)
+AC_ARG_ENABLE(javascript, [  --disable-javascript    Disable support for JavaScript],
+              enable_javascript=$enableval, enable_javascript=yes)
 AC_ARG_ENABLE(threaded-dns,[  --disable-threaded-dns  Disable the advantage of a reentrant resolver library],
               enable_threaded_dns=$enableval, enable_threaded_dns=yes)
 AC_ARG_ENABLE(rtfl,   [  --enable-rtfl           Build with rtfl messages])
@@ -183,6 +185,115 @@ fi
 
 if test "x$jpeg_ok" = "xyes"; then
   AC_DEFINE([ENABLE_JPEG], [], [Enable JPEG images])
+fi
+
+dnl ----------------
+dnl Test for libsee
+dnl ----------------
+dnl
+if test "x$enable_javascript" = "xyes"; then
+  AC_MSG_CHECKING([for libsee-config])
+
+dnl Check if the user hasn't set the variable $SEE_CONFIG
+  if test -z "$SEE_CONFIG"; then
+    SEE_CONFIG=`which libsee-config`
+  fi
+
+dnl Check if the libpng-config script was found and is executable
+  if test -n "$SEE_CONFIG" && test -x "$SEE_CONFIG"; then
+    AC_MSG_RESULT([$SEE_CONFIG])
+    see_ok="yes"
+    LIBSEE_CPPFLAGS=`$SEE_CONFIG --cppflags`
+    LIBSEE_LIBS=`$SEE_CONFIG --libs`    
+  else
+    AC_MSG_RESULT([missing])
+    see_ok="no"
+  fi
+
+dnl Try to find libpng even though libpng-config wasn't found
+  if  test "x$see_ok" = "xno"; then
+    AC_CHECK_HEADERS(see.h see/see.h, see_ok=yes && break, see_ok=no)
+
+    if test "x$see_ok" = "xyes"; then
+      old_libs="$LIBS"
+      AC_CHECK_LIB(see, SEE_interpreter_init, see_ok=yes, see_ok=no)
+      LIBS="$old_libs"
+
+      if test "x$see_ok" = "xyes"; then
+        LIBSEE_LIBS="-lsee"
+      fi
+    fi
+
+    if test "x$see_ok" = "xno"; then
+      AC_MSG_WARN([*** No libsee found. Disabling JavaScript ***])
+    fi
+  fi
+fi
+
+if test "x$see_ok" = "xyes"; then
+
+dnl ------------------------------------------------------------
+dnl external libraries
+dnl
+
+AC_ARG_WITH(boehm-gc,
+    AC_HELP_STRING([--with-boehm-gc],
+        [use Boehm-Weiser garbage collector, default=yes]),
+        [with_boehmgc=$withval], [with_boehmgc=yes])
+  if test x"$with_boehmgc" != x"no"; then
+    save_LIBSEE_LIBS="$LIBSEE_LIBS"
+    save_LIBS="$LIBS"
+    save_LDFLAGS="$LDFLAGS"
+    save_CPPFLAGS="$CPPFLAGS"
+    case "$with_boehmgc" in
+     yes)
+        LIBSEE_LIBS="$LIBSEE_LIBS -lgc"
+        LIBS="$LIBS -lgc"
+        ;;
+     *) LIBSEE_LIBS="$LIBSEE_LIBS -L${with_boehmgc}/lib -lgc"
+        LDFLAGS="$LDFLAGS -L${with_boehmgc}/lib"
+        LIBS="$LIBS -lgc"
+        CPPFLAGS="$CPPFLAGS -I${with_boehmgc}/include"
+        ;;
+    esac
+
+      # The following minimum for Boehm GC support:
+      #
+      #   #if WITH_BOEHM_GC
+      #   # include
+      #   GC_INIT();
+      #   GC_MALLOC(...);
+      #   GC_dump();
+      #   GC_gcollect();
+      #   #endif
+
+      have_boehm_gc=yes
+      AC_CHECK_HEADERS([gc/gc.h],,[have_boehm_gc=no])
+      AC_TRY_LINK([#include ],
+        [GC_INIT();
+         GC_MALLOC(1);
+         GC_gcollect();
+        ],,
+        [have_boehm_gc=no])
+      if test x"$have_boehm_gc" = x"yes"; then
+        AC_DEFINE(WITH_BOEHM_GC, [1], [Define if you have Boehm GC])
+        AC_CHECK_FUNCS([GC_malloc GC_gcollect GC_dump GC_malloc_atomic GC_free],
+                        ,[have_boehm_gc=no])
+      else
+          LIBSEE_LIBS="$save_LIBSEE_LIBS"
+          CPPFLAGS="$save_CPPFLAGS"
+      fi
+      LDFLAGS="$save_LDFLAGS"
+      LIBS="$save_LIBS"
+  else
+      have_boehm_gc=no
+  fi
+  AC_MSG_CHECKING([if we can use Boehm GC])
+  AM_CONDITIONAL(WITH_BOEHM_GC, test x"$have_boehm_gc" = x"yes")
+  AC_MSG_RESULT([$have_boehm_gc])
+
+
+  AC_DEFINE([ENABLE_JAVASCRIPT], [], [Enable JavaScript])
 fi
 
 dnl -------------
@@ -491,6 +602,8 @@ AC_SUBST(LIBJPEG_CPPFLAGS)
 AC_SUBST(LIBJPEG_CPPFLAGS)
 AC_SUBST(LIBPNG_LIBS)
 AC_SUBST(LIBPNG_CFLAGS)
+AC_SUBST(LIBSEE_LIBS)
+AC_SUBST(LIBSEE_CPPFLAGS)
 AC_SUBST(LIBZ_LIBS)
 AC_SUBST(LIBSSL_LIBS)
 AC_SUBST(LIBPTHREAD_LIBS)
diff -r 468e535f1435 src/Makefile.am
--- a/src/Makefile.am    Wed May 13 13:31:37 2009 -0400
+++ b/src/Makefile.am    Thu May 14 23:48:02 2009 +0800
@@ -14,7 +14,7 @@ dillo_LDADD = \
     ../dw/libDw-fltk.a \
     ../dw/libDw-core.a \
     ../lout/liblout.a \
-    @LIBJPEG_LIBS@ @LIBPNG_LIBS@ @LIBFLTK_LIBS@ @LIBZ_LIBS@ @LIBICONV_LIBS@
+    @LIBJPEG_LIBS@ @LIBPNG_LIBS@ @LIBFLTK_LIBS@ @LIBZ_LIBS@ @LIBICONV_LIBS@ @LIBSEE_LIBS@
 
 dillo_SOURCES = \
     dillo.cc \
diff -r 468e535f1435 src/form.cc
--- a/src/form.cc    Wed May 13 13:31:37 2009 -0400
+++ b/src/form.cc    Thu May 14 23:48:02 2009 +0800
@@ -24,6 +24,8 @@
 #include "prefs.h"
 #include "nav.h"
 #include "uicmd.hh"
+
+#include "capi.h"
 
 using namespace dw;
 using namespace dw::core;
@@ -95,6 +97,7 @@ class DilloHtmlForm {
                                   Dstr *x, Dstr *y);
 
 public:  //BUG: for now everything is public
+   char *name;
    DilloHtmlMethod method;
    DilloUrl *action;
    DilloHtmlEnc content_type;
@@ -107,7 +110,7 @@ public:  //BUG: for now everything is pu
    DilloHtmlReceiver *form_receiver;
 
 public:
-   DilloHtmlForm (DilloHtml *html,
+   DilloHtmlForm (DilloHtml *html, char *name,
                   DilloHtmlMethod method, const DilloUrl *action,
                   DilloHtmlEnc content_type, const char *charset,
                   bool enabled);
@@ -151,6 +154,7 @@ public:  //BUG: for now everything is pu
    bool init_val;     /* only meaningful for buttons */
    Dstr *file_data;   /* only meaningful for file inputs.
                          TODO: may become a list... */
+   char *onclick;
 
 private:
    void connectTo(DilloHtmlReceiver *form_receiver);
@@ -159,7 +163,7 @@ private:
 
 public:
    DilloHtmlInput (DilloHtmlInputType type, Embed *embed,
-                   const char *name, const char *init_str, bool init_val);
+                   const char *name, const char *init_str, bool init_val, const char *onclick);
    ~DilloHtmlInput ();
    void appendValuesTo(Dlist *values, bool is_active_submit);
    void reset();
@@ -194,12 +198,12 @@ private:
  * Form API
  */
 
-DilloHtmlForm *a_Html_form_new (DilloHtml *html, DilloHtmlMethod method,
+DilloHtmlForm *a_Html_form_new (DilloHtml *html, char *name, DilloHtmlMethod method,
                                 const DilloUrl *action,
                                 DilloHtmlEnc content_type, const char *charset,
                                 bool enabled)
 {
-   return new DilloHtmlForm (html, method, action, content_type, charset, enabled);
+   return new DilloHtmlForm (html, name, method, action, content_type, charset, enabled);
 }
 
 void a_Html_form_delete (DilloHtmlForm *form)
@@ -236,11 +240,11 @@ void a_Html_form_display_hiddens2(void *
  */
 static void Html_add_input(DilloHtml *html, DilloHtmlInputType type,
                            Embed *embed, const char *name,
-                           const char *init_str, bool init_val)
+                           const char *init_str, bool init_val, const char *onclick)
 {
    _MSG("name=[%s] init_str=[%s] init_val=[%d]\n", name, init_str, init_val);
    DilloHtmlInput *input = new DilloHtmlInput(type, embed, name, init_str,
-                                              init_val);
+                                              init_val, onclick);
    if (html->InFlags & IN_FORM) {
       html->getCurrentForm()->addInput(input, type);
    } else {
@@ -292,6 +296,7 @@ static DilloHtmlInput *Html_get_current_
  */
 void Html_tag_open_form(DilloHtml *html, const char *tag, int tagsize)
 {
+   char *name = 0;
    DilloUrl *action;
    DilloHtmlMethod method;
    DilloHtmlEnc content_type;
@@ -309,6 +314,9 @@ void Html_tag_open_form(DilloHtml *html,
    html->InFlags &= ~IN_OPTION;
    html->InFlags &= ~IN_TEXTAREA;
 
+   if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "name"))) {
+      name = dStrdup(attrbuf);
+   }
    method = DILLO_HTML_METHOD_GET;
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "method"))) {
       if (!dStrcasecmp(attrbuf, "post")) {
@@ -348,7 +356,7 @@ void Html_tag_open_form(DilloHtml *html,
    }
    if (!charset)
       charset = html->charset;
-   html->formNew(method, action, content_type, charset);
+   html->formNew(name, method, action, content_type, charset);
    dFree(first);
    a_Url_free(action);
 }
@@ -411,7 +419,7 @@ void Html_tag_open_input(DilloHtml *html
    DilloHtmlInputType inp_type;
    Resource *resource = NULL;
    Embed *embed = NULL;
-   char *value, *name, *type, *init_str;
+   char *value, *name, *type, *onclick, *init_str;
    const char *attrbuf, *label;
    bool init_val = false;
    ResourceFactory *factory;
@@ -431,6 +439,7 @@ void Html_tag_open_input(DilloHtml *html
    value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL);
    name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL);
    type = a_Html_get_attr_wdef(html, tag, tagsize, "type", "");
+   onclick = a_Html_get_attr_wdef(html, tag, tagsize, "onclick", NULL);
 
    init_str = NULL;
    inp_type = DILLO_HTML_INPUT_UNKNOWN;
@@ -528,7 +537,7 @@ void Html_tag_open_input(DilloHtml *html
 
    if (inp_type != DILLO_HTML_INPUT_UNKNOWN) {
       Html_add_input(html, inp_type, embed, name,
-                     (init_str) ? init_str : "", init_val);
+                     (init_str) ? init_str : "", init_val, onclick);
    }
 
    if (embed != NULL && inp_type != DILLO_HTML_INPUT_IMAGE &&
@@ -554,6 +563,8 @@ void Html_tag_open_input(DilloHtml *html
    if (init_str != value)
       dFree(init_str);
    dFree(value);
+   if(onclick)
+      dFree(onclick);
 }
 
 /*
@@ -562,6 +573,7 @@ void Html_tag_open_input(DilloHtml *html
  */
 void Html_tag_open_isindex(DilloHtml *html, const char *tag, int tagsize)
 {
+   char *name = 0;
    DilloUrl *action;
    Embed *embed;
    const char *attrbuf;
@@ -571,12 +583,15 @@ void Html_tag_open_isindex(DilloHtml *ht
       return;
    }
 
+   if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "name"))) {
+      name = dStrdup(attrbuf);
+   }
    if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "action")))
       action = a_Html_url_new(html, attrbuf, NULL, 0);
    else
       action = a_Url_dup(html->base_url);
 
-   html->formNew(DILLO_HTML_METHOD_GET, action, DILLO_HTML_ENC_URLENCODED,
+   html->formNew(name, DILLO_HTML_METHOD_GET, action, DILLO_HTML_ENC_URLENCODED,
                  html->charset);
    html->InFlags |= IN_FORM;
 
@@ -588,7 +603,7 @@ void Html_tag_open_isindex(DilloHtml *ht
    ResourceFactory *factory = HT2LT(html)->getResourceFactory();
    EntryResource *entryResource = factory->createEntryResource (20,false,NULL);
    embed = new Embed (entryResource);
-   Html_add_input(html, DILLO_HTML_INPUT_INDEX, embed, NULL, NULL, FALSE);
+   Html_add_input(html, DILLO_HTML_INPUT_INDEX, embed, NULL, NULL, FALSE, 0);
 
    HT2TB(html)->addWidget (embed, html->styleEngine->backgroundStyle ());
 
@@ -656,7 +671,7 @@ void Html_tag_open_textarea(DilloHtml *h
    /* Readonly or not? */
    if (a_Html_get_attr(html, tag, tagsize, "readonly"))
       textres->setEditable(false);
-   Html_add_input(html, DILLO_HTML_INPUT_TEXTAREA, embed, name, NULL, false);
+   Html_add_input(html, DILLO_HTML_INPUT_TEXTAREA, embed, name, NULL, false, 0);
 
    HT2TB(html)->addWidget (embed, html->styleEngine->backgroundStyle ());
    dFree(name);
@@ -744,7 +759,7 @@ void Html_tag_open_select(DilloHtml *htm
 
    HT2TB(html)->addWidget (embed, html->styleEngine->backgroundStyle ());
 
-   Html_add_input(html, type, embed, name, NULL, false);
+   Html_add_input(html, type, embed, name, NULL, false, 0);
    a_Html_stash_init(html);
    dFree(name);
 }
@@ -837,7 +852,7 @@ void Html_tag_open_button(DilloHtml *htm
       /* Render the button */
       Widget *page;
       Embed *embed;
-      char *name, *value;
+      char *name, *value, *onclick;
 
       page = new Textblock (prefs.limit_text_width);
       page->setStyle (html->styleEngine->backgroundStyle ());
@@ -857,10 +872,13 @@ void Html_tag_open_button(DilloHtml *htm
 
       value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL);
       name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL);
+      onclick = a_Html_get_attr_wdef(html, tag, tagsize, "onclick", NULL);
 
-      Html_add_input(html, inp_type, embed, name, value, FALSE);
+      Html_add_input(html, inp_type, embed, name, value, FALSE, onclick);
       dFree(name);
       dFree(value);
+      if(onclick)
+         dFree(onclick);
    }
    dFree(type);
 }
@@ -885,11 +903,13 @@ void Html_tag_close_button(DilloHtml *ht
  * Constructor
  */
 DilloHtmlForm::DilloHtmlForm (DilloHtml *html2,
+                              char *name2,
                               DilloHtmlMethod method2,
                               const DilloUrl *action2,
                               DilloHtmlEnc content_type2,
                               const char *charset, bool enabled)
 {
+   name = name2;
    html = html2;
    method = method2;
    action = a_Url_dup(action2);
@@ -907,6 +927,8 @@ DilloHtmlForm::DilloHtmlForm (DilloHtml
  */
 DilloHtmlForm::~DilloHtmlForm ()
 {
+   if(name)
+      dFree(name);
    a_Url_free(action);
    dFree(submit_charset);
    for (int j = 0; j < inputs->size(); j++)
@@ -937,6 +959,21 @@ void DilloHtmlForm::eventHandler(Resourc
  */
 void DilloHtmlForm::submit(DilloHtmlInput *active_input, EventButton *event)
 {
+  if(active_input->onclick) {
+    //printf("onclick = %s\n", active_input->onclick);
+    bool bRetVal = false;
+    char *s = active_input->onclick;
+    if(strncasecmp("return ", active_input->onclick, 7) == 0) {
+      s = active_input->onclick + 7;
+      bRetVal = true; /*Enable return value check*/
+    }
+    void *p = a_Html_script_run(html, s);
+    if(bRetVal && p == 0)  {
+printf("onClick fail...\n");
+      return;
+    }
+  }
+
    DilloUrl *url = buildQueryUrl(active_input);
    if (url) {
       if (event && event->button == 2) {
@@ -1528,13 +1565,14 @@ void DilloHtmlReceiver::clicked (Resourc
  */
 DilloHtmlInput::DilloHtmlInput (DilloHtmlInputType type2, Embed *embed2,
                                 const char *name2, const char *init_str2,
-                                bool init_val2)
+                                bool init_val2, const char *onclick2)
 {
    type = type2;
    embed = embed2;
    name = (name2) ? dStrdup(name2) : NULL;
    init_str = (init_str2) ? dStrdup(init_str2) : NULL;
    init_val = init_val2;
+   onclick = (onclick2) ? dStrdup(onclick2) : NULL;
    select = NULL;
    switch (type) {
    case DILLO_HTML_INPUT_SELECT:
@@ -1558,6 +1596,8 @@ DilloHtmlInput::~DilloHtmlInput ()
    dStr_free(file_data, 1);
    if (select)
       delete select;
+   if (onclick)
+      dFree(onclick);
 }
 
 /*
@@ -1936,3 +1976,480 @@ static void Html_option_finish(DilloHtml
          a_Html_parse_entities(html, html->Stash->str, html->Stash->len);
    }
 }
+
+/*
+ * File: dom.cc
+ *
+ * Copyright (C) 2009 Steve Chang
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ */
+
+/*
+* Document Object Model
+*/
+
+#if WITH_BOEHM_GC
+# include
+#endif
+
+#include
+
+static struct SEE_interpreter *interp = 0;
+
+/*
+ * Runs the input given by inp, printing any exceptions
+ * to stderr.
+ * This function first establishes a local exception catch context.
+ * Next, it passes the unicode input provider ('inp') to the generic
+ * evaluation procedure SEE_Global_eval which executes the program
+ * text in the ECMAScript global context. This function also examines
+ * the result of the evaluation, being careful to print out exceptions
+ * correctly.
+ * Returns 0 if an exception was uncaught, or 1 if the script ran to
+ * completion.
+ */
+static int
+run_input(struct SEE_input *inp, struct SEE_value *res)
+{
+  struct SEE_value v;
+  SEE_try_context_t ctxt, ctxt2;
+
+  interp->traceback = NULL;
+        SEE_TRY (interp, ctxt) {
+/*
+      if (debugger)
+          debug_eval(interp, debugger, inp, res);
+      else
+*/
+          SEE_Global_eval(interp, inp, res);
+        }
+        if (SEE_CAUGHT(ctxt)) {
+            fprintf(stderr, "exception:\n");
+            SEE_TRY(interp, ctxt2) {
+                SEE_ToString(interp, SEE_CAUGHT(ctxt), &v);
+                fprintf(stderr, "  ");
+                SEE_string_fputs(v.u.string, stderr);
+                fprintf(stderr, "\n");
+#ifndef NDEBUG
+                if (ctxt.throw_file)
+        fprintf(stderr, "  (thrown from %s:%d)\n",
+                        ctxt.throw_file, ctxt.throw_line);
+#endif
+    SEE_PrintContextTraceback(interp, &ctxt, stderr);
+            }
+            if (SEE_CAUGHT(ctxt2)) {
+    /* Exception while printing exception! */
+                fprintf(stderr, "[exception thrown while printing exception");
+    if (ctxt2.throw_file)
+        fprintf(stderr, " at %s:%d",
+            ctxt2.throw_file, ctxt2.throw_line);
+                fprintf(stderr, "]\n");
+      }
+      return 0;
+        }
+        return 1;
+}
+
+class DilloHtmlScript {
+  DilloHtml *html;
+  DilloHtmlScriptType type;
+  DilloUrl *src;
+  char *script;
+  struct SEE_input *input;
+
+public:
+  DilloHtmlScript(DilloHtml *html, DilloHtmlScriptType type, const DilloUrl *src, const char *script);
+  ~DilloHtmlScript();
+
+  void Script(const char *script);
+  void Input();
+};
+
+/*
+ * Called by the network engine to load javascript.
+ */
+
+static void Script_load_callback(int Op, CacheClient_t *Client)
+{
+   _MSG("Script_load_callback: Op=%d\n", Op);
+   if (Op) { /* EOF */
+/*Are we really get javascript ? Maybe some thing below.*/
+/*
+
+

400 Bad Request


+Your request has bad syntax or is inherently impossible to satisfy.
+

+thttpd/2.20c 21nov01
+
+*/
+      DilloHtmlScript *s = (DilloHtmlScript *)Client->CbData;
+      s->Script((const char *)Client->Buf);
+/*
+      printf("Load %s complete\n", a_Url_str(Client->Url));
+      printf("**************************************************\n");
+      printf("%s\n", Client->Buf);
+      printf("**************************************************\n");
+*/
+   }
+}
+
+DilloHtmlScript::DilloHtmlScript(DilloHtml *_html, DilloHtmlScriptType _type, const DilloUrl *_src, const char *_script)
+: html(_html), type(_type), script(NULL)
+{
+  //src = (_src) ? dStrdup(_src) : NULL;
+  src = a_Url_dup(_src);
+  if(_script)
+    Script(_script);
+  else {
+      DilloWeb *Web;
+      int ClientKey;
+      /* Fill a Web structure for the cache query */
+      Web = a_Web_new(src);
+      Web->bw = html->bw;
+      if ((ClientKey = a_Capi_open_url(Web, Script_load_callback, this)) != 0) {
+         a_Bw_add_client(html->bw, ClientKey, 0);
+         a_Bw_add_url(html->bw, src);
+      }
+  }
+}
+
+DilloHtmlScript::~DilloHtmlScript()
+{
+  a_Url_free(src);
+  if(script)
+    dFree(script);
+  if(input)
+    SEE_INPUT_CLOSE(input);
+}
+
+void DilloHtmlScript::Script(const char *_script)
+{
+  if(_script == NULL)
+    return;
+
+  script = dStrdup(_script);
+}
+
+void DilloHtmlScript::Input()
+{
+  input = SEE_input_utf8(interp, script);
+  if(src)
+    input->filename = SEE_intern_ascii(interp, a_Url_str(src));
+  else
+    input->filename = SEE_intern_ascii(interp, "");
+  run_input(input, NULL);
+}
+
+DilloHtmlScript *a_Html_script_new(DilloHtml *html, DilloHtmlScriptType type, const DilloUrl *src, const char *script)
+{
+  return new DilloHtmlScript(html, type, src, script);
+}
+
+/*
+*
+*/
+
+struct method {
+  const char *name;
+  void (*fn)(struct SEE_interpreter *, struct SEE_object *,
+    struct SEE_object *, int, struct SEE_value **,
+    struct SEE_value *);
+  int expected_args;
+};
+/*
+static void
+add_methods(interpreter, object, methods)
+  struct SEE_interpreter *interpreter;
+  struct SEE_object *object;
+  const struct method *methods;
+*/
+static void
+add_methods(struct SEE_interpreter *interpreter,
+  struct SEE_object* object,
+  const struct method *methods)
+{
+  unsigned int i;
+
+  for (i = 0; methods[i].name; i++)
+    SEE_CFUNCTION_PUTA(interpreter, object,
+        methods[i].name, methods[i].fn,
+        methods[i].expected_args, 0);
+}
+
+/*
+ * A write function that prints its output to stdout.
+ * No newline is appended.
+ */
+static void
+document_write(struct SEE_interpreter *interpreter,
+  struct SEE_object *self,
+  struct SEE_object *thisobj,
+  int argc,
+  struct SEE_value **argv,
+  struct SEE_value *res)
+{
+  struct SEE_value v;
+
+  if (argc) {
+    SEE_ToString(interp, argv[0], &v);
+    SEE_string_fputs(v.u.string, stdout);
+    fflush(stdout);
+  }
+  SEE_SET_UNDEFINED(res);
+}
+
+/*
+ * A function that gets forms object by name.
+*/
+static void
+document_getElementById(struct SEE_interpreter *interpreter,
+  struct SEE_object *self,
+  struct SEE_object *thisobj,
+  int argc,
+  struct SEE_value **argv,
+  struct SEE_value *res)
+{
+  struct SEE_value v, s;
+
+  if(thisobj && argc) {
+    SEE_ToString(interp, argv[0], &s);
+    SEE_OBJECT_GET(interp, thisobj, SEE_intern(interp, s.u.string), &v);
+    if (SEE_VALUE_GET_TYPE(&v) == SEE_OBJECT) {
+      SEE_SET_OBJECT(res, v.u.object);  /*Object already created, just return it.*/
+      return;
+    }
+  }
+
+  SEE_SET_UNDEFINED(res);
+}
+
+/*
+* Form submit
+*/
+static void
+form_submit(struct SEE_interpreter *interpreter,
+  struct SEE_object *self,
+  struct SEE_object *thisobj,
+  int argc,
+  struct SEE_value **argv,
+  struct SEE_value *res)
+{
+  SEE_SET_UNDEFINED(res);
+}
+
+/*
+* Form reset
+*/
+static void
+form_reset(struct SEE_interpreter *interpreter,
+  struct SEE_object *self,
+  struct SEE_object *thisobj,
+  int argc,
+  struct SEE_value **argv,
+  struct SEE_value *res)
+{
+  DilloHtmlInput *i = (DilloHtmlInput *)thisobj->host_data;
+  i->reset();
+
+  SEE_SET_UNDEFINED(res);
+}
+
+/*
+* Input focus
+*/
+static void
+input_focus(struct SEE_interpreter *interpreter,
+  struct SEE_object *self,
+  struct SEE_object *thisobj,
+  int argc,
+  struct SEE_value **argv,
+  struct SEE_value *res)
+{
+  SEE_SET_UNDEFINED(res);
+}
+
+static void
+global_alert(struct SEE_interpreter *interpreter,
+  struct SEE_object *self,
+  struct SEE_object *thisobj,
+  int argc,
+  struct SEE_value **argv,
+  struct SEE_value *res)
+{
+  SEE_SET_UNDEFINED(res);
+}
+
+/*
+*
+*/
+#if WITH_BOEHM_GC
+# include
+#endif
+
+void a_Dom_setup(DilloHtml *html)
+{
+  static int interp_initialised = 0;
+  static struct SEE_interpreter i;
+
+  #if WITH_BOEHM_GC
+    GC_INIT();
+  #endif
+
+#define INIT_INTERP_ONCE do {       \
+  if (!interp_initialised) {      \
+      SEE_interpreter_init(&i);    \
+      interp_initialised = 1;     \
+  }           \
+  } while (0)
+
+  INIT_INTERP_ONCE;
+
+  interp = &i;
+  
+  SEE_CFUNCTION_PUTA(interp, interp->Global, "alert", global_alert, 1, 0); /*form.length*/
+
+  struct SEE_object *document, *forms;
+  struct SEE_value v;
+
+  document = SEE_Object_new(interp);
+  document->host_data = html;
+  SEE_SET_OBJECT(&v, document);
+  SEE_OBJECT_PUTA(interp, interp->Global, "document", &v, 0);
+
+  static const struct method document_methods[] = {
+    { "write", document_write,  1 },
+    { "getElementById", document_getElementById, 1  },
+    {0}
+  };
+
+  add_methods(interp, document, document_methods);
+
+  /**/
+
+  forms = SEE_Object_new(interp);
+  forms->host_data = html->forms;
+  SEE_SET_OBJECT(&v, forms);
+  SEE_OBJECT_PUTA(interp, document, "forms", &v, 0);
+/*forms.length -> number of forms in a document */
+  SEE_SET_NUMBER(&v, html->forms->size());
+  SEE_OBJECT_PUTA(interp, forms, "length", &v, 0);
+
+
+  if(html->forms) {
+/*Create object according to form name*/
+    int c;
+    for(c=0;c forms->size();c++)  {
+      DilloHtmlForm* f = html->forms->get(c);
+      if(!f || !f->name)  /*Object MUST exist and have a name*/
+        continue;
+/**/
+      struct SEE_object *form = SEE_Object_new(interp);
+      form->host_data = f;
+      SEE_SET_OBJECT(&v, form);
+      SEE_OBJECT_PUTA(interp, document, f->name, &v, 0);
+/*form.length*/
+      SEE_SET_NUMBER(&v, f->inputs->size());
+      SEE_OBJECT_PUTA(interp, form, "length", &v, 0);
+
+/*form.method*/    
+      switch(f->method) {
+        case DILLO_HTML_METHOD_UNKNOWN: SEE_SET_STRING(&v, SEE_string_sprintf(interp, ""));
+          break;
+        case DILLO_HTML_METHOD_GET: SEE_SET_STRING(&v, SEE_string_sprintf(interp, "get"));
+          break;
+        case DILLO_HTML_METHOD_POST:  SEE_SET_STRING(&v, SEE_string_sprintf(interp, "post"));
+          break;
+      }
+      SEE_OBJECT_PUTA(interp, form, "method", &v, 0);
+/*form.submit()*/      
+      SEE_CFUNCTION_PUTA(interp, form, "submit", form_submit, 0, 0); /*form.submit*/
+/*form.reset()*/      
+      SEE_CFUNCTION_PUTA(interp, form, "reset", form_reset, 0, 0); /*form.reset*/
+
+/*Create object according to input name*/
+      lout::misc::SimpleVector *inputs = f->inputs;
+      if(inputs)  {
+        int cc;
+        for(cc=0;cc size();cc++) {
+          DilloHtmlInput *i = inputs->get(cc);
+          if(!i || !i->name)  /*Object MUST exist and have a name*/
+            continue;
+          struct SEE_object *inp = SEE_Object_new(interp);
+          inp->host_data = i;
+          SEE_SET_OBJECT(&v, inp);
+          SEE_OBJECT_PUTA(interp, form, i->name, &v, 0);
+
+/*input.value*/          
+          switch (i->type) {
+            case DILLO_HTML_INPUT_TEXT:
+            case DILLO_HTML_INPUT_PASSWORD:
+            case DILLO_HTML_INPUT_INDEX:
+            case DILLO_HTML_INPUT_HIDDEN: {
+              EntryResource *entryres = (EntryResource*)i->embed->getResource();
+              SEE_SET_STRING(&v, SEE_string_sprintf(interp, "%s", entryres->getText()));
+            } break;
+            default:
+              SEE_SET_STRING(&v, SEE_string_sprintf(interp, ""));
+              break;
+          }
+          SEE_OBJECT_PUTA(interp, inp, "value", &v, 0);
+/*input.focus()*/
+          SEE_CFUNCTION_PUTA(interp, inp, "focus", input_focus, 0, 0);
+        }
+      }
+    }
+  }
+}
+
+/*
+*
+*/
+
+void *a_Html_script_run(DilloHtml *html, const char *script)
+{  
+  a_Dom_setup(html);
+
+  int i;
+  for(i=0;i scripts->size();i++)  {
+    DilloHtmlScript *s = html->scripts->get(i);
+    s->Input();
+  }
+
+  static struct SEE_value res, rstr;
+  struct SEE_input *input;
+  SEE_string *r;
+
+printf("Run : %s\n", script);
+  input = SEE_input_utf8(interp, script);
+  if (run_input(input, &res)) {
+    printf(" = ");
+    SEE_PrintValue(interp, &res, stdout);
+    printf("\n");
+  }
+
+  SEE_INPUT_CLOSE(input);
+
+  switch(SEE_VALUE_GET_TYPE(&res))  {
+    case SEE_UNDEFINED:
+    case SEE_NULL:
+    case SEE_OBJECT:
+      return 0;
+    case SEE_BOOLEAN:
+      return (void *)res.u.boolean;
+    case SEE_NUMBER:
+      //return (void *)res.u.number;
+    case SEE_STRING:
+      SEE_ToString(interp, &res, &rstr);
+      r = rstr.u.string;
+      break;
+    default:
+      return 0;
+  }
+  
+  return r->data;
+}
+
diff -r 468e535f1435 src/form.hh
--- a/src/form.hh    Wed May 13 13:31:37 2009 -0400
+++ b/src/form.hh    Thu May 14 23:48:02 2009 +0800
@@ -31,6 +31,7 @@ class DilloHtml;
  */
 
 DilloHtmlForm *a_Html_form_new(DilloHtml *html,
+                               char *name,
                                DilloHtmlMethod method,
                                const DilloUrl *action,
                                DilloHtmlEnc enc,
@@ -59,4 +60,20 @@ void Html_tag_open_button(DilloHtml *htm
 void Html_tag_open_button(DilloHtml *html, const char *tag, int tagsize);
 void Html_tag_close_button(DilloHtml *html, int TagIdx);
 
+/*
+* Script
+*/
+
+void a_Dom_setup(DilloHtml *html);
+
+typedef enum {
+   DILLO_HTML_JAVASCRIPT,
+   DILLO_HTML_VBSCRIPT
+} DilloHtmlScriptType;
+
+class DilloHtmlScript;
+
+DilloHtmlScript *a_Html_script_new(DilloHtml *html, DilloHtmlScriptType type, const DilloUrl *src, const char *script);
+void *a_Html_script_run(DilloHtml *html, const char *script);
+
 #endif /* __FORM_HH__ */
diff -r 468e535f1435 src/html.cc
--- a/src/html.cc    Wed May 13 13:31:37 2009 -0400
+++ b/src/html.cc    Thu May 14 23:48:02 2009 +0800
@@ -40,6 +40,8 @@
 #include "html_common.hh"
 #include "form.hh"
 #include "table.hh"
+
+#include "dom.hh"
 
 #include "dw/textblock.hh"
 #include "dw/bullet.hh"
@@ -472,6 +474,7 @@ DilloHtml::DilloHtml(BrowserWindow *p_bw
    inputs_outside_form = new misc::SimpleVector (1);
    links = new misc::SimpleVector (64);
    images = new misc::SimpleVector (16);
+   scripts = new misc::SimpleVector   (1);
    //a_Dw_image_map_list_init(&maps);
 
    /* Initialize the main widget */
@@ -635,18 +638,28 @@ void DilloHtml::finishParsing(int Client
 /*
  * Allocate and insert form information.
  */
-int DilloHtml::formNew(DilloHtmlMethod method, const DilloUrl *action,
+int DilloHtml::formNew(char *name, DilloHtmlMethod method, const DilloUrl *action,
                        DilloHtmlEnc enc, const char *charset)
 {
    // avoid data loss on repush after CSS stylesheets have been loaded
    bool enabled = bw->NumPendingStyleSheets == 0;
-   DilloHtmlForm *form = a_Html_form_new (this, method, action,
+   DilloHtmlForm *form = a_Html_form_new (this, name, method, action,
                                           enc, charset, enabled);
    int nf = forms->size ();
    forms->increase ();
    forms->set (nf, form);
    _MSG("Html formNew: action=%s nform=%d\n", action, nf);
    return forms->size();
+}
+
+int DilloHtml::scriptNew(DilloHtmlScriptType type, const DilloUrl *src, const char *script)
+{
+   DilloHtmlScript *s = a_Html_script_new(this, type, src, script);
+   int ns = scripts->size ();
+   scripts->increase ();
+   scripts->set (ns, s);
+   _MSG("Html scriptNew: src=%s nform=%d\n", a_Url_str(src), ns);
+   return scripts->size();
 }
 
 /*
@@ -1624,6 +1637,20 @@ static void Html_tag_close_title(DilloHt
  */
 static void Html_tag_open_script(DilloHtml *html, const char *tag, int tagsize)
 {
+   const char *attrbuf;
+   attrbuf = a_Html_get_attr(html, tag, tagsize, "language");
+   if(attrbuf) {
+   if(dStristr(attrbuf, "javascript"))  {
+      //printf("JavaScript\n");
+
+      DilloUrl *url;
+      if (!(attrbuf = a_Html_get_attr(html, tag, tagsize, "src")) ||
+       !(url = a_Html_url_new(html, attrbuf, NULL, 0)))
+         goto script_done;
+
+      html->scriptNew(DILLO_HTML_JAVASCRIPT, url, 0);
+   }
+   }
+
+script_done:
    a_Html_stash_init(html);
    S_TOP(html)->parse_mode = DILLO_HTML_PARSE_MODE_VERBATIM;
 }
@@ -1633,7 +1660,10 @@ static void Html_tag_open_script(DilloHt
  */
 static void Html_tag_close_script(DilloHtml *html, int TagIdx)
 {
+   //printf("html->Stash->str = \n%s\n", html->Stash->str);
    /* eventually the stash will be sent to an interpreter for parsing */
+   if(html->Stash->str && html->Stash->str != "")
+      html->scriptNew(DILLO_HTML_JAVASCRIPT, 0, html->Stash->str);
 }
 
 /*
@@ -3425,7 +3455,7 @@ static void Html_process_tag(DilloHtml *
    }
 
    /* Handle HTML, HEAD and BODY. Elements with optional open and close */
-   if (!(html->InFlags & IN_BODY) /* && parsing HTML */)
+   if (!(html->InFlags & IN_BODY) && (ni != 54)/* && parsing HTML */)
       Html_test_section(html, ni, IsCloseTag);
 
    /* Tag processing */
diff -r 468e535f1435 src/html_common.hh
--- a/src/html_common.hh    Wed May 13 13:31:37 2009 -0400
+++ b/src/html_common.hh    Thu May 14 23:48:02 2009 +0800
@@ -14,6 +14,8 @@
 #include "form.hh"
 
 #include "styleengine.hh"
+
+#include "dom.hh"
 
 /*
  * Macros
@@ -196,6 +198,7 @@ public:  //BUG: for now everything is pu
    lout::misc::SimpleVector *inputs_outside_form;
    lout::misc::SimpleVector *links;
    lout::misc::SimpleVector *images;
+   lout::misc::SimpleVector *scripts;
    dw::ImageMapsList maps;
 
 private:
@@ -210,8 +213,9 @@ public:
    void write(char *Buf, int BufSize, int Eof);
    int getCurTagLineNumber();
    void finishParsing(int ClientKey);
-   int formNew(DilloHtmlMethod method, const DilloUrl *action,
+   int formNew(char *name, DilloHtmlMethod method, const DilloUrl *action,
                DilloHtmlEnc enc, const char *charset);
+   int scriptNew(DilloHtmlScriptType type, const DilloUrl *src, const char *script);
    DilloHtmlForm *getCurrentForm ();
    bool_t unloadedImages();
    void loadImages (const DilloUrl *pattern);


2009年5月6日 星期三

dillo cross compile for mipsel (base on fltk +nxlib)





很久以前就知道dillo這個embedded web browser.
也曾經試著cross compile過,但並不成功.
這兩天因緣際會之下又把它拿出來玩玩看.
過程如下

Requirement

jpeg-6b
libpng-1.2.24
libiconv-1.13
microwindows-0.91
nxlib-0.45

以上Libraries的cross compile就不再贅述.

fltk-2.0.x-r6483
dillo-2.0

1.Cross compile fltk-2.0.x-r6483

CFLAGS="-G 0 -I$PWD/.." CXXFLAGS="-G 0 -I$PWD/.." LDFLAGS="-s -L$PWD/../nxlib-0.45 -L$PWD/../microwindows-0.91/src/lib" CXX=mipsel-linux-uclibc-g++  CC=mipsel-linux-uclibc-gcc AR=mipsel-linux-uclibc-ar ./configure --host=mipsel-linux --target=mipsel-linux --prefix=/usr/local/MIPSEL_UCLIBC --enable-shared --with-x --disable-gl --disable-cygwin --x-includes=../ --x-libraries=$PWD/../nxlib-0.45 --cache-file=/dev/null

修改fltk2-xonfig & makeinclude
將所有 -lXi -lXext拿掉,換成-lX11 -lnano-X
之後過程中有一樣錯誤的也比照辦理修改Makefile

make
sudo PATH=$PATH:/usr/local/MIPSEL_UCLIBC make install

2.Cross compile dillo-2.0

修改configure

將fltk2_config 換成 $FLTK2_CONFIG

{ echo "$as_me:$LINENO: checking FLTK2" >&5
echo $ECHO_N "checking FLTK2... $ECHO_C" >&6; }
if sh -c "$FLTK2_CONFIG --version" >/dev/null 2>&1
then { echo "$as_me:$LINENO: result: yes" >&5
echo "${ECHO_T}yes" >&6; }
     LIBFLTK_CXXFLAGS=`$FLTK2_CONFIG --cxxflags`
     LIBFLTK_CFLAGS=`$FLTK2_CONFIG --cflags`
     LIBFLTK_LIBS=`$FLTK2_CONFIG --use-images --ldflags`
else { echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6; }
     { { echo "$as_me:$LINENO: error: FLTK2 must be installed!" >&5
echo "$as_me: error: FLTK2 must be installed!" >&2;}
   { (exit 1); exit 1; }; }
fi


FLTK2_CONFIG=../fltk-2.0.x-r6483/fltk2-config PNG_CONFIG=../libpng-1.2.24/libpng-config CC=mipsel-linux-uclibc-gcc CXX=mipsel-linux-uclibc-g++ AR=mipsel-linux-uclibc-ar ./configure --host=mipsel-linux --target=mipsel-linux --cache-file=/dev/null

patch code
http://lists.auriga.wearlab.de/pipermail/dillo-dev/2008-November/005427.html
--- dillo2/src/html.cc	2008-10-30 21:15:50.000000000 +0000
+++ dillo2-sup/src/html.cc 2008-11-11 20:53:21.000000000 +0000
@@ -3722,6 +3722,39 @@ static void Html_callback(int Op, CacheC
}

/*
+ * Determine length of word in string s
+ */
+static int Html_word_len(char *s, char *end)
+{
+ int len = 0;
+
+ while (1) {
+ if (strchr(" <\n\r\t\f\v", *s))
+ break;
+ if (!(*s & 0x80)) {
+ /* ascii */
+ len++;
+ s++;
+ } else {
+ int l;
+ unsigned unicode = utf8decode(s, end, &l);
+ len += l;
+ s += l;
+ if ((unicode >= 0xf900 && unicode <= 0xfaff) ||
+ (unicode >= 0xfe30 && unicode <= 0xfe4f) ||
+ ((unicode >= 0x2E80 && unicode <= 0xa4cf) &&
+ !(unicode >= 0x3130 && unicode <= 0x318f))) {
+ /* Treat Chinese/Japanese characters as words so that text
+ * without whitespace will wrap.
+ */
+ break;
+ }
+ }
+ }
+ return len;
+}
+
+/*
* Here's where we parse the html and put it into the Textblock structure.
* Return value: number of bytes parsed
*/
@@ -3833,7 +3866,7 @@ static int Html_write_raw(DilloHtml *htm
} else {
/* A Word: search for whitespace or tag open */
while (++buf_index < bufsize) {
- buf_index += strcspn(buf + buf_index, " <\n\r\t\f\v");
+ buf_index += Html_word_len(buf + buf_index, buf + bufsize);
if (buf[buf_index] == '<' && (ch = buf[buf_index + 1]) &&
!isalpha(ch) && !strchr("/!?", ch))

continue;


修改src/prefs.c
將 DILLORC_SYS 置換成 "/etc/dillorc"

make
遇到 -lXi -lXext的錯誤時作法如前

接著將所需要的Library都copy 至 target上

libX11.so.6
libfltk2.so
libiconv.so.2
libnano-X.so
libpng12.so
libstdc++.so.6

複製src/dillo 到target上
設定檔是/etc/dillorc
以下是dillorc內容紅字部份是依照偶的需求而修改的
PS : FireFly 的font name 是 "Sung"


# dillorc
# Sample dillo initialization file.
#
# Lines that start with a '#' are comments.
# "#option=..." shows the built-in default.
# "# option=..." is an additional example.
# "option=..." overrides the built-in value.

#-------------------------------------------------------------------------
#                             FIRST SECTION                             :)
#-------------------------------------------------------------------------

# Set the desired initial browser size
# geometry=650x545+0+20
geometry=480x272

# Change this if you want to have text-only browsing from the start.
# (there's a toggle button near the bug meter to change this on-the-fly)
#load_images=YES


# Change the buffering scheme for drawing
# 0 no double buffering - useful for debugging
# 1 light buffering using a single back buffer for all windows
# 2 full fltk-based double buffering for all windows
#buffered_drawing=1

# Set your default directory for download/save operations
save_dir=/tmp

#-------------------------------------------------------------------------
#                           RENDERING SECTION
#-------------------------------------------------------------------------

# Fontname for variable width rendering (most of the text).
#   - some fonts may slow down rendering.
#   - try to tune a fontname/font_factor combination.
# Ex. {helvetica, lucida, times, "new century schoolbook", utopia, ...}
# vw_fontname="new century schoolbook"
# vw_fontname="helvetica"
# vw_fontname="times"
# vw_fontname="Bitstream vera Serif"
# vw_fontname="arial"
#vw_fontname="DejaVu Sans"
vw_fontname="sung"

# Fontname for fixed width rendering (mainly text quoted with
)
# fw_fontname=courier
# fw_fontname="Bitstream Vera Sans Mono"
# fw_fontname="Andale Mono"
#fw_fontname="DejaVu Sans Mono"

# All fontsizes are scaled by this value
# font_factor=1.5
#font_factor=1.0

# 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
# *** NOT HOOKED UP YET ***
#
#show_tooltip=YES

# Set this to YES if you want to limit the word wrap width to the viewport
# width (may be useful for iPAQ)
# *** NOT HOOKED UP YET ***
#
#limit_text_width=NO


#-------------------------------------------------------------------------
#                            PARSING SECTION
#-------------------------------------------------------------------------

# If you prefer more accurate HTML bug diagnosis over better rendering
# (page authors and webmasters) set the following to "NO".
#
#w3c_plus_heuristics=YES


#-------------------------------------------------------------------------
#                            NETWORK SECTION
#-------------------------------------------------------------------------

# Set the start page.
# start_page="about:blank"
# start_page="http://www.dillo.org"
# start_page="file:/home/jcid/custom_page.html"
start_page="http://www.google.com.tw"

# Set the home location
# home="file:/home/jcid/HomePage/Home.html"
home="http://www.google.com.tw"

# Set the URL used by the web search dialog.
# "%s" is replaced with the search keywords separated by '+'.
# search_url="http://search.lycos.com/?query=%s"
# search_url="http://www.alltheweb.com/search?cat=web&query=%s"
#search_url="http://www.google.com/search?q=%s"

# Set the proxy information for http.
# WARNING: dillo uses wget for ftp and https. To use a proxy for those
# protocols, you will need to configure wget.
# http_proxy="http://localhost:8080/"
#(by default, no proxy is used)

# If you need to provide a  user/password pair for the proxy,
# set the proxy user name here and Dillo will ask for the password later.
# http_proxyuser="joe"
#(by default, no proxy is used)

# Set the domains to access without proxy
# no_proxy = ".hola.com .mynet.cl .hi.de"
#(by default, no proxy is used)

# Set the HTTP Referer (sic) header.
# Note that there is no option to reveal the page that you came from because it
# would endanger your privacy. 'host' and 'path' allow you to pretend that the
# link you followed was on the same site that you're going to.
# none  : Don't send any Referer header at all.
# host  : Send the requested URI's hostname.
# path  : Send the requested URI's host and path.
#http_referer=host


#-------------------------------------------------------------------------
#                            COLORS SECTION
#-------------------------------------------------------------------------

# Here we can use the HTML color names or C syntax.

# Set the background color
# bg_color=gray
# bg_color=0xd6d6c0
#bg_color=0xdcd1ba

# Set the text color
#text_color=black

# Set the link color
#link_color=blue

# If your eyes suffer with white backgrounds, change this.
#allow_white_bg=YES

# Use the same colors with all documents?
#force_my_colors=NO

# When set to YES, the page author's visited link color may be overridden
# to allow better contrast with text/links/background
#contrast_visited_color=YES

# Colors for widgets inside forms.
# YES = toolkit's default colors, NO = use page's text and background color.
# ("NO" looks less traditional but more stylish).
#standard_widget_colors=NO


#-------------------------------------------------------------------------
#                        USER INTERFACE SECTION
#-------------------------------------------------------------------------

# Size of dillo panel (used to enlarge the browsing area)
# tiny   :  recommended for iPAQ (with small_icons)
# small  :  very nice! (it's "medium" without icon titles)
# medium :  nice!
# large  :  Traditional
panel_size=tiny
# panel_size=small
# panel_size=medium
#panel_size=large

#small_icons=NO

# Here you can choose to hide some widgets of the dillo panel...
#show_back=YES
#show_forw=YES
#show_home=YES
#show_reload=YES
#show_save=YES
#show_stop=YES
#show_bookmarks=YES
#show_filemenu=YES
#show_clear_url=YES
#show_url=YES
#show_search=YES
#show_progress_box=YES

# Start dillo with the panels hidden?
#fullwindow_start=NO

# When filling out forms, our default behaviour is to submit on enterpress,
# but only when there's a single text entry (to avoid incomplete submits).
# OTOH, if you have to fill out the same form repeatedly, you may find it
# useful to keep away from the mouse by forcing enter to submit.
#enterpress_forces_submit=NO

# Some forms lack a submit button, and dillo can generate a custom one
# internally. Unfortunately there's no guarantee for it to work. :(
# (my experience is that forms that lack a submit rely on Javascript)
#generate_submit=NO

# A mouse's middle click over a link opens a new Tab.
# If you prefer to open a new Window instead, set it to NO.
#middle_click_opens_new_tab=YES

# Focus follows new Tabs.
# You can hold SHIFT to temporarily revert this behaviour.
#focus_new_tab=YES


#-------------------------------------------------------------------------
#                        DEBUG MESSAGES SECTION
#-------------------------------------------------------------------------

# Soon we should add the "show_debug_messages=NO" option...

# Generic messages (mainly for debugging specific parts)
# Change this to disable them.
#show_msg=YES


#-------------------------------------------------------------------------
#                        HTML BUG MESSAGES SECTION
#-------------------------------------------------------------------------

# Accepted by the W3C validator but "strongly discouraged" by the SPEC.
# (Such as "TAB character inside
").
#show_extra_warnings=NO


# -----------------------------------------------------------------------
# dillorc ends here.

3.Running

./nano-X -p &
./dillo
prefs: Can't open dillorc file: //.dillo/dillorc
prefs: Using /etc/dillorc
XSetErrorHandler called
nx11: display bpp = 16, bits_per_rgb 6
XInternAtom WM_DELETE_WINDOW 0
XInternAtom WM_PROTOCOLS 0
XInternAtom _MOTIF_WM_HINTS 0
XInternAtom FLTKChangeScheme 0
XInternAtom TARGETS 0
XInternAtom CLIPBOARD 0
XInternAtom XdndAware 0
XInternAtom XdndSelection 0
XInternAtom XdndEnter 0
XInternAtom XdndTypeList 0
XInternAtom XdndPosition 0
XInternAtom XdndLeave 0
XInternAtom XdndDrop 0
XInternAtom XdndStatus 0
XInternAtom XdndActionCopy 0
XInternAtom XdndFinished 0
XInternAtom text/plain;charset=UTF-8 0
XInternAtom text/plain 0
XInternAtom TEXT 0
XInternAtom text/uri-list 0
XInternAtom _NET_WM_NAME 0
XInternAtom _NET_WM_ICON_NAME 0
XInternAtom _NET_WORKAREA 0
XInternAtom _NET_CURRENT_DESKTOP 0
XInternAtom UTF8_STRING 0
XSetLocaleModifiers called
XOpenIM called
XOpenIM() failed

Pattern : -*-helvetica-medium-r-normal--*
Match : -firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
Match : -b&h-lucidabright-medium-i-normal--34-240-100-100-p-194-iso8859-1
Match : -adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso10646-1
_addFontToList : -adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso10646-1
_nxfontcount = 2
Read : 3

checking '-adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso10646-1' '-firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1'
checking '-adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso10646-1' '-b&h-lucidabright-medium-i-normal--34-240-100-100-p-194-iso8859-1'
checking '-adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso10646-1' '-adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso10646-1'
XLoadFont('-adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso10646-1') = '/phone/lib/X11/fonts/misc/helvR24.pcf' [1060]
Pattern : -*
Match : -firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
_addFontToList : -firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
Match : -b&h-lucidabright-medium-i-normal--34-240-100-100-p-194-iso8859-1
_addFontToList : -b&h-lucidabright-medium-i-normal--34-240-100-100-p-194-iso8859-1
Match : -adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso10646-1
_addFontToList : -adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso10646-1
Pattern : -*-sung-medium-*-*--*
Match : -firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
_addFontToList : -firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
Match : -b&h-lucidabright-medium-i-normal--34-240-100-100-p-194-iso8859-1
Match : -adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso10646-1
_nxfontcount = 2
Read : 3

checking '-firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1' '-firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1'
XLoadFont('-firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1') = '/phone/lib/X11/fonts/misc/fireflyR16.pcf' [1061]
nxTranslateEventMask no handler for event mask (0022c07f): 14
XChangeProperty _NET_WM_NAME
XChangeProperty (null)
XChangeProperty _NET_WM_ICON_NAME
XChangeProperty (null)
XChangeProperty WM_PROTOCOLS
XChangeProperty _MOTIF_WM_HINTS
XChangeProperty (null)
XChangeProperty XdndAware
translateNXEvent: unhandled update event subtype 6
XChangeProperty _MOTIF_WM_HINTS
_nxfontcount = 2
Read : 3

checking '-firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1' '-firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1'
XLoadFont('-firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1') = '/phone/lib/X11/fonts/misc/fireflyR16.pcf' [1062]
XParseColor: bad parse on None
XCreatePixmap 22,22 depth 16
XParseColor: bad parse on None
XParseColor: bad parse on gray70
XCreatePixmap 22,22 depth 16
XSetClipMask 828
XParseColor: bad parse on None
XCreatePixmap 22,22 depth 16
XParseColor: bad parse on None
XParseColor: bad parse on gray70
XCreatePixmap 22,22 depth 16
XSetClipMask 831
XParseColor: bad parse on None
XCreatePixmap 22,22 depth 16
XSetClipMask 833
XParseColor: bad parse on None
XCreatePixmap 22,22 depth 16
XSetClipMask 835
XParseColor: bad parse on None
XCreatePixmap 22,22 depth 16
XSetClipMask 837
XParseColor: bad parse on None
XCreatePixmap 22,22 depth 16
XSetClipMask 839
XParseColor: bad parse on None
XCreatePixmap 22,22 depth 16
XSetClipMask 841
XParseColor: bad parse on None
XCreatePixmap 11,11 depth 16
XSetClipMask 843
XParseColor: bad parse on None
XCreatePixmap 14,16 depth 16
XSetClipMask 845
XParseColor: bad parse on None
XCreatePixmap 15,15 depth 16
XParseColor: bad parse on None
XCreatePixmap 15,15 depth 16
XSetClipMask 848
XParseColor: bad parse on none
XCreatePixmap 15,15 depth 16
XSetClipMask 850
XChangeProperty _NET_WM_NAME
XChangeProperty (null)
XChangeProperty _NET_WM_ICON_NAME
XChangeProperty (null)
XChangeProperty _NET_WM_NAME
XChangeProperty (null)
XChangeProperty _NET_WM_ICON_NAME
XChangeProperty (null)
XChangeProperty _NET_WM_NAME
XChangeProperty (null)
XChangeProperty _NET_WM_ICON_NAME
XChangeProperty (null)
XSetClipMask 828
XSetClipMask 831
XSetClipMask 833
XSetClipMask 835
XSetClipMask 837
XSetClipMask 839
XSetClipMask 841
XSetClipMask 843
XSetClipMask 845
XSetClipMask 848
XParseColor: bad parse on None
XCreatePixmap 16,16 depth 16
XSetClipMask 852
XSetClipMask 828
XSetClipMask 831
XSetClipMask 833
XSetClipMask 835
XSetClipMask 837
XSetClipMask 839
XSetClipMask 841
XSetClipMask 843
XSetClipMask 845
XCreatePixmap 480,10 depth 16
XSetArcMode called
XSetArcMode called
XSetArcMode called
XSetArcMode called
XSetArcMode called
XSetArcMode called
XSetArcMode called
XSetArcMode called
XSetArcMode called
XCreatePixmap 465,224 depth 16
XSetClipMask 828
XSetClipMask 831
XSetClipMask 833
XSetClipMask 835
XSetClipMask 837
XSetClipMask 839
XSetClipMask 841
XSetClipMask 843
XSetClipMask 845
XSetClipMask 828
XSetClipMask 831
XSetClipMask 839
XSetClipMask 828
XSetClipMask 831
XParseColor: bad parse on None
XParseColor: bad parse on gray70
XCreatePixmap 22,22 depth 16
XSetClipMask 856

系統resource狀況

1038 root 3072 S ./nano-X -p
1048 root SWN [jffs2_gcd_mtd0]
1520 root 2900 S ./dillo
1521 root 2900 S ./dillo
1528 root 380 R ps
# ./rfree
total used free slab buffers cached
Mem: 29680 27456 2224 3844 44 17436
-/+ buffers/cache: 6132 19704 3844
Swap: 0 0 0

# top
Mem: 27472K used, 2208K free, 0K shrd, 44K buff, 17436K cached
Load average: 1.00 1.01 1.00 (Status: S=sleeping R=running, W=waiting)
PID USER STATUS RSS PPID %CPU %MEM COMMAND
1534 root R 392 1007 4.7 1.3 top
1038 root S 3072 1 0.0 10.3 nano-X
1520 root S 2900 942 0.0 9.7 dillo
1521 root S 2900 1520 0.0 9.7 dillo

靠,開個google首頁只用了不到 3M memory,讚啦.




不過很多網頁的排版看起來都怪怪的...應該跟偶設定的screen size有關









2009年4月24日 星期五

kaffe cross compile for mipsel



Reguirement

jikes-1.22
kaffe-1.1.7
libffi-3.0.8
microwindows-0.91

流程
1.Build and install kaffe on host( X86 )

cd jikes-1.22

./configure --prefix=/usr --cache-file=/dev/null

make
sudo make install

cd microwindows-0.91

make

cd kaffe-1.1.7

./configure --prefix=/usr/local/kaffe --with-gc=kaffe-gc --enable-pure-java-math --with-staticlib --disable-shared --disable-alsa --without-kaffe-x-awt --without-kaffe-qt-awt --without-classpath-gtk-awt --disable-gtk-peer --disable-sound --with-jikes=/usr/bin/jikes --with-kaffe-nanox-awt --with-engine=intrp --with-nanox-include=../microwindows-0.91/src/include --with-nanox-library=../microwindows-0.91/src/lib/ --cache-file=/dev/null

make
sudo make install
sudo make check

Hello.java

public class Hello
{
  public static void main (String[] args)
  {
  System.out.println ("Hello Kaffe");
  }
}

jikes -classpath /usr/local/kaffe/jre/lib/glibj.zip Hello.java

/usr/local/kaffe/bin/kaffe -Xbootclasspath:/usr/local/kaffe/jre/lib/glibj.zip Hello

gigijoe@user-desktop:~/kaffe-1.1.7/hello$ /usr/local/kaffe/bin/kaffe -Xbootclasspath:/usr/local/kaffe/jre/lib/glibj.zip Hello
Hello Kaffe

/usr/local/kaffe/bin/kaffe -v -Xbootclasspath:/usr/local/kaffe/jre/lib/glibj.zip Hello >& Hello.log

Hello.log 裡面長這個樣子

Loading java/lang/Object.class(/usr/local/kaffe/jre/lib/glibj.zip) [compressed]
Loading java/io/Serializable.class(/usr/local/kaffe/jre/lib/glibj.zip) [compressed]
Loading java/lang/Cloneable.class(/usr/local/kaffe/jre/lib/glibj.zip) [compressed]
...
...
...
Loading java/nio/charset/CoderResult$1.class(/usr/local/kaffe/jre/lib/glibj.zip) [compressed]
Loading java/nio/charset/CoderResult$Cache.class(/usr/local/kaffe/jre/lib/glibj.zip) [compressed]
Loading java/nio/charset/CoderResult$2.class(/usr/local/kaffe/jre/lib/glibj.zip) [compressed]
Hello Kaffe

手工改寫Hello.log成底下的樣子.另存成glibjmin.make

/usr/local/kaffe/bin/jar cvf glibjmin.zip \
java/lang/Object.class \
java/io/Serializable.class \
java/lang/Cloneable.class \
...
...
...
java/nio/charset/CoderResult\$1.class \
java/nio/charset/CoderResult\$Cache.class \
java/nio/charset/CoderResult\$2.class

將glibjmin.make複製到 libraries/javalib/external/classpath/lib/
cd libraries/javalib/external/classpath/lib/
chmod 755 glibjmin.make
./glibjmin.make

這樣就產生glibjmin.zip

測試Nano-X AWT
開啟一個Terminal
cd microwindows-0.91/src
bin/nano-X -p

開啟一個Terminal
cd test/awt/WidgetsDemo/
jikes -classpath /usr/local/kaffe/jre/lib/glibj.zip WidgetsDemo.java

sudo /usr/local/kaffe/bin/kaffe -Xbootclasspath:/usr/local/kaffe/jre/lib/glibj.zip -Xkaffe-nanox-awt WidgetsDemo




2.Build and install mipsel kaffe

cd libffi-3.0.8

CC=mipsel-linux-uclibc-gcc AR=mipsel-linux-uclibc-ar RANLIB=mipsel-linux-uclibc-ranlib ./configure --host=mipsel-linux --target=mipsel-linux --prefix=/usr/local/MIPSEL_UCLIBC --cache-file=/dev/null

make
sudo PATH=$PATH:/usr/local/MIPSEL_UCLIBC/bin make install

cd microwindow-0.91 -->> 這是for target用的不要跟host上的混在一起囉
(Cross compile microwindow)
make

cd kaffe-1.1.7

KAFFEH=/usr/local/kaffe/bin/kaffeh CC=mipsel-linux-uclibc-gcc AR=mipsel-linux-uclibc-ar RANLIB=mipsel-linux-uclibc-ranlib ./configure --host=mipsel-linux --target=mipsel-linux --prefix=/usr/local/kaffe-mipsel --with-gc=kaffe-gc --enable-pure-java-math --with-staticlib --disable-shared --without-kaffe-x-awt --without-kaffe-qt-awt --without-classpath-gtk-awt --disable-gtk-peer --disable-sound --with-jikes=/usr/bin/jikes --with-kaffe-nanox-awt --with-engine=intrp --with-libffi --with-nanox-include=../microwindows-0.91/src/include --with-nanox-library=../microwindows-0.91/src/lib/ --cache-file=/dev/null

make
sudo PATH=$PATH:/usr/local/MIPSEL_UCLIBC/bin make install

sudo cp -a /usr/local/MIPSEL_UCLIBC/lib/libffi.so* /usr/local/kaffe-mipsel/lib

編譯的工作到此已完成,接著將kaffe-mipsel整個複製到target上.

以之前的Hello.class在target上測試

# /usr/local/kaffe-mipsel/bin/kaffe -Xbootclasspath:/usr/local/kaffe-mipsel/jre/lib/glibj.zip Hello  
/usr/local/kaffe-mipsel/bin/kaffe: /usr/local/kaffe-mipsel/bin/kaffe: 55: uname: not found
Hello Kaffe

成功囉

將之前做出來的glibjmin.zip 複製到target上/usr/local/kaffe-mipsel/jre/lib/glibjmin.zip

在測試看看

# /usr/local/kaffe-mipsel/bin/kaffe -Xbootclasspath:/usr/local/kaffe-mipsel/jre/lib/glibjmin.zip Hello
/usr/local/kaffe-mipsel/bin/kaffe: /usr/local/kaffe-mipsel/bin/kaffe: 55: uname: not found
java.lang.NoClassDefFoundError: gnu/java/nio/charset/ISO_8859_1$Encoder
   at gnu.java.nio.charset.ISO_8859_1.newEncoder (ISO_8859_1.java:92)
   at java.lang.String.getBytes (String.java:356)
   at java.io.PrintStream.writeChars (PrintStream.java:287)
   at java.io.PrintStream.print (PrintStream.java:225)
   at java.io.PrintStream.println (PrintStream.java:505)
   at Hello.main (Hello.java:5)

喔喔,殘念了

把gnu/java/nio/charset/ISO_8859_1$Encoder.class加入glibjmin.make.
再產生glibjmin.zip

# /usr/local/kaffe-mipsel/bin/kaffe -Xbootclasspath:/usr/local/kaffe-mipsel/jre/lib/glibjmin.zip Hello
/usr/local/kaffe-mipsel/bin/kaffe: /usr/local/kaffe-mipsel/bin/kaffe: 55: uname: not found

Hello Kaffe

成功囉

3.Nano-X based AWT backend

http://www.sfr-fresh.com/unix/www/kaffe-1.1.9.tar.gz:a/kaffe-1.1.9/FAQ/FAQ.awt

cd kaffe-1.1.7/test/awt/WidgetsDemo

jikes -classpath /usr/local/kaffe/jre/lib/glibj.zip WidgetsDemo.java

將WidgetsDemo.class WidgetsDemo$Person.class複製到target上

/usr/local/kaffe-mipsel/bin/kaffe -Xbootclasspath:/usr/local/kaffe-mipsel/jre/lib/glibj.zip -Xkaffe-nanox-awt WidgetsDemo

/phone/bin/nano-X -p &

# /usr/local/kaffe-mipsel/bin/kaffe -Xbootclasspath:/usr/local/kaffe-mipsel/jre/lib/glibj.zip -Xkaffe-nanox-awt WidgetsDemo
/usr/local/kaffe-mipsel/bin/kaffe: /usr/local/kaffe-mipsel/bin/kaffe: 55: uname: not found

# ps
  PID  Uid     VmSize Stat Command
    1 root        376 S   init      
    2 root            SW  [ksoftirqd/0]
    3 root            SW< [desched/0]
    4 root            SW< [events/0]
    5 root            SW< [khelper]
   10 root            SW< [kthread]
   13 root            SW< [kblockd/0]
   26 root            SW  [khubd]
   54 root            SW  [pdflush]
   55 root            SW  [pdflush]
   57 root            SW< [aio/0]
   56 root            SW  [kswapd0]
  142 root            SW  [mtdblockd]
  130 root            SW  [kseriod]
  160 root            SW< [IRQ 8]
  163 root            SW< [IRQ 15]
  167 root            SWN [jffs2_gcd_mtd3]
  185 root            SW< [IRQ 43]
  203 root            SW  [scsi_eh_0]
  204 root            SW  [usb-storage]
  271 root        320 S   /usr/sbin/telnetd -l /bin/login
  272 root        436 S   ftpd: accepting connections on port 21              
  283 root            SW< [IRQ 27]
  295 root            SW< [IRQ 41]
  324 root        400 S   /sbin/udhcpc -s /phone/etc/udhcpc.script -i eth0 -p /
  350 root            SW< [IRQ 45]
  354 root        284 S   /phone/bin/thttpd -C /phone/web/html.conf
  364 root        364 S   /sbin/getty -L ttyS0 9600 vt100
  365 root        348 S   /sbin/syslogd -n -m 0
  366 root        344 S   /sbin/klogd -n
  368 root        336 S   /phone/bin/ntpclient -h ntp.ucsd.edu -i 86400 -so 8:0
 1392 root        536 S   -sh
 1412 root            SWN [jffs2_gcd_mtd0]
 2208 root        684 S   ftpd: 192.168.168.79: root: IDLE                    
 2256 root        488 S   /phone/bin/nano-X -p
 2280 root       7148 S   /usr/local/kaffe-mipsel/jre/bin/kaffe-bin -Xbootclass
 2300 root       7148 S   /usr/local/kaffe-mipsel/jre/bin/kaffe-bin -Xbootclass
 2301 root       7148 S   /usr/local/kaffe-mipsel/jre/bin/kaffe-bin -Xbootclass
 2302 root       7148 S   /usr/local/kaffe-mipsel/jre/bin/kaffe-bin -Xbootclass
 2303 root       7148 S   /usr/local/kaffe-mipsel/jre/bin/kaffe-bin -Xbootclass
 2304 root       7148 S   /usr/local/kaffe-mipsel/jre/bin/kaffe-bin -Xbootclass
 2306 root        468 S   -sh
 2313 root        376 R   ps
# /phone/bin/rfree
             total       used       free       slab    buffers     cached
Mem:         29680      28768        912       3620        248      16644
-/+ buffers/cache:       8256      17804       3620
Swap:            0          0          0

哈哈哈,成功啦