Added use of $CALCHISTFILE and start of 2.12.7.5

By default, the calc history file is located in ~/.calc_history.
Now, if the environment variable $CALCHISTFILE is defined
and is non-empty, then calc history file will be defined
by the $CALCHISTFILE environment variable.
This commit is contained in:
Landon Curt Noll
2021-02-03 00:51:56 -08:00
parent a8be58becb
commit 41803b878e
11 changed files with 89 additions and 33 deletions

14
hist.c
View File

@@ -51,6 +51,7 @@
#endif
#include "calc.h"
#include "lib_calc.h"
#include "hist.h"
#include "have_string.h"
@@ -1461,9 +1462,6 @@ quit_calc(void)
*/
/* name of history file */
char *my_calc_history = NULL;
size_t
hist_getline(char *prompt, char *buf, size_t len)
{
@@ -1504,8 +1502,8 @@ my_stifle_history (void)
/* only save last number of entries */
stifle_history(HISTORY_LEN);
if (my_calc_history)
write_history(my_calc_history);
if (calc_history)
write_history(calc_history);
}
@@ -1519,10 +1517,12 @@ hist_init(char UNUSED *filename)
using_history();
/* name of history file */
my_calc_history = tilde_expand("~/.calc_history");
if (calc_history == NULL) {
calc_history = tilde_expand("~/.calc_history");
}
/* read previous history */
read_history(my_calc_history);
read_history(calc_history);
atexit(my_stifle_history);