uniq: Clean up and test obsolete options.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D43402
This commit is contained in:
Dag-Erling Smørgrav 2024-01-12 16:40:40 +01:00
parent 11715600e6
commit e2ec8ee02a
2 changed files with 8 additions and 9 deletions

View file

@ -74,6 +74,7 @@ skip_fields_head() {
skip_fields_body() {
printf "1 a\n2 a\n3 b\n4 b\n5 a\n6 a\n" >input
printf "1 a\n3 b\n5 a\n" >expected
atf_check_uniq -1
atf_check_uniq -f 1
atf_check_uniq --skip-fields 1
}
@ -85,6 +86,7 @@ skip_fields_tab_head() {
skip_fields_tab_body() {
printf "1\ta\n2\ta\n3\tb\n4\tb\n5\ta\n6\ta\n" >input
printf "1\ta\n3\tb\n5\ta\n" >expected
atf_check_uniq -1
atf_check_uniq -f 1
atf_check_uniq --skip-fields 1
}
@ -107,6 +109,7 @@ skip_chars_head() {
skip_chars_body() {
printf "1 a\n2 a\n3 b\n4 b\n5 a\n6 a\n" >input
printf "1 a\n3 b\n5 a\n" >expected
atf_check_uniq +2
atf_check_uniq -s 2
atf_check_uniq --skip-chars 2
}

View file

@ -338,29 +338,25 @@ file(const char *name, const char *mode)
static void
obsolete(char *argv[])
{
int len;
char *ap, *p, *start;
char *ap, *p;
while ((ap = *++argv)) {
/* Return if "--" or not an option of any form. */
if (ap[0] != '-') {
if (ap[0] != '+')
return;
} else if (ap[1] == '-')
} else if (ap[1] == '-') {
return;
}
if (!isdigit((unsigned char)ap[1]))
continue;
/*
* Digit signifies an old-style option. Malloc space for dash,
* new option and argument.
*/
len = strlen(ap);
if ((start = p = malloc(len + 3)) == NULL)
if (asprintf(&p, "-%c%s", ap[0] == '+' ? 's' : 'f', ap + 1) < 0)
err(1, "malloc");
*p++ = '-';
*p++ = ap[0] == '+' ? 's' : 'f';
(void)strcpy(p, ap + 1);
*argv = start;
*argv = p;
}
}