From: erickson Date: Thu, 24 Feb 2005 16:43:20 +0000 (+0000) Subject: added 'last' command to redo the last command X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6761cd7b7545798722bb2b54da8ee24aedf955ae;p=working%2FOpenSRF.git added 'last' command to redo the last command git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@104 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/srfsh/srfsh.c b/src/srfsh/srfsh.c index 40d3bd8..8116742 100644 --- a/src/srfsh/srfsh.c +++ b/src/srfsh/srfsh.c @@ -7,6 +7,7 @@ char* prompt = "srfsh# "; +char* last_request; transport_client* client = NULL; int parse_request( char* request ); @@ -27,8 +28,8 @@ int main( int argc, char* argv[] ) { memset(request, 0, 256); printf(prompt); - client = client_init( argv[1], SRFSH_PORT ); - if( ! client_connect( client, argv[2], argv[3], "srfsh", 5 ) ) { + client = client_init( argv[1], SRFSH_PORT, 0 ); + if( ! client_connect( client, argv[2], argv[3], "srfsh", 5, AUTH_DIGEST ) ) { fprintf(stderr, "Unable to connect to jabber server '%s' as '%s'\n", argv[1], argv[2]); fprintf(stderr, "Most queries will be futile...\n" ); } @@ -45,6 +46,14 @@ int main( int argc, char* argv[] ) { break; } + if(!strcmp(request,"last")) { + memset(request,0,256); + strcpy(request, last_request); + printf("%s\n", request); + } else { + free(last_request); + last_request = strdup(request); + } if( !strcmp(request, "help") || !strcmp(request,"?")) print_help(); @@ -91,8 +100,10 @@ int parse_request( char* request ) { int i = 0; char* words[COMMAND_BUFSIZE]; memset(words,0,COMMAND_BUFSIZE); + //char* req = strdup(request); + char* req = request; - char* cur_tok = strtok( request, " " ); + char* cur_tok = strtok( req, " " ); if( cur_tok == NULL ) return 0; @@ -102,6 +113,8 @@ int parse_request( char* request ) { cur_tok = strtok( NULL, " " ); } + //free(req); + // not sure why (strtok?), but this is necessary memset( words + i, 0, COMMAND_BUFSIZE - i ); @@ -209,9 +222,11 @@ void print_help() { "---------------------------------------------------------------------------------\n" "Commands:\n" "---------------------------------------------------------------------------------\n" + "last - Re-performs the last command\n" + "time - Prints the current time\n" + "time - Formats seconds since epoch into readable format\n" + "---------------------------------------------------------------------------------\n" "router query servers \n" - "time\n" - "time \n" "---------------------------------------------------------------------------------\n" );