New parameter: result-set file descriptor (RSFD) to support multiple
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 7 Sep 1995 13:58:08 +0000 (13:58 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 7 Sep 1995 13:58:08 +0000 (13:58 +0000)
positions within the same result-set.
Boolean operators: and, or, not implemented.

include/rsbool.h
include/rset.h
rset/rsbool.c
rset/rset.c
rset/rsisam.c
rset/rsnull.c
rset/rstemp.c

index 03dccc1..5eb017c 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: rsbool.h,v $
- * Revision 1.2  1995-09-06 16:10:57  adam
+ * Revision 1.3  1995-09-07 13:58:08  adam
+ * New parameter: result-set file descriptor (RSFD) to support multiple
+ * positions within the same result-set.
+ * Boolean operators: and, or, not implemented.
+ *
+ * Revision 1.2  1995/09/06  16:10:57  adam
  * More work on boolean sets.
  *
  * Revision 1.1  1995/09/06  13:27:37  adam
 
 #include <rset.h>
 
-extern const rset_control *rset_kind_bool;
+extern const rset_control *rset_kind_and;
+extern const rset_control *rset_kind_or;
+extern const rset_control *rset_kind_not;
 
 typedef struct rset_bool_parms
 {
     int     key_size;
-    int     op;
     RSET    rset_l;
     RSET    rset_r;
     int (*cmp)(const void *p1, const void *p2);
index b370071..2a86097 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: rset.h,v $
- * Revision 1.6  1995-09-06 16:10:58  adam
+ * Revision 1.7  1995-09-07 13:58:08  adam
+ * New parameter: result-set file descriptor (RSFD) to support multiple
+ * positions within the same result-set.
+ * Boolean operators: and, or, not implemented.
+ *
+ * Revision 1.6  1995/09/06  16:10:58  adam
  * More work on boolean sets.
  *
  * Revision 1.5  1995/09/04  15:20:13  adam
 
 #include <stdlib.h>
 
+typedef void *RSFD;
+
 typedef struct rset_control
 {
     char *desc; /* text description of set type (for debugging) */
     void *buf;  /* state data stored by subsystem */
     struct rset_control *(*f_create)(const struct rset_control *sel, void *parms);
-    int (*f_open)(struct rset_control *ct, int wflag);
-    void (*f_close)(struct rset_control *ct);
+    RSFD (*f_open)(struct rset_control *ct, int wflag);
+    void (*f_close)(RSFD rfd);
     void (*f_delete)(struct rset_control *ct);
-    void (*f_rewind)(struct rset_control *ct);
+    void (*f_rewind)(RSFD rfd);
     int (*f_count)(struct rset_control *ct);
-    int (*f_read)(struct rset_control *ct, void *buf);
-    int (*f_write)(struct rset_control *ct, const void *buf);
+    int (*f_read)(RSFD rfd, void *buf);
+    int (*f_write)(RSFD rfd, const void *buf);
 } rset_control;
 
 typedef struct rset
@@ -55,20 +62,20 @@ RSET rset_create(const rset_control *sel, void *parms);       /* parameters? */
 #define rset_open(rs, wflag) ((*(rs)->control->f_open)((rs)->control, (wflag)))
 
 /* void rset_close(RSET rs); */
-#define rset_close(rs) ((*(rs)->control->f_close)((rs)->control))
+#define rset_close(rs, rfd) ((*(rs)->control->f_close)((rfd)))
 
 void rset_delete(RSET rs);
 
 /* void rset_rewind(RSET rs); */
-#define rset_rewind(rs) ((*(rs)->control->f_rewind)((rs)->control))
+#define rset_rewind(rs, rfd) ((*(rs)->control->f_rewind)((rfd)))
 
 /* int rset_count(RSET rs); */
 #define rset_count(rs) ((*(rs)->control->f_count)((rs)->control))
 
 /* int rset_read(RSET rs, void *buf); */
-#define rset_read(rs, buf) ((*(rs)->control->f_read)((rs)->control, (buf)))
+#define rset_read(rs, fd, buf) ((*(rs)->control->f_read)((fd), (buf)))
 
 /* int rset_write(RSET rs, const void *buf); */
-#define rset_write(rs, buf) ((*(rs)->control->f_write)((rs)->control, (buf)))
+#define rset_write(rs, fd, buf) ((*(rs)->control->f_write)((fd), (buf)))
 
 #endif
index d1bddb8..e2bec06 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: rsbool.c,v $
- * Revision 1.2  1995-09-06 16:11:55  adam
+ * Revision 1.3  1995-09-07 13:58:43  adam
+ * New parameter: result-set file descriptor (RSFD) to support multiple
+ * positions within the same result-set.
+ * Boolean operators: and, or, not implemented.
+ *
+ * Revision 1.2  1995/09/06  16:11:55  adam
  * More work on boolean sets.
  *
  * Revision 1.1  1995/09/06  13:27:15  adam
  */
 
 #include <stdio.h>
+#include <assert.h>
+
 #include <rsbool.h>
 #include <alexutil.h>
 
 static rset_control *r_create(const struct rset_control *sel, void *parms);
-static int r_open (rset_control *ct, int wflag);
-static void r_close (rset_control *ct);
+static RSFD r_open (rset_control *ct, int wflag);
+static void r_close (RSFD rfd);
 static void r_delete (rset_control *ct);
-static void r_rewind (rset_control *ct);
+static void r_rewind (RSFD rfd);
 static int r_count (rset_control *ct);
-static int r_read (rset_control *ct, void *buf);
-static int r_write (rset_control *ct, const void *buf);
+static int r_read_and (RSFD rfd, void *buf);
+static int r_read_or (RSFD rfd, void *buf);
+static int r_read_not (RSFD rfd, void *buf);
+static int r_write (RSFD rfd, const void *buf);
 
-static const rset_control control = 
+static const rset_control control_and = 
 {
-    "BOOL set type",
+    "AND set type",
     0,
     r_create,
     r_open,
@@ -35,25 +44,63 @@ static const rset_control control =
     r_delete,
     r_rewind,
     r_count,
-    r_read,
+    r_read_and,
     r_write
 };
 
-const rset_control *rset_kind_bool = &control;
+static const rset_control control_or = 
+{
+    "OR set type",
+    0,
+    r_create,
+    r_open,
+    r_close,
+    r_delete,
+    r_rewind,
+    r_count,
+    r_read_or,
+    r_write
+};
+
+static const rset_control control_not = 
+{
+    "NOT set type",
+    0,
+    r_create,
+    r_open,
+    r_close,
+    r_delete,
+    r_rewind,
+    r_count,
+    r_read_not,
+    r_write
+};
+
+
+const rset_control *rset_kind_and = &control_and;
+const rset_control *rset_kind_or = &control_or;
+const rset_control *rset_kind_not = &control_not;
 
 struct rset_bool_info {
     int key_size;
-    int op;
     RSET rset_l;
     RSET rset_r;
-    int more_l;
-    int more_r;
-    void *buf_l;
-    void *buf_r;
     int (*cmp)(const void *p1, const void *p2);
+    struct rset_bool_rfd *rfd_list;
 };
 
-static rset_control *r_create(const struct rset_control *sel, void *parms)
+struct rset_bool_rfd {
+    RSFD rfd_l;
+    RSFD rfd_r;
+    int  more_l;
+    int  more_r;
+    void *buf_l;
+    void *buf_r;
+    struct rset_bool_rfd *next;
+    struct rset_bool_info *info;
+};    
+
+static rset_control *r_create (const struct rset_control *sel, void *parms)
 {
     rset_control *newct;
     rset_bool_parms *bool_parms = parms;
@@ -65,58 +112,76 @@ static rset_control *r_create(const struct rset_control *sel, void *parms)
     newct->buf = xmalloc (sizeof(struct rset_bool_info));
     info = (struct rset_bool_info*) newct->buf;
     info->key_size = bool_parms->key_size;
-    info->op = bool_parms->op;
     info->rset_l = bool_parms->rset_l;
     info->rset_r = bool_parms->rset_r;
     info->cmp = bool_parms->cmp;
-    info->buf_l = xmalloc (info->key_size);
-    info->buf_r = xmalloc (info->key_size);
+    info->rfd_list = NULL;
     return newct;
 }
 
-static int r_open(rset_control *ct, int wflag)
+static RSFD r_open (rset_control *ct, int wflag)
 {
     struct rset_bool_info *info = ct->buf;
+    struct rset_bool_rfd *rfd;
 
     if (wflag)
     {
        logf (LOG_FATAL, "bool set type is read-only");
-       return -1;
+       return NULL;
     }
-    rset_open (info->rset_l, wflag);
-    rset_open (info->rset_r, wflag);
-    info->more_l = rset_read (info->rset_l, info->buf_l);
-    info->more_r = rset_read (info->rset_r, info->buf_r);
-    return 0;
+    rfd = xmalloc (sizeof(*rfd));
+    rfd->next = info->rfd_list;
+    info->rfd_list = rfd;
+
+    rfd->buf_l = xmalloc (info->key_size);
+    rfd->buf_r = xmalloc (info->key_size);
+    rfd->rfd_l = rset_open (info->rset_l, wflag);
+    rfd->rfd_r = rset_open (info->rset_r, wflag);
+    rfd->more_l = rset_read (info->rset_l, rfd->rfd_l, rfd->buf_l);
+    rfd->more_r = rset_read (info->rset_r, rfd->rfd_r, rfd->buf_r);
+    rfd->info = info;
+    return rfd;
 }
 
-static void r_close(rset_control *ct)
+static void r_close (RSFD rfd)
 {
-    struct rset_bool_info *info = ct->buf;
-
-    rset_close (info->rset_l);
-    rset_close (info->rset_r);
+    struct rset_bool_info *info = ((struct rset_bool_rfd*)rfd)->info;
+    struct rset_bool_rfd **rfdp;
+    
+    for (rfdp = &info->rfd_list; *rfdp; rfdp = &(*rfdp)->next)
+        if (*rfdp == rfd)
+        {
+            xfree ((*rfdp)->buf_l);
+            xfree ((*rfdp)->buf_r);
+            rset_close (info->rset_l, (*rfdp)->rfd_l);
+            rset_close (info->rset_r, (*rfdp)->rfd_r);
+            *rfdp = (*rfdp)->next;
+            free (rfd);
+            return;
+        }
+    logf (LOG_FATAL, "r_close but no rfd match!");
+    assert (0);
 }
 
-static void r_delete(rset_control *ct)
+static void r_delete (rset_control *ct)
 {
     struct rset_bool_info *info = ct->buf;
 
-    rset_delete (info->rset_l);
-    rset_delete (info->rset_r);
-    xfree (info->buf_l);
-    xfree (info->buf_r);
-    xfree (ct->buf);
+    assert (info->rfd_list == NULL);
+    xfree (info);
     xfree (ct);
 }
 
-static void r_rewind(rset_control *ct)
+static void r_rewind (RSFD rfd)
 {
-    struct rset_bool_info *info = ct->buf;
+    struct rset_bool_info *info = ((struct rset_bool_rfd*)rfd)->info;
+    struct rset_bool_rfd *p = rfd;
 
     logf (LOG_DEBUG, "rsbool_rewind");
-    rset_rewind (info->rset_l);
-    rset_rewind (info->rset_r);
+    rset_rewind (info->rset_l, p->rfd_l);
+    rset_rewind (info->rset_r, p->rfd_r);
+    p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+    p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
 }
 
 static int r_count (rset_control *ct)
@@ -124,16 +189,133 @@ static int r_count (rset_control *ct)
     return 0;
 }
 
-static int r_read (rset_control *ct, void *buf)
+static int r_read_and (RSFD rfd, void *buf)
 {
-    struct rset_bool_info *info = ct->buf;
+    struct rset_bool_rfd *p = rfd;
+    struct rset_bool_info *info = p->info;
+
+    while (p->more_l || p->more_r)
+    {
+        int cmp;
+
+        if (p->more_l && p->more_r)
+            cmp = (*info->cmp)(p->buf_l, p->buf_r);
+        else if (p->more_r)
+            cmp = 2;
+        else
+            cmp = -2;
+        if (!cmp)
+        {
+            memcpy (buf, p->buf_l, info->key_size);
+            p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+            p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+            return 1;
+        }
+        else if (cmp == 1)
+        {
+            memcpy (buf, p->buf_r, info->key_size);
+            p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+            return 1;
+        }
+        else if (cmp == -1)
+        {
+            memcpy (buf, p->buf_l, info->key_size);
+            p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+            return 1;
+        }
+        else if (cmp > 1)
+            p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+        else
+            p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+    }
+    return 0;
+}
 
-    if (!info->more_l && !info->more_r)
-        return 0;
+static int r_read_or (RSFD rfd, void *buf)
+{
+    struct rset_bool_rfd *p = rfd;
+    struct rset_bool_info *info = p->info;
+
+    while (p->more_l || p->more_r)
+    {
+        int cmp;
+
+        if (p->more_l && p->more_r)
+            cmp = (*info->cmp)(p->buf_l, p->buf_r);
+        else if (p->more_r)
+            cmp = 2;
+        else
+            cmp = -2;
+        if (!cmp)
+        {
+            memcpy (buf, p->buf_l, info->key_size);
+            p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+            p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+            return 1;
+        }
+        else if (cmp > 0)
+        {
+            memcpy (buf, p->buf_r, info->key_size);
+            p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+            return 1;
+        }
+        else
+        {
+            memcpy (buf, p->buf_l, info->key_size);
+            p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+            return 1;
+        }
+    }
+    return 0;
+}
+
+static int r_read_not (RSFD rfd, void *buf)
+{
+    struct rset_bool_rfd *p = rfd;
+    struct rset_bool_info *info = p->info;
+
+    while (p->more_l || p->more_r)
+    {
+        int cmp;
+
+        if (p->more_l && p->more_r)
+            cmp = (*info->cmp)(p->buf_l, p->buf_r);
+        else if (p->more_r)
+            cmp = 2;
+        else
+            cmp = -2;
+        if (cmp < -1)
+        {
+            memcpy (buf, p->buf_l, info->key_size);
+            p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+            return 1;
+        }
+        else if (cmp > 1)
+            p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+        else
+        {
+            memcpy (buf, p->buf_l, info->key_size);
+            do
+            {
+                p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+                if (!p->more_l)
+                    break;
+                cmp = (*info->cmp)(p->buf_l, buf);
+            } while (cmp >= -1 && cmp <= 1);
+            do
+            {
+                p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+                if (!p->more_r)
+                    break;
+                cmp = (*info->cmp)(p->buf_r, buf);
+            } while (cmp >= -1 && cmp <= 1);
+        }
+    }
     return 0;
 }
 
-static int r_write (rset_control *ct, const void *buf)
+
+static int r_write (RSFD rfd, const void *buf)
 {
     logf (LOG_FATAL, "bool set type is read-only");
     return -1;
index 0a2f92a..e10f1b1 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: rset.c,v $
- * Revision 1.4  1995-09-06 16:11:56  adam
+ * Revision 1.5  1995-09-07 13:58:43  adam
+ * New parameter: result-set file descriptor (RSFD) to support multiple
+ * positions within the same result-set.
+ * Boolean operators: and, or, not implemented.
+ *
+ * Revision 1.4  1995/09/06  16:11:56  adam
  * More work on boolean sets.
  *
  * Revision 1.3  1995/09/04  15:20:39  adam
@@ -33,9 +38,8 @@ RSET rset_create(const rset_control *sel, void *parms)
     return new;
 }
 
-void rset_delete(RSET rs)
+void rset_delete (RSET rs)
 {
-    rset_close(rs);
     (*rs->control->f_delete)(rs->control);
     xfree(rs);
 }
index e9f7958..1eb1828 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: rsisam.c,v $
- * Revision 1.8  1995-09-06 16:11:56  adam
+ * Revision 1.9  1995-09-07 13:58:43  adam
+ * New parameter: result-set file descriptor (RSFD) to support multiple
+ * positions within the same result-set.
+ * Boolean operators: and, or, not implemented.
+ *
+ * Revision 1.8  1995/09/06  16:11:56  adam
  * More work on boolean sets.
  *
  * Revision 1.7  1995/09/06  10:35:44  adam
  */
 
 #include <stdio.h>
+#include <assert.h>
 #include <rsisam.h>
 #include <alexutil.h>
 
 static rset_control *r_create(const struct rset_control *sel, void *parms);
-static int r_open (rset_control *ct, int wflag);
-static void r_close (rset_control *ct);
+static RSFD r_open (rset_control *ct, int wflag);
+static void r_close (RSFD rfd);
 static void r_delete (rset_control *ct);
-static void r_rewind (rset_control *ct);
+static void r_rewind (RSFD rfd);
 static int r_count (rset_control *ct);
-static int r_read (rset_control *ct, void *buf);
-static int r_write (rset_control *ct, const void *buf);
+static int r_read (RSFD rfd, void *buf);
+static int r_write (RSFD rfd, const void *buf);
 
 static const rset_control control = 
 {
@@ -56,47 +62,87 @@ static const rset_control control =
 
 const rset_control *rset_kind_isam = &control;
 
+struct rset_ispt_info {
+    ISPT   pt;
+    struct rset_ispt_info *next;
+    struct rset_isam_info *info;
+};
+
+struct rset_isam_info {
+    ISAM   is;
+    ISAM_P pos;
+    struct rset_ispt_info *ispt_list;
+};
+
 static rset_control *r_create(const struct rset_control *sel, void *parms)
 {
     rset_control *newct;
     rset_isam_parms *pt = parms;
+    struct rset_isam_info *info;
 
     logf (LOG_DEBUG, "rsisam_create(%s)", sel->desc);
     newct = xmalloc(sizeof(*newct));
     memcpy(newct, sel, sizeof(*sel));
-    if (!(newct->buf = (char*) is_position(pt->is, pt->pos)))
+
+    if (!(newct->buf = xmalloc (sizeof(struct rset_isam_info))))
        return 0;
+    info = newct->buf;
+    info->is = pt->is;
+    info->pos = pt->pos;
+    info->ispt_list = NULL;
     return newct;
 }
 
-static int r_open(rset_control *ct, int wflag)
+RSFD r_open (rset_control *ct, int wflag)
 {
+    struct rset_isam_info *info = ct->buf;
+    struct rset_ispt_info *ptinfo;
+
     logf (LOG_DEBUG, "risam_open");
     if (wflag)
     {
        logf (LOG_FATAL, "ISAM set type is read-only");
-       return -1;
+       return NULL;
     }
-    r_rewind(ct);
-    return 0;
+    ptinfo = xmalloc (sizeof(*ptinfo));
+    ptinfo->next = info->ispt_list;
+    info->ispt_list = ptinfo;
+    ptinfo->pt = is_position (info->is, info->pos);
+    ptinfo->info = info;
+    return ptinfo;
 }
 
-static void r_close(rset_control *ct)
+static void r_close (RSFD rfd)
 {
-    /* NOP */
+    struct rset_isam_info *info = ((struct rset_ispt_info*) rfd)->info;
+    struct rset_ispt_info **ptinfop;
+
+    for (ptinfop = &info->ispt_list; *ptinfop; ptinfop = &(*ptinfop)->next)
+        if (*ptinfop == rfd)
+        {
+            is_pt_free ((*ptinfop)->pt);
+            *ptinfop = (*ptinfop)->next;
+            free (rfd);
+            return;
+        }
+    logf (LOG_FATAL, "r_close but no rfd match!");
+    assert (0);
 }
 
-static void r_delete(rset_control *ct)
+static void r_delete (rset_control *ct)
 {
+    struct rset_isam_info *info = ct->buf;
+
     logf (LOG_DEBUG, "rsisam_delete");
-    is_pt_free((ISPT) ct->buf);
-    xfree(ct);
+    assert (info->ispt_list == NULL);
+    xfree (info);
+    xfree (ct);
 }
 
-static void r_rewind(rset_control *ct)
-{
+static void r_rewind (RSFD rfd)
+{   
     logf (LOG_DEBUG, "rsisam_rewind");
-    is_rewind((ISPT) ct->buf);
+    is_rewind( ((struct rset_ispt_info*) rfd)->pt);
 }
 
 static int r_count (rset_control *ct)
@@ -104,12 +150,12 @@ static int r_count (rset_control *ct)
     return 0;
 }
 
-static int r_read (rset_control *ct, void *buf)
+static int r_read (RSFD rfd, void *buf)
 {
-    return is_readkey((ISPT) ct->buf, buf);
+    return is_readkey( ((struct rset_ispt_info*) rfd)->pt, buf);
 }
 
-static int r_write (rset_control *ct, const void *buf)
+static int r_write (RSFD rfd, const void *buf)
 {
     logf (LOG_FATAL, "ISAM set type is read-only");
     return -1;
index 8c597b7..a278293 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: rsnull.c,v $
- * Revision 1.1  1995-09-06 10:35:44  adam
+ * Revision 1.2  1995-09-07 13:58:43  adam
+ * New parameter: result-set file descriptor (RSFD) to support multiple
+ * positions within the same result-set.
+ * Boolean operators: and, or, not implemented.
+ *
+ * Revision 1.1  1995/09/06  10:35:44  adam
  * Null set implemented.
  *
  */
 #include <alexutil.h>
 
 static rset_control *r_create(const struct rset_control *sel, void *parms);
-static int r_open (rset_control *ct, int wflag);
-static void r_close (rset_control *ct);
+static RSFD r_open (rset_control *ct, int wflag);
+static void r_close (RSFD rfd);
 static void r_delete (rset_control *ct);
-static void r_rewind (rset_control *ct);
+static void r_rewind (RSFD rfd);
 static int r_count (rset_control *ct);
-static int r_read (rset_control *ct, void *buf);
-static int r_write (rset_control *ct, const void *buf);
+static int r_read (RSFD rfd, void *buf);
+static int r_write (RSFD rfd, const void *buf);
 
 static const rset_control control = 
 {
@@ -48,27 +53,26 @@ static rset_control *r_create(const struct rset_control *sel, void *parms)
     return newct;
 }
 
-static int r_open(rset_control *ct, int wflag)
+static RSFD r_open (rset_control *ct, int wflag)
 {
     if (wflag)
     {
        logf (LOG_FATAL, "NULL set type is read-only");
-       return -1;
+       return NULL;
     }
-    return 0;
+    return "";
 }
 
-static void r_close(rset_control *ct)
+static void r_close (RSFD rfd)
 {
-    /* NOP */
 }
 
-static void r_delete(rset_control *ct)
+static void r_delete (rset_control *ct)
 {
     xfree(ct);
 }
 
-static void r_rewind(rset_control *ct)
+static void r_rewind (RSFD rfd)
 {
     logf (LOG_DEBUG, "rsnull_rewind");
 }
@@ -78,12 +82,12 @@ static int r_count (rset_control *ct)
     return 0;
 }
 
-static int r_read (rset_control *ct, void *buf)
+static int r_read (RSFD rfd, void *buf)
 {
     return 0;
 }
 
-static int r_write (rset_control *ct, const void *buf)
+static int r_write (RSFD rfd, const void *buf)
 {
     logf (LOG_FATAL, "NULL set type is read-only");
     return -1;
index 10412c4..0c835f9 100644 (file)
@@ -4,7 +4,12 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: rstemp.c,v $
- * Revision 1.6  1995-09-06 16:11:56  adam
+ * Revision 1.7  1995-09-07 13:58:44  adam
+ * New parameter: result-set file descriptor (RSFD) to support multiple
+ * positions within the same result-set.
+ * Boolean operators: and, or, not implemented.
+ *
+ * Revision 1.6  1995/09/06  16:11:56  adam
  * More work on boolean sets.
  *
  * Revision 1.5  1995/09/05  16:36:59  adam
 #include <alexutil.h>
 #include <rstemp.h>
 
-static struct rset_control *r_create(const struct rset_control *sel, 
-                                     void *parms);
-static int r_open(struct rset_control *ct, int wflag);
-static void r_close(struct rset_control *ct);
-static void r_delete(struct rset_control *ct);
-static void r_rewind(struct rset_control *ct);
-static int r_count(struct rset_control *ct);
-static int r_read (rset_control *ct, void *buf);
-static int r_write (rset_control *ct, const void *buf);
+static rset_control *r_create(const struct rset_control *sel, void *parms);
+static RSFD r_open (rset_control *ct, int wflag);
+static void r_close (RSFD rfd);
+static void r_delete (rset_control *ct);
+static void r_rewind (RSFD rfd);
+static int r_count (rset_control *ct);
+static int r_read (RSFD rfd, void *buf);
+static int r_write (RSFD rfd, const void *buf);
 
 static const rset_control control = 
 {
@@ -59,7 +63,7 @@ static const rset_control control =
 
 const rset_control *rset_kind_temp = &control;
 
-struct rset_temp_private {
+struct rset_temp_info {
     int     fd;
     char   *fname;
     size_t  key_size;
@@ -72,17 +76,22 @@ struct rset_temp_private {
     int     dirty;
 };
 
+struct rset_temp_rfd {
+    struct rset_temp_info *info;
+    struct rset_temp_rfd *next;
+};
+
 static struct rset_control *r_create(const struct rset_control *sel,
                                      void *parms)
 {
     rset_control *newct;
     rset_temp_parms *temp_parms = parms;
-    struct rset_temp_private *info;
+    struct rset_temp_info *info;
     
     logf (LOG_DEBUG, "ritemp_create(%s)", sel->desc);
     newct = xmalloc(sizeof(*newct));
     memcpy(newct, sel, sizeof(*sel));
-    newct->buf = xmalloc (sizeof(struct rset_temp_private));
+    newct->buf = xmalloc (sizeof(struct rset_temp_info));
     info = newct->buf;
 
     info->fd = -1;
@@ -98,9 +107,10 @@ static struct rset_control *r_create(const struct rset_control *sel,
     return newct;
 }
 
-static int r_open(struct rset_control *ct, int wflag)
+static RSFD r_open (struct rset_control *ct, int wflag)
 {
-    struct rset_temp_private *info = ct->buf;
+    struct rset_temp_info *info = ct->buf;
+    struct rset_temp_rfd *rfd;
 
     assert (info->fd == -1);
     if (info->fname)
@@ -115,13 +125,15 @@ static int r_open(struct rset_control *ct, int wflag)
             exit (1);
         }
     }
+    rfd = xmalloc (sizeof(*rfd));
+    rfd->info = info;
     r_rewind (ct);
-    return 0;
+    return rfd;
 }
 
-static void r_flush (struct rset_control *ct, int mk)
+static void r_flush (RSFD rfd, int mk)
 {
-    struct rset_temp_private *info = ct->buf;
+    struct rset_temp_info *info = ((struct rset_temp_rfd*) rfd)->info;
 
     if (!info->fname && mk)
     {
@@ -162,11 +174,11 @@ static void r_flush (struct rset_control *ct, int mk)
     }
 }
 
-static void r_close (struct rset_control *ct)
+static void r_close (RSFD rfd)
 {
-    struct rset_temp_private *info = ct->buf;
+    struct rset_temp_info *info = ((struct rset_temp_rfd*)rfd)->info;
 
-    r_flush (ct, 0);
+    r_flush (rfd, 0);
     if (info->fname && info->fd != -1)
     {
         close (info->fd);
@@ -176,7 +188,7 @@ static void r_close (struct rset_control *ct)
 
 static void r_delete (struct rset_control *ct)
 {
-    struct rset_temp_private *info = ct->buf;
+    struct rset_temp_info *info = ct->buf;
 
     r_close (ct);
     if (info->fname)
@@ -186,9 +198,9 @@ static void r_delete (struct rset_control *ct)
     free (info);
 }
 
-static void r_reread (struct rset_control *ct)
+static void r_reread (RSFD rfd)
 {
-    struct rset_temp_private *info = ct->buf;
+    struct rset_temp_info *info = ((struct rset_temp_rfd*)rfd)->info;
 
     if (info->fname)
     {
@@ -213,35 +225,36 @@ static void r_reread (struct rset_control *ct)
         info->pos_border = info->pos_end;
 }
 
-static void r_rewind (struct rset_control *ct)
+static void r_rewind (RSFD rfd)
 {
-    struct rset_temp_private *info = ct->buf;
+    struct rset_temp_info *info = ((struct rset_temp_rfd*)rfd)->info;
 
-    r_flush (ct, 0);
+    r_flush (rfd, 0);
     info->pos_cur = 0;
     info->pos_buf = 0;
-    r_reread (ct);
+    r_reread (rfd);
 }
 
 static int r_count (struct rset_control *ct)
 {
-    struct rset_temp_private *info = ct->buf;
+    struct rset_temp_info *info = ct->buf;
 
     return info->pos_end / info->key_size;
 }
 
-static int r_read (rset_control *ct, void *buf)
+static int r_read (RSFD rfd, void *buf)
 {
-    struct rset_temp_private *info = ct->buf;
+    struct rset_temp_info *info = ((struct rset_temp_rfd*)rfd)->info;
+
     size_t nc = info->pos_cur + info->key_size;
 
     if (nc > info->pos_border)
     {
         if (nc > info->pos_end)
             return 0;
-        r_flush (ct, 0);
+        r_flush (rfd, 0);
         info->pos_buf = info->pos_cur;
-        r_reread (ct);
+        r_reread (rfd);
     }
     memcpy (buf, info->buf_mem + (info->pos_cur - info->pos_buf),
             info->key_size);
@@ -249,16 +262,17 @@ static int r_read (rset_control *ct, void *buf)
     return 1;
 }
 
-static int r_write (rset_control *ct, const void *buf)
+static int r_write (RSFD rfd, const void *buf)
 {
-    struct rset_temp_private *info = ct->buf;
+    struct rset_temp_info *info = ((struct rset_temp_rfd*)rfd)->info;
+
     size_t nc = info->pos_cur + info->key_size;
 
     if (nc > info->pos_buf + info->buf_size)
     {
-        r_flush (ct, 1);
+        r_flush (rfd, 1);
         info->pos_buf = info->pos_cur;
-        r_reread (ct);
+        r_reread (rfd);
     }
     memcpy (info->buf_mem + (info->pos_cur - info->pos_buf), buf,
             info->key_size);