]> pd.if.org Git - pd_readline/commitdiff
More work.
authorandy <andy@obsidian.(none)>
Sun, 28 Oct 2012 01:10:39 +0000 (14:10 +1300)
committerandy <andy@obsidian.(none)>
Sun, 28 Oct 2012 01:10:39 +0000 (14:10 +1300)
funcs.c
history.c
keyhandler.c
pd_readline.c
pd_readline.h
range.c

diff --git a/funcs.c b/funcs.c
index 8ac14c685c0d129e797959084f007ad2ee7a3d14..36241e5cb97ddfd6adac38d3e1caca31de25c72b 100644 (file)
--- a/funcs.c
+++ b/funcs.c
 /* Also test for the top and bottom of the history file.  */     
 
 
 /* Also test for the top and bottom of the history file.  */     
 
 
+/*  Display a buffer  */ 
+void show(buf b)
+{ 
+   printf("%s", b.array);                      
+}      
+
+
+
+/* Enter a char into a buffer and display the buffer array.  */ 
+buf set(buf b, int i)
+{ 
+  if ( (b.index < 80)  )  
+    { 
+          b.array[b.index] = i;        
+          b.index += 1 ;
+    } 
+  else
+    { 
+          memset(b.array[0], 0, sizeof(b.array) ); 
+          b.array[0] = i;
+          b.index += 1 ;               
+    }          
+  
+  show(b); 
+  return b;    
+       
+} 
+
+
+
 /* Move up in history list. */ 
 /* Move up in history list. */ 
