From 8334863111815d3b5929a590c835df58bfd3ffe4 Mon Sep 17 00:00:00 2001 From: Liam Waldron Date: Wed, 24 Jan 2024 08:00:40 -0500 Subject: [PATCH] init --- Makefile | 14 ++++++++++ README | 41 ++++++++++++++++++++++++++++++ config.mk | 8 ++++++ src/evcli.h | 26 +++++++++++++++++++ src/libevcli.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 config.mk create mode 100644 src/evcli.h create mode 100644 src/libevcli.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cc04308 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +include config.mk + +all: + mkdir build + cp src/evcli.h build/evcli.h + $(CC) -c src/libevcli.c -o build/libevcli.o + $(AR) -rc build/libevcli.a build/libevcli.o + +install: + install build/libevcli.a $(PREFIX)/lib + install build/evcli.h $(PREFIX)/include + +clean: + rm -rf build diff --git a/README b/README new file mode 100644 index 0000000..3aa9696 --- /dev/null +++ b/README @@ -0,0 +1,41 @@ ++ libevcli + +A library unifying CLI output across Everest programs + ++ Usage + + #include + + int + main() + { + infolog("Info message"); + warnlog("Warning message"); + errlog("Error message"); + successlog("Success message"); + } + + (user)$ gcc prog.c -levcli -o prog + + No manpage is supplied, this library should be incredibly straightforward to use. + ++ Caveats + +None of the functions here can output variables. If you need to output variables: + + #include + + int + main() + { + printf(COL_BLUE "[i]" COL_RESET " %s\n", VAR); + printf(COL_YELLOW "[!]" COL_RESET " %s\n", VAR); + printf(COL_RED "[x]" COL_RESET " %s\n", VAR); + printf(COL_GREEN "[%lc]" COL_RESET "%s\n", check, VAR); + } + ++ Installation + +Run 'make' to build the static library. Run 'make install' to install the static library and header. + +Run 'make clean' to remove all built files from the source tree. diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..9996fb8 --- /dev/null +++ b/config.mk @@ -0,0 +1,8 @@ +# +# config.mk +# + +CC=/bin/gcc +AR=/bin/ar + +PREFIX=/usr diff --git a/src/evcli.h b/src/evcli.h new file mode 100644 index 0000000..2b23f13 --- /dev/null +++ b/src/evcli.h @@ -0,0 +1,26 @@ +/* + * evcli.h - Function declarations for libevcli + * + * This file is part of libevcli. + * + * Libevcli is free software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * Libevcli is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with libevcli. If + * not, see . + */ + +#ifndef EVCLI_H_ +#define EVCLI_H_ + +void infolog(char MSG[]); +void warnlog(char MSG[]); +void errlog(char MSG[]); +void successlog(char MSG[]); + +#endif diff --git a/src/libevcli.c b/src/libevcli.c new file mode 100644 index 0000000..e31eab7 --- /dev/null +++ b/src/libevcli.c @@ -0,0 +1,69 @@ +/* + * libevcli.c - Library for Everest-styled command line output + * + * Libevcli is free software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * Libevcli is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with libevcli. If + * not, see . + */ + +#include +#include +#include +#include +#include + +const wchar_t check = 0x2713; + +void +infolog(char MSG[]) +{ + if (MSG == NULL) { + return; + } + + printf(COL_BLUE "[i]" COL_RESET " %s\n", MSG); + return; +} + + +void +warnlog(char MSG[]) +{ + if (MSG == NULL) { + return; + } + + printf(COL_YELLOW "[!]" COL_RESET " %s\n", MSG); + return; +} + +void +errlog(char MSG[]) +{ + if (MSG == NULL) { + return; + } + + fprintf(stderr, COL_RED "[x]" COL_RESET " %s\n", MSG); + return; +} + +void +successlog(char MSG[]) +{ + setlocale(LC_CTYPE, ""); + + if (MSG == NULL) { + return; + } + + printf(COL_GREEN "[%lc]" COL_RESET " %s\n", check, MSG); + return; +}