From 7a1a81d517d3e95f6f9f5dba853fe6d9d8c27ab3 Mon Sep 17 00:00:00 2001 From: andy Date: Sat, 27 Oct 2012 21:17:09 +1300 Subject: [PATCH] More work. --- funcs.c | 25 +++++++++++++++++-------- history.c | 10 +++++++++- keyhandler.c | 42 +++++++++++++++++++++++++++++++++++++----- pd_readline.c | 6 +++++- pd_readline.h | 9 +++++---- 5 files changed, 73 insertions(+), 19 deletions(-) diff --git a/funcs.c b/funcs.c index e259f16..87e0d50 100644 --- a/funcs.c +++ b/funcs.c @@ -13,9 +13,14 @@ #include #include "pd_readline.h" +/* Note - make the up and down funcs return a buffer. */ +/* A line from the history file can be put into the */ +/* array member of the buffer. */ +/* Also test for the top and bottom of the history file. */ + /* Move up in history list. */ -int up(int i) +buf up(int i) { @@ -24,7 +29,7 @@ int up(int i) /* Move down in history list. */ -int down(int i) +buf down(int i) { @@ -63,17 +68,21 @@ buf insch(buf b) } +void enter(void) +{ + printf("Enter "); +} + + -/* Function to handle escape sequences. */ -int esc(int i) +/* Function for special key combinations */ +/* (Ctrl, Alt, function keys. */ +int spec(int i) { - - -} - +} diff --git a/history.c b/history.c index f84ec24..2370750 100644 --- a/history.c +++ b/history.c @@ -39,7 +39,9 @@ char hist[20][80]; -/* Read the file into the array of strings. */ +/* Read the file into the array of strings. */ +/* TO DO - look at reading file into a series of structs. */ + void readhistory(char *fname) { int retval = fexists(fname); @@ -64,5 +66,11 @@ void readhistory(char *fname) } +/* TO DO - a function that reads in the 2d history array, and */ +/* returns a struct with one line from the array, and the index */ +/* of the line. */ + + + diff --git a/keyhandler.c b/keyhandler.c index 80ad5e5..6d8ca52 100644 --- a/keyhandler.c +++ b/keyhandler.c @@ -59,16 +59,48 @@ char getche(void) { -void keyhandler(void) +/* Arrow keys are esc [ A to esc [ D */ +/* Alt keys are just esc then key (e.g. Alt-g is esc g ). */ +/* Ctrl (then letter) keys are just Dec 1 to Dec 26 */ + +void keyhandler(buf b) { + int i = getch(); switch(i) { - case (27): puts("1"); /* escape() ; */ - case (33): puts("2"); /* dosomething(); */ - case (42): puts("3"); /* something(); */ - default: puts("4"); /* stuff(); */ + case (1): break; /* Ctrl a */ + case (2): break; /* Ctrl b */ + case (3): break; /* Ctrl c */ + + case (10): enter(); /* Enter */ + + case (27): spec(i); break; /* esc */ + + case (32): printf("%c", i); break; /* Printable chars. */ + case (33): printf("%c", i); break; /* Printable chars. */ + case (34): printf("%c", i); break; /* Printable chars. */ + + case (65): printf("%c", i); break; /* "A" */ + case (66): printf("%c", i); break; /* "B" */ + case (67): printf("%c", i); break; /* "C" */ + case (68): printf("%c", i); break; /* "D" */ + case (69): printf("%c", i); break; /* "E" */ + case (70): printf("%c", i); break; /* "F" */ + + case (97): printf("%c", i); break; /* "a" */ + case (98): printf("%c", i); break; /* "b" */ + case (99): printf("%c", i); break; /* "c" */ + case (100): printf("%c", i); break; /* "d" */ + case (101): printf("%c", i); break; /* "e" */ + case (102): printf("%c", i); break; /* "f" */ + + case (126): printf("%c", i); break; /* "~" */ + + case (127): delch(b); break; + + default: break; /* stuff(); */ } } diff --git a/pd_readline.c b/pd_readline.c index 756e5dd..c92870a 100644 --- a/pd_readline.c +++ b/pd_readline.c @@ -29,6 +29,10 @@ int main(void) { + /* Create a buffer for the text. */ + buf mybuf; + + /* Read in the command history file. */ readhistory("test.txt"); @@ -36,7 +40,7 @@ int main(void) while(1) { - keyhandler(); + keyhandler(mybuf); } diff --git a/pd_readline.h b/pd_readline.h index f05ec8e..497564e 100644 --- a/pd_readline.h +++ b/pd_readline.h @@ -16,19 +16,20 @@ typedef struct { /* Cursor movement funcs. */ -int up(int i); -int down(int i); +buf up(int i); +buf down(int i); buf left(buf b); buf right(buf b); buf delch(buf b); buf insch(buf b); +void enter(void); /* Escape-key handling. */ -int esc(int i); +int spec(int i); /* Other funcs. */ void readhistory(char *fname); -void keyhandler(void); +void keyhandler(buf b); -- 2.40.0