C-Menu
0.2.9
A User Interface Toolkit
Toggle main menu visibility
Loading...
Searching...
No Matches
stripansi.c
Go to the documentation of this file.
1
/** @file stripansi.c
2
@brief removes ansi escape sequences beginning with "\033["" and ending in
3
"m" or "K"
4
@author Bill Waller
5
Copyright (c) 2025, 2026
6
MIT License
7
billxwaller@gmail.com
8
@date 2026-02-09
9
*/
10
11
#
include
<
cm
.
h
>
12
#
include
<
stdio
.
h
>
13
14
/** @brief strip ANSI SGR sequences
15
@param argc Argument count (should be 2 for the program name and input file)
16
@param argv Argument vector (argv[1] should be the input file name)
17
@details This function iterates through the input string, copying characters
18
to the output buffer while skipping over any ANSI escape sequences. It looks
19
for sequences that start with "\033[" and end with "m" or "K", and removes
20
them from the output. */
21
int
main
(
int
argc,
char
*argv[]) {
22
char
23
in_buf[2048];
/**< Buffer to hold the input string read from the file */
24
char
out_buf[2048];
/**< Buffer to hold the cleaned output string */
25
if
(argc != 2) {
26
fprintf(stderr,
"Usage: %s [file_with_ansi_codes]\n"
, argv[0]);
27
return
1;
28
}
29
FILE *in_fp = fopen(argv[1],
"r"
);
30
if
(!in_fp) {
31
perror(
"Error opening file"
);
32
return
1;
33
}
34
while
(fgets(in_buf,
sizeof
(in_buf), in_fp)) {
35
strip_ansi
(
out_buf
,
in_buf
)
;
36
fputs(out_buf, stdout);
37
}
38
fclose(in_fp);
39
return
0;
40
}
main
int main(int argc, char **argv)
Definition
amort.c:30
strip_ansi
size_t strip_ansi(char *, char *)
Strips ANSI SGR escape sequences (ending in 'm') from string s to d.
Definition
futil.c:829
stripansi.c
Generated by
1.17.0