1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

utils: seperated print_{copyright,version}(), box and color parts of utils

This commit is contained in:
Steffen Vogel 2018-07-18 08:13:13 +02:00
parent fc80bf809d
commit 583e3b730f
7 changed files with 169 additions and 59 deletions

47
include/villas/boxes.h Normal file
View file

@ -0,0 +1,47 @@
/** Various helper functions.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @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 <http://www.gnu.org/licenses/>.
*********************************************************************************/
#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: ┘ */

40
include/villas/colors.h Normal file
View file

@ -0,0 +1,40 @@
/** Various helper functions.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @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 <http://www.gnu.org/licenses/>.
*********************************************************************************/
#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 */

View file

@ -0,0 +1,38 @@
/** Various helper functions.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @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 <http://www.gnu.org/licenses/>.
*********************************************************************************/
#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

View file

@ -36,7 +36,9 @@ extern "C" {
#include <villas/config.h>
#include <villas/log.h>
#include <villas/copyright.h>
#include <villas/colors.h>
#include <villas/boxes.h>
#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

View file

@ -72,6 +72,7 @@ set(LIB_SRC
table.c
bitset.c
signal.c
copyright.c
)
if(IBVERBS_FOUND AND RDMACM_FOUND)

40
lib/copyright.c Normal file
View file

@ -0,0 +1,40 @@
/** General purpose helper functions.
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @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 <http://www.gnu.org/licenses/>.
*********************************************************************************/
#include <stdio.h>
#include <villas/copyright.h>
#include <villas/colors.h>
#include <villas/config.h>
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 <StVogel@eonerc.rwth-aachen.de>\n");
}
void print_version()
{
printf("%s\n", BUILDID);
}

View file

@ -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 <StVogel@eonerc.rwth-aachen.de>\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;