diff --git a/include/villas/boxes.h b/include/villas/boxes.h new file mode 100644 index 000000000..2ad23ad0e --- /dev/null +++ b/include/villas/boxes.h @@ -0,0 +1,47 @@ +/** Various helper functions. + * + * @file + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program 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 + * any later version. + * + * This program 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 this program. If not, see . + *********************************************************************************/ + +#pragma once + +/* Alternate character set + * + * The suffixed of the BOX_ macro a constructed by + * combining the following letters in the written order: + * - U for a line facing upwards + * - D for a line facing downwards + * - L for a line facing leftwards + * - R for a line facing rightwards + * + * E.g. a cross can be constructed by combining all line fragments: + * BOX_UDLR + */ +#define BOX(chr) "\e(0" chr "\e(B" +#define BOX_LR BOX("\x71") /**< Boxdrawing: ─ */ +#define BOX_UD BOX("\x78") /**< Boxdrawing: │ */ +#define BOX_UDR BOX("\x74") /**< Boxdrawing: ├ */ +#define BOX_UDLR BOX("\x6E") /**< Boxdrawing: ┼ */ +#define BOX_UDL BOX("\x75") /**< Boxdrawing: ┤ */ +#define BOX_ULR BOX("\x76") /**< Boxdrawing: ┴ */ +#define BOX_UL BOX("\x6A") /**< Boxdrawing: ┘ */ +#define BOX_DLR BOX("\x77") /**< Boxdrawing: ┘ */ +#define BOX_DL BOX("\x6B") /**< Boxdrawing: ┘ */ diff --git a/include/villas/colors.h b/include/villas/colors.h new file mode 100644 index 000000000..916d3a22f --- /dev/null +++ b/include/villas/colors.h @@ -0,0 +1,40 @@ +/** Various helper functions. + * + * @file + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program 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 + * any later version. + * + * This program 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 this program. If not, see . + *********************************************************************************/ + +#pragma once + +/* CPP stringification */ +#define XSTR(x) STR(x) +#define STR(x) #x + +/* Some color escape codes for pretty log messages */ +#define CLR(clr, str) "\e[" XSTR(clr) "m" str "\e[0m" +#define CLR_GRY(str) CLR(30, str) /**< Print str in gray */ +#define CLR_RED(str) CLR(31, str) /**< Print str in red */ +#define CLR_GRN(str) CLR(32, str) /**< Print str in green */ +#define CLR_YEL(str) CLR(33, str) /**< Print str in yellow */ +#define CLR_BLU(str) CLR(34, str) /**< Print str in blue */ +#define CLR_MAG(str) CLR(35, str) /**< Print str in magenta */ +#define CLR_CYN(str) CLR(36, str) /**< Print str in cyan */ +#define CLR_WHT(str) CLR(37, str) /**< Print str in white */ +#define CLR_BLD(str) CLR( 1, str) /**< Print str in bold */ diff --git a/include/villas/copyright.h b/include/villas/copyright.h new file mode 100644 index 000000000..a0603c8cd --- /dev/null +++ b/include/villas/copyright.h @@ -0,0 +1,38 @@ +/** Various helper functions. + * + * @file + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program 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 + * any later version. + * + * This program 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 this program. If not, see . + *********************************************************************************/ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/** Print copyright message to stdout. */ +void print_copyright(); + +/** Print version to stdout. */ +void print_version(); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/utils.h b/include/villas/utils.h index d47d42f75..8d6079f42 100644 --- a/include/villas/utils.h +++ b/include/villas/utils.h @@ -36,7 +36,9 @@ extern "C" { #include #include - +#include +#include +#include #ifdef __GNUC__ #define LIKELY(x) __builtin_expect((x),1) @@ -46,45 +48,6 @@ extern "C" { #define UNLIKELY(x) (x) #endif -/* Some color escape codes for pretty log messages */ -#define CLR(clr, str) "\e[" XSTR(clr) "m" str "\e[0m" -#define CLR_GRY(str) CLR(30, str) /**< Print str in gray */ -#define CLR_RED(str) CLR(31, str) /**< Print str in red */ -#define CLR_GRN(str) CLR(32, str) /**< Print str in green */ -#define CLR_YEL(str) CLR(33, str) /**< Print str in yellow */ -#define CLR_BLU(str) CLR(34, str) /**< Print str in blue */ -#define CLR_MAG(str) CLR(35, str) /**< Print str in magenta */ -#define CLR_CYN(str) CLR(36, str) /**< Print str in cyan */ -#define CLR_WHT(str) CLR(37, str) /**< Print str in white */ -#define CLR_BLD(str) CLR( 1, str) /**< Print str in bold */ - -/* Alternate character set - * - * The suffixed of the BOX_ macro a constructed by - * combining the following letters in the written order: - * - U for a line facing upwards - * - D for a line facing downwards - * - L for a line facing leftwards - * - R for a line facing rightwards - * - * E.g. a cross can be constructed by combining all line fragments: - * BOX_UDLR - */ -#define BOX(chr) "\e(0" chr "\e(B" -#define BOX_LR BOX("\x71") /**< Boxdrawing: ─ */ -#define BOX_UD BOX("\x78") /**< Boxdrawing: │ */ -#define BOX_UDR BOX("\x74") /**< Boxdrawing: ├ */ -#define BOX_UDLR BOX("\x6E") /**< Boxdrawing: ┼ */ -#define BOX_UDL BOX("\x75") /**< Boxdrawing: ┤ */ -#define BOX_ULR BOX("\x76") /**< Boxdrawing: ┴ */ -#define BOX_UL BOX("\x6A") /**< Boxdrawing: ┘ */ -#define BOX_DLR BOX("\x77") /**< Boxdrawing: ┘ */ -#define BOX_DL BOX("\x6B") /**< Boxdrawing: ┘ */ - -/* CPP stringification */ -#define XSTR(x) STR(x) -#define STR(x) #x - #define CONCAT_DETAIL(x, y) x##y #define CONCAT(x, y) CONCAT_DETAIL(x, y) #define UNIQUE(x) CONCAT(x, __COUNTER__) @@ -141,12 +104,6 @@ extern "C" { /* Forward declarations */ struct timespec; -/** Print copyright message to stdout. */ -void print_copyright(); - -/** Print version to stdout. */ -void print_version(); - /** Normal random variate generator using the Box-Muller method * * @param m Mean diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index dd8753a5a..336790ebf 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -72,6 +72,7 @@ set(LIB_SRC table.c bitset.c signal.c + copyright.c ) if(IBVERBS_FOUND AND RDMACM_FOUND) diff --git a/lib/copyright.c b/lib/copyright.c new file mode 100644 index 000000000..d68e6b387 --- /dev/null +++ b/lib/copyright.c @@ -0,0 +1,40 @@ +/** General purpose helper functions. + * + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program 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 + * any later version. + * + * This program 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 this program. If not, see . + *********************************************************************************/ + +#include + +#include +#include +#include + +void print_copyright() +{ + printf("VILLASnode %s (built on %s %s)\n", + CLR_BLU(BUILDID), CLR_MAG(__DATE__), CLR_MAG(__TIME__)); + printf(" Copyright 2014-2017, Institute for Automation of Complex Power Systems, EONERC\n"); + printf(" Steffen Vogel \n"); +} + +void print_version() +{ + printf("%s\n", BUILDID); +} diff --git a/lib/utils.c b/lib/utils.c index b30ad0027..cd43e7a48 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -36,19 +36,6 @@ pthread_t main_thread; -void print_copyright() -{ - printf("VILLASnode %s (built on %s %s)\n", - CLR_BLU(BUILDID), CLR_MAG(__DATE__), CLR_MAG(__TIME__)); - printf(" Copyright 2014-2017, Institute for Automation of Complex Power Systems, EONERC\n"); - printf(" Steffen Vogel \n"); -} - -void print_version() -{ - printf("%s\n", BUILDID); -} - int version_parse(const char *s, struct version *v) { return sscanf(s, "%u.%u", &v->major, &v->minor) != 2;