]> git.lizzy.rs Git - linenoise.git/commitdiff
now the API to add an history entry has a const argument
authorantirez <antirez@gmail.com>
Tue, 23 Mar 2010 12:49:32 +0000 (13:49 +0100)
committerantirez <antirez@gmail.com>
Tue, 23 Mar 2010 12:49:32 +0000 (13:49 +0100)
README.markdown
linenoise.c
linenoise.h

index 5edb2b29774141d09253f9ca8ef3e1a945b9077a..41e35c7d800c41bbeeb6943090d7559de20ee809 100644 (file)
@@ -23,7 +23,7 @@ Since it's so young I guess there are a few bugs, or the lib may not compile or
 
 The library is currently less than 400 lines of code. In order to use it in your project just look at the *example.c* file in the source distribution, it is trivial. Linenoise is BSD code, so you can use both in free software and commercial software.
 
-## Tested in...
+## Tested with...
 
  * Linux text only console ($TERM = linux)
  * Linux KDE terminal application ($TERM = xterm)
@@ -31,6 +31,7 @@ The library is currently less than 400 lines of code. In order to use it in your
  * Mac OS X iTerm ($TERM = xterm)
  * Mac OS X default Terminal.app ($TERM = xterm)
  * OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
+ * IBM AIX 6.1
 
 Please test it everywhere you can and report back!
 
index 5950d493b4af80bc1ccc695cc04133b851bac46b..81396305442ed6d85f326249a90d22793027e207 100644 (file)
@@ -90,7 +90,7 @@ static int history_len = 0;
 char **history = NULL;
 
 static void linenoiseAtExit(void);
-int linenoiseHistoryAdd(char *line);
+int linenoiseHistoryAdd(const char *line);
 
 static void freeHistory(void) {
     if (history) {
@@ -357,20 +357,22 @@ char *linenoise(const char *prompt) {
 }
 
 /* Using a circular buffer is smarter, but a bit more complex to handle. */
-int linenoiseHistoryAdd(char *line) {
+int linenoiseHistoryAdd(const char *line) {
+    char *linecopy;
+
     if (history_max_len == 0) return 0;
     if (history == 0) {
         history = malloc(sizeof(char*)*history_max_len);
         if (history == NULL) return 0;
         memset(history,0,(sizeof(char*)*history_max_len));
     }
-    line = strdup(line);
-    if (!line) return 0;
+    linecopy = strdup(line);
+    if (!linecopy) return 0;
     if (history_len == history_max_len) {
         memmove(history,history+1,sizeof(char*)*(history_max_len-1));
         history_len--;
     }
-    history[history_len] = line;
+    history[history_len] = linecopy;
     history_len++;
     return 1;
 }
index ff45e2c47bb36df1f70a026a53a49a938509a3c2..57bf9d18c1fbc2dc5919a93491603724ae4c6fb3 100644 (file)
@@ -35,7 +35,7 @@
 #define __LINENOISE_H
 
 char *linenoise(const char *prompt);
-int linenoiseHistoryAdd(char *line);
+int linenoiseHistoryAdd(const char *line);
 int linenoiseHistorySetMaxLen(int len);
 
 #endif /* __LINENOISE_H */