This commit is contained in:
Liam Waldron 2024-01-24 08:00:40 -05:00
commit 8334863111
5 changed files with 158 additions and 0 deletions

14
Makefile Normal file
View File

@ -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

41
README Normal file
View File

@ -0,0 +1,41 @@
+ libevcli
A library unifying CLI output across Everest programs
+ Usage
#include <evcli.h>
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 <stdio.h>
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.

8
config.mk Normal file
View File

@ -0,0 +1,8 @@
#
# config.mk
#
CC=/bin/gcc
AR=/bin/ar
PREFIX=/usr

26
src/evcli.h Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#ifndef EVCLI_H_
#define EVCLI_H_
void infolog(char MSG[]);
void warnlog(char MSG[]);
void errlog(char MSG[]);
void successlog(char MSG[]);
#endif

69
src/libevcli.c Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#include <color.h>
#include <locale.h>
#include <stdio.h>
#include <syslog.h>
#include <wchar.h>
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;
}