"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "hist.c" between
calc-2.12.7.2.tar.bz2 and calc-2.12.7.6.tar.bz2

About: Calc is a C-style arbitrary precision calculator.

hist.c  (calc-2.12.7.2.tar.bz2):hist.c  (calc-2.12.7.6.tar.bz2)
skipping to change at line 53 skipping to change at line 53
#if defined(HAVE_UNISTD_H) #if defined(HAVE_UNISTD_H)
#include <unistd.h> #include <unistd.h>
#endif #endif
#include "have_stdlib.h" #include "have_stdlib.h"
#if defined(HAVE_STDLIB_H) #if defined(HAVE_STDLIB_H)
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#include "calc.h" #include "calc.h"
#include "lib_calc.h"
#include "hist.h" #include "hist.h"
#include "have_string.h" #include "have_string.h"
#include "have_strdup.h" #include "have_strdup.h"
#if !defined(HAVE_STRDUP) #if !defined(HAVE_STRDUP)
# define strdup(x) calc_strdup((CONST char *)(x)) # define strdup(x) calc_strdup((CONST char *)(x))
#endif /* HAVE_STRDUP */ #endif /* HAVE_STRDUP */
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
# include <string.h> # include <string.h>
skipping to change at line 1390 skipping to change at line 1391
/* /*
* The readline/history libs do most of the dirty work for us, so we can * The readline/history libs do most of the dirty work for us, so we can
* replace hist_init() and hist_term() with dummies when using readline. * replace hist_init() and hist_term() with dummies when using readline.
* For hist_getline() we have to add a newline that readline removed but * For hist_getline() we have to add a newline that readline removed but
* calc expects. For hist_saveline(), we have to undo this. hist_getline() * calc expects. For hist_saveline(), we have to undo this. hist_getline()
* also has to cope with the different memory management schemes of calc and * also has to cope with the different memory management schemes of calc and
* readline. * readline.
*/ */
/* name of history file */
char *my_calc_history = NULL;
size_t size_t
hist_getline(char *prompt, char *buf, size_t len) hist_getline(char *prompt, char *buf, size_t len)
{ {
char *line; char *line;
buf[0] = '\0'; buf[0] = '\0';
line = readline(prompt); line = readline(prompt);
if (!line) { if (!line) {
switch (conf->ctrl_d) { switch (conf->ctrl_d) {
case CTRL_D_NEVER_EOF: case CTRL_D_NEVER_EOF:
skipping to change at line 1431 skipping to change at line 1429
hist_term(void) hist_term(void)
{ {
} }
S_FUNC void S_FUNC void
my_stifle_history (void) my_stifle_history (void)
{ {
/* only save last number of entries */ /* only save last number of entries */
stifle_history(HISTORY_LEN); stifle_history(HISTORY_LEN);
if (my_calc_history) if (calc_history)
write_history(my_calc_history); write_history(calc_history);
} }
int int
hist_init(char UNUSED *filename) hist_init(char UNUSED *filename)
{ {
/* used when parsing conditionals in ~/.inputrc */ /* used when parsing conditionals in ~/.inputrc */
rl_readline_name = "calc"; rl_readline_name = "calc";
/* initialize interactive variables */ /* initialize interactive variables */
using_history(); using_history();
/* name of history file */ /* 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 previous history */
read_history(my_calc_history); read_history(calc_history);
atexit(my_stifle_history); atexit(my_stifle_history);
return HIST_SUCCESS; return HIST_SUCCESS;
} }
void void
hist_saveline(char *line, int len) hist_saveline(char *line, int len)
{ {
STATIC char *prev = NULL; STATIC char *prev = NULL;
 End of changes. 5 change blocks. 
7 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)