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)
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
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)
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;
return OK;
}
-int next_char(struct te_buffer *buf)
+
+int move_right(struct te_buffer *buf)
{
if (buf == NULL)
return;
#define __BUFFER_H__
#include <stdio.h>
+#include <Python.h>
#include "bstrlib.h"
#include "queue.h"
#include "config.h"
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;
};
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
void input_loop(void)
{
while(1) {
- char c = getch();
+ int c = getch();
switch(c) {
case 'q':
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);
+
}
}
#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();
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)
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, ...)
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, ...);