]> khamidou — GitHub mirrors - te.git/commitdiff
fixed python-related compilation bug
authorkhamidou <karim@lambda-expr.org>
Mon, 8 Jun 2009 10:00:35 +0000 (12:00 +0200)
committerkhamidou <karim@lambda-expr.org>
Mon, 8 Jun 2009 10:00:35 +0000 (12:00 +0200)
Makefile
buffer.c
buffer.h
keyb.c
main.c
screen.c
screen.h

index 29242943a3ec6efd15d4cf6638945b1346694e49..781371ef43d13832712757f40345ab5cda8eb237 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CC=gcc
-CFLAGS=-c -g
-LDFLAGS=-lcurses
-OBJS=main.o errors.o screen.o buffer.o keyb.o bstrlib.o
+CFLAGS=-c -g `python2.5-config --includes`
+LDFLAGS=-lcurses `python2.5-config --ldflags`
+OBJS=main.o errors.o screen.o buffer.o keyb.o bstrlib.o python-bindings.o
 
 te: $(OBJS)
        $(CC) $(LDFLAGS) -o te $(OBJS)
@@ -24,6 +24,9 @@ keyb.o: keyb.c
 bstrlib.o: bstrlib.c
        $(CC) $(CFLAGS) bstrlib.c
 
+python-bindings.o: python-bindings.c python-bindings.h
+       $(CC) $(CFLAGS) python-bindings.c
+
 clean: $(OBJS)
        rm $(OBJS)
        rm te
\ No newline at end of file
index 76b9fcdeee31d0353fb4b8025bf2318b9835bf25..44ae16512524f0f9c5d75a7254ca36277b484438 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -65,7 +65,7 @@ int line_length(bstring b, int point)
 
        int c_offset = bstrchrp(b, '\n', point);
        if (c_offset == BSTR_ERR)
-               c_offset = 0;
+               c_offset = blength(b);
 
        int p_offset = bstrrchrp(b, '\n', c_offset - 1);
        if (p_offset == BSTR_ERR)
@@ -93,10 +93,37 @@ int screen_line_length(bstring b, int point)
                        count += 1;
        }
 
-       return count;
 }
 
+/*
+  accessor and mutators for the contents of the buffer.
+
+ */
 int prev_char(struct te_buffer *buf)
+{
+       if (buf == NULL)
+               return;
+
+       return bchar(buf->contents, buf->point - 1);
+}
+
+int curr_char(struct te_buffer *buf)
+{
+       if (buf == NULL)
+               return;
+
+       return bchar(buf->contents, buf->point);
+}
+
+int next_char(struct te_buffer *buf)
+{
+       if (buf == NULL)
+               return;
+
+       return bchar(buf->contents, buf->point + 1);
+}
+
+int move_left(struct te_buffer *buf)
 {
        if (buf == NULL)
                return;
@@ -109,7 +136,8 @@ int prev_char(struct te_buffer *buf)
        return OK;
 }
 
-int next_char(struct te_buffer *buf)
+
+int move_right(struct te_buffer *buf)
 {
        if (buf == NULL)
                return;
index 72d5b8d56215ed679906ebb9947a60575e27fbd8..cd3dde797cb5b340193c3775ebe5dc31105d87e3 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -2,6 +2,7 @@
 #define __BUFFER_H__
 
 #include <stdio.h>
+#include <Python.h>
 #include "bstrlib.h"
 #include "queue.h"
 #include "config.h"
@@ -14,6 +15,8 @@ struct te_buffer {
        int point;              /* offset in "contents" */
        struct te_char *scr_top, *scr_bottom; /* the first and last char of the screen */
 
+       PyObject *pyBuffer;     /* pointer to the buffer object */
+
        TAILQ_HEAD(te_chars_head, te_char) chars_head;
        TAILQ_ENTRY(te_buffer) buffers;
 };
@@ -31,8 +34,10 @@ void                                 init_buffers(void);
 int                            line_length(bstring b, int point);
 int                            screen_line_length(bstring b, int point);
 int                            prev_char(struct te_buffer *buf);
+int                            curr_char(struct te_buffer *buf);
 int                            next_char(struct te_buffer *buf);
-
+int                            move_right(struct te_buffer *buf);
+int                            move_left(struct te_buffer *buf);
 
 
 #endif
diff --git a/keyb.c b/keyb.c
index 13a741f93a9119f618334c7e26da4a0fcd4a8076..30ee644666171ace0c9f475d06bdb986d397a749 100644 (file)
--- a/keyb.c
+++ b/keyb.c
@@ -3,7 +3,7 @@
 void input_loop(void)
 {
        while(1) {
-               char c = getch();
+               int c = getch();
                
                switch(c) {
                case 'q':
@@ -11,16 +11,27 @@ void input_loop(void)
 
                case 'k':
                case KEY_LEFT:
-                       move_left(current_buf);
+                       screen_move_left(current_buf);
                        break;
 
                case 'l':
                case KEY_RIGHT:
-                       move_right(current_buf);
+                       screen_move_right(current_buf);
+                       break;
+
+               case 'd':
+               case KEY_DOWN:
+                       screen_move_down(current_buf);
                        break;
                }
 
                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);
+
        }
 
 }
diff --git a/main.c b/main.c
index ba19fbefc138fa8a1fef906190f1694d941d285a..1a050ba28a683f8fc6f64c4aa992f42a95049d8f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -4,16 +4,18 @@
 
 #include <stdio.h>
 #include <curses.h>
