Skip to content

Commit

Permalink
[sort_ros] add -u switch to unique output
Browse files Browse the repository at this point in the history
  • Loading branch information
roytam1 committed Dec 9, 2024
1 parent f7da6e1 commit b82f798
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions sort_ros/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
/* Reverse flag */
int rev;

/* Unique flag */
int uniq;

/* Help flag */
int help;

Expand Down Expand Up @@ -79,6 +82,7 @@ void usage(void)
fputs(" Command | SORT [options] > [drive:][path]file\n", stderr);
fputs(" Options:\n", stderr);
fputs(" /R Reverse order\n", stderr);
fputs(" /U Unique ouput\n", stderr);
fputs(" /+n Start sorting with column n\n", stderr);
fputs(" /? Help\n", stderr);
}
Expand All @@ -94,6 +98,7 @@ int main(int argc, char **argv)

sortcol = 0;
rev = 0;
uniq = 0;
while (--argc)
{
if (*(cp = *++argv) == '/')
Expand All @@ -105,6 +110,11 @@ int main(int argc, char **argv)
rev = 1;
break;

case 'U':
case 'u':
uniq = 1;
break;

case '?':
case 'h':
case 'H':
Expand Down Expand Up @@ -186,8 +196,14 @@ int main(int argc, char **argv)

for (i = 0; i < nr; i++)
{
fputs(list[i], stdout);
fputs("\n", stdout);
int print = 1;
if(uniq && i > 0 && !strcmp(list[i-1],list[i]))
print = 0;

if(print) {
fputs(list[i], stdout);
fputs("\n", stdout);
}
}

/* Cleanup memory */
Expand Down

0 comments on commit b82f798

Please sign in to comment.