diff options
-rw-r--r-- | src/history.c | 19 | ||||
-rw-r--r-- | src/history.h | 4 |
2 files changed, 12 insertions, 11 deletions
diff --git a/src/history.c b/src/history.c index 552d2f4..24a73d6 100644 --- a/src/history.c +++ b/src/history.c @@ -59,7 +59,7 @@ void destroy_history(struct history * h) { return; } -void load_history(struct history * h) { +void load_history(struct history * h, wchar_t mode) { char infofile[PATHLEN]; wchar_t linea[FBUFLEN]; int c; @@ -78,9 +78,11 @@ void load_history(struct history * h) { int s = wcslen(linea)-1; del_range_wchars(linea, s, s); - if (linea[0] == L':') { + if (linea[0] == mode && mode == L':') { del_range_wchars(linea, 0, 0); add(h, linea); + } else if (mode != L':' && (linea[0] == L'=' || linea[0] == L'<' || linea[0] == L'>' || linea[0] == L'\\')) { + add(h, linea); } } fclose(f); @@ -92,8 +94,7 @@ void load_history(struct history * h) { // Save history to file // returns 0 on success, -1 otherwise -int save_history(struct history * h) { - if (h->mode != ':' ) return -1; +int save_history(struct history * h, char * mode) { char infofile [PATHLEN]; char * home; FILE * f; @@ -103,8 +104,8 @@ int save_history(struct history * h) { if ((home = getenv("HOME"))) { sprintf(infofile, "%s/", home); strcat(infofile, HISTORY_FILE); - f = fopen(infofile, "w"); - if (f == NULL) return -1; + f = fopen(infofile, mode); + if (f == NULL) return 0; // Go to the end for (i=1; i < h->len; i++) { @@ -112,14 +113,14 @@ int save_history(struct history * h) { } // Traverse list back to front, so the history is saved in chronological order for (i=0; i < h->len; i++) { - fwprintf(f, L":"); + if (! strcmp(mode, "w")) fwprintf(f, L":"); // mode 'w' means we are saving the command mode history fwprintf(f, L"%ls\n", nl->line); nl = nl->pant; } fclose(f); - return 0; + return 1; } - return -1; + return 0; } // Remove history element diff --git a/src/history.h b/src/history.h index 3d75016..ed31132 100644 --- a/src/history.h +++ b/src/history.h @@ -13,8 +13,8 @@ struct hlist { struct history * create_history(char mode); void destroy_history(struct history * h); -void load_history(); -int save_history(struct history * h); +void load_history(struct history * h, wchar_t mode); +int save_history(struct history * h, char * mode); void del_item_from_history(struct history * h, int pos); int move_item_from_history_by_str(struct history * h, wchar_t * item, int pos); void add(struct history * h, wchar_t * line); |