]> pd.if.org Git - pd_readline/commitdiff
BIG improvement - the stack-smash problem has been fixed. The code is now a bit simpl...
authorandy <andy@obsidian.(none)>
Thu, 6 Sep 2012 05:18:20 +0000 (17:18 +1200)
committerandy <andy@obsidian.(none)>
Thu, 6 Sep 2012 05:18:20 +0000 (17:18 +1200)
README
pd_readline.c

diff --git a/README b/README
index 9442b266a85ca5f82697d2f2b49199c046902780..c826c97964fef454dbe6e370178d386391eea2ef 100644 (file)
--- a/README
+++ b/README
@@ -4,13 +4,18 @@
   This repo is for the storage of a public-domain  
 readline-and-command-history implementation. 
 
-Update - 5th Sep 2012 - 
+Update - 6th Sep 2012 - 
 
 Almost there!  
-The code now "pretty much" works as expected. 
-( However, pressing Enter exits the program rather 
+The code now pretty much works as expected. 
+
+It looks like the stack-smash problem has now 
+been fixed. I've give the code a pretty good 
+hammering and it didn't give me problems. 
+
+Pressing Enter still exits the program rather 
 than storing the existing command-line and "staying 
-in the program". I hope to fix this soon. )   
+in the program". I hope to change this soon.     
 
 You can edit a command-line (using backspace). 
 You can move around with left and right-arrow 
@@ -19,10 +24,6 @@ Command-history can be recalled from a file with
 the up-arrow key, and you can scroll up and down 
 through the command-history. 
 
-*** CAUTION! *** - There is, however, an occasional 
-problem with "stack-smashing". 
-
-
 This code is released to the public domain.  
 "Share and enjoy........ ;)  "  
 
index 2a0ed63dfbcefb9733095bf79221a4b391d4d0c4..b4b886efa8ef540bb510ffbed48c4a55ebf1141c 100644 (file)
 /*  See the UNLICENSE file for details.                */ 
 
 /*  TO DO -                                            */ 
-/*  a) Fix the "stack smash" problem.                  */  
-/*  b) Put much of the code into a header file.        */    
-/*  c) Change so that pressing Enter adds the current  */  
+/*  a) Add support for Home and End (of line) keys.    */ 
+/*  b) Add support for function keys.                  */ 
+/*  c) Add support for Insert key so that text can be  */ 
+/*     inserted.                                       */   
+/*  d) Put much of the code into a header file.        */    
+/*  e) Change so that pressing Enter adds the current  */  
 /*     line of commands to the command-history.        */ 
 /*     ( May look at using Ctrl-D to exit, as Python   */ 
 /*     does with its command-line. )                   */           
-/*  d) Add support for copying and pasting text via    */ 
+/*  f) Add support for copying and pasting text via    */ 
 /*     Ctrl-C and Ctrl-V.                              */  
 
 
@@ -95,6 +98,7 @@ char *chop(char *s)
 char hist[20][80];  
 
 
+
 /* Read the file into the array of strings.  */ 
 void readfile(char *fname) 
 { 
@@ -151,11 +155,6 @@ int main(void)
 /* Our "command-history" file.  */ 
 readfile("test.txt"); 
 
-/* Main buffer for the command-line. */ 
-char buffer[80];  
-    
-/* Main buffer "pointer"  */ 
-int bufpnt = 0; 
       
 /* "Pointer" for the history file. */ 
 int histpnt = 20;       
@@ -164,16 +163,13 @@ int histpnt = 20;
   while(1) 
     {  
                    
-      int key = getch();      
-      buffer[bufpnt] = key;                                   
-      bufpnt += 1;        
+      int key = getch();               
        
       /* Printable chars. */  
       if ( (key >= 32)  && (key <= 126) ) 
       { 
                /* We have a printable key so print it. */   
-               putchar(key);   
-               bufpnt += 1;            
+               putchar(key);           
       }  
                                                                        
       /* Up arrow is 27, 91, 65.    ( ESC [ A )   */   
@@ -188,13 +184,10 @@ int histpnt = 20;
       /* Backspace */ 
       else if(key == 127) 
       { 
-                /* Move left 1 char and delete that char */ 
-                bufpnt -= 1;   
+                /* Move left 1 char and delete that char */            
                 printf("\033[1D");
                 printf("\040"); 
-                printf("\033[1D");              
-                /* Move 1 char to left again */  
-                bufpnt -= 1;           
+                printf("\033[1D");                              
          }           
         
      /* We have an escape key-sequence */                           
@@ -210,11 +203,7 @@ int histpnt = 20;
                          histpnt -= 1;                                                         
                          /* Clear to end of line. */ 
                          printf("\033[80D"); 
-                         printf("\033[K"); 
-                         /* Move buffer pointer to start of line */ 
-                         bufpnt = 0;  
-                         /* Clear the array. */ 
-                         memset(buffer, 0, sizeof(char)*80);                                             
+                         printf("\033[K");                      
                          /* Print the pointed-at command-sequence. */ 
                          putline(hist[histpnt]);                        
           }  
@@ -225,24 +214,20 @@ int histpnt = 20;
                          histpnt += 1;                                                                                  
                          /* Clear to end of line. */ 
                          printf("\033[80D"); 
-                         printf("\033[K"); 
-                         /* Move buffer pointer to start of line */ 
-                         bufpnt = 0; 
-                         /* Clear the array. */ 
-                         memset(buffer, 0, sizeof(char)*80);                                                                     
+                         printf("\033[K");                                              
                          /* Print the pointed-at command-sequence. */ 
                          putline(hist[histpnt]);                         
                  }  
                  
                  if(key == 67)  /* Left arrow */ 
           {    
-                        /* Move one character to the left. */                                                                    
+                        /* Move one character to the left. */                           
                          printf("\033[1C"); 
           }
           
           if(key == 68)  /* Right arrow */ 
           {    
-                       /* Move one character to the right. */                                                                                                                                                                   
+                       /* Move one character to the right. */                                    
                          printf("\033[1D"); 
           }