From 11b86ff1a85efe5d1170ea8c90ebca5ac313e24f Mon Sep 17 00:00:00 2001 From: Inqiyad Sabr Date: Sun, 2 Nov 2025 10:07:40 +0600 Subject: Add files --- Makefile | 33 +++++++++++++++++++++++++++++++ README.md | 25 +++++++++++++++++++++++ c2x | 8 ++++++++ g2x.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100755 c2x create mode 100644 g2x.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4f2f0c0 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +.POSIX: + +RM := /bin/rm +DESTDIR := /usr/local/bin + +CFLAGS := -std=c99 -Wfloat-equal -Og +CFLAGS += -Wall -Werror -Wextra -Wpedantic +CFLAGS += -m64 -no-pie -pipe +CFLAGS += -ffunction-sections -fdata-sections +CFLAGS += -D_XOPEN_SOURCE=500L -flto +CFLAGS += -march=native -mtune=generic + +LDFLAGS := -static -Wl,--build-id=none +LDFLAGS += -ffunction-sections -fdata-sections +#LDFLAGS += -Wl,--strip-all +LDFLAGS += -Wl,--flto + +.SUFFIXES: .c .o + +g2x: $(FILES) *.o + $(CC) $(LDFLAGS) *.o -o g2x + +.c.o: + $(CC) $(CFLAGS) -c *.c + +clean: + $(RM) ./*.o + +install: + install -s -m 0755 g2x $(DESTDIR) + install -m 0755 c2x $(DESTDIR) + +.PHONY: make clean install diff --git a/README.md b/README.md new file mode 100644 index 0000000..b5838a1 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Gemini To XHTML(XML) +This is a very simple gemini to xml generator written in C. + +# About +The g2x executable is a single file to file xml generator, there's a handy script named c2x (capsule 2 xhtml), that generates the entire capsule in XHTML for you, then you can use your favourite web server to host it. + +# Usage +You use your shell pipes '>' and '<'. + +* generate one html from gmi file +``` +./g2h < index.gmi > index.html +``` + +* Generate a whole ass mfkin gemsite +``` +./c2x +``` + +without the "/"... btw. + +That's it, just add your style.css at the *_xhtml root and you got XHTML! HELL YEAH! Hhhmm... I mean HTML is kinda messed up and you should always just use XHTML. + +# Addenum +I thought I might add how I work. I have my gemsite as a git repo where I have a post-receive hook that copies my gemsite to a gemsite folder, and then it runs `c2x` on the gemsite root folder and I get a `gemsite_xhtml` folder, being the XHTML root. Then I just nginx and you know the deal. diff --git a/c2x b/c2x new file mode 100755 index 0000000..8ee737c --- /dev/null +++ b/c2x @@ -0,0 +1,8 @@ +#!/bin/sh +[ -s ./"$1_xhtml" ] && rm -rf "./${1}_xhtml" +cp -r ./"${1}" ./"${1}_xhtml" +cd ./"${1}_xhtml" || exit +for file in $(find ./* | grep ".gmi" | sed 's/.gmi//'); do + g2x < "./${file}.gmi" > "./${file}.html" + rm "./${file}.gmi" +done diff --git a/g2x.c b/g2x.c new file mode 100644 index 0000000..cf23072 --- /dev/null +++ b/g2x.c @@ -0,0 +1,68 @@ +#include +#define BUFSIZE 4096 // Read +#define xmlput(n)\ + for(i = n; buf[i] != '\n'; i++) {\ + switch(buf[i]) {\ + default: putchar(buf[i]); break;\ + case '>' : fputs(">",stdout); break;\ + case '<' : fputs("<",stdout); break;\ + case '&' : fputs("&",stdout); break;\ + case '\'': fputs("'",stdout); break;\ + case '"' : fputs(""",stdout); break;}} +int main(void) { + char buf[BUFSIZE]; int i; + fputs( + "\n" + "\n" + "\n\n" + "\n" + "\n" + "",stdout + ); while (fgets(buf,BUFSIZE,stdin) != NULL) { + if (buf[2] == '#')/* ### */ { + fputs("

",stdout); + xmlput(4); fputs("

\n",stdout); + continue; + } else if (buf[1] == '#') /* ## */ { + fputs("

",stdout); + xmlput(3); fputs("

\n",stdout); + continue; + } else if (buf[0] == '#') /* # */ { + fputs("

",stdout); + xmlput(2); fputs("

\n",stdout); + continue; + } else if (buf[0] == '*') { + fputs("
  • ",stdout); xmlput(2); + fputs("
\n",stdout); continue; + } else if (buf[0] == '=' && buf[1] == '>')/* link */ { + fputs("

",stdout); xmlput(i+1); + fputs("

\n",stdout); + continue; + } else if (buf[0] == '`' && buf[2] == '`')/* code */ { + fputs("
",stdout);
+			fgets(buf,BUFSIZE,stdin);
+			while (buf[0] != '`' && buf[2] != '`') {
+				xmlput(0); fputs("\n",stdout);
+				fgets(buf,BUFSIZE,stdin);
+			} fputs("
",stdout); + continue; + } else if (buf[0] == '>') { + fputs("
",stdout); xmlput(2); + fputs("
\n",stdout); + continue; + } fputs("

",stdout); + xmlput(0); fputs("

\n",stdout); + } fputs("",stdout); + fputs("",stdout); +} -- cgit v1.2.3