src/cforth/linenoise.c
int linenoiseHistoryAdd(const char *line) {
    char *linecopy;

    if (history_max_len == 0) return 0;
    if (history == NULL) {
        history = malloc(sizeof(char*)*history_max_len);
        if (history == NULL) return 0;
        memset(history,0,(sizeof(char*)*history_max_len));
	atexit(freeHistory);
    }
    linecopy = strdup(line);
    if (!linecopy) return 0;
    if (history_len == history_max_len) {
        free(history[0]);
        memmove(history,history+1,sizeof(char*)*(history_max_len-1));
        history_len--;
    }
    history[history_len] = linecopy;
    history_len++;
    return 1;
}
/* Using a circular buffer is smarter, but a bit more complex to handle. */
Using a circular buffer is smarter, but a bit more complex to handle.
Using a circular buffer is smarter but a bit more complex to handle .
int linenoiseHistoryAdd(const char *line) {
    char *linecopy;
    if (history_max_len == 0) return 0;
    if (history == NULL) {
        history = malloc(sizeof(char*)*history_max_len);
        if (history == NULL) return 0;
        memset(history,0,(sizeof(char*)*history_max_len));
	atexit(freeHistory);
    }
    linecopy = strdup(line);
    if (!linecopy) return 0;
    if (history_len == history_max_len) {
        free(history[0]);
        memmove(history,history+1,sizeof(char*)*(history_max_len-1));
        history_len--;
    }
    history[history_len] = linecopy;
    history_len++;
    return 1;
}
int linenoiseHistoryAdd ( const char * line ) { char * linecopy ; if ( history_max_len == 0 ) return 0 ; if ( history == NULL ) { history = malloc ( sizeof ( char * ) * history_max_len ) ; if ( history == NULL ) return 0 ; memset ( history , 0 , ( sizeof ( char * ) * history_max_len ) ) ; atexit ( freeHistory ) ; } linecopy = strdup ( line ) ; if ( ! linecopy ) return 0 ; if ( history_len == history_max_len ) { free ( history [ 0 ] ) ; memmove ( history , history + 1 , sizeof ( char * ) * ( history_max_len - 1 ) ) ; history_len -- ; } history [ history_len ] = linecopy ; history_len ++ ; return 1 ; }
Using a circular buffer is smarter, but a bit more complex to handle.
Using a circular buffer is smarter but a bit more complex to handle .