diff --git a/.gitignore b/.gitignore index e69de29..ff42fac 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,2 @@ +histui +object/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..038a65a --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +.PHONY: clean run + +ifeq (${DEBUG}, 1) + LFLAGS += --debug --trace + CXXFLAGS += -Wall -Wextra -Wpedantic + CXXFLAGS += -DDEBUG -O0 -ggdb -fno-inline + WRAP := valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all +else + CXXFLAGS += -O3 -fno-stack-protector -fno-exceptions -fno-rtti +endif + +LDLIBS += $$(pkgconf --cflags --libs ncurses) $$(pkgconf --cflags --libs readline) +CXXFLAGS += -std=gnu++20 -I./source/ -I./object/ -I./ + +OBJECT.d:=object/ +SOURCE.d:=source/ +SOURCE:=main.cpp tui.cpp db.cpp config.l +SOURCE:=$(addprefix ${SOURCE.d},${SOURCE}) +OBJECT:=$(addprefix ${OBJECT.d},$(subst ${SOURCE.d},,$(addsuffix .o,$(basename ${SOURCE})))) + +OUTPUT:=histui + +${OUTPUT}: ${OBJECT} + ${LINK.cpp} ${OBJECT} -o ${OUTPUT} ${LDLIBS} + +object/%.l.cpp: source/%.l + ${LEX} ${LFLAGS} -o $@ $< + +object/%.o: object/%.l.cpp + ${COMPILE.cpp} $< -o $@ + +object/%.o: source/%.cpp + ${COMPILE.cpp} $< -o $@ + +clean: + -rm ${OBJECT.d}/* + -rm ./${OUTPUT} + +run: + ./${OUTPUT} diff --git a/object/.gitkeep b/object/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/source/config.hpp b/source/config.hpp new file mode 100644 index 0000000..85965cc --- /dev/null +++ b/source/config.hpp @@ -0,0 +1 @@ +int read_config(const char * const file); diff --git a/source/config.l b/source/config.l new file mode 100644 index 0000000..55f3a80 --- /dev/null +++ b/source/config.l @@ -0,0 +1,11 @@ +%option noyywrap +%option nodefault +%option noyylineno + +%% + +%% + +int read_config(const char * const file) { + return 0; +} diff --git a/source/db.cpp b/source/db.cpp new file mode 100644 index 0000000..4aec741 --- /dev/null +++ b/source/db.cpp @@ -0,0 +1,11 @@ +#include "db.hpp" + +inline const char * db_file; + +signed export_main(int argc, char * * argv) { + return 0; +} + +signed import_main(int argc, char * * argv) { + return 0; +} diff --git a/source/db.hpp b/source/db.hpp new file mode 100644 index 0000000..9ec86dd --- /dev/null +++ b/source/db.hpp @@ -0,0 +1,24 @@ +#include +#include +#include + +struct Shell { + size_t id; + std::string name; +}; + +struct Entry { + std::string line; + time_t timestamp; + Shell * shell; +}; + +extern const char * db_file; + +extern void append_entry(const Entry * const entry); +extern std::vector search(const char * const query); +extern std::vector inspect(const Entry * const entry); + +extern signed export_main(int argc, char * * argv); +extern signed import_main(int argc, char * * argv); + diff --git a/source/main.cpp b/source/main.cpp new file mode 100644 index 0000000..9708823 --- /dev/null +++ b/source/main.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include + +#include "tui.hpp" +#include "db.hpp" + +using namespace std; + +[[ noreturn ]] +void version() { + puts("Histui " + #include "version.inc" + ); + + exit(0); +} + +[[ noreturn ]] +void usage(int exit_value = 0) { + ; + exit(exit_value); +} + +void global_options(const int argc, const char * const * const argv) { + for(int i = 0; i < argc; i++) { + if (not strcmp(argv[i], "-v") + || not strcmp(argv[i], "--version")) { + version(); + } + if (not strcmp(argv[i], "-h") + || not strcmp(argv[i], "--help")) { + usage(); + } + } +} + +typedef signed (*mainlike_t)(int argc, char * * argv); +map verb_table = { + {"tui", tui_main}, + {"import", import_main}, + {"export", export_main}, +}; + +signed main(int argc, char * * argv) { + if (argc < 2) { + usage(2); + } + + global_options(argc, argv); + + for (const auto &i : verb_table) { + if (not strcmp(argv[1], i.first)) { + return i.second(argc, argv); + } + } + + return 1; +} diff --git a/source/tui.cpp b/source/tui.cpp new file mode 100644 index 0000000..1644d43 --- /dev/null +++ b/source/tui.cpp @@ -0,0 +1,11 @@ +#include "tui.hpp" + +#include +#include + +#include "config.hpp" + +signed tui_main(int argc, char * * argv) { + read_config(NULL); + return 0; +} diff --git a/source/tui.hpp b/source/tui.hpp new file mode 100644 index 0000000..7022e00 --- /dev/null +++ b/source/tui.hpp @@ -0,0 +1 @@ +signed tui_main(int argc, char * * argv); diff --git a/source/version.inc b/source/version.inc new file mode 100644 index 0000000..75dad67 --- /dev/null +++ b/source/version.inc @@ -0,0 +1 @@ +"0.1"