Fix: Remove new-lines from commands in ZOOM shell.
[yaz-moved-to-github.git] / zoom / zoomsh.c
index 9f9d0e4..e403a17 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoomsh.c,v 1.2 2001-10-24 12:24:43 adam Exp $
+ * $Id: zoomsh.c,v 1.6 2001-11-16 10:18:20 adam Exp $
  *
  * ZOOM-C Shell
  */
@@ -96,7 +96,8 @@ static void cmd_close (Z3950_connection *c, Z3950_resultset *r,
        const char *h;
        if (!c[i])
            continue;
-       if ((h = Z3950_connection_host(c[i])) && !strcmp (h, host))
+       if ((h = Z3950_connection_option_get(c[i], "host"))
+            && !strcmp (h, host))
        {
            Z3950_connection_destroy (c[i]);
            c[i] = 0;
@@ -117,16 +118,17 @@ static void display_records (Z3950_connection c,
     for (i = 0; i<count; i++)
     {
        int pos = i + start;
-       const char *db = Z3950_resultset_get (r, pos, "database", 0);
+        Z3950_record rec = Z3950_resultset_record (r, pos);
+       const char *db = Z3950_record_get (rec, "database", 0);
        int len;
-       const char *rec = Z3950_resultset_get (r, pos, "render", &len);
-       const char *syntax = Z3950_resultset_get (r, pos, "syntax", 0);
+       const char *render = Z3950_record_get (rec, "render", &len);
+       const char *syntax = Z3950_record_get (rec, "syntax", 0);
        /* if rec is non-null, we got a record for display */
        if (rec)
        {
            printf ("%d %s %s\n", pos+1, (db ? db : "unknown"), syntax);
-           if (rec)
-               fwrite (rec, 1, len, stdout);
+           if (render)
+               fwrite (render, 1, len, stdout);
            putchar ('\n');
        }
     }
@@ -146,7 +148,7 @@ static void cmd_show (Z3950_connection *c, Z3950_resultset *r,
        Z3950_options_set (options, "count", count_str);
 
     for (i = 0; i<MAX_CON; i++)
-       Z3950_resultset_records (r[i], 0, 0);
+       Z3950_resultset_records (r[i], 0, atoi(start_str), atoi(count_str));
     while (Z3950_event (MAX_CON, c))
        ;
 
@@ -159,7 +161,7 @@ static void cmd_show (Z3950_connection *c, Z3950_resultset *r,
            continue;
        if ((error = Z3950_connection_error(c[i], &errmsg, &addinfo)))
            fprintf (stderr, "%s error: %s (%d) %s\n",
-                    Z3950_connection_host(c[i]), errmsg,
+                    Z3950_connection_option_get(c[i], "host"), errmsg,
                     error, addinfo);
        else if (r[i])
        {
@@ -175,11 +177,11 @@ static void cmd_search (Z3950_connection *c, Z3950_resultset *r,
                        Z3950_options options,
                        const char **args)
 {
-    Z3950_search s;
+    Z3950_query s;
     int i;
     
-    s = Z3950_search_create ();
-    if (Z3950_search_prefix (s, *args))
+    s = Z3950_query_create ();
+    if (Z3950_query_prefix (s, *args))
     {
        fprintf (stderr, "Bad PQF: %s\n", *args);
        return;
@@ -207,7 +209,7 @@ static void cmd_search (Z3950_connection *c, Z3950_resultset *r,
            continue;
        if ((error = Z3950_connection_error(c[i], &errmsg, &addinfo)))
            fprintf (stderr, "%s error: %s (%d) %s\n",
-                    Z3950_connection_host(c[i]), errmsg,
+                    Z3950_connection_option_get(c[i], "host"), errmsg,
                     error, addinfo);
        else if (r[i])
        {
@@ -215,13 +217,13 @@ static void cmd_search (Z3950_connection *c, Z3950_resultset *r,
            int start = Z3950_options_get_int (options, "start", 0);
            int count = Z3950_options_get_int (options, "count", 0);
 
-           printf ("%s: %d hits\n", Z3950_connection_host(c[i]),
+           printf ("%s: %d hits\n", Z3950_connection_option_get(c[i], "host"),
                    Z3950_resultset_size(r[i]));
            /* and display */
            display_records (c[i], r[i], start, count);
        }
     }
-    Z3950_search_destroy (s);
+    Z3950_query_destroy (s);
 }
 
 static void cmd_help (Z3950_connection *c, Z3950_resultset *r,
@@ -268,7 +270,7 @@ static void cmd_connect (Z3950_connection *c, Z3950_resultset *r,
     for (j = -1, i = 0; i<MAX_CON; i++)
     {
        const char *h;
-       if (c[i] && (h = Z3950_connection_host(c[i])) &&
+       if (c[i] && (h = Z3950_connection_option_get(c[i], "host")) &&
            !strcmp (h, host))
        {
            Z3950_connection_destroy (c[i]);
@@ -290,7 +292,8 @@ static void cmd_connect (Z3950_connection *c, Z3950_resultset *r,
     Z3950_connection_connect (c[i], host, 0);
 
     if ((error = Z3950_connection_error(c[i], &errmsg, &addinfo)))
-       printf ("%s error: %s (%d) %s\n", Z3950_connection_host(c[i]),
+       printf ("%s error: %s (%d) %s\n",
+                Z3950_connection_option_get(c[i], "host"),
                errmsg, error, addinfo);
     
 }
@@ -329,6 +332,7 @@ void shell(Z3950_connection *c, Z3950_resultset *r, Z3950_options options)
     while (1)
     {
         char buf[1000];
+       char *cp;
        const char *bp = buf;
 #if HAVE_READLINE_READLINE_H
        char* line_in;
@@ -350,6 +354,8 @@ void shell(Z3950_connection *c, Z3950_resultset *r, Z3950_options options)
        if (!fgets (buf, 999, stdin))
            break;
 #endif 
+       if ((cp = strchr(buf, '\n')))
+           *cp = '\0';
        if (!cmd_parse (c, r, options, &bp))
            break;
     }