X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Fclient.c;h=1055bff2438856d561957d7bc696f79db8cd4849;hb=07dca8aeae6bc30c59e71b30a9ad83da57c0440d;hp=3ea046e12cea2b6b91c66fe9465df66b4c1d3a4d;hpb=2ede0bb278b22c8ce1cdd48e9a11a5924d433763;p=yaz-moved-to-github.git diff --git a/client/client.c b/client/client.c index 3ea046e..1055bff 100644 --- a/client/client.c +++ b/client/client.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 1995-2006, Index Data ApS + * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: client.c,v 1.320 2006-12-06 21:35:57 adam Exp $ + * $Id: client.c,v 1.325 2007-01-24 11:50:18 adam Exp $ */ /** \file client.c * \brief yaz-client program @@ -78,9 +78,12 @@ #include "admin.h" #include "tabcomplete.h" +#include "fhistory.h" #define C_PROMPT "Z> " +static file_history_t file_history = 0; + static char *sru_method = "soap"; static char *codeset = 0; /* character set for output */ static int hex_dump = 0; @@ -1633,7 +1636,25 @@ static int process_searchResponse(Z_SearchResponse *res) last_hit_count = *res->resultCount; if (setnumber >= 0) printf (", setno %d", setnumber); - printf ("\n"); + putchar('\n'); + if (res->resultSetStatus) + { + printf("Result Set Status: "); + switch(*res->resultSetStatus) + { + case Z_SearchResponse_subset: + printf("subset"); break; + case Z_SearchResponse_interim: + printf("interim"); break; + case Z_SearchResponse_none: + printf("none"); break; + case Z_SearchResponse_estimate: + printf("estimate"); break; + default: + printf("%d", *res->resultSetStatus); + } + putchar('\n'); + } display_searchResult (res->additionalSearchInfo); printf("records returned: %d\n", *res->numberOfRecordsReturned); @@ -2167,12 +2188,14 @@ static int cmd_update_common(const char *arg, int version) if (parse_cmd_doc(&arg, out, &rec_buf, &rec_len, 1) == 0) return 0; +#if YAZ_HAVE_XML2 if (protocol == PROTO_HTTP) return cmd_update_SRW(action_no, recid, rec_buf, rec_len); - else - return cmd_update_Z3950(version, action_no, recid, rec_buf, rec_len); +#endif + return cmd_update_Z3950(version, action_no, recid, rec_buf, rec_len); } +#if YAZ_HAVE_XML2 static int cmd_update_SRW(int action_no, const char *recid, char *rec_buf, int rec_len) { @@ -2209,6 +2232,7 @@ static int cmd_update_SRW(int action_no, const char *recid, return send_srw(srw); } } +#endif static int cmd_update_Z3950(int version, int action_no, const char *recid, char *rec_buf, int rec_len) @@ -2803,11 +2827,18 @@ static int cmd_show(const char *arg) return 2; } +void exit_client(int code) +{ + file_history_save(file_history); + file_history_destroy(&file_history); + exit(code); +} + int cmd_quit(const char *arg) { printf("See you later, alligator.\n"); xmalloc_trav (""); - exit(0); + exit_client(0); return 0; } @@ -3691,24 +3722,24 @@ void source_rcfile(void) { /* Look for a $HOME/.yazclientrc and source it if it exists */ struct stat statbuf; - char buffer[1000]; - char* homedir=getenv("HOME"); + char fname[1000]; + char* homedir = getenv("HOME"); - if( homedir ) { - - sprintf(buffer,"%s/.yazclientrc",homedir); + sprintf(fname, "%.500s%s%s", homedir ? homedir : "", + homedir ? "/" : "", + ".yazclientrc"); - if(stat(buffer,&statbuf)==0) { - cmd_source(buffer, 0 ); - } - - }; - - if(stat(".yazclientrc",&statbuf)==0) { - cmd_source(".yazclientrc", 0 ); - } + if (stat(fname,&statbuf)==0) + cmd_source(fname, 0 ); } +void add_to_readline_history(void *client_data, const char *line) +{ +#if HAVE_READLINE_HISTORY_H + if (strlen(line)) + add_history(line); +#endif +} static void initialize(void) { @@ -3747,6 +3778,10 @@ static void initialize(void) } source_rcfile(); + + file_history = file_history_new(); + file_history_load(file_history); + file_history_trav(file_history, 0, add_to_readline_history); } @@ -4377,6 +4412,7 @@ static struct { {"displaycharset", cmd_displaycharset, "",NULL,0,NULL}, {"marccharset", cmd_marccharset, "",NULL,0,NULL}, {"lang", cmd_lang, "",NULL,0,NULL}, + {"source", cmd_source_echo, "",NULL,1,NULL}, {".", cmd_source_echo, "",NULL,1,NULL}, {"!", cmd_subshell, "Subshell command",NULL,1,NULL}, {"set_apdufile", cmd_set_apdufile, "",NULL,1,NULL}, @@ -4687,7 +4723,7 @@ static void client(void) if (*line_in) add_history(line_in); #endif - strncpy(line, line_in, 10239); + strncpy(line, line_in, sizeof(line)-1); free(line_in); } #endif @@ -4696,11 +4732,13 @@ static void client(void) char *end_p; printf (C_PROMPT); fflush(stdout); - if (!fgets(line, 10239, stdin)) + if (!fgets(line, sizeof(line)-1, stdin)) break; if ((end_p = strchr (line, '\n'))) *end_p = '\0'; } + if (isatty(0)) + file_history_add_line(file_history, line); process_cmd_line(line); } } @@ -4859,8 +4897,9 @@ int main(int argc, char **argv) #endif xfree(open_command); } - client (); - exit (0); + client(); + exit_client(0); + return 0; } /* * Local variables: