#include "strings.h"
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/param.h>
#include "tcl.h"
#include "tclInt.h"
#include "tclUnix.h"

#ifdef HAVE_Z3950_LIB
extern char *tz3950_client();

/* TKZ_ClientCmd --
 *
 *  Passes a Z39.50 command to the client interface (libzlib.a)
 *
 * Results:
 *	A standard Tcl result.
 *
 *----------------------------------------------------------------------
 */

	/* ARGSUSED */
int
TKZ_ClientCmd(dummy, interp, argc, argv)
    ClientData dummy;			/* Not used. */
    Tcl_Interp *interp;			/* Current interpreter. */
    int argc;				/* Number of arguments. */
    char **argv;			/* Argument strings. */
{

  char *result, *tmp, c;
  int i = 0, j = 0;

  char query_buffer[8000];

  if (*argv[0] == 'Z' || *argv[0] == 'z') 
    sprintf(query_buffer,"%s ",argv[0]); 
  else {
    Tcl_AppendResult(interp, "Bad Z39.50 command \"", argv[0], 
		     "\"", (char *) NULL);
    return TCL_ERROR;
  }
    
  for (i = 1; i < argc; i++) {
    strcat (query_buffer," ");
    strcat (query_buffer, argv[i]);
  }

  /* ship it off to zclient */
  result = tz3950_client(query_buffer);

  /* check the results and set Tcl return string */
  Tcl_AppendResult(interp, result, (char *) NULL);

  if (strncmp(result,"ERROR:",6)==0)
    return TCL_ERROR;
  else  
    return TCL_OK;
}
  
#endif
