From 61b248363db79b1fabaa47e2737a59787a94ed75 Mon Sep 17 00:00:00 2001 From: LDA Date: Sat, 10 Aug 2024 09:52:11 +0200 Subject: [PATCH] [ADD/WIP] Codenames, try to get codeblocks basics Mostly focused on the LMDB support right now, sorry! --- Makefile | 6 +++++- src/Main.c | 5 +++-- src/StrSplit.c | 19 +++++++++++++------ src/XEP-0393.c | 13 +++++++++++++ src/include/StringSplit.h | 2 +- src/include/XEP393.h | 1 + src/include/XMPPFormTool.h | 6 ++++++ 7 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index f62f333..520f635 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,12 @@ # =========================== Parsee Flags ============================= + +# phantasmagoria - test runs without an actual code +CODE=phantasmagoria NAME=Parsee VERSION=0.0.0 + REPOSITORY=$(shell git remote get-url origin) # =========================== Compilation Flags ============================ @@ -22,7 +26,7 @@ AYAS=ayaya ETC=etc INCLUDES=src/include CC=cc -CFLAGS=-I$(SOURCE) -I$(INCLUDES) -I$(CYTO_INC) -DNAME="\"$(NAME)\"" -DVERSION="\"$(VERSION)\"" -DREPOSITORY=\"$(REPOSITORY)\" -g -ggdb -Wall -Werror +CFLAGS=-I$(SOURCE) -I$(INCLUDES) -I$(CYTO_INC) -DNAME="\"$(NAME)\"" -DVERSION="\"$(VERSION)\"" -DREPOSITORY=\"$(REPOSITORY)\" -DCODE=\"$(CODE)\" -g -ggdb -Wall -Werror LDFLAGS=-L $(CYTO_LIB) -lCytoplasm -g -ggdb AFLAGS=-C "$(ETC)/ayadoc/style.css" -p "$(NAME)" BINARY=parsee diff --git a/src/Main.c b/src/Main.c index 674ec28..a345778 100644 --- a/src/Main.c +++ b/src/Main.c @@ -38,11 +38,12 @@ Main(void) Cron *cron = NULL; start = UtilTsMillis(); + /* TODO: Read args(config file, HTTP/XMPP threads, ...) */ memset(&conf, 0, sizeof(conf)); Log(LOG_INFO, - "%s - v%s (Cytoplasm %s)", - NAME, VERSION, CytoplasmGetVersionStr() + "%s - v%s[%s] (Cytoplasm %s)", + NAME, VERSION, CODE, CytoplasmGetVersionStr() ); Log(LOG_INFO, "======================="); LogConfigIndent(LogConfigGlobal()); diff --git a/src/StrSplit.c b/src/StrSplit.c index 0139be4..91ecec7 100644 --- a/src/StrSplit.c +++ b/src/StrSplit.c @@ -225,13 +225,14 @@ StrViewLines(StringRect view) return view.end_line - view.start_line + 1; } -void -PrintRect(StringRect rect) +char * +StrViewToStr(StringRect rect) { size_t i; + char *ret = NULL, *rtmp; if (!rect.source_lines) { - return; + return NULL; } for (i = 0; i < StrViewLines(rect); i++) @@ -239,16 +240,22 @@ PrintRect(StringRect rect) char *line = NULL, *tmp; char cbuf[2] = { 0, '\0' }; size_t chi = 0; + bool last = i == StrViewLines(rect) - 1; while ((*cbuf = StrGet(&rect, i, chi)) != '\0' && chi++ <= StrViewChars(rect, i)) { - tmp = line; + rtmp = line; line = StrConcat(2, line, cbuf); - Free(tmp); + Free(rtmp); } - Log(LOG_INFO, line); + tmp = ret; + ret = StrConcat(3, ret, line, last ? "\n" : "\n"); + Free(tmp); + Free(line); } + + return ret; } diff --git a/src/XEP-0393.c b/src/XEP-0393.c index 3fa7358..8f3cef2 100644 --- a/src/XEP-0393.c +++ b/src/XEP-0393.c @@ -103,6 +103,7 @@ DecodeQuote(StringRect rect, size_t *skip) return ret; } + static StringRect DecodeSpan(StringRect rect, char del, size_t *skip) { @@ -300,6 +301,18 @@ ShoveXML(XEP393Element *element, XMLElement *xmlparent) return; } + if (element->type == XEP393_CODE) + { + XMLElement *pre, *code, *text; + pre = XMLCreateTag("pre"); + code = XMLCreateTag("code"); + text = XMLCreateText(element->text_data); + XMLAddChild(code, text); + XMLAddChild(pre, code); + XMLAddChild(xmlparent, pre); + return; + } + switch (element->type) { case XEP393_ITALIC: diff --git a/src/include/StringSplit.h b/src/include/StringSplit.h index 7160ac4..e2fd906 100644 --- a/src/include/StringSplit.h +++ b/src/include/StringSplit.h @@ -57,5 +57,5 @@ extern StringRect StrShift(StringRect rect, int n); extern size_t StrViewLines(StringRect); extern size_t StrViewChars(StringRect, int line); -extern void PrintRect(StringRect rect); +extern char * StrViewToStr(StringRect rect); #endif diff --git a/src/include/XEP393.h b/src/include/XEP393.h index 19f8b38..c7b7af4 100644 --- a/src/include/XEP393.h +++ b/src/include/XEP393.h @@ -14,6 +14,7 @@ typedef enum XEP393Type { XEP393_EMPH, XEP393_SRKE, XEP393_MONO, + XEP393_CODE, XEP393_TEXT, XEP393_QUOT, XEP393_LINE, diff --git a/src/include/XMPPFormTool.h b/src/include/XMPPFormTool.h index f4af07f..e01ae48 100644 --- a/src/include/XMPPFormTool.h +++ b/src/include/XMPPFormTool.h @@ -1,6 +1,12 @@ #ifndef PARSEE_FORM_H #define PARSEE_FORM_H +/*-* + * This is a szt of macros to handle XML forms. Aya does not yet support + * macros. TODO! + * -------- + * Written-By: LDA */ + #define Report(id, label) do \ { \ field = XMLCreateTag("field"); \