From 9f420131ee591ad97847cc1599c05fbd8b2e0203 Mon Sep 17 00:00:00 2001 From: DTB Date: Thu, 4 Jul 2024 20:16:54 -0600 Subject: [PATCH] dj(1): more work adapting hard skipping to the main loop --- src/dj.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/dj.c b/src/dj.c index e3972aa..aee9c38 100644 --- a/src/dj.c +++ b/src/dj.c @@ -270,23 +270,27 @@ int main(int argc, char *argv[]){ return oserr(io[i].fn); do{ + assert(io[0].bufuse == 0); + { /* read */ static char skipping = 0; + int t; if(io[0].seek > 0) skipping = 1; - if(Io_read(&io[0])->bufuse == 0 && !noerror) + t = io[0].bufuse; + if(Io_read(&io[0])->bufuse == t && !noerror) Io_read(&io[0]); /* second chance */ - if(io[0].bufuse == 0) /* that's all she wrote */ + if(io[0].bufuse == t) /* that's all she wrote */ break; - if(io[0].bufuse < io[0].bs){ + if(/* t < io[0].bufuse && */ io[0].bufuse < io[0].bs){ fprintf(stderr, "%s: Partial read:\n\t", program_name); fprintio(stderr, fmt, io); if(!noerror) count = 1; - if(align >= 0){ + if(!skipping && align >= 0){ /* fill the rest of the ibuf with padding */ memset(&(io[0].buf)[io[0].bufuse], align, io[0].bs - io[0].bufuse); @@ -315,7 +319,7 @@ int main(int argc, char *argv[]){ (n = MIN(io[0].bufuse, io[1].bs - io[1].bufuse))); io[1].bufuse += n; /* permute out the copied units */ - memmove(io[0].buf, &{io[0].buf)[n], io[0].bs - n); + memmove(io[0].buf, &(io[0].buf)[n], io[0].bs - n); io[0].bufuse -= n; if(io[0].bs + io[1].bufuse <= io[1].bs && count != 1) @@ -330,7 +334,7 @@ int main(int argc, char *argv[]){ break; } - if(0 < io[1].bufuse && io[1].bufuse < t){ + if(0 < io[1].bufuse /* && io[1].bufuse < t */){ fprintf(stderr, "%s: Partial write:\n\t", program_name); fprintio(stderr, fmt, io); if(!noerror)