* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: client.c,v 1.324 2007-01-24 09:54:04 adam Exp $
+ * $Id: client.c,v 1.325 2007-01-24 11:50:18 adam Exp $
*/
/** \file client.c
* \brief yaz-client program
#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;
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;
}
{
/* 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)
{
}
source_rcfile();
+
+ file_history = file_history_new();
+ file_history_load(file_history);
+ file_history_trav(file_history, 0, add_to_readline_history);
}
if (*line_in)
add_history(line_in);
#endif
- strncpy(line, line_in, 10239);
+ strncpy(line, line_in, sizeof(line)-1);
free(line_in);
}
#endif
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);
}
}
#endif
xfree(open_command);
}
- client ();
- exit (0);
+ client();
+ exit_client(0);
+ return 0;
}
/*
* Local variables: