yaz-client now reads commands from file given by option -f if
authorAdam Dickmeiss <adam@indexdata.dk>
Sun, 3 Jun 2007 14:59:33 +0000 (14:59 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Sun, 3 Jun 2007 14:59:33 +0000 (14:59 +0000)
specified; then tries to read .yazclientrc in current directory.
Failing that, it reads .yazclientrc from user's home directory.

NEWS
client/client.c
doc/yaz-client-man.xml

diff --git a/NEWS b/NEWS
index 10d1c16..689e7ac 100644 (file)
--- 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.
 
 Added support for correlationInfo Note and ID for Record Update via
 ZOOM C.
 
index e1b52ed..2619544 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2007, Index Data ApS
  * See the file LICENSE for details.
  *
  * 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
  */
 /** \file client.c
  *  \brief yaz-client program
@@ -3750,26 +3750,40 @@ int cmd_push_command(const char* arg)
     return 1;
 }
 
     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;
         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
     {
     }
     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
 }
 
 #endif
 }
 
-static void initialize(void)
+static void initialize(const char *rc_file)
 {
     FILE *inf;
     int i;
 {
     FILE *inf;
     int i;
@@ -3821,7 +3835,7 @@ static void initialize(void)
 
     cmd_format("usmarc");
     
 
     cmd_format("usmarc");
     
-    source_rcfile();
+    source_rc_file(rc_file);
 
     file_history = file_history_new();
     file_history_load(file_history);
 
     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))
     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;
     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;
     char *open_command = 0;
     char *auth_command = 0;
     char *arg;
+    const char *rc_file = 0;
     int ret;
     
 #if HAVE_LOCALE_H
     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);
 
     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)
         {
     {
         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 'v':
             yaz_log_init(yaz_log_mask_str(arg), "", 0);
             break;
+        case 'f':
+            rc_file = arg;
+            break;
         case 'V':
             show_version();
             break;
         case 'V':
             show_version();
             break;
@@ -4944,7 +4962,7 @@ int main(int argc, char **argv)
             exit (1);
         }      
     }
             exit (1);
         }      
     }
-    initialize();
+    initialize(rc_file);
     if (auth_command)
     {
 #ifdef HAVE_GETTIMEOFDAY
     if (auth_command)
     {
 #ifdef HAVE_GETTIMEOFDAY
index 2fffa3a..1114339 100644 (file)
@@ -8,7 +8,7 @@
      <!ENTITY % idcommon SYSTEM "common/common.ent">
      %idcommon;
 ]>
      <!ENTITY % idcommon SYSTEM "common/common.ent">
      %idcommon;
 ]>
-<!-- $Id: yaz-client-man.xml,v 1.15 2007-06-03 08:06:32 adam Exp $ -->
+<!-- $Id: yaz-client-man.xml,v 1.16 2007-06-03 14:59:34 adam Exp $ -->
 <refentry id="yaz-client">
  <refentryinfo>
   <productname>YAZ</productname>
 <refentry id="yaz-client">
  <refentryinfo>
   <productname>YAZ</productname>
@@ -32,6 +32,7 @@
    <arg choice="opt"><option>-b <replaceable>filename</replaceable></option></arg>
    <arg choice="opt"><option>-c <replaceable>filename</replaceable></option></arg>
    <arg choice="opt"><option>-d <replaceable>dump</replaceable></option></arg>
    <arg choice="opt"><option>-b <replaceable>filename</replaceable></option></arg>
    <arg choice="opt"><option>-c <replaceable>filename</replaceable></option></arg>
    <arg choice="opt"><option>-d <replaceable>dump</replaceable></option></arg>
+   <arg choice="opt"><option>-f <replaceable>cmdfile</replaceable></option></arg>
    <arg choice="opt"><option>-k <replaceable>size</replaceable></option></arg>
    <arg choice="opt"><option>-m <replaceable>filename</replaceable></option></arg>
    <arg choice="opt"><option>-p <replaceable>addr</replaceable></option></arg>
    <arg choice="opt"><option>-k <replaceable>size</replaceable></option></arg>
    <arg choice="opt"><option>-m <replaceable>filename</replaceable></option></arg>
    <arg choice="opt"><option>-p <replaceable>addr</replaceable></option></arg>
 
  </refsynopsisdiv>
   
 
  </refsynopsisdiv>
   
-  <refsect1><title>DESCRIPTION</title>
-   <para>
-    <command>yaz-client</command> 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.
-   </para>
-   <para>
-    If the <replaceable>addr</replaceable> is specified, the client creates
-    a connection to the Z39.50/SRU target at the address given.
-   </para>
+ <refsect1><title>DESCRIPTION</title>
   <para>
   <para>
-   When <command>yaz-client</command> is invoked it attemps to read
-   <filename>.yazclientrc</filename> from current working directory.
-   If <filename>.yazclientrc</filename> does not exist in current directory
-   YAZ client reads <filename>.yazclientrc</filename> from the
-   home directory, where the home directory is given by environment
-   variable <literal>HOME</literal>. 
-   For those files that are readable, the YAZ client executes commands
-   in those files. See COMMANDS section for description of commands.
+   <command>yaz-client</command> 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.
+  </para>
+  <para>
+   If the <replaceable>addr</replaceable> is specified, the client creates
+   a connection to the Z39.50/SRU target at the address given.
+  </para>
+  <para>
+   When <command>yaz-client</command> is started it tries to read
+   commands from one of the following files:
+   <itemizedlist>
+    <listitem><para>
+      Command file if it is given by option -f. 
+     </para></listitem>
+    <listitem><para>
+      <filename>.yazclientrc</filename> in current working directory.
+     </para></listitem>
+    <listitem><para>
+      <filename>.yazclientrc</filename> in the user's home directory.
+      The value of the <literal>HOME</literal> is used to determine
+      the home directory. Normally, <literal>HOME</literal> is only set
+      on POSIX systems such as Linux, FreeBSD, Solaris.
+     </para></listitem>
+   </itemizedlist>
   </para>
  </refsect1>
   <refsect1>
   </para>
  </refsect1>
   <refsect1>
        where DDD is 001, 002, 003, ..
       </para></listitem>
     </varlistentry>
        where DDD is 001, 002, 003, ..
       </para></listitem>
     </varlistentry>
+
+    <varlistentry>
+     <term>-f <replaceable>cmdfile</replaceable></term>
+     <listitem><para>
+      Reads commands from <replaceable>cmdfile</replaceable>. When
+      this option is used, YAZ client does not read .yazclientrc
+      from current directory or home directory.
+      </para></listitem>
+    </varlistentry>
+
     <varlistentry>
      <term>-k <replaceable>size</replaceable></term>
      <listitem><para>
     <varlistentry>
      <term>-k <replaceable>size</replaceable></term>
      <listitem><para>