From 084009d9abae9396f3314c2e0aef41a3da943ab4 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 5 Jun 2014 09:34:45 +0000 Subject: [PATCH] added debug() and assert() functions git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@18 8ec27952-4edc-4aab-86aa-e87bb2611832 --- Makefile | 12 +++++------- include/utils.h | 12 +++++++++++- src/server.c | 17 +++++++---------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index ae986bf25..400694e84 100644 --- a/Makefile +++ b/Makefile @@ -6,16 +6,14 @@ VPATH = src CC = gcc RM = rm -f -GIT_TAG = $(shell git describe --tags) +GIT_TAG = $(shell git describe --tags --abbrev=0) GIT_REV = $(shell git rev-parse --short HEAD) -LDFLAGS = -pthread -lrt -CFLAGS = -std=c99 -Iinclude/ -D_XOPEN_SOURCE=500 -CFLAGS += -D__GIT_REV__='"$(GIT_REV)"' -D__GIT_TAG__='"$(GIT_TAG)"' +V ?= 0 -ifdef (DEBUG) - CFLAGS += -DDEBUG=$(DEBUG) -g -endif +LDFLAGS = -pthread -lrt +CFLAGS = -g -std=c99 -Iinclude/ -D_XOPEN_SOURCE=500 -DV=$(V) +CFLAGS += -D__GIT_REV__='"$(GIT_REV)"' -D__GIT_TAG__='"$(GIT_TAG)"' .PHONY: all clean doc diff --git a/include/utils.h b/include/utils.h index c95d69818..47cba8a32 100644 --- a/include/utils.h +++ b/include/utils.h @@ -1,7 +1,7 @@ /** * Some helper functions * - * @author Steffen Vogel + * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC */ @@ -26,6 +26,16 @@ enum log_level */ void print(enum log_level lvl, const char *fmt, ...); +#define assert(exp) do { \ + if (exp); print(FATAL, "Assertion failed: '%s' in %s, %s:%d", \ + #exp, __FUNCTION__, __BASE_FILE__, __LINE__); \ + } while(0) + +#define debug(lvl, ...) do { \ + if (lvl <= V) \ + print(DEBUG, __VA_ARGS__); \ + } while (0) + /** * @brief Print short usage info to stdout */ diff --git a/src/server.c b/src/server.c index b5686c87b..ff89373f2 100644 --- a/src/server.c +++ b/src/server.c @@ -56,27 +56,24 @@ void quit() for (int i = 0; i < MAX_NODES && nodes[i]; i++) node_destroy(nodes[i]); - print(INFO, "Goodbye!"); - _exit(0); + debug(1, "Goodbye!"); + _exit(EXIT_SUCCESS); } int main(int argc, char *argv[]) { atexit(&quit); - assert(0); - if (argc != 1) { - printf("Usage: s2ss [config]\n"); + printf("Usage: %s [config]\n", argv[0]); printf(" config is an optional path to a configuration file\n\n"); - printf("Simulator2Simulator Server %s\n", VERSION); - printf(" Build: %s %s\n", __DATE__, __TIME__); - printf(" Contact: Steffen Vogel \n\n"); exit(EXIT_FAILURE); } - print(INFO, "Good morning! This is s2ss %s", VERSION); + debug(1, "Good morning! This is s2ss %s", VERSION); init(); /* Setup paths and nodes manually */