commit eccf0a28bbe0c4b3ec7019f5f5df9e5429bb3666 Author: damage Date: Thu Jan 16 22:46:20 2025 +0100 init ci diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a04f09 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/logs/messages +/bin \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..52f9ffe --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "/usr/include/lua5.4" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9db366d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,34 @@ +{ + "configurations": [ + { + "name": "messages", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}/bin/${fileBasenameNoExtension}", + "args": [ + "${fileDirname}/lua/messages.lua", + "${fileDirname}/logs/messages" + ], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Automatische Strukturierung und Einrückung für gdb aktivieren", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Disassemblierungsvariante auf Intel festlegen", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "C/C++: gcc Aktive Datei kompilieren", + "miDebuggerPath": "/usr/bin/gdb" + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..5935333 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,30 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc Aktive Datei kompilieren", + "command": "/usr/bin/gcc", + "args": [ + "-fdiagnostics-color=always", + "-I/usr/include/lua5.4", + "-g", + "${file}", + "-llua5.4", + "-o", + "${fileDirname}/bin/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Vom Debugger generierte Aufgabe." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/logfoo.c b/logfoo.c new file mode 100644 index 0000000..b607505 --- /dev/null +++ b/logfoo.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define EXIT_LOGFILE_HANDLING 2 +#define EXIT_LUAFILE_HANDLING 3 + +void trim(char *string) { + if (strlen(string) > 0 && string[strlen(string) - 1] == '\n') { + string[strlen(string) - 1] = '\0'; + trim(string); + } +} + +int main(int argc, char *argv[]) { + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + int status; + char *logfile = argv[2]; + char *luafile = argv[1]; + char *line = NULL; + size_t len = 0; + ssize_t read; + FILE *fp; + lua_State *L; + L = luaL_newstate(); + luaL_openlibs(L); + + fp = fopen(logfile, "r"); + if (errno) { + fprintf(stderr, "Error opening file %s: %s\n", logfile, strerror(errno)); + return EXIT_LOGFILE_HANDLING; + } + + status = luaL_dofile(L, luafile); + if (status) { + fprintf(stderr, "Error reading LUA file %s: %s\n", luafile, lua_tostring(L, -1)); + return EXIT_LUAFILE_HANDLING; + } + + while ((read = getline(&line, &len, fp)) != -1) { + trim(line); + + lua_getglobal(L, "format"); + lua_pushlstring(L, line, read); + if (lua_pcall(L, 1, 1, 0) != 0) { + fprintf(stderr, "Error running LUA function 'format': %s\n", lua_tostring(L, -1)); + return EXIT_LUAFILE_HANDLING; + } + printf("%s\n", lua_tostring(L, -1)); + lua_pop(L, 1); + } + if (errno) { + fprintf(stderr, "Error readling file %s: %s\n", logfile, strerror(errno)); + return EXIT_LOGFILE_HANDLING; + } + + free(line); + lua_close(L); + + fclose(fp); +} \ No newline at end of file diff --git a/lua/messages.lua b/lua/messages.lua new file mode 100644 index 0000000..7d7c4dc --- /dev/null +++ b/lua/messages.lua @@ -0,0 +1,3 @@ +function format (line) + return line:gsub(" ", "\n"); +end \ No newline at end of file