FossilOrigin-Name: db3937de01580bd3adf1a531ea1dc7b966beaba4cba7629a3b1f0b9e939746b3
This commit is contained in:
nekobit 2022-05-26 05:29:26 +00:00
parent dd3818abbc
commit 0a580d0a32
3 changed files with 106 additions and 2 deletions

View file

@ -1,3 +1,4 @@
template
filec
emojitoc
**/*.cgi

View file

@ -3,7 +3,7 @@ GIT ?= git
MASTODONT_DIR = mastodont-c/
MASTODONT = $(MASTODONT_DIR)libmastodont.a
CFLAGS += -Wall -I $(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-ignored-qualifiers -I/usr/include/ $(shell pkg-config --cflags libcurl libcjson libpcre)
LDFLAGS = -lm -L$(MASTODONT_DIR) -lmastodont $(shell pkg-config --libs libcjson libcurl libpcre) -lfcgi
LDFLAGS = -L$(MASTODONT_DIR) -lmastodont $(shell pkg-config --libs libcjson libcurl libpcre) -lfcgi
SRC = $(wildcard src/*.c)
OBJ = $(patsubst %.c,%.o,$(SRC))
HEADERS = $(wildcard src/*.h)
@ -19,9 +19,12 @@ MASTODONT_URL = https://fossil.nekobit.net/mastodont-c
all: $(MASTODONT_DIR) dep_build $(TARGET)
apache: all apache_start
$(TARGET): filec $(PAGES_CMP) $(OBJ) $(HEADERS)
$(TARGET): filec template $(PAGES_CMP) $(OBJ) $(HEADERS)
$(CC) -o $(TARGET) $(OBJ) $(LDFLAGS)
template: src/template/main.o
$(CC) -o template $<
filec: src/file-to-c/main.o
$(CC) -o filec $<

100
src/template/main.c Normal file
View file

@ -0,0 +1,100 @@
/*
* Treebird - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum args
{
ARG_FILENAME = 1,
ARG_VARIABLE
};
enum tmpl_type
{
TMPL_INT,
TMPL_UINT,
TMPL_STR,
TMPL_STRLEN
}
long filesize(FILE* file)
{
long orig = ftell(file);
fseek(file, 0, SEEK_END);
long size = ftell(file);
fseek(file, orig, SEEK_SET);
return size;
}
void print_template(char* var, char* buf)
{
char* buf_prev = buf;
char* buf_curr = buf;
char** tokens;
printf("#ifndef __%s\n", var);
printf("#define __%s\n", var);
printf("static const char data_%s[] = {", var);
while (1)
{
buf_curr = strstr(buf_curr, "{{");
}
/* for (size_t i = 0; i < size; ++i) */
/* { */
/* printf("0X%hhX,", buf[i]); */
/* } */
/* puts("0};\n#endif"); */
puts("#endif");
}
int main(int argc, char** argv)
{
char* buf;
FILE* file = fopen(argv[ARG_FILENAME], "rb");
long size = filesize(file);
if (!(buf = malloc(size)))
{
perror("malloc");
return 1;
}
if (fread(buf, 1, size, file) != size)
{
fputs("Didn't read correctly!", stderr);
free(buf);
return 1;
}
fclose(file);
print_template(argv[ARG_VARIABLE], buf);
free(buf);
return 0;
}