From: Adam Dickmeiss Date: Sun, 3 Jun 2007 14:59:33 +0000 (+0000) Subject: yaz-client now reads commands from file given by option -f if X-Git-Tag: YAZ.3.0.10~61 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=8cd0ea1bdddd37a48526a3e52045cada428379c5 yaz-client now reads commands from file given by option -f if specified; then tries to read .yazclientrc in current directory. Failing that, it reads .yazclientrc from user's home directory. --- diff --git a/NEWS b/NEWS index 10d1c16..689e7ac 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +Fixed bug #1157: yaz-client does not read .yazclientrc from current +directory. yaz-client now reads commands from file given by option -f +if specified; then tries to read .yazclientrc in current directory. +Failing that, it reads .yazclientrc from user's home directory. + Added support for correlationInfo Note and ID for Record Update via ZOOM C. diff --git a/client/client.c b/client/client.c index e1b52ed..2619544 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: client.c,v 1.343 2007-06-03 08:06:31 adam Exp $ + * $Id: client.c,v 1.344 2007-06-03 14:59:34 adam Exp $ */ /** \file client.c * \brief yaz-client program @@ -3750,26 +3750,40 @@ int cmd_push_command(const char* arg) return 1; } -void source_rcfile(void) +void source_rc_file(const char *rc_file) { - /* Look for .yazclientrc and read it if it exists. + /* If rc_file != NULL, source that. Else + Look for .yazclientrc and read it if it exists. If it does not exist, read $HOME/.yazclientrc instead */ struct stat statbuf; - char fname[1000]; - strcpy(fname, ".yazclientrc"); - if (stat(fname, &statbuf)==0) + if (rc_file) { - cmd_source(fname, 0); + if (stat(rc_file, &statbuf) == 0) + cmd_source(rc_file, 0); + else + { + fprintf(stderr, "yaz_client: cannot source '%s'\n", rc_file); + exit(1); + } } else { - const char* homedir = getenv("HOME"); - if (homedir) + char fname[1000]; + strcpy(fname, ".yazclientrc"); + if (stat(fname, &statbuf)==0) { - sprintf(fname, "%.800s/%s", homedir, ".yazclientrc"); - if (stat(fname, &statbuf)==0) - cmd_source(fname, 0); + cmd_source(fname, 0); + } + else + { + const char* homedir = getenv("HOME"); + if (homedir) + { + sprintf(fname, "%.800s/%s", homedir, ".yazclientrc"); + if (stat(fname, &statbuf)==0) + cmd_source(fname, 0); + } } } } @@ -3782,7 +3796,7 @@ void add_to_readline_history(void *client_data, const char *line) #endif } -static void initialize(void) +static void initialize(const char *rc_file) { FILE *inf; int i; @@ -3821,7 +3835,7 @@ static void initialize(void) cmd_format("usmarc"); - source_rcfile(); + source_rc_file(rc_file); file_history = file_history_new(); file_history_load(file_history); @@ -3932,7 +3946,7 @@ static void http_response(Z_HTTP_Response *hres) const char *connection_head = z_HTTP_header_lookup(hres->headers, "Connection"); if (!yaz_srw_check_content_type(hres)) - printf("Content type does not appear to be XML"); + printf("Content type does not appear to be XML\n"); else { Z_SOAP *soap_package = 0; @@ -4829,6 +4843,7 @@ int main(int argc, char **argv) char *open_command = 0; char *auth_command = 0; char *arg; + const char *rc_file = 0; int ret; #if HAVE_LOCALE_H @@ -4853,7 +4868,7 @@ int main(int argc, char **argv) ODR_MASK_SET(&z3950_options, Z_Options_delSet); ODR_MASK_SET(&z3950_options, Z_Options_negotiationModel); - while ((ret = options("k:c:q:a:b:m:v:p:u:t:Vxd:", argv, argc, &arg)) != -2) + while ((ret = options("k:c:q:a:b:m:v:p:u:t:Vxd:f:", argv, argc, &arg)) != -2) { switch (ret) { @@ -4924,6 +4939,9 @@ int main(int argc, char **argv) case 'v': yaz_log_init(yaz_log_mask_str(arg), "", 0); break; + case 'f': + rc_file = arg; + break; case 'V': show_version(); break; @@ -4944,7 +4962,7 @@ int main(int argc, char **argv) exit (1); } } - initialize(); + initialize(rc_file); if (auth_command) { #ifdef HAVE_GETTIMEOFDAY diff --git a/doc/yaz-client-man.xml b/doc/yaz-client-man.xml index 2fffa3a..1114339 100644 --- a/doc/yaz-client-man.xml +++ b/doc/yaz-client-man.xml @@ -8,7 +8,7 @@ %idcommon; ]> - + YAZ @@ -32,6 +32,7 @@ + @@ -43,25 +44,33 @@ - DESCRIPTION - - yaz-client is a Z39.50/SRU client (origin) with a - simple command line interface that allows you to test behavior and - performance of Z39.50 targets and SRU servers. - - - If the addr is specified, the client creates - a connection to the Z39.50/SRU target at the address given. - + DESCRIPTION - When yaz-client is invoked it attemps to read - .yazclientrc from current working directory. - If .yazclientrc does not exist in current directory - YAZ client reads .yazclientrc from the - home directory, where the home directory is given by environment - variable HOME. - For those files that are readable, the YAZ client executes commands - in those files. See COMMANDS section for description of commands. + yaz-client is a Z39.50/SRU client (origin) with a + simple command line interface that allows you to test behavior and + performance of Z39.50 targets and SRU servers. + + + If the addr is specified, the client creates + a connection to the Z39.50/SRU target at the address given. + + + When yaz-client is started it tries to read + commands from one of the following files: + + + Command file if it is given by option -f. + + + .yazclientrc in current working directory. + + + .yazclientrc in the user's home directory. + The value of the HOME is used to determine + the home directory. Normally, HOME is only set + on POSIX systems such as Linux, FreeBSD, Solaris. + + @@ -101,6 +110,16 @@ where DDD is 001, 002, 003, .. + + + -f cmdfile + + Reads commands from cmdfile. When + this option is used, YAZ client does not read .yazclientrc + from current directory or home directory. + + + -k size