about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2025-01-10 04:07:36 +0300
committerNakidai <nakidai@disroot.org>2025-01-10 04:07:36 +0300
commite8a758d1a1b3fd6db757196268ff02375a6a73da (patch)
tree042faa3dc8b2159ef1a5f4ac05b30c53c3a0fcc5
parentac86a131a75474bcc77b92b3d3833f74e1878bfb (diff)
downloadtr2cyr-e8a758d1a1b3fd6db757196268ff02375a6a73da.tar.gz
tr2cyr-e8a758d1a1b3fd6db757196268ff02375a6a73da.zip
Make this cooler v1.1.0
Now it's a library (installable) UwU
-rw-r--r--.gitignore3
-rw-r--r--Makefile71
-rw-r--r--tr2cyr.3117
-rw-r--r--tr2cyr.c60
-rw-r--r--tr2cyr.h12
-rw-r--r--tr2cyr_exec.c23
6 files changed, 221 insertions, 65 deletions
diff --git a/.gitignore b/.gitignore
index 251ecbd..076f64d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
 tr2cyr
+*.o
+*.a
+*.so
diff --git a/Makefile b/Makefile
index 55836a3..15ce722 100644
--- a/Makefile
+++ b/Makefile
@@ -1,17 +1,74 @@
 DESTDIR ?= /usr/local
 
-all: tr2cyr
+CFLAGS.tr2cyr += -DEXEC
+
+OBJS += tr2cyr.o
+OBJS.tr2cyr += tr2cyr_exec.o
+
+
+all: tr2cyr tr2cyr.a tr2cyr.so
+
+tr2cyr tr2cyr.a tr2cyr.so: ${OBJS}
+tr2cyr: ${OBJS.tr2cyr}
+
+tr2cyr.c tr2cyr_exec.c: tr2cyr.h
+
+.SUFFIXES: .o .a
+.o.a:
+	${AR} rcs $@ $^
+
+.SUFFIXES: .o .so
+.o.so:
+	${LD} -shared -o $@ ${LDFLAGS} ${LDLIBS} $^
 
 README: README.7
 	mandoc -Tascii $< | col -b > $@
 
-install: tr2cyr
-	install -d ${DESTDIR}/bin ${DESTDIR}/share/man/man1
+clean:
+	${RM} tr2cyr tr2cyr.a tr2cyr.so ${OBJS} ${OBJS.tr2cyr}
+
+
+.PHONY: install
+install: install_bin install_lib install_man1 install_man3
+
+.PHONY: install_bin
+install_bin: tr2cyr
+	install -d ${DESTDIR}/bin
 	install -m755 tr2cyr ${DESTDIR}/bin
+
+.PHONY: install_lib
+install_lib: tr2cyr.a tr2cyr.so
+	install -d ${DESTDIR}/lib ${DESTDIR}/include
+	install -m644 tr2cyr.a ${DESTDIR}/lib
+	install -m755 tr2cyr.so ${DESTDIR}/lib
+	install -m644 tr2cyr.h ${DESTDIR}/include
+
+.PHONY: install_man1
+install_man1:
+	install -d ${DESTDIR}/share/man/man1
 	install -m644 tr2cyr.1 ${DESTDIR}/share/man/man1
 
-uninstall:
-	${RM} ${DESTDIR}/bin/tr2cyr ${DESTDIR}/share/man/man1/tr2cyr.1
+.PHONY: install_man3
+install_man3:
+	install -d ${DESTDIR}/share/man/man3
+	install -m644 tr2cyr.3 ${DESTDIR}/share/man/man3
 
-clean:
-	${RM} tr2cyr
+
+.PHONY: uninstall
+uninstall: uninstall_bin uninstall_lib uninstall_man1 uninstall_man3
+
+.PHONY: uninstall_bin
+uninstall_bin:
+	${RM} ${DESTDIR}/bin/tr2cyr
+
+.PHONY: uninstall_lib
+uninstall_lib:
+	${RM} ${DESTDIR}/lib/tr2cyr.a ${DESTDIR}/lib/tr2cyr.so ${DESTDIR}/include/tr2cyr.h
+
+.PHONY: uninstall_man1
+uninstall_man1:
+	${RM} ${DESTDIR}/share/man/man1/tr2cyr.1
+
+.PHONY: uninstall_man3
+uninstall_man3:
+	${RM} ${DESTDIR}/share/man/man1/tr2cyr.3
diff --git a/tr2cyr.3 b/tr2cyr.3
new file mode 100644
index 0000000..12d06f4
--- /dev/null
+++ b/tr2cyr.3
@@ -0,0 +1,117 @@
+.Dd January 10, 2025
+.Dt TR2CYR 3
+.Os
+.
+.Sh NAME
+.Nm tr2cyr
+.Nd Convert transliteration
+into cyrillic text
+.
+.Sh SYNOPSIS
+.In tr2cyr.h
+.
+.Ft int
+.Fo tr2cyr
+.Fa "tr2cyr_reader *reader"
+.Fa "void *readerarg"
+.Fa "tr2cyr_writer *writer"
+.Fa "void *writerarg"
+.Fc
+.
+.Sh DESCRIPTION
+.Fn tr2cyr
+calls
+.Fa reader
+until it returns
+.Dv WEOF
+calling
+.Fa writer
+with converted
+(or not)
+character.
+.Fa readerarg
+and
+.Fa writerarg
+are passed to
+.Fa reader
+and
+.Fa writer
+accordingly.
+.
+.Pp
+.Fn tr2cyr
+converts
+according to the table below
+.Bl -tag -width Ds
+.It Sy a 

