Skip to content

Commit 2a74ccd

Browse files
authored
cat: add -A flag (equivalent to GNU cat -A) (#357)
Add -A flag to cat(1) utility, which is equivalent to -et (enables vflag, eflag, and tflag). This matches the behavior of GNU cat. Updated man page and added a new ATF test case to verify equivalence. AI-Assisted-by: Gemini CLI <noreply@google.com>
1 parent 327827f commit 2a74ccd

4 files changed

Lines changed: 40 additions & 4 deletions

File tree

bin/cat/cat.1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@
3939
.Nd concatenate and print files
4040
.Sh SYNOPSIS
4141
.Nm
42-
.Op Fl belnstuv
42+
.Op Fl Abelnstuv
4343
.Op Ar
4444
.Sh DESCRIPTION
45-
The
4645
.Nm
4746
utility reads files sequentially, writing them to the standard output.
4847
The
@@ -70,6 +69,15 @@ domain binding capability available in
7069
.Pp
7170
The options are as follows:
7271
.Bl -tag -width indent
72+
.It Fl A
73+
Display non-printing characters (see the
74+
.Fl v
75+
option), display a dollar sign
76+
.Pq Ql \&$
77+
at the end of each line, and display tab characters as
78+
.Ql ^I .
79+
Equivalent to
80+
.Fl et .
7381
.It Fl b
7482
Number the non-blank output lines, starting at 1.
7583
.It Fl e
@@ -185,7 +193,7 @@ utility is compliant with the
185193
specification.
186194
.Pp
187195
The flags
188-
.Op Fl belnstv
196+
.Op Fl Abelnstv
189197
are extensions to the specification.
190198
.Sh HISTORY
191199
A

bin/cat/cat.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int udom_open(const char *path, int flags);
116116
#ifdef BOOTSTRAP_CAT
117117
#define SUPPORTED_FLAGS "lu"
118118
#else
119-
#define SUPPORTED_FLAGS "belnstuv"
119+
#define SUPPORTED_FLAGS "Abelnstuv"
120120
#endif
121121

122122
#ifndef NO_UDOM_SUPPORT
@@ -176,6 +176,9 @@ main(int argc, char *argv[])
176176

177177
while ((ch = getopt(argc, argv, SUPPORTED_FLAGS)) != -1)
178178
switch (ch) {
179+
case 'A':
180+
eflag = tflag = vflag = 1;
181+
break;
179182
case 'b':
180183
bflag = nflag = 1; /* -b implies -n */
181184
break;

bin/cat/tests/A_flag_test.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# SPDX-License-Identifier: BSD-2-Clause
3+
#
4+
# Copyright (c) 2026 MidnightBSD
5+
#
6+
7+
atf_test_case A_flag
8+
A_flag_head()
9+
{
10+
atf_set "descr" "Verify that -A is equivalent to -et"
11+
}
12+
13+
A_flag_body()
14+
{
15+
printf "tab\tchar\nnon-print\001\nend" > input
16+
atf_check -o save:expected cat -et input
17+
atf_check -o file:expected cat -A input
18+
}
19+
20+
atf_init_test_cases()
21+
{
22+
atf_add_test_case A_flag
23+
}

bin/cat/tests/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ PACKAGE= tests
33

44
NETBSD_ATF_TESTS_SH= cat_test
55

6+
ATF_TESTS_SH+= A_flag_test
7+
68
${PACKAGE}FILES+= d_align.in
79
${PACKAGE}FILES+= d_align.out
810
${PACKAGE}FILES+= d_b_output.in

0 commit comments

Comments
 (0)