//------------------------------------------------------------------------------ void save_history() { int max_history; char buffer[512]; get_history_file_name(buffer, sizeof(buffer)); // Get max history size. max_history = get_clink_setting_int("history_file_lines"); max_history = (max_history == 0) ? INT_MAX : max_history; if (max_history < 0) { unlink(buffer); return; } // Write new history to the file, and truncate to our maximum. if (append_history(g_new_history_count, buffer) != 0) { write_history(buffer); } if (max_history != INT_MAX) { history_truncate_file(buffer, max_history); } g_new_history_count = 0; }
//------------------------------------------------------------------------------ static void load_history() { char buffer[1024]; get_history_file_name(buffer, sizeof(buffer)); read_history(buffer); history_set_pos(history_length); }
//------------------------------------------------------------------------------ void save_history() { int max_history; char buffer[1024]; const char* c; if (get_clink_setting_int("persist_history") == 0) { return; } get_history_file_name(buffer, sizeof(buffer)); // Get max history size. c = rl_variable_value("history-size"); max_history = (c != NULL) ? atoi(c) : 1000; // Write new history to the file, and truncate to our maximum. if (append_history(g_new_history_count, buffer) != 0) { write_history(buffer); } history_truncate_file(buffer, max_history); }
//------------------------------------------------------------------------------ static void load_history() { char buffer[1024]; if (get_clink_setting_int("persist_history")) { get_history_file_name(buffer, sizeof(buffer)); read_history(buffer); } using_history(); }
//------------------------------------------------------------------------------ void save_history() { static const int max_history = 200; char buffer[1024]; get_history_file_name(buffer, sizeof(buffer)); // Write new history to the file, and truncate to our maximum. if (append_history(g_new_history_count, buffer) != 0) { write_history(buffer); } history_truncate_file(buffer, max_history); }
int history_mgmt_remove(char *cmd) { int offset=history_search_pos(cmd, 0, 0), occurences=0; while(offset>=0) { occurences++; free_history_entry(remove_history(offset)); offset=history_search_pos(cmd, 0, ++offset); } if(occurences) { write_history(get_history_file_name()); dirty=true; } return occurences; }
//------------------------------------------------------------------------------ void load_history() { char buffer[512]; get_history_file_name(buffer, sizeof(buffer)); // Clear existing history. stifle_history(0); unstifle_history(); g_new_history_count = 0; // Read from disk. read_history(buffer); using_history(); }
HistoryItems *get_prioritized_history() { using_history(); char *historyFile = get_history_file_name(); if(read_history(historyFile)!=0) { fprintf(stderr, "\nUnable to read history file from '%s'!\n",historyFile); exit(EXIT_FAILURE); } HISTORY_STATE *historyState=history_get_history_state(); if(historyState->length > 0) { HashSet rankmap; hashset_init(&rankmap); HashSet blacklist; int i; hashset_init(&blacklist); for(i=0; i<4; i++) { hashset_add(&blacklist, commandBlacklist[i]); } RadixSorter rs; radixsort_init(&rs, 100000); RankedHistoryItem *r; RadixItem *radixItem; HIST_ENTRY **historyList=history_list(); char **rawHistory=malloc(sizeof(char*) * historyState->length); int rawOffset=historyState->length-1; char *line; for(i=0; i<historyState->length; i++, rawOffset--) { line=historyList[i]->line; rawHistory[rawOffset]=line; if(hashset_contains(&blacklist, line)) { continue; } if((r=hashset_get(&rankmap, line))==NULL) { r=malloc(sizeof(RankedHistoryItem)); r->rank=HISTORY_RANKING_FUNCTION(0, i, strlen(line)); r->item=historyList[i]->line; hashset_put(&rankmap, line, r); radixItem=malloc(sizeof(RadixItem)); radixItem->key=r->rank; radixItem->data=r; radixItem->next=NULL; radixsort_add(&rs, radixItem); } else { radixItem=radix_cut(&rs, r->rank, r); assert(radixItem); if(radixItem) { r->rank=HISTORY_RANKING_FUNCTION(r->rank, i, strlen(line)); radixItem->key=r->rank; radixsort_add(&rs, radixItem); } } } DEBUG_RADIXSORT(); RadixItem **prioritizedRadix=radixsort_dump(&rs); prioritizedHistory=malloc(sizeof(HistoryItems)); prioritizedHistory->count=rs.size; prioritizedHistory->items=malloc(rs.size * sizeof(char*)); prioritizedHistory->raw=rawHistory; for(i=0; i<rs.size; i++) { if(prioritizedRadix[i]->data) { prioritizedHistory->items[i]=((RankedHistoryItem *)(prioritizedRadix[i]->data))->item; } free(prioritizedRadix[i]->data); free(prioritizedRadix[i]); } radixsort_destroy(&rs); return prioritizedHistory; } else { return NULL; } }