Fix win version.
[yaz-moved-to-github.git] / client / client.c
index fe742f4..00764e4 100644 (file)
@@ -2,7 +2,7 @@
  * 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>
@@ -140,7 +140,7 @@ static void print_stringn(const unsigned char *buf, size_t len)
    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]);
 }
@@ -264,6 +264,16 @@ static int process_initResponse(Z_InitResponse *res)
         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;
@@ -481,7 +491,7 @@ static void print_record(const unsigned char *buf, size_t len)
     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)
@@ -557,13 +567,14 @@ 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)
                 {
@@ -2061,7 +2072,7 @@ int cmd_set_apdufile(char* arg)
   
     if(apdu_file && apdu_file != stderr) { /* don't close stdout*/
         perror("unable to close apdu log file");      
-    };
+    }
     apdu_file=NULL;
   
     if(strlen(arg)<1) {
@@ -2107,7 +2118,7 @@ int cmd_set_marcdump(char* arg)
 {
     if(marcdump && marcdump != stderr) { /* don't close stdout*/
         perror("unable to close apdu log file");      
-    };
+    }
     marcdump=NULL;
     
     if(strlen(arg)<1) {
@@ -2284,7 +2295,7 @@ static void initialize(void)
 struct timeval tv_start, tv_end;
 #endif
 
-void  wait_and_handle_responce() 
+void wait_and_handle_responce() 
 {
     
     int res;
@@ -2293,11 +2304,7 @@ void  wait_and_handle_responce()
     Z_APDU *apdu;
     
     
-    if (conn
-#ifdef USE_SELECT
-        && FD_ISSET(cs_fileno(conn), &input)
-#endif
-        )
+    if (conn)
     {
         do
         {
@@ -2393,6 +2400,7 @@ void  wait_and_handle_responce()
                 ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
 #endif
     }
+    xfree (netbuffer);
 }
 
 
@@ -2477,11 +2485,11 @@ void process_cmd_line(char* line)
         for(;*p; ++p) {
             if(!isspace(*p)) {
                 lastnonspace = p;
-            };
-        };
+            }
+        }
         if(lastnonspace) 
             *(++lastnonspace) = 0;
-    };
+    }
     
 
     for (i = 0; cmd[i].cmd; i++)
@@ -2504,15 +2512,16 @@ void process_cmd_line(char* line)
     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;
     }
@@ -2520,7 +2529,7 @@ char *command_generator(const char *text, int state)
         if (!strncmp(cmd[idx].cmd,text,strlen(text))) {
             ++idx;  /* skip this entry on the next run */
             return strdup(cmd[idx-1].cmd);
-        };
+        }
     }
     return NULL;
 }
@@ -2548,7 +2557,7 @@ char ** readline_completer(char *text, int start, int end) {
         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;
@@ -2578,16 +2587,19 @@ char ** readline_completer(char *text, int start, int end) {
         } 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);
@@ -2595,14 +2607,10 @@ static void client(void)
 
     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;
@@ -2610,9 +2618,12 @@ static void client(void)
             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);
@@ -2620,10 +2631,9 @@ static void client(void)
                 break;
             if ((end_p = strchr (line, '\n')))
                 *end_p = '\0';
-#endif 
+        }
         process_cmd_line(line);
     }
-    }
 }
 
 int main(int argc, char **argv)