1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-10-01 03:36:26 -04:00

Move code for the SEE object interface

This commit is contained in:
Jonas Fonseca 2005-10-26 22:11:34 +02:00 committed by Jonas Fonseca
parent a5d205c047
commit d7f002c8a1
4 changed files with 226 additions and 198 deletions

View File

@ -3,6 +3,6 @@ include $(top_builddir)/Makefile.config
INCLUDES += $(SEE_CFLAGS)
OBJS = see.o hooks.o core.o
OBJS = see.o core.o hooks.o interface.o
include $(top_srcdir)/Makefile.lib

View File

@ -1,4 +1,4 @@
/* Ruby interface (scripting engine) */
/* SEE interface (scripting engine) */
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -9,18 +9,14 @@
#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/interface.h"
#include "scripting/see/see.h"
#include "session/session.h"
#include "util/error.h"
#include "util/file.h"
#include "util/string.h"
@ -55,195 +51,6 @@ 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 string string;
struct terminal *term;
SEE_SET_UNDEFINED(res);
if (!argc) return;
SEE_ToString(see, argv[0], &v);
if (!convert_see_string(&string, v.u.string))
return;
if (!see_ses && list_empty(terminals)) {
usrerror("[SEE] %s", string.source);
done_string(&string);
return;
}
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);
}
#if DATADRIVEN
_IDEA
struct object_info browser_object[] = {
"ELinks", SEE_ATTR_READONLY,
{ /* Properties: */
{ "version", SEE_STRING, VERSION, SEE_ATTR_READONLY },
{ "home", SEE_STRING, NULL, SEE_ATTR_READONLY },
},
{ /* Methods: (as name, handler, args) */
{ "write", elinks_see_write, SEE_ATTR_READONLY },
{ NULL }
},
};
struct object_info *see_
#endif
static void
init_see_environment(struct SEE_interpreter *see)
{
unsigned char *home;
struct SEE_object *obj, *navigator;
struct SEE_value value;
struct SEE_string *name;
/* TODO: Initialize strings.
SEE_intern_global(s_print = &S_print);
* */
/* 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, "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, "appHome");
SEE_OBJECT_PUT(see, navigator, name, &value, SEE_ATTR_READONLY);
/* 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
see_abort_handler(struct SEE_interpreter *see, const char *msg)
{
@ -270,8 +77,8 @@ init_see(struct module *module)
/* Initialise an interpreter */
SEE_interpreter_init(see);
/* Set up the ELinks module interface. */
init_see_environment(see);
/* Set up the ELinks interface. */
init_see_interface(see);
if (elinks_home) {
path = straconcat(elinks_home, SEE_HOOKS_FILENAME, NULL);

View File

@ -0,0 +1,212 @@
/* The ELinks SEE interface: */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <see/see.h>
#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"
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 string string;
struct terminal *term;
SEE_SET_UNDEFINED(res);
if (!argc) return;
SEE_ToString(see, argv[0], &v);
if (!convert_see_string(&string, v.u.string))
return;
if (!see_ses && list_empty(terminals)) {
usrerror("[SEE] %s", string.source);
done_string(&string);
return;
}
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);
}
#if DATADRIVEN
_IDEA
struct object_info browser_object[] = {
"ELinks", SEE_ATTR_READONLY,
{ /* Properties: */
{ "version", SEE_STRING, VERSION, SEE_ATTR_READONLY },
{ "home", SEE_STRING, NULL, SEE_ATTR_READONLY },
},
{ /* Methods: (as name, handler, args) */
{ "write", elinks_see_write, SEE_ATTR_READONLY },
{ NULL }
},
};
struct object_info *see_
#endif
void
init_see_interface(struct SEE_interpreter *see)
{
unsigned char *home;
struct SEE_object *obj, *navigator;
struct SEE_value value;
struct SEE_string *name;
/* TODO: Initialize strings.
SEE_intern_global(s_print = &S_print);
* */
/* 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, "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, "appHome");
SEE_OBJECT_PUT(see, navigator, name, &value, SEE_ATTR_READONLY);
/* 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);
}

View File

@ -0,0 +1,9 @@
#ifndef EL__SCRIPTING_SEE_INTERFACE_H
#define EL__SCRIPTING_SEE_INTERFACE_H
struct SEE_interpreter;
void init_see_interface(struct SEE_interpreter *see);
#endif