From: erickson Date: Fri, 4 Mar 2005 22:30:23 +0000 (+0000) Subject: added history file so history is saved across sessions X-Git-Tag: osrf_rel_2_0_1~1694 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=256b011be6fb190a9678fa5fa6fc6ecfc4c1af53;p=OpenSRF.git added history file so history is saved across sessions git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@178 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/srfsh/srfsh.c b/src/srfsh/srfsh.c index 901bd72..063c153 100644 --- a/src/srfsh/srfsh.c +++ b/src/srfsh/srfsh.c @@ -28,6 +28,7 @@ int main( int argc, char* argv[] ) { fatal_handler( "Unable to bootstrap client for requests"); } /* --------------------------------------------- */ + load_history(); client = osrf_system_get_transport_client(); @@ -51,6 +52,8 @@ int main( int argc, char* argv[] ) { free(req_copy); } + if(history_file != NULL ) + write_history(history_file); free(request); client_disconnect( client ); client_free( client ); @@ -64,6 +67,26 @@ void sig_child_handler( int s ) { child_dead = 1; } + +int load_history() { + + char* home = getenv("HOME"); + int l = strlen(home) + 24; + char fbuf[l]; + + memset(fbuf, 0, l); + sprintf(fbuf,"%s/.srfsh_history",home); + history_file = strdup(fbuf); + + if(!access(history_file, F_OK)) { + //set_history_length(999); + history_length = 999; + read_history(history_file); + } + return 1; +} + + int parse_error( char* words[] ) { if( ! words ) diff --git a/src/srfsh/srfsh.h b/src/srfsh/srfsh.h index 782fc40..bd52cfd 100644 --- a/src/srfsh/srfsh.h +++ b/src/srfsh/srfsh.h @@ -18,6 +18,8 @@ /* shell prompt */ char* prompt = "srfsh# "; +char* history_file = NULL; + int child_dead = 0; /* true if we're pretty printing json results */ @@ -47,6 +49,7 @@ char* json_printer( json* object ); char* tabs(int count); void sig_child_handler( int s ); +int load_history();