dj(1): more work adapting hard skipping to the main loop

This commit is contained in:
dtb 2024-07-04 20:16:54 -06:00
parent 1fab60d779
commit 9f420131ee
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B

View File

@ -270,23 +270,27 @@ int main(int argc, char *argv[]){
return oserr(io[i].fn); return oserr(io[i].fn);
do{ do{
assert(io[0].bufuse == 0);
{ /* read */ { /* read */
static char skipping = 0; static char skipping = 0;
int t;
if(io[0].seek > 0) if(io[0].seek > 0)
skipping = 1; 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 */ 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; 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); fprintf(stderr, "%s: Partial read:\n\t", program_name);
fprintio(stderr, fmt, io); fprintio(stderr, fmt, io);
if(!noerror) if(!noerror)
count = 1; count = 1;
if(align >= 0){ if(!skipping && align >= 0){
/* fill the rest of the ibuf with padding */ /* fill the rest of the ibuf with padding */
memset(&(io[0].buf)[io[0].bufuse], align, memset(&(io[0].buf)[io[0].bufuse], align,
io[0].bs - io[0].bufuse); 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))); (n = MIN(io[0].bufuse, io[1].bs - io[1].bufuse)));
io[1].bufuse += n; io[1].bufuse += n;
/* permute out the copied units */ /* 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; io[0].bufuse -= n;
if(io[0].bs + io[1].bufuse <= io[1].bs && count != 1) if(io[0].bs + io[1].bufuse <= io[1].bs && count != 1)
@ -330,7 +334,7 @@ int main(int argc, char *argv[]){
break; 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); fprintf(stderr, "%s: Partial write:\n\t", program_name);
fprintio(stderr, fmt, io); fprintio(stderr, fmt, io);
if(!noerror) if(!noerror)