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)
* 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!
char **history = NULL;
static void linenoiseAtExit(void);
-int linenoiseHistoryAdd(char *line);
+int linenoiseHistoryAdd(const char *line);
static void freeHistory(void) {
if (history) {
}
/* 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;
}
#define __LINENOISE_H
char *linenoise(const char *prompt);
-int linenoiseHistoryAdd(char *line);
+int linenoiseHistoryAdd(const char *line);
int linenoiseHistorySetMaxLen(int len);
#endif /* __LINENOISE_H */