]> khamidou — GitHub mirrors - te.git/commitdiff
no message
authorkhamidou <karim@lambda-expr.org>
Thu, 9 Jul 2009 17:08:18 +0000 (19:08 +0200)
committerkhamidou <karim@lambda-expr.org>
Thu, 9 Jul 2009 17:08:18 +0000 (19:08 +0200)
Makefile
keyb.c
keyb.h
py2c.py [deleted file]
screen.c
screen.h

index 757b300e68a7a642c55aa958ec825838a7dd2369..222c065a25cc561100e74dace71ab24b92515fa7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CC=gcc
-CFLAGS=-c -g `lua-config --include`
-LDFLAGS=-lcurses `lua-config --libs`
-OBJS=main.o errors.o screen.o buffer.o keyb.o bstrlib.o lua-api.o
+CFLAGS=-c -g
+LDFLAGS=-lcurses
+OBJS=main.o errors.o screen.o buffer.o keyb.o bstrlib.o
 
 te: $(OBJS)
        $(CC) $(LDFLAGS) -o te $(OBJS)
@@ -24,9 +24,6 @@ keyb.o: keyb.c
 bstrlib.o: bstrlib.c
        $(CC) $(CFLAGS) bstrlib.c
 
-lua-api.o: lua-api.c
-       $(CC) $(CFLAGS) lua-api.c
-
 clean: 
        rm $(OBJS)
        rm *~
diff --git a/keyb.c b/keyb.c
index c227ac2a7f5ce9849ed7a55dc2819acbbf55d821..52c8c7a9fe558407d5bb94793b32941dea792f84 100644 (file)
--- a/keyb.c
+++ b/keyb.c
 #include "keyb.h"
 
+int command_mode = 1;  /* command mode = 1, input mode = 0 */
+char *str;
+
 void input_loop(void)
 {
        while(1) {
                int c = getch();
                
-               switch(c) {
-               case 'q':
-                       exit(0);
-
-               case KEY_LEFT:
-                       screen_move_left(current_buf);
-                       break;
-
-               case KEY_RIGHT:
-                       screen_move_right(current_buf);
-                       break;
-
-               case KEY_DOWN:
-                       screen_move_down(current_buf);
-                       break;
-
-               case KEY_UP:
-                       screen_move_up(current_buf);
-                       break;
-
-               case KEY_BACKSPACE:
-                       screen_delete_char(current_buf);
-                       break;
-
-               case 'w':
-                       write_buffer(current_buf);
-                       break;
-               default:
-                       screen_insert_char(current_buf, c);
-                       refresh();
-                       break;
-               }
-               
+               if (command_mode)
+                       process_command(c);
+               else 
+                       process_input(c);
+
                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); */
 
        }
 
 }
+
+
+void process_command(int c)
+{
+                       switch(c) {
+                       case 'q':
+                               exit(0);
+
+                       case 'h':
+                       case KEY_LEFT:
+                               screen_move_left(current_buf);
+                               break;
+
+                       case 'l':
+                       case KEY_RIGHT:
+                               screen_move_right(current_buf);
+                               break;
+
+                       case 'j':
+                       case KEY_DOWN:
+                               screen_move_down(current_buf);
+                               break;
+
+                       case 'k':
+                       case KEY_UP:
+                               screen_move_up(current_buf);
+                               break;
+
+                       case 'w':
+                               write_buffer(current_buf);
+                               break;
+
+                       case 'i':
+                       case KEY_END:
+                               /* switch between command and input mode */
+                               command_mode = 0;
+                               break;
+
+                       case 'v':
+                               str = read_user_input();
+                               miniprintf("you entered : %s", str);
+                               break;
+
+                       default:
+                               miniprintf("%c - invalid command", c);
+                               break;
+                       }
+}
+
+void process_input(int c)
+{
+                       switch(c) {
+                       case KEY_BACKSPACE:
+                               screen_delete_char(current_buf);
+                               break;
+
+                       case KEY_LEFT:
+                               screen_move_left(current_buf);
+                               break;
+
+                       case KEY_RIGHT:
+                               screen_move_right(current_buf);
+                               break;
+
+                       case KEY_DOWN:
+                               screen_move_down(current_buf);
+                               break;
+
+                       case KEY_UP:
+                               screen_move_up(current_buf);
+                               break;
+                               
+                       case KEY_END:
+                               command_mode = 1;
+                               break;
+
+                       default:
+                               screen_insert_char(current_buf, c);
+                               refresh();
+                               break;
+                       }
+
+}
diff --git a/keyb.h b/keyb.h
index 003c3653f445ee17b3d5282b19b879af5d619ed4..eec90caf5caad679d15b92906b11708c7784e094 100644 (file)
--- a/keyb.h
+++ b/keyb.h
@@ -6,6 +6,8 @@
 #include "screen.h"
 
 void input_loop(void);
+void process_command(int c); /* process a command */
+void process_input(int c);   /* process a normal char - that is, not a command */
 
 struct te_buffer *current_buf;
 
diff --git a/py2c.py b/py2c.py
deleted file mode 100755 (executable)
index a813612..0000000
--- a/py2c.py
+++ /dev/null
@@ -1,29 +0,0 @@
-#! /usr/bin/env python
-# 
-# py2c takes as parameters a list of python files and creates one big C file
-# that contains strings that are fed to the python interpreter.
-
-import sys
-
-try:
-    ofile = open("py2cout.c", "w+")
-except IOError:
-    print "Unable to open py2cout.c"
-    sys.exit(-1)
-
-skel = 
-"/* This code has been generated by py2c.py
-#include <Python.h>"
-
-ofile.write(skel)
-
-for i in sys.argv[1:]:
-    try:
-        f = open(i, "r")
-    except IOError:
-        print "Unable to open " + i
-        sys.exit(-1)
-
-    c = f.read()
-    
-
index dcf1acbe1f109158f131353e2d02763cbf906b33..ac1cebd655d005b83900e7e5bb5901b093a7c29a 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -1,3 +1,4 @@
+#include "zalloc.h"
 #include "screen.h"
 #include "util.h"
 
@@ -269,6 +270,11 @@ void screen_delete_char(struct te_buffer *buf)
        move_right(buf); /* yes it's ugly but I don't feel like recoding screen_move_right atm */
 }
 
+void screen_switch_buffer(struct te_buffer *buf)
+{
+       
+}
+
 /*
   display a message in the status bar.
  */
@@ -332,6 +338,26 @@ void notifyprintf(char *fmt, ...)
        getch(); /* discard input */
 }
 
+char *read_user_input(void)
+{
+       char *s = zalloc(255);
+       int c = 0;
+       int i = 0;
+
+       for (i = 0; i < 255 && c != KEY_ENTER; i++) {
+               c = getch();
+               waddch(minibuffer_win, c);
+               *(s + i) = c;
+       }
+
+       if ((void *) c == NULL)
+               fail("Unable to allocate memory at __FILE__:__LINE__\n");
+
+       if (getnstr(c, 255) == ERR)
+               return (char *) ERR;
+
+       return (char *) c;
+}
 
 void console_signal_handler(int sig)
 {
index 96dd6aa2de3491c628527d42917af5ab923f41e9..bcb31a3d3268ddc3534c55cf86d8158823779022 100644 (file)
--- a/screen.h
+++ b/screen.h
@@ -27,6 +27,7 @@ void screen_move_down(struct te_buffer *buf);
 void statusprintf(char *fmt, ...);
 void miniprintf(char *fmt, ...);
 void notifyprintf(char *fmt, ...);
+char *read_user_input(void);
 
 void console_signal_handler(int sig);