+.It Sy b

+.It Sy v

+.It Sy g

+.It Sy d

+.It Sy e

+.It Sy yo

+.It Sy yz

+.It Sy z

+.It Sy i

+.It Sy j

+.It Sy k

+.It Sy l

+.It Sy m

+.It Sy n

+.It Sy o

+.It Sy p
+п
+.It Sy r

+.It Sy s

+.It Sy t

+.It Sy u

+.It Sy f

+.It Sy h

+.It Sy c

+.It Sy yc

+.It Sy ys

+.It Sy yg

+.It Sy y"

+.It Sy yi

+.It Sy y'

+.It Sy ye

+.It Sy yu

+.It Sy ya

+.El
+.
+.Sh BUGS
+You can tell me
+about bugs you encountered
+.Lk https://github.com/nakidai/tr2cyr/issues/new here .
diff --git a/tr2cyr.c b/tr2cyr.c
index fc6cfcb..7682d23 100644
--- a/tr2cyr.c
+++ b/tr2cyr.c
@@ -1,50 +1,11 @@
 #include <errno.h>
-#include <locale.h>
-#include <stddef.h>
-#include <stdio.h>
 #include <wchar.h>
 #include <wctype.h>
 
-/*
- * a = а
- * b = б
- * v = в
- * g = г
- * d = д
- * e = е
- * yo = ё
- * yz = ж
- * z = з
- * i = и
- * j = й
- * k = к
- * l = л
- * m = м
- * n = н
- * o = о
- * p = п
- * r = р
- * s = с
- * t = т
- * u = у
- * f = ф
- * h = х
- * c = ц
- * yc = ч
- * ys = ш
- * yg = щ
- * y" = ъ
- * yi = ы
- * y' = ь
- * ye = э
- * yu = ю
- * ya = я
- */
+#include "tr2cyr.h"
 
-typedef int Translator_Writer(wchar_t ch, void *arg);
-typedef wint_t Translator_Reader(size_t i, void *arg);
 
-int Translator_convert(Translator_Reader *reader, void *readerarg, Translator_Writer *writer, void *writerarg)
+int tr2cyr(tr2cyr_reader *reader, void *readerarg, tr2cyr_writer *writer, void *writerarg)
 {
     size_t i;
     int lowercase;
@@ -122,20 +83,3 @@ int Translator_convert(Translator_Reader *reader, void *readerarg, Translator_Wr
     }
     return errno ? -1 : 0;
 }
-
-static wint_t reader(size_t i, void *arg)
-{
-    return getwchar();
-}
-
-static int writer(wchar_t ch, void *arg)
-{
-    (void)arg;
-    return putwchar(ch) == WEOF ? -1 : 0;
-}
-
-int main(int argc, char **argv)
-{
-    setlocale(LC_CTYPE, "");
-    Translator_convert(&reader, 0, &writer, 0);
-}
diff --git a/tr2cyr.h b/tr2cyr.h
new file mode 100644
index 0000000..d551a58
--- /dev/null
+++ b/tr2cyr.h
@@ -0,0 +1,12 @@
+#ifndef __TR2CYR_H__
+#define __TR2CYR_H__
+
+#include <wchar.h>
+
+
+typedef int tr2cyr_writer(wchar_t ch, void *arg);
+typedef wint_t tr2cyr_reader(size_t i, void *arg);
+
+int tr2cyr(tr2cyr_reader *reader, void *readerarg, tr2cyr_writer *writer, void *writerarg);
+
+#endif /* __TR2CYR_H__ */
diff --git a/tr2cyr_exec.c b/tr2cyr_exec.c
new file mode 100644
index 0000000..762dc5e
--- /dev/null
+++ b/tr2cyr_exec.c
@@ -0,0 +1,23 @@
+#include <locale.h>
+#include <stdio.h>
+#include <wchar.h>
+
+#include "tr2cyr.h"
+
+
+static wint_t reader(size_t i, void *arg)
+{
+    return getwchar();
+}
+
+static int writer(wchar_t ch, void *arg)
+{
+    (void)arg;
+    return putwchar(ch) == WEOF ? -1 : 0;
+}
+
+int main(int argc, char **argv)
+{
+    setlocale(LC_CTYPE, "");
+    tr2cyr(&reader, 0, &writer, 0);
+}