diff options
author | andmarti1424 <andmarti@gmail.com> | 2017-03-17 22:32:40 -0300 |
---|---|---|
committer | andmarti1424 <andmarti@gmail.com> | 2017-03-17 22:32:40 -0300 |
commit | 1c770a1e7806e9ad5b6589d3323f8ead5a091205 (patch) | |
tree | 7b5f324a6ab1746b9e19dbacb56863edd4be4cc7 /src/history.c | |
parent | daf7294bfa39acb29e6504b5d307b105702e62fb (diff) |
Changes to support input mode history
Diffstat (limited to 'src/history.c')
-rw-r--r-- | src/history.c | 19 |
1 files changed, 10 insertions, 9 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 |