]> mj.ucw.cz Git - libucw.git/commitdiff
Fastbuf: fbmulti allows reading of one subbuf more times
authorJan 'Moskyt' Matejka <mq@ucw.cz>
Mon, 9 Jul 2012 13:42:30 +0000 (15:42 +0200)
committerJan 'Moskyt' Matejka <mq@ucw.cz>
Thu, 19 Jul 2012 13:25:27 +0000 (15:25 +0200)
ucw/fb-multi.c
ucw/fb-multi.t

index 20d8590e7f110401f192d53173faad5660672d55..c9eac1511ed89e75ed10e1010a13e2537c0fd89a 100644 (file)
@@ -46,8 +46,11 @@ fbmulti_subbuf_next(struct fastbuf *f)
   if (next == NULL)
     return 0;
   
-  if (f->seek)
+  if (f->seek) {
+    bseek(FB_MULTI(f)->cur->fb, 0, SEEK_SET);
     next->begin = FB_MULTI(f)->cur->end;
+  }
+
   FB_MULTI(f)->cur = next;
   return 1;
 }
@@ -219,6 +222,24 @@ int main(int argc, char ** argv)
            putchar(bgetc(f));
          }
 
+         bclose(f);
+         break;
+       }
+      case 'i':
+       {
+         char *data = "Insae";
+         struct fastbuf fb[4];
+         fbbuf_init_read(&fb[0], data, 1, 0);
+         fbbuf_init_read(&fb[1], data + 1, 1, 0);
+         fbbuf_init_read(&fb[2], data + 2, 2, 0);
+         fbbuf_init_read(&fb[3], data + 4, 1, 0);
+
+         struct fastbuf* f = fbmulti_create(8, &fb[0], &fb[1], &fb[2], &fb[1], &fb[3], NULL);
+
+         char buffer[9];
+         while(bgets(f, buffer, 9))
+           puts(buffer);
+
          bclose(f);
          break;
        }
index de8190fd8e1914a0e6ae1f8654f77bf80877fb75..0b8a11fcdd6e2c22b55685be52fa14256841e63c 100644 (file)
@@ -11,3 +11,7 @@ Out:  One
 Name:  Read Mingle
 Run:   ../obj/ucw/fb-multi-t m
 Out:   Mingle
+
+Name:  Read Insane
+Run:   ../obj/ucw/fb-multi-t i
+Out:   Insane