dj(1): remove do/while statement in read loop

This commit is contained in:
dtb 2024-07-19 19:18:04 -06:00
parent c8b4f7a8b3
commit 9086bf0d08
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B

View File

@ -158,7 +158,7 @@ usage(char *s) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int align; /* low 8b used, negative if no alignment is being done */ int align; /* low 8b used, negative if no alignment is being done */
int count; /* 0 if dj(1) runs until no more reads are possible */ int count; /* -1 if dj(1) runs until no more reads are possible */
char *fmt; /* == fmt_asv (default) or fmt_human (-H) */ char *fmt; /* == fmt_asv (default) or fmt_human (-H) */
size_t i; /* side of io being modified */ size_t i; /* side of io being modified */
char noerror; /* 0=exits (default) 1=retries on partial reads or writes */ char noerror; /* 0=exits (default) 1=retries on partial reads or writes */
@ -166,7 +166,7 @@ int main(int argc, char *argv[]) {
/* Set defaults. */ /* Set defaults. */
align = -1; align = -1;
count = 0; count = -1;
fmt = fmt_asv; fmt = fmt_asv;
noerror = 0; noerror = 0;
for (i = 0; i < (sizeof io) / (sizeof *io); ++i) { for (i = 0; i < (sizeof io) / (sizeof *io); ++i) {
@ -284,7 +284,10 @@ int main(int argc, char *argv[]) {
return oserr(io[1].fn, errno); return oserr(io[1].fn, errno);
} }
do { /* while(count == 0 || --count > 0); */ for ( ;
count == -1 || count > 0;
count -= (count != -1) /* decrement if counting */
) {
assert(io[0].bufuse == 0); assert(io[0].bufuse == 0);
{ /* read */ { /* read */
@ -303,7 +306,7 @@ int main(int argc, char *argv[]) {
assert(io[0].bufuse >= t); assert(io[0].bufuse >= t);
if (io[0].bufuse == t) /* that's all she wrote */ { break; } if (io[0].bufuse == t) { break; } /* that's all she wrote */
if (/* t < io[0].bufuse && */ 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);
@ -326,7 +329,7 @@ int main(int argc, char *argv[]) {
if (skipping > 0) { if (skipping > 0) {
io[0].seek -= skipping; io[0].seek -= skipping;
io[0].bufuse = 0; io[0].bufuse = 0;
count += (count != 0); count += (count != -1); /* increment if counting */
continue; continue;
} }
} }
@ -393,7 +396,7 @@ int main(int argc, char *argv[]) {
if(!noerror) { count = 1; } if(!noerror) { count = 1; }
} }
} }
} while(count == 0 || --count > 0); }
fprintio(stderr, fmt, io); fprintio(stderr, fmt, io);