libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

commit 3c6d0cd6736508d0a7af5ada9d8a5bada00dc38b
parent 905b20fe11f1ce6a5812b4310d9050ed6a6e9002
Author: Remy Noulin <loader2x@gmail.com>
Date:   Wed, 23 Oct 2019 14:17:04 +0200

add logXSuccess, logXFailure and logExit to log a string and exit

These new macros are useful to know at which line a program exits

add XSuccess and XFailure

completion.txt      |  7 ++++++-
documentation.md    | 31 +++++++++++++++++++++++++++++--
release/libsheepy.h | 38 ++++++++++++++++++++++++++++++++++++--
src/libsheepy.c     |  4 ++++
src/libsheepy.h     | 38 ++++++++++++++++++++++++++++++++++++--
5 files changed, 111 insertions(+), 7 deletions(-)

Diffstat:
Mcompletion.txt | 7++++++-
Mdocumentation.md | 31+++++++++++++++++++++++++++++--
Mrelease/libsheepy.h | 38++++++++++++++++++++++++++++++++++++--
Msrc/libsheepy.c | 4++++
Msrc/libsheepy.h | 38++++++++++++++++++++++++++++++++++++--
5 files changed, 111 insertions(+), 7 deletions(-)

diff --git a/completion.txt b/completion.txt @@ -11,8 +11,13 @@ no off boolS(x) XSUCCESS +XSuccess XFAILURE -exitFailure(data) +XFailure +logXSuccess(string) +logXFailure(string) +logExit(exitCode, string) +exitFailure(cond) procbegin procend funcbegin diff --git a/documentation.md b/documentation.md @@ -42,8 +42,13 @@ no off boolS(x) XSUCCESS +XSuccess XFAILURE -exitFailure(data) +XFailure +logXSuccess(string) +logXFailure(string) +logExit(exitCode, string) +exitFailure(cond) procbegin procend funcbegin @@ -1392,14 +1397,36 @@ extern const bool FALSE; * success */ #define XSUCCESS exit(EXIT_SUCCESS); +#define XSuccess XSUCCESS /* * failure */ #define XFAILURE exit(EXIT_FAILURE); +#define XFailure XFAILURE +/* + * log string with logP and exit with success + * + * This is useful to know at which line a program exits + */ +#define logXSuccess(string) MACRO(\ +/* + * log string with logC and exit with failure + * + * This is useful to know at which line a program exits + */ +#define logXFailure(string) MACRO(\ +/* + * log string with logI and exit with exitCode + * + * This is useful to know at which line a program exits + */ +#define logExit(exitCode, string) MACRO (\ /* * exit failure + * + * Exits when cond is false */ -#define exitFailure(data) \ +#define exitFailure(cond) \ /* * defines for macro begin and end * diff --git a/release/libsheepy.h b/release/libsheepy.h @@ -133,17 +133,51 @@ extern const bool FALSE; * success */ #define XSUCCESS exit(EXIT_SUCCESS); +#define XSuccess XSUCCESS /** * failure */ #define XFAILURE exit(EXIT_FAILURE); +#define XFailure XFAILURE + +/** + * log string with logP and exit with success + * + * This is useful to know at which line a program exits + */ +#define logXSuccess(string) MACRO(\ + logP("Success: %s", string);\ + XSuccess;\ + ) + +/** + * log string with logC and exit with failure + * + * This is useful to know at which line a program exits + */ +#define logXFailure(string) MACRO(\ + logC("Failed: %s", string);\ + XFailure;\ + ) + +/** + * log string with logI and exit with exitCode + * + * This is useful to know at which line a program exits + */ +#define logExit(exitCode, string) MACRO (\ + logI("Exit: %s", string);\ + exit(exitCode);\ + ) /** * exit failure + * + * Exits when cond is false */ -#define exitFailure(data) \ - if (!data) \ +#define exitFailure(cond) \ + if (!cond) \ exit(EXIT_FAILURE); diff --git a/src/libsheepy.c b/src/libsheepy.c @@ -54436,6 +54436,10 @@ int MAIN(int ARGC, char** ARGV) { /* f32 x = 0 */ /* f64 p = 0 */ + logExit(EXIT_SUCCESS, "qweqwe"); + logXSuccess("qweqwe"); + logXFailure("qweqwe"); + logSystemf("ls /home/%s/.ssh/", "remy"); char *rel = relPath("/wer/w/e", "../wer/ef");; diff --git a/src/libsheepy.h b/src/libsheepy.h @@ -133,17 +133,51 @@ extern const bool FALSE; * success */ #define XSUCCESS exit(EXIT_SUCCESS); +#define XSuccess XSUCCESS /** * failure */ #define XFAILURE exit(EXIT_FAILURE); +#define XFailure XFAILURE + +/** + * log string with logP and exit with success + * + * This is useful to know at which line a program exits + */ +#define logXSuccess(string) MACRO(\ + logP("Success: %s", string);\ + XSuccess;\ + ) + +/** + * log string with logC and exit with failure + * + * This is useful to know at which line a program exits + */ +#define logXFailure(string) MACRO(\ + logC("Failed: %s", string);\ + XFailure;\ + ) + +/** + * log string with logI and exit with exitCode + * + * This is useful to know at which line a program exits + */ +#define logExit(exitCode, string) MACRO (\ + logI("Exit: %s", string);\ + exit(exitCode);\ + ) /** * exit failure + * + * Exits when cond is false */ -#define exitFailure(data) \ - if (!data) \ +#define exitFailure(cond) \ + if (!cond) \ exit(EXIT_FAILURE);