]> pd.if.org Git - pd_readline/commitdiff
More work.
authorandy <andy@obsidian.(none)>
Sat, 27 Oct 2012 08:17:09 +0000 (21:17 +1300)
committerandy <andy@obsidian.(none)>
Sat, 27 Oct 2012 08:17:09 +0000 (21:17 +1300)
funcs.c
history.c
keyhandler.c
pd_readline.c
pd_readline.h

diff --git a/funcs.c b/funcs.c
index e259f16c68c6265e0ed5cc27a6519ae0aeb02030..87e0d505a7a847bec6d66ccca3a2b4e863d2e815 100644 (file)
--- a/funcs.c
+++ b/funcs.c
 #include <stdlib.h> 
 #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)
 { 
        
        
-       
-       
-}      
-
 
+}      
 
 
 
index f84ec24bda425a41a49ebe8277fa45c919ea49f8..23707502c626fb6d9a5a78686220405b05c4facf 100644 (file)
--- 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.                                                  */ 
+
+
 
 
index 80ad5e5461f310dabafdc539c1d0a517fa638533..6d8ca52d2f4b37c2c3289a362a566078321aa40e 100644 (file)
@@ -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();         */ 
   }   
   
 } 
index 756e5ddd5c6f022c13f466a8ec6c946633f22b81..c92870a1e5e60ce6dde18a642e3cee88aa0dc159 100644 (file)
 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);   
         
   }         
                                       
index f05ec8efeea01af504064f9f6c25c8f76cfc9a10..497564e725517f0b94aa2831da9965b06ac6669f 100644 (file)
@@ -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);