Browse Source

basic structure

master
anon 2 months ago
parent
commit
5bfa9710ff
11 changed files with 163 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +40
    -0
      Makefile
  3. +0
    -0
      object/.gitkeep
  4. +1
    -0
      source/config.hpp
  5. +11
    -0
      source/config.l
  6. +11
    -0
      source/db.cpp
  7. +24
    -0
      source/db.hpp
  8. +61
    -0
      source/main.cpp
  9. +11
    -0
      source/tui.cpp
  10. +1
    -0
      source/tui.hpp
  11. +1
    -0
      source/version.inc

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
histui
object/

+ 40
- 0
Makefile View 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
- 0
object/.gitkeep View File


+ 1
- 0
source/config.hpp View File

@@ -0,0 +1 @@
int read_config(const char * const file);

+ 11
- 0
source/config.l View File

@@ -0,0 +1,11 @@
%option noyywrap
%option nodefault
%option noyylineno

%%

%%

int read_config(const char * const file) {
return 0;
}

+ 11
- 0
source/db.cpp View 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
- 0
source/db.hpp View 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
- 0
source/main.cpp View 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
- 0
source/tui.cpp View 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
- 0
source/tui.hpp View File

@@ -0,0 +1 @@
signed tui_main(int argc, char * * argv);

+ 1
- 0
source/version.inc View File

@@ -0,0 +1 @@
"0.1"

Loading…
Cancel
Save