-buf up(int i
+buf up(buf b
 { 
   
 
 { 
   
 
@@ -29,7 +59,7 @@ buf up(int i)
 
 
 /* Move down in history list. */ 
 
 
 /* Move down in history list. */ 
-buf down(int i
+buf down(buf b
 { 
 
 
 { 
 
 
index 23707502c626fb6d9a5a78686220405b05c4facf..dd70ed5797bfeb7196526333eb9e18b433708633 100644 (file)
--- a/history.c
+++ b/history.c
@@ -9,6 +9,8 @@
 #include <string.h>   
 #include <stdio.h> 
 #include <stdlib.h> 
 #include <string.h>   
 #include <stdio.h> 
 #include <stdlib.h> 
+#include <malloc.h>
+#include "pd_readline.h"  
 
 
 /*  Helper function, to let us see if a file */ 
 
 
 /*  Helper function, to let us see if a file */ 
@@ -40,10 +42,12 @@ 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) 
+buf readhistory(char *fname) 
 { 
 { 
+       
+   /*  Create a history buffer.  */ 
+   buf h;      
+       
    int retval = fexists(fname); 
         
    int i; 
    int retval = fexists(fname); 
         
    int i; 
@@ -53,22 +57,33 @@ void readhistory(char *fname)
          /* append new commands to it. */ 
          FILE *fptr;  
          fptr = fopen(fname, "rw"); 
          /* append new commands to it. */ 
          FILE *fptr;  
          fptr = fopen(fname, "rw"); 
-                          
+               
+      char line[80] ; 
+                                          
          for(i=0; i<20; i++)  
          for(i=0; i<20; i++)  
-         {  
-               chop(fgets(hist[i], 80, fptr) );  
+         { 
+               fgets(line, 80, fptr);                   
+               chop(line) ;   
+               memcpy(hist[i], line, 80) ;   
+               puts(hist[i]); 
          }
          
    }  /* retval == 0  */          
        
        else puts("Error! File does not exist. \n");  
        
          }
          
    }  /* retval == 0  */          
        
        else puts("Error! File does not exist. \n");  
        
+       /* Read the most recent command into histbuf */ 
+       /* and set the index to 19.                  */
+       /*  
+           h.index = 19; 
+        h.array = hist[h.index] ;  
+    */
+       
+       return h;
+       
 }      
 
 }      
 
-
-/* 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 9636491b59caae9bd181deb132ceae2b1f71155a..0ba3c6a368bcd9503e01ecf77369fe98408351c7 100644 (file)
@@ -65,17 +65,12 @@ char getche(void) {
 /*  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        */ 
 
 /*  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        */ 
 
-/* TO DO: Use the helper function range                     */  
-/*  (  range(rstart, rend, val).  )                         */ 
-/* to handle entire ranges at once.                         */        
-
-
 void keyhandler(buf b) 
 { 
     
 void keyhandler(buf b) 
 { 
     
-  int i = getch(); 
+  int a = getch();    
   
   
-  int t = type(i); 
+  int t = type(a); 
     
   switch(t)
   { 
     
   switch(t)
   { 
@@ -83,13 +78,13 @@ void keyhandler(buf b)
        case (1):   break;     /*  Ctrl a  */   
        case (2):   break;     /*  Ctrl b  */   
        case (3):   getch();  spec(); break;   /*  Ctrl c  */     
        case (1):   break;     /*  Ctrl a  */   
        case (2):   break;     /*  Ctrl b  */   
        case (3):   getch();  spec(); break;   /*  Ctrl c  */     
-       case (4):   printf("%c", i);  break;    /*  Printable chars.  */    
+       case (4):   set(b, a);   break;    /*  Printable chars.  */    
        case (5):   delch(b);  break;  
        case (6):   break;  
        default:    break; 
                     
   }   
        case (5):   delch(b);  break;  
        case (6):   break;  
        default:    break; 
                     
   }   
-  
+   
 }    
 
 
 }    
 
 
index c92870a1e5e60ce6dde18a642e3cee88aa0dc159..8649fc1c036553e33069d19e13ecfce3a86bca96 100644 (file)
 int main(void) 
 { 
   
 int main(void) 
 { 
   
-  /* Create a buffer for the text.  */ 
+  /* Create a buffer for entered text.  */ 
   buf mybuf;  
   buf mybuf;  
-  
+  mybuf.index = 0;
+   
   
   /* Read in the command history file. */ 
   
   /* Read in the command history file. */ 
-  readhistory("test.txt");  
-  
+  buf histbuf = readhistory("test.txt");  
+    
   
   while(1) 
   {  
        
   
   while(1) 
   {  
        
-    keyhandler(mybuf);   
-        
+    keyhandler(mybuf);  
+         
   }         
                                       
   return 0;
   }         
                                       
   return 0;
index a79e7a67bac07308ba0f13ca148acbf532af4d65..ea5efbe4354f724e496b9535810a2c31e02308cb 100644 (file)
@@ -15,9 +15,11 @@ typedef struct {
 
 
 
 
 
 
-/*  Cursor movement funcs. */ 
-buf up(int i); 
-buf down(int i); 
+/*  Buffer funcs. */ 
+buf set(buf b, int i);
+void show(buf b);
+buf up(buf b); 
+buf down(buf b); 
 buf left(buf b); 
 buf right(buf b); 
 buf delch(buf b); 
 buf left(buf b); 
 buf right(buf b); 
 buf delch(buf b); 
@@ -32,7 +34,7 @@ void spec(void);
 
 
 /*  Other funcs.  */  
 
 
 /*  Other funcs.  */  
-void readhistory(char *fname); 
+buf readhistory(char *fname); 
 void keyhandler(buf b);  
 
 
 void keyhandler(buf b);  
 
 
diff --git a/range.c b/range.c
index ddb7ce0af54190b7905959f4a30425f142a45a1f..c4c6cfe80eed669335040ec18d1d03986fc97f23 100644 (file)
--- a/range.c
+++ b/range.c
@@ -40,6 +40,13 @@ int g = range(50, 80, 91);
 printf("%d %d %d %d %d %d %d \n", a, b, c, d, e, f, g);   
 
 
 printf("%d %d %d %d %d %d %d \n", a, b, c, d, e, f, g);   
 
 
+int i = 65; 
+char s[2]; 
+
+snprintf(s, 2, "%c", i);  
+
+printf("%s \n" , s ); 
+
 return 0; 
 
 
 return 0;