From 67992355b448deaf24d9f304efb3ec18a0c52e2f Mon Sep 17 00:00:00 2001 From: lp19 Date: Thu, 23 Jan 2025 09:16:13 +0100 Subject: [PATCH] add cron basics --- libs/json | 2 +- makefile | 16 +++++++++++++--- src/command.cpp | 3 +++ src/main.cpp | 9 +++++++++ src/main.h | 2 ++ src/setup.h | 4 +++- 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/libs/json b/libs/json index 3780b41..960b763 160000 --- a/libs/json +++ b/libs/json @@ -1 +1 @@ -Subproject commit 3780b41dd070436f3f55327b0a88f27a52e2dfa8 +Subproject commit 960b763ecd144f156d05ec61f577b04107290137 diff --git a/makefile b/makefile index d77a66b..0081f50 100644 --- a/makefile +++ b/makefile @@ -3,12 +3,22 @@ CFLAGS = -std=c++17 -Wall -static -static-libgcc -static-libstdc++ SRCDIR = ./src BINDIR = ./bin -$(BINDIR)/autom: $(SRCDIR)/main.cpp $(SRCDIR)/command.cpp $(SRCDIR)/inputparser.cpp $(SRCDIR)/settings.cpp - $(CC) $(CFLAGS) $^ -o $@ -.PHONY: clean + +.PHONY: clean generate build + +all: generate build + +generate: + mkdir -p $(BINDIR) + clean: rm -f $(BINDIR)/autom +build: $(BINDIR)/autom + +$(BINDIR)/autom: $(SRCDIR)/main.cpp $(SRCDIR)/command.cpp $(SRCDIR)/inputparser.cpp $(SRCDIR)/settings.cpp + $(CC) $(CFLAGS) $^ -o $@ + install: cp $(BINDIR)/autom /usr/local/bin/autom \ No newline at end of file diff --git a/src/command.cpp b/src/command.cpp index ae89ab0..c5aefb4 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1,4 +1,7 @@ #include "command.h" +#include +#include +#include Command::Command() {} diff --git a/src/main.cpp b/src/main.cpp index 8872505..53e4524 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,7 @@ void input(int argc, char *argv[]) command.addCommand("remove", "[script] - Remove a script", removeScript); command.addCommand("show", "[script] - Shows a script", showScript); command.addCommand("config", " - Configures autom", config); + command.addCommand("cron", " - Executes cron jobs", cron); command.addCommand("logo", "- Shows the autom logo", logo); command.addDefaultCommand(runScript); @@ -604,6 +605,14 @@ void removeScript(int argc, char *argv[]) } } +void cron(int argc, char *argv[]) +{ + std::string cron_file = settings.value["cron_file"]; + + Cron cron(); + cron.run(); +} + // help function for showing help message void help(int argc, char *argv[]) { diff --git a/src/main.h b/src/main.h index e71e60e..6a8fdbe 100644 --- a/src/main.h +++ b/src/main.h @@ -48,6 +48,8 @@ void editScript_fn(std::string name, std::string dir); void removeScript(int argc, char *argv[]); // show a script in the autom directory void showScript(int argc, char *argv[]); +// cron function for executing cron jobs +void cron(int argc, char *argv[]); // help function for showing help message void help(int argc, char *argv[]); diff --git a/src/setup.h b/src/setup.h index 95cc19f..f18e899 100644 --- a/src/setup.h +++ b/src/setup.h @@ -70,7 +70,9 @@ public: {"editor", editor}, {"search_dirs", {home}}, {"temp_dir", home + "/temp"}, - {"autom_home_dir", home}}; + {"autom_home_dir", home}, + {"cron_file", home + "/cron.txt"}, + {"scripts", {}}}; file << j.dump(4);