]> khamidou — GitHub mirrors - te.git/commitdiff
added slang support
authorkhamidou <karim@lambda-expr.org>
Fri, 17 Jul 2009 11:12:16 +0000 (13:12 +0200)
committerkhamidou <karim@lambda-expr.org>
Fri, 17 Jul 2009 11:12:16 +0000 (13:12 +0200)
buffer.c
buffer.h
interp.c [new file with mode: 0644]
interp.h [new file with mode: 0644]
keyb.c
main.c

index a7dd84ee7cdbaf818244e9896d9622253019510a..eddb9286ca14a006896cb763fa32e1d8b276cdb2 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -38,6 +38,15 @@ void free_buffer(struct te_buffer *b)
        free(b);
 }
 
+void free_all_buffers(void)
+{
+       struct te_buffer *b;
+       TAILQ_FOREACH(b, &buffers_head, buffers) {
+               free_buffer(b);
+       }
+
+}
+
 struct te_buffer* search_buffer(char *name)
 {
        if (name == NULL)
index 95bad3a3d700e5dc0506a13c10884263aacf3bca..00755bbd9ba7df3b20f11dcd032679a893e27736 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -21,7 +21,8 @@ TAILQ_HEAD(te_buffers_head, te_buffer) buffers_head;
 
 struct te_buffer               *alloc_and_insert_buffer(void);
 void                           free_buffer(struct te_buffer *b);
-struct te_buffer* search_buffer(char *name);
+void                           free_all_buffers(void);
+struct te_buffer*              search_buffer(char *name);
 struct te_buffer*              load_buffer(char *filename);
 
 void                           init_buffers(void);
diff --git a/interp.c b/interp.c
new file mode 100644 (file)
index 0000000..8bf574c
--- /dev/null
+++ b/interp.c
@@ -0,0 +1,37 @@
+#include "interp.h"
+#include "screen.h"
+
+void init_interp(void)
+{
+       if (SLang_init_all () == - 1)
+               exit (EXIT_FAILURE);
+
+       if (SLadd_intrin_fun_table(te_intrinsics, NULL) == -1)
+       {
+               fail("Unable to load the S-lang interface - exiting.");
+       }
+
+       if (SLang_load_file ("tests/test.sl") == -1)
+       {
+               /* Clear the error and reset the interpreter */
+               SLang_restart (1);
+       }
+
+/* TODO : load the file named .terc. */
+/*     if (SLang_load_file ("site.sl") == -1) */
+/*     { */
+/*             /\* Clear the error and reset the interpreter *\/ */
+/*             SLang_restart (1); */
+/*     } */
+
+}
+
+void intrin_miniprintf(char **s)
+{
+       miniprintf("%s", *s);
+}
+
+void intrin_statusprintf(char **s)
+{
+       statusprintf("%s", *s);
+}
diff --git a/interp.h b/interp.h
new file mode 100644 (file)
index 0000000..bdc3961
--- /dev/null
+++ b/interp.h
@@ -0,0 +1,32 @@
+/*
+  interp.h : bindings for the S-lang interpreter.
+ */
+#ifndef __INTERP_H__
+#define __INTERP_H__
+
+#include <stdlib.h>
+#include <slang.h>
+#include "buffer.h"
+
+void intrin_statusprintf(char **s);
+void intrin_miniprintf(char **s);
+
+SLang_Intrin_Fun_Type te_intrinsics [] = 
+{
+       /* table entries */
+       MAKE_INTRINSIC_1("miniprintf", intrin_miniprintf, SLANG_VOID_TYPE, SLANG_STRING_TYPE),
+       MAKE_INTRINSIC_1("statusprintf", intrin_statusprintf, SLANG_VOID_TYPE, SLANG_STRING_TYPE),
+
+       SLANG_END_INTRIN_FUN_TABLE
+};
+
+SLang_CStruct_Field_Type buffer_type_layout [] =
+{
+       MAKE_CSTRUCT_FIELD(struct te_buffer, name, "name", SLANG_STRING_TYPE, 0),
+       MAKE_CSTRUCT_FIELD(struct te_buffer, point, "point", SLANG_INT_TYPE, 0),
+       MAKE_CSTRUCT_FIELD(struct te_buffer, dirty, "dirty", SLANG_INT_TYPE, 0),
+
+      SLANG_END_CSTRUCT_TABLE
+};
+
+#endif
diff --git a/keyb.c b/keyb.c
index 674d9e99a740cce35e6b5b58b3c1e326fda3b5f8..02d4dc3b6545ccba1d8e3962f5adcd29dab2daab 100644 (file)
--- a/keyb.c
+++ b/keyb.c
@@ -15,10 +15,10 @@ void input_loop(void)
 
                refresh();
 
-               miniprintf("%c, line length: %d, y: %d, x%d",
-                          (bchar(current_buf->contents, current_buf->point) == '\n') ? 'N' : bchar(current_buf->contents, current_buf->point),
-                          screen_line_length(current_buf->contents, current_buf->point),
-                          current_buf->y, current_buf->x);
+/*             miniprintf("%c, line length: %d, y: %d, x%d", */
+/*                        (bchar(current_buf->contents, current_buf->point) == '\n') ? 'N' : bchar(current_buf->contents, current_buf->point), */
+/*                        screen_line_length(current_buf->contents, current_buf->point), */
+/*                        current_buf->y, current_buf->x); */
 
        }
 
diff --git a/main.c b/main.c
index 7c129ec077417bfa401c7a33885ba0c18f23537f..29c370769252597bcbf375a45d7c93f34d6660ef 100644 (file)
--- a/main.c
+++ b/main.c
@@ -4,9 +4,11 @@
 
 #include <stdio.h>
 #include <curses.h>
-#include "interp.h"
+//#include "interp.h"
 #include "screen.h"
 
+void init_interp(void);
+
 extern struct te_buffer *current_buf;
 
 int main(int argc, char **argv)
@@ -15,7 +17,10 @@ int main(int argc, char **argv)
        init_interp();
        init_windows();
 
-       current_buf = load_buffer("tests/bufferfuncs.c");
+       if (argc != 1)
+               current_buf = load_buffer(argv[1]);
+       else 
+               current_buf = load_buffer("tests/bufferfuncs.c");
 
        paint_buffer(current_buf);
        refresh();