aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-11-02 19:09:22 -0500
committerRob Landley <rob@landley.net>2018-11-02 19:09:22 -0500
commit49e1d8733ebcaf130623c68a2393a3c43702a524 (patch)
tree24b60a4f13ed5ca4b87e0fa8094fdb7d73b6a4e8 /toys/posix
parent6a6b12317149b41b163513e345f43167778f113f (diff)
downloadtoybox-49e1d8733ebcaf130623c68a2393a3c43702a524.tar.gz
Trivial cleanup of uniq.c.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/uniq.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/toys/posix/uniq.c b/toys/posix/uniq.c
index c127cfe9..114fc19b 100644
--- a/toys/posix/uniq.c
+++ b/toys/posix/uniq.c
@@ -31,18 +31,18 @@ GLOBALS(
long maxchars;
long nchars;
long nfields;
+
long repeats;
)
static char *skip(char *str)
{
- long nchars = TT.nchars, nfields;
+ long nchars = TT.nchars, nfields = TT.nfields;
// Skip fields first
- for (nfields = TT.nfields; nfields; str++) {
+ while (nfields--) {
while (*str && isspace(*str)) str++;
while (*str && !isspace(*str)) str++;
- nfields--;
}
// Skip chars
while (*str && nchars--) str++;
@@ -61,7 +61,7 @@ static void print_line(FILE *f, char *line)
void uniq_main(void)
{
FILE *infile = stdin, *outfile = stdout;
- char *thisline = NULL, *prevline = NULL, *tmpline, eol = '\n';
+ char *thisline = 0, *prevline = 0, *tmpline, eol = '\n';
size_t thissize, prevsize = 0, tmpsize;
if (toys.optc >= 1) infile = xfopen(toys.optargs[0], "r");
@@ -70,8 +70,7 @@ void uniq_main(void)
if (toys.optflags & FLAG_z) eol = 0;
// If first line can't be read
- if (getdelim(&prevline, &prevsize, eol, infile) < 0)
- return;
+ if (getdelim(&prevline, &prevsize, eol, infile) < 0) return;
while (getdelim(&thisline, &thissize, eol, infile) > 0) {
int diff;
@@ -86,16 +85,13 @@ void uniq_main(void)
t2 = prevline;
}
- if (TT.maxchars == 0) {
+ if (TT.maxchars == 0)
diff = !(toys.optflags & FLAG_i) ? strcmp(t1, t2) : strcasecmp(t1, t2);
- } else {
- diff = !(toys.optflags & FLAG_i) ? strncmp(t1, t2, TT.maxchars)
- : strncasecmp(t1, t2, TT.maxchars);
- }
+ else diff = !(toys.optflags & FLAG_i) ? strncmp(t1, t2, TT.maxchars)
+ : strncasecmp(t1, t2, TT.maxchars);
- if (diff == 0) { // same
- TT.repeats++;
- } else {
+ if (!diff) TT.repeats++;
+ else {
print_line(outfile, prevline);
TT.repeats = 0;