From 3a66022c6d735a3def3e52f4883178dfafe6d24f Mon Sep 17 00:00:00 2001 From: DTB Date: Wed, 26 Jun 2024 15:28:02 -0600 Subject: [PATCH] dj(1): more refactor (get rid of the c scratch variable, use scoping) --- src/dj.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/dj.c b/src/dj.c index 5632645..a9e7cdf 100644 --- a/src/dj.c +++ b/src/dj.c @@ -287,7 +287,7 @@ int main(int argc, char *argv[]){ program_name = argv[0]; while((c = getopt(argc, argv, "a:b:B:c:i:hHns:S:o:")) != -1) switch(c){ - case 'i': case 'o': i = (c == 'o') + case 'i': case 'o': i = (c == 'o'); if(optarg[0] == '-' && optarg[1] == '\0'){ /* optarg == "-" */ io[i].fd = i ? STDIN_FILENO : STDOUT_FILENO; io[i].fn = i ? stdin_name : stdout_name; @@ -356,27 +356,30 @@ int main(int argc, char *argv[]){ ++io[0].rec; /* write */ - do{ if(io[1].bs > io[0].bs){ + do{ + int t; + + if(io[1].bs > io[0].bs){ Io_bufxapp(&io[1], &io[0]); if(io[0].bs + io[1].bufuse <= io[1].bs && count != 1) continue; /* we could write more */ }else Io_bufxfer(&io[1], &io[0], MIN(io[0].bufuse, io[1].bs)); - c = io[1].bufuse; + t = io[1].bufuse; Io_write(&io[1]); - if(!noerror && io[1].bufuse == c) + if(!noerror && io[1].bufuse == t) Io_write(&io[1]); /* second chance */ - if(c == io[1].bufuse){ /* no more love */ + if(t == io[1].bufuse){ /* no more love */ count = 1; break; - }else if(c > io[1].bufuse && io[1].bufuse > 0){ + }else if(t > io[1].bufuse && io[1].bufuse > 0){ io[1].prec += 1; fprintf(stderr, "%s: Partial write:\n\t", program_name); output(io, fmt_output); if(!noerror) count = 1; - }else if(io[1].bufuse == 0 && c < io[1].bs) + }else if(io[1].bufuse == 0 && t < io[1].bs) ++io[1].prec; else ++io[1].rec;