Update of /cvsroot/monetdb/MonetDB4/src/modules/plain
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv29439/src/modules/plain

Modified Files:
        ascii_io.mx 
Log Message:
add support for line offsets (ie ignore the first N lines)


Index: ascii_io.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB4/src/modules/plain/ascii_io.mx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- ascii_io.mx 10 Dec 2007 18:04:14 -0000      1.16
+++ ascii_io.mx 13 Dec 2007 14:50:31 -0000      1.17
@@ -907,18 +907,20 @@
 ASCIIload_file(ascii *as, bstream *b, stream *out)
 {
        int res = 0, done = 0;
-       size_t i = 0;
+       size_t i = 1;
        char *sep = as->format[as->nr_attrs - 1].sep;
        int seplen = as->format[as->nr_attrs - 1].seplen;
+       size_t nr = as->offset + as->nr;
+       size_t offset = as->offset;
 
        if (ascii_io_debug)
                stream_printf(GDKerr, "ASCIIload_file\n");
 
-       while ((b->pos < b->len || !b->eof) && res == 0 && (as->nr == ~(size_t) 
0 || i < as->nr)) {
+       while ((b->pos < b->len || !b->eof) && res == 0 && (nr == ~(size_t) 0 
|| i <= nr)) {
                char *s, *end;
 
                if (b->pos >= b->len && read_more(b, out, b->size - (b->len - 
b->pos)) == EOF) {
-                       if (as->nr != ~(size_t)0 && i < as->nr) {
+                       if (nr != ~(size_t)0 && i <= nr) {
                                res = 1; 
                                if (b->len > b->pos) {
                                        GDKerror("ASCIIload_file: read error 
(after loading %d records)\n", BATcount(as->format[0].c));
@@ -936,7 +938,7 @@
 
                        if (e) {
                                *e = '\0';
-                               if (insert_line(as, s) < 0) {
+                               if (i>=offset && insert_line(as, s) < 0) {
                                        s = e + seplen;
                                        b->pos = (s - b->buf);
                                        res = -1;
@@ -956,6 +958,7 @@
                                                /* some data left? */
                                                res = 1; 
                                                if (b->len > b->pos &&
+                                                   i>=offset &&
                                                    insert_line(as, s) < 0) {
                                                        
GDKerror("ASCIIload_file: read error (after loading %d records)\n", 
BATcount(as->format[0].c));
                                                        res = -1;
@@ -973,11 +976,11 @@
                        i++;
                        if (ascii_io_debug && (i % 100000) == 0)
                                stream_printf(GDKerr, "inserted " SZFMT "\n", 
i);
-                       if (as->nr != ~(size_t) 0 && i >= as->nr)
+                       if (nr != ~(size_t) 0 && i > nr)
                                break;
                }
        }
-       as->nr = i;
+       as->nr = i-as->offset-1;
        if (res < 0)
                return res;
        return (ssize_t) as->nr;


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to