added history file so history is saved across sessions
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 4 Mar 2005 22:30:23 +0000 (22:30 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 4 Mar 2005 22:30:23 +0000 (22:30 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@178 9efc2488-bf62-4759-914b-345cdb29e865

src/srfsh/srfsh.c
src/srfsh/srfsh.h

index 901bd72..063c153 100644 (file)
@@ -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 )
index 782fc40..bd52cfd 100644 (file)
@@ -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();