diff --git a/src/color.h b/src/color.h index c5816d0..a424b8d 100644 --- a/src/color.h +++ b/src/color.h @@ -1,3 +1,7 @@ + +// Header guard +#ifndef RESET + #define RESET "\033[0m" #define BLACK "\033[30m" /* Black */ #define RED "\033[31m" /* Red */ @@ -14,4 +18,6 @@ #define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ #define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ -#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ \ No newline at end of file +#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ + +#endif \ No newline at end of file diff --git a/src/const.h b/src/const.h index d73efeb..f3a413f 100644 --- a/src/const.h +++ b/src/const.h @@ -1,2 +1,6 @@ +#ifndef VERSION + #define VERSION "0.5" -#define NAME "bakatui" \ No newline at end of file +#define NAME "bakatui" + +#endif \ No newline at end of file diff --git a/src/flags.cpp b/src/flags.cpp new file mode 100644 index 0000000..9aeaea1 --- /dev/null +++ b/src/flags.cpp @@ -0,0 +1,24 @@ +#include "const.h" +#include +#include "helper_funcs.h" +#include + +void PrintHelp() { + std::cout << "Usage: " << NAME << " [OPTIONS]" << "\n" + << "-h Show this help menu\n" + << "-V Show version\n" + << "-v verbose mode\n" + << "-L Force new login\n" + << "-S Ignore SSL cert validity\n"; + safe_exit(0); + } + +void PrintVersion() { + std::cout << NAME" " << VERSION"\n" << "License GPLv3: GNU GPL version 3 .\n"; + safe_exit(0); + } + +void DeleteLogin(std::string savedir_path) { + std::remove((savedir_path + "/authfile").c_str()); + std::remove((savedir_path + "/urlfile").c_str()); +} \ No newline at end of file diff --git a/src/flags.h b/src/flags.h new file mode 100644 index 0000000..f865ebd --- /dev/null +++ b/src/flags.h @@ -0,0 +1,10 @@ +#include +// header guard +#ifndef _ba_fl_hg_ +#define _ba_fl_hg_ + +void PrintHelp(); +void PrintVersion(); +void DeleteLogin(std::string savedir_path); + +#endif \ No newline at end of file diff --git a/src/helper_funcs.h b/src/helper_funcs.h index 22e6299..19c3fd8 100644 --- a/src/helper_funcs.h +++ b/src/helper_funcs.h @@ -1,9 +1,16 @@ #include #include + +// header guard +#ifndef _ba_hf_hg_ +#define _ba_hf_hg_ + void safe_exit(int code); std::string bool_to_string(bool bool_in); std::string SoRAuthFile(bool save, std::string data); void get_input_and_login(); void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); -std::string rm_tr_le_whitespace(const std::string &s); \ No newline at end of file +std::string rm_tr_le_whitespace(const std::string &s); + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 2e14d76..f0ed721 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,6 @@ #include "color.h" #include "helper_funcs.h" #include "main_menu.h" -#include "marks.h" #include "net.h" #include #include @@ -13,17 +12,12 @@ #include #include #include -#include "const.h" +#include "flags.h" +#include "types.h" std::string baka_api_url; -void PrintHelp() { - std::cout << "Usage: " << NAME << " [OPTIONS]" << "\n" - << "-h Show this help menu\n" - << "-v Show version\n" - << "-L Force new login\n"; - safe_exit(0); -} +Config config; int main(int argc, char **argv) { // signal handlers @@ -36,18 +30,22 @@ int main(int argc, char **argv) { signal(SIGSEGV, safe_exit); { - int opt; - while ((opt = getopt(argc, argv, "vf:")) != -1) { // "f:" expects a value - switch (opt) { - case 'h': PrintHelp(); break; - case 'L': break; - case 'v': break; - default: /* handle error */; - } - } std::string savedir_path = std::getenv("HOME"); savedir_path.append("/.local/share/bakatui"); + + int opt; + while ((opt = getopt(argc, argv, "hVvLS:")) != -1) { + switch (opt) { + case 'h': PrintHelp(); break; + case 'V': PrintVersion(); break; + case 'v': config.verbose = true; break; + case 'L': DeleteLogin(savedir_path); break; + case 'S': config.ignoressl = true; break; + default: std::cerr << RED"[ERROR]" << RESET" invalid option: " << (char)optopt << "\ntry: -h\n"; safe_exit(EINVAL); + } + } + std::string urlfile_path = std::string(savedir_path) + "/url"; std::ifstream urlfile; urlfile.open(urlfile_path); diff --git a/src/main.h b/src/main.h index 9f53b09..ecd1f4c 100644 --- a/src/main.h +++ b/src/main.h @@ -1,4 +1,11 @@ #include #include +#include "types.h" +// header guard +#ifndef _ba_ma_hg_ +#define _ba_ma_hg_ extern std::string baka_api_url; +extern Config config; + +#endif \ No newline at end of file diff --git a/src/main_menu.h b/src/main_menu.h index 1119823..2c6274c 100644 --- a/src/main_menu.h +++ b/src/main_menu.h @@ -1 +1,7 @@ -void main_menu(); \ No newline at end of file +// header guard +#ifndef _ba_mm_hg_ +#define _ba_mm_hg_ + +void main_menu(); + +#endif \ No newline at end of file diff --git a/src/marks.h b/src/marks.h index 9166ad6..370219c 100644 --- a/src/marks.h +++ b/src/marks.h @@ -1 +1,5 @@ -void marks_page(); \ No newline at end of file +// header guard +#ifndef _ba_mp_hg_ +#define _ba_mp_hg_ +void marks_page(); +#endif \ No newline at end of file diff --git a/src/net.h b/src/net.h index 2f6191c..4557c1c 100644 --- a/src/net.h +++ b/src/net.h @@ -1,6 +1,9 @@ #include #include #include +// header guard +#ifndef _ba_ne_hg_ +#define _ba_ne_hg_ using nlohmann::json; @@ -9,4 +12,5 @@ namespace bakaapi { void login(std::string username, std::string password); void refresh_access_token(); json get_data_from_endpoint(std::string endpoint); -} // namespace bakaapi \ No newline at end of file +} // namespace bakaapi +#endif \ No newline at end of file diff --git a/src/timetable.cpp b/src/timetable.cpp index 3b3655f..ff0343e 100644 --- a/src/timetable.cpp +++ b/src/timetable.cpp @@ -1,4 +1,8 @@ #include "timetable.h" +#include +#include "net.h" + +using nlohmann::json; #define NLINES 10 #define NCOLS 40 @@ -9,5 +13,10 @@ #define DEFAULT_PADDING 4 void timetable_page() { - + // DONT FORGET TO UNCOMMENT + json resp_from_api = bakaapi::get_data_from_endpoint("api/3/marks"); + // std::ifstream f("test-data/marks3.json"); + // json resp_from_api = json::parse(f); + // calculate table size + } \ No newline at end of file diff --git a/src/timetable.h b/src/timetable.h index f79d1b6..9563bea 100644 --- a/src/timetable.h +++ b/src/timetable.h @@ -1 +1,6 @@ -void timetable_page(); \ No newline at end of file +// header guard +#ifndef _ba_ti_hg_ +#define _ba_ti_hg_ + +void timetable_page(); +#endif \ No newline at end of file diff --git a/src/types.h b/src/types.h new file mode 100644 index 0000000..376f699 --- /dev/null +++ b/src/types.h @@ -0,0 +1,9 @@ +// header guard +#ifndef _ba_ty_hg_ +#define _ba_ty_hg_ + +struct Config { + bool verbose = false; + bool ignoressl = false; +}; +#endif \ No newline at end of file