* Copyright (c) 1995-2002, Index Data
* See the file LICENSE for details.
*
- * $Id: client.c,v 1.139 2002-01-30 14:51:45 adam Exp $
+ * $Id: client.c,v 1.145 2002-02-24 12:24:40 adam Exp $
*/
#include <stdio.h>
size_t i;
for (i = 0; i<len; i++)
if ((buf[i] <= 126 && buf[i] >= 32) || strchr ("\n\r\t\f", buf[i]))
- fputc (buf[i], stdout);
+ printf ("%c", buf[i]);
else
printf ("\\X%02X", buf[i]);
}
printf (" namedResultSets");
setnumber = 0;
}
+ if (ODR_MASK_GET(res->options, Z_Options_encapsulation))
+ printf (" encapsulation");
+ if (ODR_MASK_GET(res->options, Z_Options_resultCount))
+ printf (" resultCount");
+ if (ODR_MASK_GET(res->options, Z_Options_negotiationModel))
+ printf (" negotiationModel");
+ if (ODR_MASK_GET(res->options, Z_Options_duplicateDetection))
+ printf (" duplicateDetection");
+ if (ODR_MASK_GET(res->options, Z_Options_queryType104))
+ printf (" queryType104");
printf ("\n");
fflush (stdout);
return 0;
print_stringn (buf, len);
/* add newline if not already added ... */
if (i <= 0 || buf[i-1] != '\n')
- fputc ('\n', stdout);
+ printf ("\n");
}
static void display_record(Z_External *r)
{
if (
#if AVOID_MARC_DECODE
- /* primitive check for a marc OID 5.1-29 */
- ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30
+ /* primitive check for a marc OID 5.1-29 except 16 */
+ ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 &&
+ ent->oidsuffix[1] != 16
#else
- 1
+ 1
#endif
- )
- {
+ )
+ {
if (marc_display_exl (octet_buf, NULL, 0 /* debug */,
r->u.octet_aligned->len) <= 0)
{
if(apdu_file && apdu_file != stderr) { /* don't close stdout*/
perror("unable to close apdu log file");
- };
+ }
apdu_file=NULL;
if(strlen(arg)<1) {
{
if(marcdump && marcdump != stderr) { /* don't close stdout*/
perror("unable to close apdu log file");
- };
+ }
marcdump=NULL;
if(strlen(arg)<1) {
struct timeval tv_start, tv_end;
#endif
-void wait_and_handle_responce()
+void wait_and_handle_responce()
{
int res;
Z_APDU *apdu;
- if (conn
-#ifdef USE_SELECT
- && FD_ISSET(cs_fileno(conn), &input)
-#endif
- )
+ if (conn)
{
do
{
((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
#endif
}
+ xfree (netbuffer);
}
for(;*p; ++p) {
if(!isspace(*p)) {
lastnonspace = p;
- };
- };
+ }
+ }
if(lastnonspace)
*(++lastnonspace) = 0;
- };
+ }
for (i = 0; cmd[i].cmd; i++)
if (res >= 2)
wait_and_handle_responce();
- if(apdu_file) fflush(apdu_file);
- if(marcdump) fflush(marcdump);
+ if(apdu_file)
+ fflush(apdu_file);
+ if(marcdump)
+ fflush(marcdump);
}
char *command_generator(const char *text, int state)
{
- static idx; // index is the last used the last time command_generator was called
- char *command;
+ static int idx;
if (state==0) {
idx = 0;
}
if (!strncmp(cmd[idx].cmd,text,strlen(text))) {
++idx; /* skip this entry on the next run */
return strdup(cmd[idx-1].cmd);
- };
+ }
}
return NULL;
}
if ((res = sscanf(rl_line_buffer, "%31s %1023[^;]", word, arg)) <= 0) {
rl_attempted_completion_over = 1;
return NULL;
- };
+ }
if(start != strlen(word) +1 ) {
rl_attempted_completion_over = 1;
} else {
rl_attempted_completion_over = 1;
return 0;
- };
- };
+ }
+ }
#else
return 0;
#endif
-};
+}
static void client(void)
{
+ char line[1024];
+
+ line[1023] = '\0';
#if HAVE_GETTIMEOFDAY
gettimeofday (&tv_start, 0);
while (1)
{
-#ifdef USE_SELECT
- fd_set input;
-#endif
- char line[1024];
-
- {
+ char *line_in = NULL;
#if HAVE_READLINE_READLINE_H
- char* line_in=NULL;
+ if (isatty(0))
+ {
line_in=readline(C_PROMPT);
if (!line_in)
break;
if (*line_in)
add_history(line_in);
#endif
- strcpy(line,line_in);
+ strncpy(line, line_in, 1023);
free (line_in);
-#else
+ }
+#endif
+ if (!line_in)
+ {
char *end_p;
printf (C_PROMPT);
fflush(stdout);
break;
if ((end_p = strchr (line, '\n')))
*end_p = '\0';
-#endif
+ }
process_cmd_line(line);
}
- }
}
int main(int argc, char **argv)