+/*
+ * do_scan: Perform scan
+ */
+static int do_scan (void *o, Tcl_Interp *interp, int argc, char **argv)
+{
+ Z_ScanRequest req;
+ Z_APDU apdu, *apdup = &apdu;
+ IRScanObj *obj = o;
+ IRObj *p = obj->parent;
+ int r, pos;
+ struct ccl_rpn_node *rpn;
+
+ p->scan_child = o;
+ if (argc != 3)
+ {
+ interp->result = "wrong # args";
+ return TCL_ERROR;
+ }
+ if (!p->set_inher.num_databaseNames)
+ {
+ interp->result = "no databaseNames";
+ return TCL_ERROR;
+ }
+ if (!p->cs_link)
+ {
+ interp->result = "not connected";
+ return TCL_ERROR;
+ }
+ apdu.which = Z_APDU_scanRequest;
+ apdu.u.scanRequest = &req;
+ req.referenceId = NULL;
+ req.num_databaseNames = p->set_inher.num_databaseNames;
+ req.databaseNames = p->set_inher.databaseNames;
+ req.attributeSet = oid_getoidbyent (&p->bib1);
+
+#if 0
+ if (!(req.termListAndStartPoint =
+ ir_malloc (interp, sizeof(*req.termListAndStartPoint))))
+ return TCL_ERROR;
+ req.termListAndStartPoint->num_attributes = 0;
+ req.termListAndStartPoint->attributeList = NULL;
+ if (!(req.termListAndStartPoint->term = ir_malloc (interp,
+ sizeof(Z_Term))))
+ return TCL_ERROR;
+ req.termListAndStartPoint->term->which = Z_Term_general;
+ if (!(req.termListAndStartPoint->term->u.general =
+ ir_malloc (interp, sizeof(*req.termListAndStartPoint->
+ term->u.general))))
+ return TCL_ERROR;
+ if (ir_strdup (interp, &req.termListAndStartPoint->term->u.general->buf,
+ argv[2]) == TCL_ERROR)
+ return TCL_ERROR;
+ req.termListAndStartPoint->term->u.general->len =
+ req.termListAndStartPoint->term->u.general->size = strlen(argv[2]);
+#else
+ rpn = ccl_find_str(p->bibset, argv[2], &r, &pos);
+ if (r)
+ {
+ Tcl_AppendResult (interp, "CCL error: ", ccl_err_msg (r), NULL);
+ return TCL_ERROR;
+ }
+ ccl_pr_tree (rpn, stderr);
+ fprintf (stderr, "\n");
+ if (!(req.termListAndStartPoint = ccl_scan_query (rpn)))
+ return TCL_ERROR;
+#endif
+ req.stepSize = &obj->stepSize;
+ req.numberOfTermsRequested = &obj->numberOfTermsRequested;
+ req.preferredPositionInResponse = &obj->preferredPositionInResponse;
+ printf ("stepSize=%d\n", *req.stepSize);
+ printf ("numberOfTermsRequested=%d\n", *req.numberOfTermsRequested);
+ printf ("preferredPositionInResponse=%d\n",
+ *req.preferredPositionInResponse);
+
+ if (!z_APDU (p->odr_out, &apdup, 0))
+ {
+ interp->result = odr_errlist [odr_geterror (p->odr_out)];
+ odr_reset (p->odr_out);
+ return TCL_ERROR;
+ }
+ p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
+ if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
+ {
+ interp->result = "cs_put failed in scan";
+ return TCL_ERROR;
+ }
+ else if (r == 1)
+ {
+ ir_select_add_write (cs_fileno(p->cs_link), p);
+ printf("Sent part of scanRequest (%d bytes).\n", p->slen);
+ }
+ else
+ {
+ printf ("Whole scan request\n");
+ }
+ return TCL_OK;
+}
+
+/*
+ * do_stepSize: Set/get replace Step Size
+ */
+static int do_stepSize (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRScanObj *p = obj;
+ return get_set_int (&p->stepSize, interp, argc, argv);
+}
+
+/*
+ * do_numberOfTermsRequested: Set/get Number of Terms requested
+ */
+static int do_numberOfTermsRequested (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRScanObj *p = obj;
+ return get_set_int (&p->numberOfTermsRequested, interp, argc, argv);
+}
+
+
+/*
+ * do_preferredPositionInResponse: Set/get preferred Position
+ */
+static int do_preferredPositionInResponse (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRScanObj *p = obj;
+ return get_set_int (&p->preferredPositionInResponse, interp, argc, argv);
+}
+
+/*
+ * do_scanStatus: Get scan status
+ */
+static int do_scanStatus (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRScanObj *p = obj;
+ return get_set_int (&p->scanStatus, interp, argc, argv);
+}
+
+/*
+ * do_numberOfEntriesReturned: Get number of Entries returned
+ */
+static int do_numberOfEntriesReturned (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRScanObj *p = obj;
+ return get_set_int (&p->numberOfEntriesReturned, interp, argc, argv);
+}
+
+/*
+ * do_positionOfTerm: Get position of Term
+ */
+static int do_positionOfTerm (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRScanObj *p = obj;
+ return get_set_int (&p->positionOfTerm, interp, argc, argv);
+}
+
+/*
+ * do_scanLine: get Scan Line (surrogate or normal) after response
+ */
+static int do_scanLine (void *obj, Tcl_Interp *interp, int argc, char **argv)
+{
+ IRScanObj *p = obj;
+ int i;
+ char numstr[20];
+
+ if (argc != 3)
+ {
+ interp->result = "wrong # args";
+ return TCL_ERROR;
+ }
+ if (Tcl_GetInt (interp, argv[2], &i) == TCL_ERROR)
+ return TCL_ERROR;
+ if (!p->entries_flag || p->which != Z_ListEntries_entries || !p->entries
+ || i >= p->num_entries || i < 0)
+ return TCL_OK;
+ switch (p->entries[i].which)
+ {
+ case Z_Entry_termInfo:
+ Tcl_AppendElement (interp, "T");
+ if (p->entries[i].u.term.buf)
+ Tcl_AppendElement (interp, p->entries[i].u.term.buf);
+ else
+ Tcl_AppendElement (interp, "");
+ sprintf (numstr, "%d", p->entries[i].u.term.globalOccurrences);
+ Tcl_AppendElement (interp, numstr);
+ break;
+ case Z_Entry_surrogateDiagnostic:
+ return
+ mk_nonSurrogateDiagnostics (interp, p->entries[i].u.diag.condition,
+ p->entries[i].u.diag.addinfo);
+ break;
+ }
+ return TCL_OK;
+}
+
+/*
+ * ir_scan_obj_method: IR Scan Object methods
+ */
+static int ir_scan_obj_method (ClientData clientData, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ static IRMethod tab[] = {
+ { 0, "scan", do_scan },
+ { 0, "stepSize", do_stepSize },
+ { 0, "numberOfTermsRequested", do_numberOfTermsRequested },
+ { 0, "preferredPositionInResponse", do_preferredPositionInResponse },
+ { 0, "scanStatus", do_scanStatus },
+ { 0, "numberOfEntriesReturned", do_numberOfEntriesReturned },
+ { 0, "positionOfTerm", do_positionOfTerm },
+ { 0, "scanLine", do_scanLine },
+ { 0, NULL, NULL}
+ };
+
+ if (argc < 2)
+ {
+ interp->result = "wrong # args";
+ return TCL_ERROR;
+ }
+ return ir_method (clientData, interp, argc, argv, tab, 0);
+}
+
+/*
+ * ir_scan_obj_delete: IR Scan Object disposal
+ */
+static void ir_scan_obj_delete (ClientData clientData)
+{
+ free ( (void*) clientData);
+}
+
+/*
+ * ir_scan_obj_mk: IR Scan Object creation
+ */
+static int ir_scan_obj_mk (ClientData clientData, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ Tcl_CmdInfo parent_info;
+ IRScanObj *obj;
+
+ if (argc != 2)
+ {
+ interp->result = "wrong # args";
+ return TCL_ERROR;
+ }
+ if (get_parent_info (interp, argv[1], &parent_info, NULL) == TCL_ERROR)
+ return TCL_ERROR;
+ if (!(obj = ir_malloc (interp, sizeof(*obj))))
+ return TCL_ERROR;
+
+ obj->stepSize = 0;
+ obj->numberOfTermsRequested = 20;
+ obj->preferredPositionInResponse = 1;
+
+ obj->entries = NULL;
+ obj->nonSurrogateDiagnostics = NULL;
+
+ obj->parent = (IRObj *) parent_info.clientData;
+ Tcl_CreateCommand (interp, argv[1], ir_scan_obj_method,
+ (ClientData) obj, ir_scan_obj_delete);
+ return TCL_OK;
+}
+
+/* ------------------------------------------------------- */
+