Fix: Remove new-lines from commands in ZOOM shell.
[yaz-moved-to-github.git] / zoom / zoomsh.c
index 8ff31b1..e403a17 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoomsh.c,v 1.3 2001-11-06 17:05:19 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');
        }
     }
@@ -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])
        {
@@ -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,7 +217,7 @@ 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);
@@ -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;
     }