chiark / gitweb /
writeable lookups now compile
[chiark-tcl.git] / cdb / writeable.c
index fb7a67f3ffe64781a4b4fe4ea7506331c4abfe39..1059a104e330d2c56e9d53569be47b25044190fc 100644 (file)
@@ -94,9 +94,8 @@ static void ht_maybeupdate(HashTable *ht, const char *key,
 
 static const HashValue *ht_lookup(HashTable *ht, const char *key) {
   Tcl_HashEntry *he;
-  const HashValue *htv;
   
-  he= Tcl_FindHashEntry(ht, key);
+  he= Tcl_FindHashEntry(&ht->t, key);
   if (!he) return 0;
   
   return Tcl_GetHashValue(he);
@@ -847,11 +846,11 @@ int cht_do_cdbwr_delete(ClientData cd, Tcl_Interp *ip, void *rw_v,
 
 /*---------- Lookups ----------*/
 
-static int wrlookup(Tcl_Interp *ip, void *rw_v, const char *key,
+static int lookup_rw(Tcl_Interp *ip, void *rw_v, const char *key,
                    const Byte **data_r, int *len_r /* -1 => notfound */) {
   Rw *rw= rw_v;
   const HashValue *val;
-  int r, l;
+  int r;
 
   val= ht_lookup(&rw->logincore, key);
   if (val) {
@@ -870,50 +869,16 @@ static int wrlookup(Tcl_Interp *ip, void *rw_v, const char *key,
   return TCL_OK;
 } 
 
-int cht_cdb_dosomelookup(ClientData cd, Tcl_Interp *ip, void *db_v,
-                        int (*somelookup)(Tcl_Interp *ip, void *db_v,
-                                          const char *key,
-                                          const Byte **data_r, int *len_r),
-                        const char *key, Tcl_Obj *def,
-                        Tcl_Obj **result) {
-  int r, len;
-  const Byte *data;
-  
-  r= somelookup(ip, db_v, key, &data, &len);
-  if (r) return r;
-  if (len>0) {
-    r= storeanswer();
-  }
-  if (def) {
-    *result= def;
-    return TCL_OK;
-  }
-  return cht_staticerr(ip, "cdbwr lookup key not found", "CDB NOTFOUND");
-  
-  if (len<0) *result= def;
-  else *result= Tcl_NewStringObj(
+int cht_do_cdbwr_lookup(ClientData cd, Tcl_Interp *ip, void *rw_v,
+                       const char *key, Tcl_Obj *def,
+                       Tcl_Obj **result) {
+  return cht_cdb_dosomelookup(ip, rw_v, key, def, result,
+                             lookup_rw, cht_cdb_storeanswer_string);
 }
-
-static int storeanswer
   
-int cht_do_cdbwr_lookup(ClientData cd, Tcl_Interp *ip, void *rw_v,
-                       const char *key, HBytes_Value def,
-                       HBytes_Value *result) {
-    *result= Tcl_NewStringObj(data, len);
-    if (!*result) return cht_staticerr(ip, "Tcl_NewStringObj failed for"
-          " lookup (utf-8 encoding problem?)", "CDB BADSTRING");
-    return TCL_OK;
 int cht_do_cdbwr_lookup_hb(ClientData cd, Tcl_Interp *ip, void *rw_v,
-                          const char *key, HBytes_Value def,
-                          HBytes_Value *result) {
-  Rw *rw= rw_v;
-  int r;
-
-  r= lookup(ip, rw, key, &data, &len);
-  if (r) return r;
-  if (len>0) {
-    cht_hb_array(result, data, len);
-    return TCL_OK;
-  }
-  if (!HBYTES_ISSENTINEL(def)) {
-    cht_hb_array(result, cht_hb_data(&def), cht_hb
+                          const char *key, Tcl_Obj *def,
+                          Tcl_Obj **result) {
+  return cht_cdb_dosomelookup(ip, rw_v, key, def, result,
+                             lookup_rw, cht_cdb_storeanswer_hb);
+}