basic structure
This commit is contained in:
parent
ef3aabce1f
commit
5bfa9710ff
2
.gitignore
vendored
2
.gitignore
vendored
@ -0,0 +1,2 @@
|
|||||||
|
histui
|
||||||
|
object/
|
40
Makefile
Normal file
40
Makefile
Normal file
@ -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}
|
0
object/.gitkeep
Normal file
0
object/.gitkeep
Normal file
1
source/config.hpp
Normal file
1
source/config.hpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
int read_config(const char * const file);
|
11
source/config.l
Normal file
11
source/config.l
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
%option noyywrap
|
||||||
|
%option nodefault
|
||||||
|
%option noyylineno
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
int read_config(const char * const file) {
|
||||||
|
return 0;
|
||||||
|
}
|
11
source/db.cpp
Normal file
11
source/db.cpp
Normal file
@ -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;
|
||||||
|
}
|
24
source/db.hpp
Normal file
24
source/db.hpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <time.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<Entry> search(const char * const query);
|
||||||
|
extern std::vector<Entry> inspect(const Entry * const entry);
|
||||||
|
|
||||||
|
extern signed export_main(int argc, char * * argv);
|
||||||
|
extern signed import_main(int argc, char * * argv);
|
||||||
|
|
61
source/main.cpp
Normal file
61
source/main.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#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<const char*, mainlike_t> 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;
|
||||||
|
}
|
11
source/tui.cpp
Normal file
11
source/tui.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "tui.hpp"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ncurses.h>
|
||||||
|
|
||||||
|
#include "config.hpp"
|
||||||
|
|
||||||
|
signed tui_main(int argc, char * * argv) {
|
||||||
|
read_config(NULL);
|
||||||
|
return 0;
|
||||||
|
}
|
1
source/tui.hpp
Normal file
1
source/tui.hpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
signed tui_main(int argc, char * * argv);
|
1
source/version.inc
Normal file
1
source/version.inc
Normal file
@ -0,0 +1 @@
|
|||||||
|
"0.1"
|
Loading…
Reference in New Issue
Block a user