commit c3b25703bf7d62c2bbac9dd4cd8bc7ec4cafa489 Author: 諏訪子 Date: Tue Jan 6 21:10:07 2026 +0900 SVNからのミラー diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f261af8 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +# 1.0.0 (2024/10) +* 開始 diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..777a97f --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,13 @@ +Copyright © 2018-2024 by 076.moe + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD +TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL ISC 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..721601a --- /dev/null +++ b/Makefile @@ -0,0 +1,101 @@ +UNAME_S != uname -s +UNAME_M != uname -m +OS = ${UNAME_S} +ARCH = ${UNAME_M} + +.if ${UNAME_S} == "OpenBSD" +OS = openbsd +.elif ${UNAME_S} == "NetBSD" +OS = netbsd +.elif ${UNAME_S} == "FreeBSD" +OS = freebsd +.elif ${UNAME_S} == "Linux" +OS = linux +.endif + +.if ${UNAME_M} == "x86_64" +ARCH = amd64 +.endif + +NAME = txtconv +UDDUNAME != cat uddu.c | grep "const char \*sofname" | awk '{print $$5}' |\ + sed "s/\"//g" | sed "s/;//" +UAAUNAME != cat uaau.c | grep "const char \*sofname" | awk '{print $$5}' |\ + sed "s/\"//g" | sed "s/;//" +ADDANAME != cat adda.c | grep "const char \*sofname" | awk '{print $$5}' |\ + sed "s/\"//g" | sed "s/;//" +VERSION != cat common.h | grep "const char \*version" | awk '{print $$5}' |\ + sed "s/\"//g" | sed "s/;//" + +PREFIX = /usr/local +.if ${UNAME_S} == "Linux" +PREFIX = /usr +.elif ${UNAME_S} == "Haiku" +PREFIX = /boot/home/config/non-packaged +.endif + +MANPREFIX = ${PREFIX}/share/man +.if ${UNAME_S} == "OpenBSD" +MANPREFIX = ${PREFIX}/man +.elif ${UNAME_S} == "Haiku" +MANPREFIX = ${PREFIX}/documentation/man +.endif + +CC = cc +CFLAGS = -Wall -Wextra -O3 + +LDFLAGS = -static -lc +.if ${UNAME_S} == "Haiku" || ${UNAME_S} == "Darwin" || ${UNAME_S} == "SunOS"\ + || ${UNAME_S} == "Minix" +LDFLAGS = -lc +.endif + +all: compile + +compile: + ${CC} ${CFLAGS} -o uddu uddu.c ${LDFLAGS} + strip uddu + ${CC} ${CFLAGS} -o uaau uaau.c ${LDFLAGS} + strip uaau + ${CC} ${CFLAGS} -o adda adda.c ${LDFLAGS} + strip adda + +clean: + rm -rf uddu uaau adda + +dist: compile + mkdir -p ${NAME}-${VERSION} release/src\ + release/bin/${VERSION}/${OS}/${ARCH} release/man/${VERSION} + cp -R LICENSE.txt Makefile README.md CHANGELOG.md\ + *.1 *.c common.h ${NAME}-${VERSION} + tar zcfv release/src/${NAME}-${VERSION}.tar.gz ${NAME}-${VERSION} + rm -rf ${NAME}-${VERSION} + sed "s/VERSION/${VERSION}/g" < uddu.1 > release/man/${VERSION}/uddu.1 + sed "s/VERSION/${VERSION}/g" < uaau.1 > release/man/${VERSION}/uaau.1 + sed "s/VERSION/${VERSION}/g" < adda.1 > release/man/${VERSION}/adda.1 + cp -R uddu uaau adda release/bin/${VERSION}/${OS}/${ARCH} + +install: + mkdir -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${MANPREFIX}/man1 + cp -rf uddu ${DESTDIR}${PREFIX}/bin + cp -rf uaau ${DESTDIR}${PREFIX}/bin + cp -rf adda ${DESTDIR}${PREFIX}/bin + chmod 755 ${DESTDIR}${PREFIX}/bin/uddu + chmod 755 ${DESTDIR}${PREFIX}/bin/uaau + chmod 755 ${DESTDIR}${PREFIX}/bin/adda + sed "s/VERSION/${VERSION}/g" < uddu.1 > ${DESTDIR}${MANPREFIX}/man1/uddu.1 + sed "s/VERSION/${VERSION}/g" < uaau.1 > ${DESTDIR}${MANPREFIX}/man1/uaau.1 + sed "s/VERSION/${VERSION}/g" < adda.1 > ${DESTDIR}${MANPREFIX}/man1/adda.1 + chmod 644 ${DESTDIR}${MANPREFIX}/man1/uddu.1 + chmod 644 ${DESTDIR}${MANPREFIX}/man1/uaau.1 + chmod 644 ${DESTDIR}${MANPREFIX}/man1/adda.1 + +uninstall: + rm -rf ${DESTDIR}${PREFIX}/bin/uddu + rm -rf ${DESTDIR}${PREFIX}/bin/uaau + rm -rf ${DESTDIR}${PREFIX}/bin/adda + rm -rf ${DESTDIR}${MANPREFIX}/man1/uddu.1 + rm -rf ${DESTDIR}${MANPREFIX}/man1/uaau.1 + rm -rf ${DESTDIR}${MANPREFIX}/man1/adda.1 + +.PHONY: all compile clean dist install uninstall diff --git a/README.md b/README.md new file mode 100644 index 0000000..a04dc71 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# txconv + +## インストールする方法 | Installation +### OpenBSD +```sh +make +doas make install +``` + +### NetBSD | FreeBSD | Dragonfly BSD +```sh +make +sudo make install +``` + +### CRUX +```sh +sudo prt-get bmake +bmake +sudo bmake install +``` + +### Void +```sh +sudo xbps-install bmake +bmake +sudo bmake install +``` + +### Artix +```sh +sudo pacman -S base-devel bmake +bmake +sudo bmake install +``` + +### Debian | Devuan | Ubuntu | Linux Mint | PopOS +```sh +sudo apt install -y build-essential bmake git +bmake +sudo bmake install +``` + +### Fedora | Red Hat | CentOS | Rocky Linux +```sh +sudo dnf install bmake clang +bmake +sudo bmake install +``` diff --git a/adda.1 b/adda.1 new file mode 100644 index 0000000..d455985 --- /dev/null +++ b/adda.1 @@ -0,0 +1,12 @@ +.TH ADDA 1 VERSION +.SH NAME +adda - Amiga/MacOS 9 to DOS, DOS to Amiga/MacOS 9 +.br +.B adda +[-s] +.SH DESCRIPTION +.PP +Amiga/MacOS 9 to DOS, DOS to Amiga/MacOS 9 +.SH AUTHORS +.PP +テクニカル諏訪子(開発者) diff --git a/adda.c b/adda.c new file mode 100644 index 0000000..bb68b84 --- /dev/null +++ b/adda.c @@ -0,0 +1,102 @@ +#include +#include +#include +#include "common.h" + +const char *sofname = "adda"; +const char *syoumei = "Amiga/MacOS 9 to DOS, DOS to Amiga/MacOS 9"; + +void amiga_to_dos(FILE *in, FILE *out) { + int c; + + while ((c = fgetc(in)) != EOF) { + if (c != '\r') { + fputc(c, out); + } + if ((c = fgetc(in)) != '\n') { + fputc('\r', out); + fputc('\n', out); + ungetc(c, in); + } else { + fputc('\r', out); + fputc('\n', out); + } + } +} + +void dos_to_amiga(FILE *in, FILE *out) { + int c; + int last_char = '\0'; + + while ((c = fgetc(in)) != EOF) { + if (last_char == '\r' && c == '\n') continue; + if (last_char != '\r' && c == '\n') fputc('\r', out); + else fputc(c, out); + last_char = c; + } +} + +int detect_line_ending(FILE *in) { + int c; + int islf = 0; + int iscr = 0; + while ((c = fgetc(in)) != EOF) { + if (c == '\r') iscr = 1; + if (c == '\n') islf = 1; + } + if (iscr && islf) return 1; // DOS + return 0; // Amiga +} + +void usage() { + fprintf(stderr, "%s-%s\n%s\n", sofname, version, syoumei); + fprintf(stderr, "usage: %s <ファイル.txt>\n", sofname); +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + usage(); + return 1; + } + + FILE *in = fopen(argv[1], "r"); + if (in == NULL) { + perror("fopen input"); + usage(); + return 1; + } + + FILE *tmp = fopen("tmp.txt", "w"); + if (tmp == NULL) { + perror("fopen tmp"); + fclose(in); + usage(); + return 1; + } + + int line_ending_style = detect_line_ending(in); + rewind(in); + + if (line_ending_style == 0) { // AMIGA + amiga_to_dos(in, tmp); + } else { // DOS + dos_to_amiga(in, tmp); + } + + fclose(in); + fclose(tmp); + + if (remove(argv[1]) != 0) { + perror("元のファイルの削除"); + usage(); + return 1; + } + + if (rename("tmp.txt", argv[1]) != 0) { + perror("tmpファイル名の変更"); + usage(); + return 1; + } + + return 0; +} diff --git a/common.h b/common.h new file mode 100644 index 0000000..10489d6 --- /dev/null +++ b/common.h @@ -0,0 +1,6 @@ +#ifndef COMMON_H +#define COMMON_H + +const char *version = "1.0.0"; + +#endif diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..550aa57 --- /dev/null +++ b/test.txt @@ -0,0 +1,2 @@ +manco +pussy diff --git a/uaau.1 b/uaau.1 new file mode 100644 index 0000000..87e2efc --- /dev/null +++ b/uaau.1 @@ -0,0 +1,12 @@ +.TH UAAU 1 VERSION +.SH NAME +uaau - Unix/BeOS/Plan9 to Amiga/MacOS 9, Amiga/MacOS 9 to Unix/BeOS/Plan9 +.br +.B uaau +[-s] +.SH DESCRIPTION +.PP +Unix/BeOS/Plan9 to Amiga/MacOS 9, Amiga/MacOS 9 to Unix/BeOS/Plan9 +.SH AUTHORS +.PP +テクニカル諏訪子(開発者) diff --git a/uaau.c b/uaau.c new file mode 100644 index 0000000..8ab0a75 --- /dev/null +++ b/uaau.c @@ -0,0 +1,89 @@ +#include +#include +#include +#include "common.h" + +const char *sofname = "uaau"; +const char *syoumei = + "Unix/BeOS/Plan9 to Amiga/MacOS 9, Amiga/MacOS 9 to Unix/BeOS/Plan9"; + +void unix_to_amiga(FILE *in, FILE *out) { + int c; + while ((c = fgetc(in)) != EOF) { + if (c == '\n') fputc('\r', out); + else fputc(c, out); + } +} + +void amiga_to_unix(FILE *in, FILE *out) { + int c; + while ((c = fgetc(in)) != EOF) { + if (c == '\r') fputc('\n', out); + else fputc(c, out); + } +} + +int detect_line_ending(FILE *in) { + int c; + int islf = 0; + int iscr = 0; + while ((c = fgetc(in)) != EOF) { + if (c == '\r') iscr = 1; + if (c == '\n') islf = 1; + } + if (iscr && !islf) return 1; // Amiga + return 0; // Unix +} + +void usage() { + fprintf(stderr, "%s-%s\n%s\n", sofname, version, syoumei); + fprintf(stderr, "usage: %s <ファイル.txt>\n", sofname); +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + usage(); + return 1; + } + + FILE *in = fopen(argv[1], "r"); + if (in == NULL) { + perror("fopen input"); + usage(); + return 1; + } + + FILE *tmp = fopen("tmp.txt", "w"); + if (tmp == NULL) { + perror("fopen tmp"); + fclose(in); + usage(); + return 1; + } + + int line_ending_style = detect_line_ending(in); + rewind(in); + + if (line_ending_style == 0) { // UNIX + unix_to_amiga(in, tmp); + } else { // AMIGA + amiga_to_unix(in, tmp); + } + + fclose(in); + fclose(tmp); + + if (remove(argv[1]) != 0) { + perror("元のファイルの削除"); + usage(); + return 1; + } + + if (rename("tmp.txt", argv[1]) != 0) { + perror("tmpファイル名の変更"); + usage(); + return 1; + } + + return 0; +} diff --git a/uddu.1 b/uddu.1 new file mode 100644 index 0000000..03fc83b --- /dev/null +++ b/uddu.1 @@ -0,0 +1,12 @@ +.TH UDDU 1 VERSION +.SH NAME +uddu - Unix/BeOS/Plan9 to DOS, DOS to Unix/BeOS/Plan9 +.br +.B uddu +[-s] +.SH DESCRIPTION +.PP +Unix/BeOS/Plan9 to DOS, DOS to Unix/BeOS/Plan9 +.SH AUTHORS +.PP +テクニカル諏訪子(開発者) diff --git a/uddu.c b/uddu.c new file mode 100644 index 0000000..85777c0 --- /dev/null +++ b/uddu.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include "common.h" + +const char *sofname = "uddu"; +const char *syoumei = "Unix/BeOS/Plan9 to DOS, DOS to Unix/BeOS/Plan9"; + +void unix_to_dos(FILE *in, FILE *out) { + int c; + while ((c = fgetc(in)) != EOF) { + if (c == '\n') fputc('\r', out); + fputc(c, out); + } +} + +void dos_to_unix(FILE *in, FILE *out) { + int c; + while ((c = fgetc(in)) != EOF) { + if (c == '\r') continue; + fputc(c, out); + } +} + +int detect_line_ending(FILE *in) { + int c; + int islf = 0; + int iscr = 0; + while ((c = fgetc(in)) != EOF) { + if (c == '\r') iscr = 1; + if (c == '\n') islf = 1; + } + if (iscr && islf) return 1; // DOS + return 0; // Unix +} + +void usage() { + fprintf(stderr, "%s-%s\n%s\n", sofname, version, syoumei); + fprintf(stderr, "usage: %s <ファイル.txt>\n", sofname); +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + usage(); + return 1; + } + + FILE *in = fopen(argv[1], "r"); + if (in == NULL) { + perror("fopen input"); + usage(); + return 1; + } + + FILE *tmp = fopen("tmp.txt", "w"); + if (tmp == NULL) { + perror("fopen tmp"); + fclose(in); + usage(); + return 1; + } + + int line_ending_style = detect_line_ending(in); + rewind(in); + + if (line_ending_style == 0) { // UNIX + unix_to_dos(in, tmp); + } else { // DOS + dos_to_unix(in, tmp); + } + + fclose(in); + fclose(tmp); + + if (remove(argv[1]) != 0) { + perror("元のファイルの削除"); + usage(); + return 1; + } + + if (rename("tmp.txt", argv[1]) != 0) { + perror("tmpファイル名の変更"); + usage(); + return 1; + } + + return 0; +}