* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: client.c,v 1.342 2007-05-30 21:56:59 adam Exp $
+ * $Id: client.c,v 1.344 2007-06-03 14:59:34 adam Exp $
*/
/** \file client.c
* \brief yaz-client program
return 1;
}
-void source_rcfile(void)
+void source_rc_file(const char *rc_file)
{
- /* Look for a $HOME/.yazclientrc and source 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];
- char* homedir = getenv("HOME");
- sprintf(fname, "%.500s%s%s", homedir ? homedir : "",
- homedir ? "/" : "",
- ".yazclientrc");
-
- if (stat(fname,&statbuf)==0)
- cmd_source(fname, 0 );
+ if (rc_file)
+ {
+ 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
+ {
+ char fname[1000];
+ strcpy(fname, ".yazclientrc");
+ if (stat(fname, &statbuf)==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);
+ }
+ }
+ }
}
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;
cmd_format("usmarc");
- source_rcfile();
+ source_rc_file(rc_file);
file_history = file_history_new();
file_history_load(file_history);
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;
char *open_command = 0;
char *auth_command = 0;
char *arg;
+ const char *rc_file = 0;
int ret;
#if HAVE_LOCALE_H
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)
{
case 'v':
yaz_log_init(yaz_log_mask_str(arg), "", 0);
break;
+ case 'f':
+ rc_file = arg;
+ break;
case 'V':
show_version();
break;
exit (1);
}
}
- initialize();
+ initialize(rc_file);
if (auth_command)
{
#ifdef HAVE_GETTIMEOFDAY