diff --git a/.gitignore b/.gitignore index 60f4fe4..9cc28d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ +ncac + +*.o *.swp *.swo -bazel-* - tags diff --git a/BUILD b/BUILD deleted file mode 100644 index 991c4eb..0000000 --- a/BUILD +++ /dev/null @@ -1,12 +0,0 @@ -cc_binary( - name = "ncac", - srcs = [ - "ncac.cc", - "ncac.h", - ], - deps = [ - "//asana", - "//ui", - "@system_include//:curses" - ], -) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..eb13813 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +CFLAGS=--std=c18 -O2 -Wall -Wextra -pedantic +LDLIBS=-lncurses -lcurl + +ncac: ui/base.o asana/fetch.o ncac.o diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index 0c21457..0000000 --- a/WORKSPACE +++ /dev/null @@ -1,25 +0,0 @@ -new_local_repository( - name = "system_include", - path = "/usr/lib", - build_file_content = """ -cc_library( - name = "curses", - srcs = ["libcurses.dylib"], - visibility = ["//visibility:public"], -) - -cc_library( - name = "curl", - srcs = ["libcurl.dylib"], - visibility = ["//visibility:public"], -) - """, -) - -new_http_archive( - name = "gtest", - url = "https://github.com/google/googletest/archive/release-1.8.0.tar.gz", - sha256 = "58a6f4277ca2bc8565222b3bbd58a177609e9c488e8a72649359ba51450db7d8", - build_file = "gtest.BUILD", - strip_prefix = "googletest-release-1.8.0", -) diff --git a/asana/asana.c b/asana/asana.c new file mode 100644 index 0000000..e69de29 diff --git a/asana/asana.h b/asana/asana.h new file mode 100644 index 0000000..c7081bf --- /dev/null +++ b/asana/asana.h @@ -0,0 +1,4 @@ +#ifndef ASANA_ASANA_H_ +#define ASANA_ASANA_H_ + +#endif // ASANA_ASANA_H_ diff --git a/asana/fetch.c b/asana/fetch.c new file mode 100644 index 0000000..533425c --- /dev/null +++ b/asana/fetch.c @@ -0,0 +1,19 @@ +#include "fetch.h" + +#include +#include + + CURL *curl; + +bool asana_init() { + curl_global_init(CURL_GLOBAL_ALL); + curl = curl_easy_init(); + if (!curl) return false; + + return true; +} + +void asana_cleanup() { + curl_global_cleanup(); +} + diff --git a/asana/fetch.h b/asana/fetch.h new file mode 100644 index 0000000..15d3cec --- /dev/null +++ b/asana/fetch.h @@ -0,0 +1,16 @@ +#ifndef ASANA_FETCH_H_ +#define ASANA_FETCH_H_ + +#include + +/** + * initialize libcurl + */ +bool asana_init(); + +/** + * cleanup libcurl before program end + */ +void asana_cleanup(); + +#endif // ASANA_FETCH_H_ diff --git a/gtest.BUILD b/gtest.BUILD deleted file mode 100644 index 44cfcb8..0000000 --- a/gtest.BUILD +++ /dev/null @@ -1,13 +0,0 @@ -cc_library( - name = "main", - srcs = glob( - ["src/*.cc"], - exclude = ["src/gtest-all.cc"] - ), - hdrs = glob([ - "include/**/*.h", - "src/*.h" - ]), - copts = ["-Iexternal/gtest/include"], - visibility = ["//visibility:public"], -) diff --git a/ncac b/ncac deleted file mode 120000 index cd59d26..0000000 --- a/ncac +++ /dev/null @@ -1 +0,0 @@ -bazel-bin/ncac \ No newline at end of file diff --git a/ncac b/ncac new file mode 100755 index 0000000..d2645b0 Binary files /dev/null and b/ncac differ diff --git a/ncac.cc b/ncac.c similarity index 68% rename from ncac.cc rename to ncac.c index 9d0f566..4cd55a6 100644 --- a/ncac.cc +++ b/ncac.c @@ -2,10 +2,9 @@ #include #include +#include #include -#include - #include "ui/base.h" #include "asana/fetch.h" @@ -21,10 +20,10 @@ int main(int argc, char **argv) { while(1) { switch (input = getch()) { case 'a': - ui::draw_text("Hello, world!", &curs_x, &curs_y); + draw_text("Hello, world!", &curs_x, &curs_y); break; case 'b': - ui::draw_text("Goodbye, world!", &curs_x, &curs_y); + draw_text("Goodbye, world!", &curs_x, &curs_y); break; case 'q': finish(SIGTERM); @@ -36,26 +35,26 @@ int main(int argc, char **argv) { static void finish(int sig) { endwin(); - asana::deinit(); + asana_cleanup(); exit(0); } static void setup() { // initialize the asana client - if (!asana::init()) { - std::cerr << "Unable to initialize the Asana client\n" << EOF; + if (!asana_init()) { + fprintf(stderr, "Unable to initialize the Asana client\n"); exit(1); } // initialize ncurses if (!initscr()) { - std::cerr << "Unable to initialize the curses screen.\n" << EOF; + fprintf(stderr, "Unable to initialize the curses screen.\n"); exit(1); } // don't buffer or echo input if (cbreak() == ERR) { - std::cerr << "Unable to initialize.\n" << EOF; + fprintf(stderr, "Unable to initialize.\n"); exit(1); } noecho(); diff --git a/ui/BUILD b/ui/BUILD deleted file mode 100644 index 4986231..0000000 --- a/ui/BUILD +++ /dev/null @@ -1,7 +0,0 @@ -cc_library( - name="ui", - srcs = ["base.cc"], - hdrs = ["base.h"], - deps = ["@system_include//:curses"], - visibility = ["//visibility:public"], -) diff --git a/ui/base.c b/ui/base.c new file mode 100644 index 0000000..3ea99c0 --- /dev/null +++ b/ui/base.c @@ -0,0 +1,18 @@ +#include "base.h" + +#include +#include + + +void draw_text(char *text, int *x, int *y) { + if (!text || strnlen(text, 1) == 0) return; + + mvaddch(*y, *x, *text); + ++text; + + for (; *text != '\0'; ++text) { + addch(*text); + } + + getyx(stdscr, *y, *x); +} diff --git a/ui/base.cc b/ui/base.cc deleted file mode 100644 index ecbb95d..0000000 --- a/ui/base.cc +++ /dev/null @@ -1,23 +0,0 @@ -#include "base.h" - -#include -#include - -#include - -namespace ui { - void draw_text(const std::string text, int *x, int *y) { - if (!text.length()) return; - - auto iter = text.begin(); - - mvaddch(*y, *x, *iter); - ++iter; - - for (; iter != text.end(); ++iter) { - addch(*iter); - } - - getyx(stdscr, *y, *x); - } -} diff --git a/ui/base.h b/ui/base.h index ea7f085..cc907c8 100644 --- a/ui/base.h +++ b/ui/base.h @@ -1,14 +1,10 @@ #ifndef UI_BASE_H_ #define UI_BASE_H_ -#include +/** + * Prints the string text starting at position *x, *y. x and y are updated to + * the position after the last character + */ +void draw_text(char *text, int *x, int *y); -namespace ui { - /** - * Prints the string text starting at position *x, *y. x and y are updated to - * the position after the last character - */ - void draw_text(const std::string text, int *x, int *y); - -} // namespace ui #endif // UI_BASE_H_