init ci
This commit is contained in:
commit
eccf0a28bb
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/logs/messages
|
||||||
|
/bin
|
17
.vscode/c_cpp_properties.json
vendored
Normal file
17
.vscode/c_cpp_properties.json
vendored
Normal file
@ -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
|
||||||
|
}
|
34
.vscode/launch.json
vendored
Normal file
34
.vscode/launch.json
vendored
Normal file
@ -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"
|
||||||
|
}
|
30
.vscode/tasks.json
vendored
Normal file
30
.vscode/tasks.json
vendored
Normal file
@ -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"
|
||||||
|
}
|
70
logfoo.c
Normal file
70
logfoo.c
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lualib.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
|
|
||||||
|
#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 <lua file> <log file>\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);
|
||||||
|
}
|
3
lua/messages.lua
Normal file
3
lua/messages.lua
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
function format (line)
|
||||||
|
return line:gsub(" ", "\n");
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user