From 9d4ed7ab9981d20756b21ee536f9df93dedd6648 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Mon, 24 Oct 2005 14:06:04 +0200 Subject: [PATCH 1/7] Make some Makefile.lib commands quiet since we use echo. --- Makefile.lib | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile.lib b/Makefile.lib index 091774556..b33a922ce 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -106,18 +106,18 @@ cleanall-default: clean-default install-default: all-default ifdef PROGS - $(MKINSTALLDIRS) $(DESTDIR)$(bindir) - $(foreach file,$(PROGS), \ + @$(MKINSTALLDIRS) $(DESTDIR)$(bindir) + @$(foreach file,$(PROGS), \ $(call ncmd,installprog,$(file),$(DESTDIR)$(bindir));) endif ifdef MAN1 - $(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1 - $(foreach file,$(MAN1), \ + @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1 + @$(foreach file,$(MAN1), \ $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man1);) endif ifdef MAN5 - $(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5 - $(foreach file,$(MAN5), \ + @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5 + @$(foreach file,$(MAN5), \ $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man5);) endif From eaee3d5f44ea249895ff52e155a3eeae5fd6a5f4 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 25 Oct 2005 17:33:01 +0200 Subject: [PATCH 2/7] Simplify the creation of out-of-tree Makefiles They now always use the absolute path to the src Makefile. Silence the mkinstalldir call. --- configure.in | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/configure.in b/configure.in index 66bd63a1f..813f2296c 100644 --- a/configure.in +++ b/configure.in @@ -1265,18 +1265,15 @@ AC_OUTPUT([ \ src/intl/gettext/ref-del.sed ]) -srcdir2="$(cd "$srcdir" && pwd)" -if test "$srcdir2" != "$builddir"; then - MAKEFILES=$("$MAKE" -C "$srcdir" list | grep Makefile) +abs_srcdir="$(cd "$srcdir" && pwd)" +# builddir is always absolute! +if test "$abs_srcdir" != "$builddir"; then + MAKEFILES=$("$MAKE" -C "$abs_srcdir" list | grep Makefile) for i in $MAKEFILES; do - $MKINSTALLDIRS "$builddir/$(dirname $i)" - grep top_builddir= "$srcdir/$i" > "$builddir/$i" - case "$srcdir" in - /*) echo "include $srcdir/$i" >> "$builddir/$i" ;; - *) echo "include \$(top_builddir)/$srcdir/$i" >> "$builddir/$i" ;; - esac - echo "creating $builddir/$i" + echo "creating $i" + $MKINSTALLDIRS "$builddir/$(dirname $i)" >/dev/null + echo "include $abs_srcdir/$i" > "$builddir/$i" done fi From 7659f284ac3c58041d3a8585d1d4cf73b9a1f41d Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 25 Oct 2005 17:43:33 +0200 Subject: [PATCH 3/7] Try to comply to the client-side javascript interface and not our own Renames the following things: ELinks.write() -> alert() or navigator.alert() ELinks.version -> navigator.appVersion ELinks.home -> navigator.appHome The last one is not defined by the client-side javascript interface. --- contrib/see/hooks.js | 7 ++++--- src/scripting/see/core.c | 27 ++++++++++++++------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/contrib/see/hooks.js b/contrib/see/hooks.js index 9e0fcf874..e788d962e 100644 --- a/contrib/see/hooks.js +++ b/contrib/see/hooks.js @@ -3,8 +3,9 @@ * Copyright (c) Jonas Fonseca, 2005 */ -function quit() { - // ELinks.write("quiting ... " + ELinks.version); +function quit() +{ + // alert("quiting ... " + navigator.appVersion); } /********************************************************************* @@ -206,7 +207,7 @@ function expand_smartprefix(context, current_url) return true } else { - ELinks.write('smartprefix "' + nick + '" has unsupported type "' + typeof smartprefixes[nick] + '".') + alert('smartprefix "' + nick + '" has unsupported type "' + typeof smartprefixes[nick] + '".') return false } } diff --git a/src/scripting/see/core.c b/src/scripting/see/core.c index c0555adba..8d54750d6 100644 --- a/src/scripting/see/core.c +++ b/src/scripting/see/core.c @@ -53,7 +53,7 @@ alert_see_error(struct session *ses, unsigned char *msg) /* The ELinks module: */ static void -elinks_see_write(struct SEE_interpreter *see, struct SEE_object *self, +navigator_alert(struct SEE_interpreter *see, struct SEE_object *self, struct SEE_object *thisobj, int argc, struct SEE_value **argv, struct SEE_value *res) { @@ -99,7 +99,7 @@ static void init_see_environment(struct SEE_interpreter *see) { unsigned char *home; - struct SEE_object *obj, *elinks; + struct SEE_object *obj, *navigator; struct SEE_value value; struct SEE_string *name; @@ -107,28 +107,29 @@ init_see_environment(struct SEE_interpreter *see) SEE_intern_global(s_print = &S_print); * */ - /* Create the elinks browser object. Add it to the global space */ - elinks = SEE_Object_new(see); - SEE_SET_OBJECT(&value, elinks); - name = SEE_string_sprintf(see, "ELinks"); + /* Create the navigator browser object. Add it to the global space */ + navigator = SEE_Object_new(see); + SEE_SET_OBJECT(&value, navigator); + name = SEE_string_sprintf(see, "navigator"); SEE_OBJECT_PUT(see, see->Global, name, &value, SEE_ATTR_READONLY); /* Create a string and attach as 'ELinks.version' */ SEE_SET_STRING(&value, SEE_string_sprintf(see, VERSION)); - name = SEE_string_sprintf(see, "version"); - SEE_OBJECT_PUT(see, elinks, name, &value, SEE_ATTR_READONLY); + name = SEE_string_sprintf(see, "appVersion"); + SEE_OBJECT_PUT(see, navigator, name, &value, SEE_ATTR_READONLY); /* Create a string and attach as 'ELinks.home' */ home = elinks_home ? elinks_home : (unsigned char *) CONFDIR; SEE_SET_STRING(&value, SEE_string_sprintf(see, home)); - name = SEE_string_sprintf(see, "home"); - SEE_OBJECT_PUT(see, elinks, name, &value, SEE_ATTR_READONLY); + name = SEE_string_sprintf(see, "appHome"); + SEE_OBJECT_PUT(see, navigator, name, &value, SEE_ATTR_READONLY); /* Create a 'write' method and attach to the browser object. */ - name = SEE_string_sprintf(see, "write"); - obj = SEE_cfunction_make(see, elinks_see_write, name, 1); + name = SEE_string_sprintf(see, "alert"); + obj = SEE_cfunction_make(see, navigator_alert, name, 1); SEE_SET_OBJECT(&value, obj); - SEE_OBJECT_PUT(see, elinks, name, &value, 0); + SEE_OBJECT_PUT(see, navigator, name, &value, 0); + SEE_OBJECT_PUT(see, see->Global, name, &value, 0); } static void From a317dd71fba9ed2ed2b54500f3452365ac46f420 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 25 Oct 2005 19:10:30 +0200 Subject: [PATCH 4/7] Print the invalid option value --- src/config/options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/options.c b/src/config/options.c index 2e1b05d76..50ddac42f 100644 --- a/src/config/options.c +++ b/src/config/options.c @@ -282,7 +282,7 @@ get_opt_( case OPT_LONG: if (opt->value.number < opt->min || opt->value.number > opt->max) - elinks_internal("Option %s has invalid value!", name); + elinks_internal("Option %s has invalid value %d!", name, opt->value.number); break; case OPT_COMMAND: if (!opt->value.command) From 1f69d4b93185ddea7f33d5da99aae54c8f194108 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 25 Oct 2005 19:13:33 +0200 Subject: [PATCH 5/7] Add support for navigator.preference() and navigator.savePreferences() It required that the 'context' session was saved in see_ses (similarly to the lua_ses variable) Anyway, now you can use var opt_value = navigator.preference("ui.window_title) navigator.preference("ui.window_title", false) navigator.savePreferences() to get and set optinos + save the changes. --- src/scripting/see/core.c | 124 ++++++++++++++++++++++++++++++++++++-- src/scripting/see/core.h | 1 + src/scripting/see/hooks.c | 24 +++++--- 3 files changed, 133 insertions(+), 16 deletions(-) diff --git a/src/scripting/see/core.c b/src/scripting/see/core.c index 8d54750d6..947407135 100644 --- a/src/scripting/see/core.c +++ b/src/scripting/see/core.c @@ -9,12 +9,16 @@ #include "elinks.h" #include "bfu/dialog.h" +#include "config/conf.h" #include "config/home.h" +#include "config/options.h" +#include "config/opttypes.h" #include "intl/gettext/libintl.h" #include "main/module.h" #include "scripting/scripting.h" #include "scripting/see/core.h" #include "scripting/see/see.h" +#include "session/session.h" #include "util/error.h" #include "util/file.h" #include "util/string.h" @@ -23,6 +27,7 @@ #define SEE_HOOKS_FILENAME "hooks.js" struct SEE_interpreter see_interpreter; +struct session *see_ses; struct string * @@ -52,29 +57,125 @@ alert_see_error(struct session *ses, unsigned char *msg) /* The ELinks module: */ +static void +navigator_preference(struct SEE_interpreter *see, struct SEE_object *self, + struct SEE_object *thisobj, int argc, struct SEE_value **argv, + struct SEE_value *res) +{ + struct SEE_value v; + struct string opt_name; + struct option *opt; + + SEE_SET_UNDEFINED(res); + + if (argc != 1 && argc != 2) return; + + SEE_ToString(see, argv[0], &v); + if (!convert_see_string(&opt_name, v.u.string)) + return; + + opt = get_opt_rec(config_options, opt_name.source); + done_string(&opt_name); + /* FIXME: Alert? */ + if (!opt) return; + + /* Set option */ + switch (opt->type) { + case OPT_BOOL: + { + long value = opt->value.number; + + if (argc == 1) { + SEE_SET_BOOLEAN(res, value); + return; + } + + SEE_ToBoolean(see, argv[1], &v); + value = !!v.u.boolean; + opt->value.number = value; + break; + } + case OPT_INT: + case OPT_LONG: + { + long value; + + if (argc == 1) { + SEE_SET_NUMBER(res, opt->value.number); + return; + } + + SEE_ToInteger(see, argv[1], &v); + value = SEE_ToInt32(see, &v); + if (opt->min <= value && value <= opt->max) + option_types[opt->type].set(opt, (unsigned char *) (&value)); + break; + } + case OPT_STRING: + case OPT_CODEPAGE: + case OPT_LANGUAGE: + case OPT_COLOR: + { + struct string opt_value; + + if (argc == 1) { + SEE_SET_STRING(res, SEE_string_sprintf(see, opt->value.string)); + return; + } + + SEE_ToString(see, argv[1], &v); + if (!convert_see_string(&opt_value, v.u.string)) + return; + + option_types[opt->type].set(opt, opt_value.source); + done_string(&opt_value); + break; + } + default: + return; + } + + if (argc == 2) { + opt->flags |= OPT_TOUCHED; + call_change_hooks(see_ses, opt, opt); + } +} + +static void +navigator_save_preferences(struct SEE_interpreter *see, struct SEE_object *self, + struct SEE_object *thisobj, int argc, struct SEE_value **argv, + struct SEE_value *res) +{ + if (see_ses) + write_config(see_ses->tab->term); +} + static void navigator_alert(struct SEE_interpreter *see, struct SEE_object *self, struct SEE_object *thisobj, int argc, struct SEE_value **argv, struct SEE_value *res) { - struct SEE_value v; + struct SEE_value v; struct string string; + struct terminal *term; - SEE_SET_UNDEFINED(res); + SEE_SET_UNDEFINED(res); - if (!argc) return; + if (!argc) return; SEE_ToString(see, argv[0], &v); if (!convert_see_string(&string, v.u.string)) return; - if (list_empty(terminals)) { + if (!see_ses && list_empty(terminals)) { usrerror("[SEE] %s", string.source); done_string(&string); return; } - info_box(terminals.next, MSGBOX_NO_TEXT_INTL | MSGBOX_FREE_TEXT, + term = see_ses ? see_ses->tab->term : terminals.next; + + info_box(term, MSGBOX_NO_TEXT_INTL | MSGBOX_FREE_TEXT, N_("SEE Message"), ALIGN_LEFT, string.source); } @@ -124,12 +225,23 @@ init_see_environment(struct SEE_interpreter *see) name = SEE_string_sprintf(see, "appHome"); SEE_OBJECT_PUT(see, navigator, name, &value, SEE_ATTR_READONLY); - /* Create a 'write' method and attach to the browser object. */ + /* Create an 'alert' method and attach to the browser object. */ + /* FIXME: The browser object and the Global object should be identical. */ name = SEE_string_sprintf(see, "alert"); obj = SEE_cfunction_make(see, navigator_alert, name, 1); SEE_SET_OBJECT(&value, obj); SEE_OBJECT_PUT(see, navigator, name, &value, 0); SEE_OBJECT_PUT(see, see->Global, name, &value, 0); + + name = SEE_string_sprintf(see, "preference"); + obj = SEE_cfunction_make(see, navigator_preference, name, 1); + SEE_SET_OBJECT(&value, obj); + SEE_OBJECT_PUT(see, navigator, name, &value, 0); + + name = SEE_string_sprintf(see, "savePreferences"); + obj = SEE_cfunction_make(see, navigator_save_preferences, name, 1); + SEE_SET_OBJECT(&value, obj); + SEE_OBJECT_PUT(see, navigator, name, &value, 0); } static void diff --git a/src/scripting/see/core.h b/src/scripting/see/core.h index bf108e439..a3ee58b08 100644 --- a/src/scripting/see/core.h +++ b/src/scripting/see/core.h @@ -9,6 +9,7 @@ struct session; struct string; extern struct SEE_interpreter see_interpreter; +extern struct session *see_ses; struct string *convert_see_string(struct string *string, struct SEE_string *source); void alert_see_error(struct session *ses, unsigned char *msg); diff --git a/src/scripting/see/hooks.c b/src/scripting/see/hooks.c index 7ae890a72..e22c4e4af 100644 --- a/src/scripting/see/hooks.c +++ b/src/scripting/see/hooks.c @@ -21,7 +21,8 @@ * to do is explained in doc/events.txt */ static struct SEE_value * -call_see_hook(struct SEE_interpreter *see, unsigned char *name, +call_see_hook(struct SEE_interpreter *see, struct session *ses, + unsigned char *name, struct SEE_value *args[], int argc, struct SEE_value *result) { @@ -36,6 +37,8 @@ call_see_hook(struct SEE_interpreter *see, unsigned char *name, || !SEE_OBJECT_HAS_CALL(hook.u.object)) return NULL; + see_ses = ses; + SEE_TRY(see, try_context) { SEE_OBJECT_CALL(see, hook.u.object, NULL, argc, args, result); } @@ -52,18 +55,20 @@ call_see_hook(struct SEE_interpreter *see, unsigned char *name, if (init_string(&error_msg)) { convert_see_string(&error_msg, value.u.string); - alert_see_error(NULL, error_msg.source); + alert_see_error(ses, error_msg.source); done_string(&error_msg); } } if (SEE_CAUGHT(try_context2)) { - WDBG("exception thrown while printing exception"); + alert_see_error(ses, "exception thrown while printing exception"); } + see_ses = NULL; return NULL; } + see_ses = NULL; return result; } @@ -80,6 +85,7 @@ script_hook_goto_url(va_list ap, void *data) if (*url == NULL) return EVENT_HOOK_STATUS_NEXT; + see_ses = ses; SEE_SET_STRING(args[0], SEE_string_sprintf(see, "%s", *url)); if (!ses || !have_location(ses)) { @@ -89,7 +95,7 @@ script_hook_goto_url(va_list ap, void *data) SEE_string_sprintf(see, "%s", struri(cur_loc(ses)->vs.uri))); } - if (!call_see_hook(see, "goto_url", args, sizeof_array(args), &result)) + if (!call_see_hook(see, ses, "goto_url", args, sizeof_array(args), &result)) return EVENT_HOOK_STATUS_NEXT; switch (SEE_VALUE_GET_TYPE(&result)) { @@ -120,14 +126,12 @@ script_hook_follow_url(va_list ap, void *data) struct SEE_value args_[1], *args[1] = { &args_[0] }; struct SEE_value result; - evhook_use_params(url && ses); - if (*url == NULL) return EVENT_HOOK_STATUS_NEXT; SEE_SET_STRING(args[0], SEE_string_sprintf(see, "%s", *url)); - if (!call_see_hook(see, "follow_url", args, sizeof_array(args), &result)) + if (!call_see_hook(see, ses, "follow_url", args, sizeof_array(args), &result)) return EVENT_HOOK_STATUS_NEXT; switch (SEE_VALUE_GET_TYPE(&result)) { @@ -168,7 +172,7 @@ script_hook_pre_format_html(va_list ap, void *data) SEE_SET_STRING(args[0], SEE_string_sprintf(see, "%s", url)); SEE_SET_STRING(args[1], SEE_string_sprintf(see, "%s", *html)); - if (!call_see_hook(see, "pre_format_html", args, sizeof_array(args), &result)) + if (!call_see_hook(see, ses, "pre_format_html", args, sizeof_array(args), &result)) return EVENT_HOOK_STATUS_NEXT; switch (SEE_VALUE_GET_TYPE(&result)) { @@ -209,7 +213,7 @@ script_hook_get_proxy(va_list ap, void *data) SEE_SET_STRING(args[0], SEE_string_sprintf(see, "%s", url)); - if (!call_see_hook(see, "get_proxy", args, sizeof_array(args), &result)) + if (!call_see_hook(see, NULL, "get_proxy", args, sizeof_array(args), &result)) return EVENT_HOOK_STATUS_NEXT; switch (SEE_VALUE_GET_TYPE(&result)) { @@ -237,7 +241,7 @@ script_hook_quit(va_list ap, void *data) struct SEE_interpreter *see = &see_interpreter; struct SEE_value result; - call_see_hook(see, "quit", NULL, 0, &result); + call_see_hook(see, NULL, "quit", NULL, 0, &result); return EVENT_HOOK_STATUS_NEXT; } From 1c8f2a3d19119405166bf2a6e992cd7713c94819 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 25 Oct 2005 23:41:26 +0200 Subject: [PATCH 6/7] Enter all directories and print all Makefiles for 'make list' --- Makefile.lib | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile.lib b/Makefile.lib index b33a922ce..dfde57c88 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -73,7 +73,14 @@ OBJS += $(OBJS-yes) endif ifneq ($(findstring cleanall,$(MAKECMDGOALS)),) +INCLUDE_ALL=1 +endif +ifneq ($(findstring list,$(MAKECMDGOALS)),) +INCLUDE_ALL=1 +endif + +ifdef INCLUDE_ALL ifdef SUBDIRS-no SUBDIRS += $(SUBDIRS-no) endif From 44cf54f0fc1ecf97dcf87831f4f56020c2bd81b3 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Wed, 26 Oct 2005 00:34:13 +0200 Subject: [PATCH 7/7] Fix out-of-tree build when srcdir has no Makefile.config By recursively 'bootstrapping' the builddir specific Makefiles we no longer depend on running make in the srcdir. The problem was pointed out by zas. --- Makefile.lib | 16 ++++++++++------ configure.in | 9 ++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Makefile.lib b/Makefile.lib index dfde57c88..a35c721c1 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -76,7 +76,9 @@ ifneq ($(findstring cleanall,$(MAKECMDGOALS)),) INCLUDE_ALL=1 endif -ifneq ($(findstring list,$(MAKECMDGOALS)),) +ifneq ($(findstring init,$(MAKECMDGOALS)),) +# FIXME: Detect when $(subdir)/Makefile is $(srcdir)/$(subdir)/Makefile +# and error out so the user won't overwrite the 'master' Makefiles. INCLUDE_ALL=1 endif @@ -103,8 +105,10 @@ CLEAN += $(PROG) all-default: $(LIB_O) $(PROGS) $(MAN1) $(MAN5) -list-default: - @echo '$(RELPATH)Makefile' +init-default: + @$(foreach subdir,$(sort $(SUBDIRS)), \ + $(MKINSTALLDIRS) $(subdir) >/dev/null; \ + echo 'include $(SRC)/$(RELPATH)/$(subdir)/Makefile' > $(subdir)/Makefile;) clean-default: -test -z "$(CLEAN)" || $(RM) $(CLEAN) @@ -130,9 +134,9 @@ endif # Recursion: -.PHONY: all-recursive install-recursive clean-recursive cleanall-recursive list-recursive +.PHONY: all-recursive install-recursive clean-recursive cleanall-recursive init-recursive -all-recursive install-recursive clean-recursive cleanall-recursive list-recursive: +all-recursive install-recursive clean-recursive cleanall-recursive init-recursive: ifdef SUBDIRS @$(foreach subdir,$(sort $(SUBDIRS)), \ $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || exit 1;) @@ -143,7 +147,7 @@ install: install-recursive install-default install-local clean: clean-recursive clean-default clean-local cleanall: cleanall-recursive cleanall-default -list: list-recursive list-default +init: init-default init-recursive all-local: install-local: diff --git a/configure.in b/configure.in index 813f2296c..cad84d8cb 100644 --- a/configure.in +++ b/configure.in @@ -1268,13 +1268,8 @@ AC_OUTPUT([ \ abs_srcdir="$(cd "$srcdir" && pwd)" # builddir is always absolute! if test "$abs_srcdir" != "$builddir"; then - MAKEFILES=$("$MAKE" -C "$abs_srcdir" list | grep Makefile) - - for i in $MAKEFILES; do - echo "creating $i" - $MKINSTALLDIRS "$builddir/$(dirname $i)" >/dev/null - echo "include $abs_srcdir/$i" > "$builddir/$i" - done + echo "include $abs_srcdir/Makefile" > "$builddir/Makefile" + "$MAKE" "SRC=$abs_srcdir" init fi