Simplified select handling. Only one function ir_tcl_select_set has
[ir-tcl-moved-to-github.git] / ir-tcl.c
index 68d04b4..d87d4d8 100644 (file)
--- a/ir-tcl.c
+++ b/ir-tcl.c
@@ -5,7 +5,14 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: ir-tcl.c,v $
- * Revision 1.76  1996-02-20 16:09:51  adam
+ * Revision 1.78  1996-02-21 10:16:08  adam
+ * Simplified select handling. Only one function ir_tcl_select_set has
+ * to be externally defined.
+ *
+ * Revision 1.77  1996/02/20  17:52:58  adam
+ * Uses the YAZ oid system to name record syntax object identifiers.
+ *
+ * Revision 1.76  1996/02/20  16:09:51  adam
  * Bug fix: didn't set element set names stamp correctly on result
  * set records when element set names were set to the empty string.
  *
 
 #define CS_BLOCK 0
 
+#define IRTCL_GENERIC_FILES 0
+
 #include "ir-tclp.h"
 
 typedef struct {
@@ -295,6 +304,28 @@ static void ir_deleteDiags (IrTcl_Diagnostic **dst_list, int *dst_num);
 static int do_disconnect (void *obj, Tcl_Interp *interp, 
                           int argc, char **argv);
 
+static void ir_select_notify (ClientData clientData, int r, int w, int e);
+
+void ir_select_add (int fd, void *obj)
+{
+    ir_tcl_select_set (ir_select_notify, fd, obj, 1, 0, 0);
+}
+
+void ir_select_add_write (int fd, void *obj)
+{
+    ir_tcl_select_set (ir_select_notify, fd, obj, 1, 1, 0);
+}
+
+void ir_select_remove (int fd, void *obj)
+{
+    ir_tcl_select_set (NULL, fd, obj, 0, 0, 0);
+}
+
+void ir_select_remove_write (int fd, void *obj)
+{
+    ir_tcl_select_set (ir_select_notify, fd, obj, 1, 0, 0);
+}
+
 static IrTcl_RecordList *new_IR_record (IrTcl_SetObj *setobj, 
                                         int no, int which, 
                                         const char *elements)
@@ -335,30 +366,6 @@ static IrTcl_RecordList *new_IR_record (IrTcl_SetObj *setobj,
     return rl;
 }
 
-static struct {
-    enum oid_value value;
-    const char *name;
-} IrTcl_recordSyntaxTab[] = { 
-{ VAL_UNIMARC,    "UNIMARC" },
-{ VAL_INTERMARC,  "INTERMARC" },
-{ VAL_CCF,        "CCF" },
-{ VAL_USMARC,     "USMARC" },
-{ VAL_UKMARC,     "UKMARC" },
-{ VAL_NORMARC,    "NORMARC" },
-{ VAL_LIBRISMARC, "LIBRISMARC" },
-{ VAL_DANMARC,    "DANMARC" },
-{ VAL_FINMARC,    "FINMARC" },
-{ VAL_MAB,        "MAB" },
-{ VAL_CANMARC,    "CANMARC" },
-{ VAL_SBN,        "SBN" },
-{ VAL_PICAMARC,   "PICAMARC" },
-{ VAL_AUSMARC,    "AUSMARC" },
-{ VAL_IBERMARC,   "IBERMARC" },
-{ VAL_SUTRS,      "SUTRS" },
-{ VAL_GRS1,       "GRS1" },
-{ 0, NULL }
-};
-
 /* 
  * IrTcl_eval
  */
@@ -380,13 +387,21 @@ int IrTcl_eval (Tcl_Interp *interp, const char *command)
 /*
  * IrTcl_getRecordSyntaxStr: Return record syntax name of object id
  */
-static const char *IrTcl_getRecordSyntaxStr (enum oid_value value)
+static char *IrTcl_getRecordSyntaxStr (enum oid_value value)
 {
-    int i;
-    for (i = 0; IrTcl_recordSyntaxTab[i].name; i++) 
-        if (IrTcl_recordSyntaxTab[i].value == value)
-            return IrTcl_recordSyntaxTab[i].name;
-    return "USMARC";
+    int *o;
+    struct oident ent, *entp;
+
+    ent.proto = PROTO_Z3950;
+    ent.oclass = CLASS_RECSYN;
+    ent.value = value;
+
+    o = oid_getoidbyent (&ent);
+    entp = oid_getentbyoid (o);
+    
+    if (!entp)
+        return "";
+    return entp->desc;
 }
 
 /*
@@ -394,11 +409,7 @@ static const char *IrTcl_getRecordSyntaxStr (enum oid_value value)
  */
 static enum oid_value IrTcl_getRecordSyntaxVal (const char *name)
 {
-    int i;
-    for (i = 0; IrTcl_recordSyntaxTab[i].name; i++) 
-        if (!strcmp (IrTcl_recordSyntaxTab[i].name, name))
-            return IrTcl_recordSyntaxTab[i].value;
-    return 0;
+    return oid_getvalbyname (name);
 }
 
 static IrTcl_RecordList *find_IR_record (IrTcl_SetObj *setobj, int no)
@@ -1577,6 +1588,11 @@ static int do_preferredRecordSyntax (void *obj, Tcl_Interp *interp,
                            ir_tcl_malloc (sizeof(*p->preferredRecordSyntax))))
             *p->preferredRecordSyntax = IrTcl_getRecordSyntaxVal (argv[2]);
     }
+    else if (argc == 2)
+    {
+        Tcl_AppendElement (interp, IrTcl_getRecordSyntaxStr
+                           (*p->preferredRecordSyntax));
+    }
     return TCL_OK;
             
 }
@@ -3379,7 +3395,7 @@ static void ir_scanResponse (void *o, Z_ScanResponse *scanrs,
 /*
  * ir_select_read: handle incoming packages
  */
-void ir_select_read (ClientData clientData)
+static void ir_select_read (ClientData clientData)
 {
     IrTcl_Obj *p = clientData;
     Z_APDU *apdu;
@@ -3553,7 +3569,7 @@ void ir_select_read (ClientData clientData)
 /*
  * ir_select_write: handle outgoing packages - not yet written.
  */
-void ir_select_write (ClientData clientData)
+static void ir_select_write (ClientData clientData)
 {
     IrTcl_Obj *p = clientData;
     int r;
@@ -3622,6 +3638,14 @@ void ir_select_write (ClientData clientData)
     }
 }
 
+static void ir_select_notify (ClientData clientData, int r, int w, int e)
+{
+    if (r)
+        ir_select_read (clientData);
+    if (w)
+        ir_select_write (clientData);
+}
+
 /* ------------------------------------------------------- */
 
 /*