$(srcdir)/script-lib-plymouth.script \
$(srcdir)/script-lib-math.c \
$(srcdir)/script-lib-math.h \
- $(srcdir)/script-lib-math.script
+ $(srcdir)/script-lib-math.script \
+ $(srcdir)/script-lib-string.c \
+ $(srcdir)/script-lib-string.h \
+ $(srcdir)/script-lib-string.script
MAINTAINERCLEANFILES = Makefile.in
CLEANFILES = *.script.h
-BUILT_SOURCES = script-lib-image.script.h script-lib-sprite.script.h script-lib-math.script.h script-lib-plymouth.script.h
+BUILT_SOURCES = script-lib-image.script.h \
+ script-lib-sprite.script.h \
+ script-lib-plymouth.script.h \
+ script-lib-math.script.h \
+ script-lib-string.script.h
%.script.h: %.script
sed -e 's/\\/\\\\/g' \
#include "script-lib-sprite.h"
#include "script-lib-plymouth.h"
#include "script-lib-math.h"
+#include "script-lib-string.h"
#include <linux/kd.h>
script_lib_image_data_t *script_image_lib;
script_lib_plymouth_data_t *script_plymouth_lib;
script_lib_math_data_t *script_math_lib;
+ script_lib_string_data_t *script_string_lib;
} view_t;
struct _ply_boot_splash_plugin
view->script_plymouth_lib = script_lib_plymouth_setup (view->script_state,
plugin->mode);
view->script_math_lib = script_lib_math_setup (view->script_state);
+ view->script_string_lib = script_lib_string_setup (view->script_state);
ply_trace ("executing script file");
script_return_t ret = script_execute (view->script_state,
script_lib_image_destroy (view->script_image_lib);
script_lib_plymouth_destroy (view->script_plymouth_lib);
script_lib_math_destroy (view->script_math_lib);
+ script_lib_string_destroy (view->script_string_lib);
}
static void
--- /dev/null
+/* script-lib-string.c - string script functions library
+ *
+ * Copyright (C) 2009 Charlie Brej <cbrej@cs.man.ac.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by: Charlie Brej <cbrej@cs.man.ac.uk>
+ */
+#define _GNU_SOURCE
+#include "script.h"
+#include "script-parse.h"
+#include "script-execute.h"
+#include "script-object.h"
+#include "script-lib-string.h"
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+
+#include "script-lib-string.script.h"
+
+
+static script_return_t script_lib_string_char_at (script_state_t *state,
+ void *user_data)
+{
+ char *text = script_obj_as_string (state->this);
+ int index = script_obj_hash_get_number (state->local, "index");
+ int count;
+ char charstring [2];
+
+ if (!text || index < 0)
+ {
+ free (text);
+ return script_return_obj(script_obj_new_string ("sdfsd"));
+ }
+ for (count = 0; count < index; count++)
+ {
+ if (text[count] == '\0')
+ {
+ free (text);
+ return script_return_obj(script_obj_new_string ("sdfasdf asd"));
+ }
+ }
+ charstring[0] = text[index];
+ charstring[1] = '\0';
+ free (text);
+ return script_return_obj(script_obj_new_string (charstring));
+}
+
+script_lib_string_data_t *script_lib_string_setup (script_state_t *state)
+{
+ script_lib_string_data_t *data = malloc (sizeof (script_lib_string_data_t));
+
+ script_obj_t *string_hash = script_obj_hash_get_element (state->global, "String");
+ script_add_native_function (string_hash,
+ "CharAt",
+ script_lib_string_char_at,
+ NULL,
+ "index",
+ NULL);
+ script_obj_unref (string_hash);
+ data->script_main_op = script_parse_string (script_lib_string_string, "script-lib-string.script");
+ script_return_t ret = script_execute (state, data->script_main_op);
+ script_obj_unref (ret.object);
+
+ return data;
+}
+
+void script_lib_string_destroy (script_lib_string_data_t *data)
+{
+ script_parse_op_free (data->script_main_op);
+ free (data);
+}
+
--- /dev/null
+/* script-lib-string.h - string script functions library
+ *
+ * Copyright (C) 2009 Charlie Brej <cbrej@cs.man.ac.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by: Charlie Brej <cbrej@cs.man.ac.uk>
+ */
+#ifndef SCRIPT_LIB_STRING_H
+#define SCRIPT_LIB_STRING_H
+
+#include "script.h"
+
+typedef struct
+{
+ script_op_t *script_main_op;
+} script_lib_string_data_t;
+
+script_lib_string_data_t *script_lib_string_setup (script_state_t *state);
+void script_lib_string_destroy (script_lib_string_data_t *data);
+
+#endif /* SCRIPT_LIB_STRING_H */
--- /dev/null
+String |= fun(text)
+{
+ return text | global.String;
+};