+#include "python-bindings.h"
 #include "screen.h"
 
 extern struct te_buffer *current_buf;
 
 int main(int argc, char **argv)
 {
+       init_python();
        init_buffers();
        init_windows();
 
-       current_buf = load_buffer("screen.c");
+       current_buf = load_buffer("README");
        paint_buffer(current_buf);
        refresh();
        input_loop();
index 3606918ac1ad1a64f663478f501f1e84c1ef9cf3..31018cb747eeef76dfa8901f1c8563b1053d4334 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -60,9 +60,10 @@ void screen_prev_line(struct te_buffer *buf)
        if (buf == NULL)
                return;
 
-       buf->x = 0;
-       if (buf->y > 0)
+       if (buf->y > 0) {
                buf->y--;
+               buf->x = screen_line_length(buf->contents, buf->point);
+       }
 }
 
 void screen_next_line(struct te_buffer *buf)
@@ -75,78 +76,90 @@ void screen_next_line(struct te_buffer *buf)
                buf->y++;
 }
 
-void move_left(struct te_buffer *buf)
+void screen_move_left(struct te_buffer *buf)
 {
        if (buf == NULL)
                return;
 
-       if (bchar(buf->contents, buf->point) == '\n') {
-               screen_prev_line(buf);
-               prev_char(buf);
+       if(move_left(buf) == ERR)
                return;
-       }
-
-       if(prev_char(buf) == ERR)
-               return;
-
-       if (buf->x > 0)
-               if (bchar(buf->contents, buf->point) == '\t')
-                       buf->x -= TAB_LEN;
-               else {
-                       buf->x--;
-               }
-
-       else if (buf->y > 0) {
-               buf->y--;
-               buf->x = screen_line_length(buf->contents, buf->point);
+       
+       if (curr_char(buf) == '\n') {
+                       screen_prev_line(buf);
+       } else { 
+               if (buf->x > 0)
+                       if (curr_char(buf) == '\t') {
+                               buf->x -= TAB_LEN;
+                       } else {
+                                       buf->x--;
+                       }
        }
 
        move(buf->y, buf->x);
-       refresh();
-       miniprintf("%c, y: %d, x%d", bchar(buf->contents, buf->point), buf->y, buf->x);
 }
 
-void move_right(struct te_buffer *buf)
+void screen_move_right(struct te_buffer *buf)
 {
        if (buf == NULL)
                return;
 
-       if (bchar(buf->contents, buf->point) == '\n') {
-               screen_next_line(buf);
-               next_char(buf);
-               return;
-       }
-
-       if (next_char(buf) == ERR) /* last char of the document */
+       if (move_right(buf) == ERR) /* last char of the document */
                return;
 
-       if (buf->x < screen_line_length(buf->contents, buf->point)) {
+       if (prev_char(buf) == '\n') {
+               screen_next_line(buf);
+       } else { 
+               if (buf->x <= screen_line_length(buf->contents, buf->point)) {
                /* tab is the only character larger than 1 */
-               if (bchar(buf->contents, buf->point) == '\t')
-                       buf->x += TAB_LEN;
-               else {
-                       buf->x++;
+                       if (prev_char(buf) == '\t') {
+                               buf->x += TAB_LEN;
+                       } else {
+                               buf->x++;
+                       }
                }
-       }
-       else if (buf->y < LINES - 3) {
-               buf->y++;
-               buf->x = 0;
-       }
 
+               else { /* FIXME: scroll the screen instead of testing this
+                         condition
+                      */
+                       screen_next_line(buf);
+               }
+       }
 
        move(buf->y, buf->x);
-       refresh();
-       miniprintf("%c, y: %d, x%d", bchar(buf->contents, buf->point), buf->y, buf->x);
 }
 
-void move_up(struct te_buffer *buf)
+void screen_move_up(struct te_buffer *buf)
 {
+       if (buf == NULL)
+               return;
 
+       
 }
 
-void move_down(struct te_buffer *buf)
+void screen_move_down(struct te_buffer *buf)
 {
+       if (buf == NULL)
+               return;
+
+       int     line_len  = line_length(buf->contents, buf->point);
+       int     sline_len = screen_line_length(buf->contents, buf->point);
+       int     count = 0;
+
+       do {
+               /* move until the end of line */
+               if(move_right(buf) == ERR)
+                       break;
+
+       } while(curr_char(buf) != '\n');
+
+       screen_next_line(buf);
+
+       for(count = 0; count < line_len && curr_char(buf) != '\n'; count++) {
+               move_right(buf);
+               screen_move_right(buf);
+       }
 
+       return;
 }
 
 void statusprintf(char *fmt, ...)
index 1feac12d38cdee36f013a8dd7a5dcb6ccd19d5cf..5c3d4f12dff7088022c57cc0decb2af3f7d9b39d 100644 (file)
--- a/screen.h
+++ b/screen.h
@@ -18,10 +18,10 @@ void paint_buffer(struct te_buffer *buf);
 
 void scroll_up(struct te_buffer *buf);
 void scroll_down(struct te_buffer *buf);
-void move_left(struct te_buffer *buf);
-void move_right(struct te_buffer *buf);
-void move_up(struct te_buffer *buf);
-void move_down(struct te_buffer *buf);
+void screen_move_left(struct te_buffer *buf);
+void screen_move_right(struct te_buffer *buf);
+void screen_move_up(struct te_buffer *buf);
+void screen_move_down(struct te_buffer *buf);
 
 void statusprintf(char *fmt, ...);
 void miniprintf(char *fmt, ...);