From 91103235348e0ebf2a602f6db2dc429fe5289739 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Sun, 20 Apr 2025 22:49:48 +0300 Subject: Add files --- .gitignore | 1 + LICENSE | 10 ++++++++++ Makefile | 24 ++++++++++++++++++++++++ README | 13 +++++++++++++ deansi.1 | 20 ++++++++++++++++++++ deansi.c | 22 ++++++++++++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README create mode 100644 deansi.1 create mode 100644 deansi.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..75ab262 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +deansi diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7ae8865 --- /dev/null +++ b/LICENSE @@ -0,0 +1,10 @@ +Permission to use, copy, modify, and/or distribute this software for +any purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL +WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE +FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN +AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e666b2e --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +RM ?= rm -f +PREFIX ?= /usr/local/ +BINDIR ?= ${PREFIX}/bin +MANDIR ?= ${PREFIX}/man + + +.PHONY: all +all: deansi + +install: all + install -d ${BINDIR} ${MANDIR}/man1 + install -m755 deansi ${BINDIR} + install -m644 deansi.1 ${MANDIR}/man1 + +uninstall: + ${RM} ${BINDIR}/deansi + ${RM} ${MANDIR}/man1/deansi.1 + +.PHONY: clean +clean: + ${RM} deansi + +README: deansi.1 + mandoc -Ios=deansi -Tascii deansi.1 | col -b > README diff --git a/README b/README new file mode 100644 index 0000000..b6319cc --- /dev/null +++ b/README @@ -0,0 +1,13 @@ +DEANSI(1) General Commands Manual DEANSI(1) + +NAME + deansi - remove ansi escape sequences + +SYNOPSIS + deansi + +DESCRIPTION + deansi prints input excluding every control sequence introducer commands + from the input, allowing to read output in tools like less(1) without -R. + +deansi April 20, 2025 deansi diff --git a/deansi.1 b/deansi.1 new file mode 100644 index 0000000..ecbc7b9 --- /dev/null +++ b/deansi.1 @@ -0,0 +1,20 @@ +.Dd April 20, 2025 +.Dt DEANSI 1 +.Os +. +.Sh NAME +.Nm deansi +.Nd remove ansi escape sequences +. +.Sh SYNOPSIS +.Nm +. +.Sh DESCRIPTION +.Nm +prints input +excluding every control sequence introducer commands +from the input, +allowing to read output in tools like +.Xr less 1 +without +.Fl R . diff --git a/deansi.c b/deansi.c new file mode 100644 index 0000000..d1194eb --- /dev/null +++ b/deansi.c @@ -0,0 +1,22 @@ +#include + + +int main(int argc, char **argv) +{ + int ch, next, csi; + + csi = 0; + while ((ch = getchar()) != EOF) + { + if (ch == 27 /* ^[ */) + if ((next = getchar()) == '[') + csi = 1; + else if (next != EOF) + ungetc(next, stdin); + if (!csi) + putchar(ch); + if (ch >= 0x40 && ch <= 0x7e) + csi = 0; + } + return ferror(stdin); +} -- cgit 1.4.1