about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2025-04-20 22:49:48 +0300
committerNakidai <nakidai@disroot.org>2025-04-20 22:49:48 +0300
commit91103235348e0ebf2a602f6db2dc429fe5289739 (patch)
tree232675179519783d3c049205eeb1417383d60113
downloaddeansi-91103235348e0ebf2a602f6db2dc429fe5289739.tar.gz
deansi-91103235348e0ebf2a602f6db2dc429fe5289739.zip
Add files v1.0.0
-rw-r--r--.gitignore1
-rw-r--r--LICENSE10
-rw-r--r--Makefile24
-rw-r--r--README13
-rw-r--r--deansi.120
-rw-r--r--deansi.c22
6 files changed, 90 insertions, 0 deletions
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 <stdio.h>
+
+
+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);
+}