Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

now the API to add an history entry has a const argument

  • Loading branch information...
commit 9a986552d553b07ce94348f04ae659a0dd56850f 1 parent 9c21ea2
@antirez authored
Showing with 10 additions and 7 deletions.
  1. +2 −1  README.markdown
  2. +7 −5 linenoise.c
  3. +1 −1  linenoise.h
View
3  README.markdown
@@ -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!
View
12 linenoise.c
@@ -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;
}
View
2  linenoise.h
@@ -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 */
Please sign in to comment.
Something went wrong with that request. Please try again.