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

21
CHANGES
View File

@@ -42,6 +42,27 @@ The following are the changes from calc version 2.12.7.1 to date:
Fixed issues relating to compiling on macOS. Fixed issues
where <unistd.h> is needed.
Fixed typos in help/intro and README.md. <<GitHub guilhermgonzaga>>
Copied missing description lines from help/intro to README.md
"What is calc?" section. <<GitHub guilhermgonzaga>>
GCC 7 added a warning on fall throughs in case statements. It's
enabled by -Wextra and treated as an error due to -Wall so it
breaks compilation. See -Wimplicit-fallthrough in the GCC
manual. The default value is 3, which means a comment matching
some specific regexes is enough to disable the warning.
Fixed spaces vs tabs and use FALLTHRU as it's used elsewhere.
Fixed one FALLTHRU comment that was inconsistent with others.
<<thanks jcul>>
Fixed minor typo on help/power. <<GitHub thegithubr>>
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.
The following are the changes from calc version 2.12.6.10: to 2.12.7.0:

View File

@@ -1054,7 +1054,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.7.4
VERSION= 2.12.7.5
# Names of shared libraries with versions
#
@@ -5475,6 +5475,7 @@ hist.o: have_unistd.h
hist.o: have_unused.h
hist.o: hist.c
hist.o: hist.h
hist.o: lib_calc.h
hist.o: longbits.h
hist.o: nametype.h
hist.o: qmath.h

1
calc.h
View File

@@ -48,6 +48,7 @@
#define HOME "HOME" /* environment variable for home dir */
#define PAGER "PAGER" /* environment variable for help */
#define SHELL "SHELL" /* environment variable for shell */
#define CALCHISTFILE "CALCHISTFILE" /* history file environment variable */
#define DEFAULTCALCBINDINGS "bindings" /* default calc bindings file */
#define DEFAULTCALCHELP "help" /* help file that -h prints */
#define DEFAULTSHELL "sh" /* default shell to use */

View File

@@ -1103,6 +1103,14 @@ Default value: binding
This variable is not used if calc was compiled with GNU-readline support.
In that case, the standard readline mechanisms (see readline(3)) are used.
.sp
.TP 5
CALCHISTFILE
Location of the calc history file.
.sp
Default value: ~/.calc_history
.sp
This variable is not used if calc was compiled with GNU-readline support.
.sp
.SH CREDIT
\&
.br

View File

@@ -348,7 +348,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.7.4
VERSION= 2.12.7.5
# Names of shared libraries with versions
#

View File

@@ -348,7 +348,7 @@ EXT=
# The default calc versions
#
VERSION= 2.12.7.4
VERSION= 2.12.7.5
# Names of shared libraries with versions
#

View File

@@ -7,7 +7,8 @@ Environment variables
/ ./ ../ ~
If this variable does not exist, a compiled value
If this variable does not exist, or if this
variable is an empty string, a compiled value
is used. Typically compiled in value is:
.:./cal:~/cal:${CALC_SHAREDIR}:${CUSTOMCALDIR}
@@ -27,7 +28,8 @@ Environment variables
line), calc searches for files along the :-separated
$CALCRC environment variable.
If this variable does not exist, a compiled value
If this variable does not exist, or if this
variable is an empty string, a compiled value
is used. Typically compiled in value is:
${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit
@@ -66,7 +68,8 @@ Environment variables
This value is taken to be the home directory of the
current user. It is used when files begin with '~/'.
If this variable does not exist, the home directory password
If this variable does not exist, or if this
variable is an empty string, the home directory password
entry of the current user is used. If that information
is not available, '.' is used.
@@ -75,7 +78,8 @@ Environment variables
When invoking help, this environment variable is used
to display a help file.
If this variable does not exist, a compiled value
If this variable does not exist, or if this
variable is an empty string, a compiled value
is used. Typically compiled in value is something
such as 'more', 'less', 'pg' or 'cat'.
@@ -84,11 +88,20 @@ Environment variables
When a !-command is used, the program indicated by
this environment variable is used.
If this variable does not exist, a compiled value
If this variable does not exist, or if this
variable is an empty string, a compiled value
is used. Typically compiled in value is something
such as 'sh' is used.
## Copyright (C) 1999 Landon Curt Noll
CALCHISTFILE
This value is taken to be the calc history file.
If this variable does not exist, or if this
variable is an empty string, then ~/.calc_history
is used.
## Copyright (C) 1999,2021 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

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);

View File

@@ -145,6 +145,7 @@ char *calcbindings = NULL; /* $CALCBINDINGS or default */
char *home = NULL; /* $HOME or default */
char *pager = NULL; /* $PAGER or default */
char *shell = NULL; /* $SHELL or default */
char *calc_history = NULL; /* $CALCHISTFILE or ~/.calc_history */
int stdin_tty = FALSE; /* TRUE if stdin is a tty */
int havecommands = FALSE; /* TRUE if have one or more cmd args */
long stoponerror = 0; /* >0 => stop, <0 => continue, ==0 => use -c */
@@ -546,6 +547,12 @@ initenv(void)
shell = (c ? strdup(c) : NULL);
if (shell == NULL || *shell == '\0')
shell = DEFAULTSHELL;
/* determine the $CALCHISTFILE value */
c = (no_env ? NULL : getenv(CALCHISTFILE));
calc_history = (c ? strdup(c) : NULL);
if (calc_history == NULL || *calc_history == '\0')
calc_history = NULL; /* will use ~/.calc_history */
}

View File

@@ -74,4 +74,9 @@ EXTERN int calc_print_scanwarn_msg;
/* number of parse/scan warnings found */
EXTERN unsigned long calc_warn_cnt;
/*
* calc history file
*/
EXTERN char *calc_history;
#endif /* !INCLUDE_MATH_ERROR_H */

View File

@@ -45,7 +45,7 @@ static char *program;
#define MAJOR_VER 2 /* major library version */
#define MINOR_VER 12 /* minor library version */
#define MAJOR_PATCH 7 /* major software level under library version */
#define MINOR_PATCH 4 /* minor software level or 0 if not patched */
#define MINOR_PATCH 5 /* minor software level or 0 if not patched */
/*