diff --git a/Makefile.am b/Makefile.am index 6c55942..3e8bae1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,7 +18,7 @@ INSTALLER_LOG_FILE = "./installer.log" PACK_NAME = $(SHARED_LIB)-$(VERSION)-$(OS)-$(MACHINE) # Source files -demo_SOURCES = src/koliseo.c static/amboso.c static/demo.c +demo_SOURCES = src/koliseo.c static/amboso.c static/demo.c static/kls_banner.c lib_SOURCES = src/koliseo.c # Linking rule @@ -42,10 +42,6 @@ else AM_LDFLAGS += -s endif -if CURSES_BUILD -AM_CFLAGS += -DKOLISEO_HAS_CURSES -endif - if GULP_BUILD AM_CFLAGS += -DKOLISEO_HAS_GULP endif diff --git a/README.md b/README.md index 6861fd1..6095134 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,9 @@ + [Basic example](#basic_example) + [Extra features](#extra_features) + [Region](#extra_region) - + [Curses](#extra_curses) + [Debug](#extra_debug) + [Gulp](#extra_gulp) + [List template](#list_template) - + [Title banner](#extra_title) + [Experimental](#extra_exper) + [How to use extras](#extra_howto) + [Documentation](#docs) @@ -106,10 +104,6 @@ int main(void) - Extra utility functions - Help you estimate relative memory usage by some particular type of object. May prove useful in some scenarios. -### Curses - - Utility functions that extend ncurses API to provide debug info. - ### Core debug Extra debug for core calls, may be too verbose for some applications. @@ -138,10 +132,6 @@ int main(void) This is inspired by the dynamic array example by [David Priver](#credits). -### Title banner - - Include an ASCII art string to be printed as a title banner. - ### Experimental Include some experimental (NOT WELL TESTED. USE WITH CAUTION) functions. @@ -155,10 +145,8 @@ int main(void) The preprocessor macros to enable them manually are: - Region: `KOLISEO_HAS_REGION` - - Curses: `KOLISEO_HAS_CURSES` - Debug: `KLS_DEBUG_CORE` - Gulp: `KOLISEO_HAS_GULP` - - Title banner: `KOLISEO_HAS_TITLE` - Experimental: `KOLISEO_HAS_EXPER` ## Documentation @@ -201,9 +189,7 @@ int main(void) - Run `./configure --enable-debug` to setup the `Makefile` appropriately and build with `-DKLS_DEBUG_CORE` flag. - By default, enabling debug this way also adds `-DKLS_SETCONF_DEBUG` to the demo build. This preproc guard lets you really debug kls initialisation, by printing logs from inside `kls_set_conf()`. - Run `./configure --enable-region` to setup the `Makefile` appropriately and build with `-DKOLISEO_HAS_REGION` flag. - - Run `./configure --enable-curses` to setup the `Makefile` appropriately and build with `-DKOLISEO_HAS_CURSES` flag. - Run `./configure --enable-gulp` to setup the `Makefile` appropriately and build with `-DKOLISEO_HAS_GULP` flag. - - Run `./configure --enable-title` to setup the `Makefile` appropriately and build with `-DKOLISEO_HAS_TITLE` flag. - Run `./configure --enable-exper` to setup the `Makefile` appropriately and build with `-DKOLISEO_HAS_EXPER` flag. diff --git a/amboso b/amboso index b71d2fc..75c36e4 160000 --- a/amboso +++ b/amboso @@ -1 +1 @@ -Subproject commit b71d2fc676ce1177b24f2b84c849b65ea92f8913 +Subproject commit 75c36e46f7b92680f788ddc156d813e506392067 diff --git a/configure.ac b/configure.ac index 260cf56..2b9b85a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ # Define the package name and version -AC_INIT([koliseo], [0.4.5], [jgabaut@github.com]) +AC_INIT([koliseo], [0.4.6], [jgabaut@github.com]) # Verify automake version and enable foreign option AM_INIT_AUTOMAKE([foreign -Wall]) @@ -19,10 +19,6 @@ AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], [Enable debug build])], [enable_debug=$enableval], [enable_debug=no]) -AC_ARG_ENABLE([curses], - [AS_HELP_STRING([--enable-curses], [Enable curses functions])], - [enable_curses=$enableval], - [enable_curses=no]) AC_ARG_ENABLE([gulp], [AS_HELP_STRING([--enable-gulp], [Enable gulp header])], [enable_gulp=$enableval], @@ -41,7 +37,6 @@ AC_ARG_ENABLE([exper], [enable_exper=no]) AM_CONDITIONAL([LOCATE_BUILD], [test "$enable_locate" = "yes"]) AM_CONDITIONAL([DEBUG_BUILD], [test "$enable_debug" = "yes"]) -AM_CONDITIONAL([CURSES_BUILD], [test "$enable_curses" = "yes"]) AM_CONDITIONAL([GULP_BUILD], [test "$enable_gulp" = "yes"]) AM_CONDITIONAL([REGION_BUILD], [test "$enable_region" = "yes"]) AM_CONDITIONAL([TITLE_BUILD], [test "$enable_title" = "yes"]) @@ -52,15 +47,9 @@ case "${host_os}" in mingw*) echo "Building for mingw32: [$host_cpu-$host_vendor-$host_os]" # mingw32 specific flags - if test "$enable_curses" = "yes"; then - echo "Building with curses header" - build_windows=yes - AC_SUBST([KOLISEO_CFLAGS], ["-I/usr/x86_64-w64-mingw32/include -static -fstack-protector -DNCURSES_STATIC"]) - AC_SUBST([KOLISEO_LDFLAGS], ["-L/usr/x86_64-w64-mingw32/lib -lncursesw"]) - else - AC_SUBST([KOLISEO_CFLAGS], ["-I/usr/x86_64-w64-mingw32/include -static -fstack-protector"]) - AC_SUBST([KOLISEO_LDFLAGS], ["-L/usr/x86_64-w64-mingw32/lib"]) - fi + build_windows=yes + AC_SUBST([KOLISEO_CFLAGS], ["-I/usr/x86_64-w64-mingw32/include -static -fstack-protector"]) + AC_SUBST([KOLISEO_LDFLAGS], ["-L/usr/x86_64-w64-mingw32/lib"]) AC_SUBST([CCOMP], ["/usr/bin/x86_64-w64-mingw32-gcc"]) AC_SUBST([OS], ["w64-mingw32"]) AC_SUBST([TARGET], ["demo.exe"]) @@ -70,14 +59,8 @@ case "${host_os}" in echo "Building for macos: [$host_cpu-$host_vendor-$host_os]" build_mac=yes # macOS specific flags - if test "$enable_curses" = "yes"; then - echo "Building with curses header" - AC_SUBST([KOLISEO_LDFLAGS], ["-L/opt/homebrew/opt/ncurses/lib -lncurses"]) - AC_SUBST([KOLISEO_CFLAGS], ["-I/opt/homebrew/opt/ncurses/include"]) - else - AC_SUBST([KOLISEO_LDFLAGS], [""]) - AC_SUBST([KOLISEO_CFLAGS], [""]) - fi + AC_SUBST([KOLISEO_LDFLAGS], [""]) + AC_SUBST([KOLISEO_CFLAGS], [""]) AC_SUBST([OS], ["darwin"]) AC_SUBST([TARGET], ["demo"]) AC_SUBST([SHARED_LIB], ["libkoliseo.so"]) @@ -86,12 +69,7 @@ case "${host_os}" in echo "Building for Linux: [$host_cpu-$host_vendor-$host_os]" build_linux=yes # Linux specific flags - if test "$enable_curses" = "yes"; then - echo "Building with curses header" - AC_SUBST([KOLISEO_LDFLAGS], ["-lncurses"]) - else - AC_SUBST([KOLISEO_LDFLAGS], [""]) - fi + AC_SUBST([KOLISEO_LDFLAGS], [""]) AC_SUBST([KOLISEO_CFLAGS], [""]) AC_SUBST([OS], ["Linux"]) AC_SUBST([TARGET], ["demo"]) @@ -109,7 +87,7 @@ AM_CONDITIONAL([LINUX_BUILD], [test "$build_linux" = "yes"]) # Set a default version number if not specified externally AC_ARG_VAR([VERSION], [Version number]) if test -z "$VERSION"; then - VERSION="0.4.5" + VERSION="0.4.6" fi # Output variables to the config.h header diff --git a/docs/koliseo.doxyfile b/docs/koliseo.doxyfile index 9335e45..8a0ed73 100644 --- a/docs/koliseo.doxyfile +++ b/docs/koliseo.doxyfile @@ -48,7 +48,7 @@ PROJECT_NAME = koliseo # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.4.5 +PROJECT_NUMBER = 0.4.6 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/invil b/invil index b6cf0b7..2bb595a 160000 --- a/invil +++ b/invil @@ -1 +1 @@ -Subproject commit b6cf0b7efe34af35257dd4798abe627e2ef5a4dd +Subproject commit 2bb595a00e0114e15ad2751e7bff5ff57acf70f1 diff --git a/src/koliseo.c b/src/koliseo.c index eff0ead..29fcb60 100644 --- a/src/koliseo.c +++ b/src/koliseo.c @@ -28,6 +28,15 @@ static const KLS_Conf KLS_DEFAULT_CONF__ = { .kls_block_while_has_temp = 1, .kls_log_fp = NULL, .kls_log_filepath = "", + .err_handlers = { +#ifndef KOLISEO_HAS_LOCATE + .OOM_handler = &KLS_OOM_default_handler__, + .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler__, +#else + .OOM_handler = &KLS_OOM_default_handler_dbg__, + .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__, +#endif // KOLISEO_HAS_LOCATE + }, }; /**< Inner config used for any Koliseo used to host the regions for another Koliseo in the KLS_BASIC config.*/ #endif @@ -43,6 +52,15 @@ KLS_Conf KLS_DEFAULT_CONF = { .kls_verbose_lvl = 0, .kls_log_fp = NULL, .kls_log_filepath = "", + .err_handlers = { +#ifndef KOLISEO_HAS_LOCATE + .OOM_handler = &KLS_OOM_default_handler__, + .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler__, +#else + .OOM_handler = &KLS_OOM_default_handler_dbg__, + .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__, +#endif // KOLISEO_HAS_LOCATE + }, }; /**< Config used by any new Koliseo by default.*/ KLS_Stats KLS_STATS_DEFAULT = { @@ -69,74 +87,6 @@ const char* kls_reglist_backend_strings[KLS_REGLIST_TOTAL_BACKENDS] = { static bool kls_set_conf(Koliseo * kls, KLS_Conf conf); //Declare function used internally by kls_new() and kls_new_conf() -#ifdef KOLISEO_HAS_TITLE -/** - * Defines title banner. - */ -char *kls_title[KLS_TITLEROWS + 1] = { - " .',,,. ", - " ...''',,;;:cl;. ", - " ..''''''.... .co, ", - " .'',,,'.. 'ol. ", - " ..''''.. .co. ", - " ..'.. cl. ", - " ..'... . . .:'... . . .. ..... ... ", - " .... . ..:c,'. .oc .ll. :dddxo. ld. 'x: .cxddx; :kxodo, .lddxx; ", - " .,.. .cl,.. .cxd:.. ;Ol;do. :Ol. c0c .kx. lO; ;0d..:: .xk' .xx' 'kx. ", - " .,.. 'dOl. .''......lKOkc. .kx. ;0l ;0l .xk. 'xk; 'Ok;'. l0; .xk. ", - " ''.;, .,;;............. .xKKO' ;0c c0: lO; 'Od. .lko. :0koo:. .xk. 'Od. ", - " ',.'c;. ....... 'Oo:ko. c0; .xk. .xx. :0c . ;Od. .oO, 'Od. c0: ", - " ,; ....... .::. :O; lO; :0l..okc. 'Od... .oO' .ld'.:Od. 'kk,... .kk,.:kd. ", - " ;xc,... . 'd: .:d; ;l. .l: .:dool''c. 'ddolc. .cc. 'ldooc. 'dxoll:. 'odoo:. ", - " .lx;. . ,d; .ll. .''. ;l:' ", - " :o. ;, cc .. . ,cc:::c, ", - " .c; .. .' ....',,;;;;;;;;;;,,,,,,,,,,;;;ox;........'cddoollcc:;,,'.. ", - " ,: ...',:clodxkO0KKXXXXXXKKK000000KKKKXXXXKKKXXXKKKKKKKKKXNNNNNNNNNNNXXKOxoc;'. ", - " .:. ..';cldkOKXXXXK0Okxxdolc::;,''.','......';clc::cloONNNNNNNNNNNNNNNNNNNNNNNNNNNNNNK0xl;. ", - " :xxxOKKK0kxoddl;,';od;. 'cl, .ckko. ,d00Ol. .xXNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNKkl;. ", - ".lKX0xoc,';;. .ll. ;xO; .oX0, ,ONXl ,0NNNK; .lKNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNX0o' ", - ".xk;. . .;. .:, .dc 'OK; .dNNo. ;0NNNXc ;kXNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNk.", - " :c .. .. .l, .k0, .xXXo ;0XNNXc .l0NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNO'", - " :; .'. .;:. .,cl;....,loddo;.. 'dKNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN0,", - ".c, ....',;;:cclllooddddddddddodxxxxxxxdddddddolllccccc:cxXNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNK;", - ".l:',:cloxxkkkOkkxxdollcc::;,,'''.............................',cONNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNXc", - ":00OOxdoc:;,'... .. .. . .oNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNXl", - ":o,..',. .. ';. .co' ;d, 'oOk; .o00kd; .oOkd, :KNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNXl", - ":; ,o' .. .l: ;0o .dXo. 'xNNk. 'ONNNNO' :KNNNd. cKNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNXo", - "c; .. .. '; 'ko. 'ONo. .kNNO' ,0NNNNK; :KNNXd. :0NNNNNNNNNNNNNNNNNNNNNNNNNNNNNXo", - "l, .. 'ko 'OXl ,0NNO' 'ONNNNK; ;KNNXl. ;ONNNNNNNNNNNNNNNNNNNNNNNNNNNNXl", - "cc.............';'...;do'...:k0c....:0XX0:...'xXXXX0c...:0XK0l.......c0NNNNNNNNNNNNNNNNNNNNXXXXXXKO,", - ".;:;;;;;;:::::::::cc:::::::::c:;;;;,;ccc:;,,,,:cccc:;;;;;ccc:;,,,,,;;;clloooooooooooooooooollcc:;,. " -}; - -/** - * Prints the title banner to the passed FILE pointer. - * @see kls_title - * @param fp The FILE to print to. - */ -void kls_print_title_2file(FILE *fp) -{ - if (fp == NULL) { - fprintf(stderr, - "[KLS] kls_print_title_2file(): Passed file pointer was NULL.\n"); - exit(EXIT_FAILURE); - } - for (int i = 0; i < KLS_TITLEROWS; i++) { - fprintf(fp, "%s\n", kls_title[i]); - } -} - -/** - * Prints the title banner to stdout. - * @see kls_title - */ -void kls_print_title(void) -{ - kls_print_title_2file(stdout); -} - -#endif // KOLISEO_HAS_TITLE - /** * Returns the constant string representing current version for Koliseo. * @return A constant string in MAJOR-MINOR-PATCH format for current Koliseo version. @@ -173,11 +123,74 @@ const char* kls_reglist_backend_string(KLS_RegList_Alloc_Backend kls_be) } #endif // KOLISEO_HAS_REGION +/** + * Used internally for handling Out-Of-Memory in push calls when no user handler is provided. + * @param kls The Koliseo used in the push call + * @param available The Koliseo's available memory + * @param padding The current push call's padding + * @param size The current push call's size + * @param count The current push call's count + * @see KLS_Conf + */ +#ifndef KOLISEO_HAS_LOCATE +void KLS_OOM_default_handler__(Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count) +#else +void KLS_OOM_default_handler_dbg__(Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc) +#endif // KOLISEO_HAS_LOCATE +{ +#ifndef KOLISEO_HAS_LOCATE + fprintf(stderr, + "[KLS] Out of memory. size*count [%td] was bigger than available-padding [%td].\n", + size * count, available - padding); +#else + fprintf(stderr, + "[KLS] " KLS_Loc_Fmt "Out of memory. size*count [%td] was bigger than available-padding [%td].\n", + KLS_Loc_Arg(loc), + size * count, available - padding); +#endif // KOLISEO_HAS_LOCATE + kls_free(kls); // Is it even worth it to try? + exit(EXIT_FAILURE); // Better than nothing. May change to return NULL instead? Requiring refactor of handler signature +} + +#ifndef KOLISEO_HAS_LOCATE +void KLS_PTRDIFF_MAX_default_handler__(struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count) +#else +void KLS_PTRDIFF_MAX_default_handler_dbg__(struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc) +#endif +{ +#ifndef _WIN32 +#ifndef KOLISEO_HAS_LOCATE + fprintf(stderr, + "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%li].\n", + count, PTRDIFF_MAX / size); +#else + fprintf(stderr, + "[KLS] " KLS_Loc_Fmt "count [%td] was bigger than PTRDIFF_MAX/size [%li].\n", + KLS_Loc_Arg(loc), + count, PTRDIFF_MAX / size); +#endif // KOLISEO_HAS_LOCATE +#else +#ifndef KOLISEO_HAS_LOCATE + fprintf(stderr, + "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n", + count, PTRDIFF_MAX / size); +#else + fprintf(stderr, + "[KLS] " KLS_Loc_Fmt "count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n", + KLS_Loc_Arg(loc), + count, PTRDIFF_MAX / size); +#endif // KOLISEO_HAS_LOCATE +#endif // _WIN32 + kls_free(kls); + exit(EXIT_FAILURE); +} + /** * Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS. + * Passes custom error handlers for errors in push calls. * @see KLS_Conf */ -KLS_Conf kls_conf_init(int autoset_regions, int alloc_backend, ptrdiff_t reglist_kls_size, int autoset_temp_regions, int collect_stats, int verbose_lvl, int block_while_has_temp, FILE* log_fp, const char* log_filepath) +KLS_Conf kls_conf_init_handled(int autoset_regions, int alloc_backend, ptrdiff_t reglist_kls_size, int autoset_temp_regions, int collect_stats, int verbose_lvl, int block_while_has_temp, FILE* log_fp, const char* log_filepath, KLS_Err_Handlers err_handlers) { KLS_Conf res = {0}; #ifdef KOLISEO_HAS_REGION @@ -197,9 +210,39 @@ KLS_Conf kls_conf_init(int autoset_regions, int alloc_backend, ptrdiff_t reglist res.kls_log_fp = log_fp; res.kls_log_filepath = log_filepath; + if (err_handlers.OOM_handler != NULL) { + res.err_handlers.OOM_handler = err_handlers.OOM_handler; + } else { +#ifndef KOLISEO_HAS_LOCATE + res.err_handlers.OOM_handler = &KLS_OOM_default_handler__; +#else + res.err_handlers.OOM_handler = &KLS_OOM_default_handler_dbg__; +#endif // KOLISEO_HAS_LOCATE + } + + if (err_handlers.PTRDIFF_MAX_handler != NULL) { + res.err_handlers.PTRDIFF_MAX_handler = err_handlers.PTRDIFF_MAX_handler; + } else { +#ifndef KOLISEO_HAS_LOCATE + res.err_handlers.PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler__; +#else + res.err_handlers.PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__; +#endif // KOLISEO_HAS_LOCATE + } + return res; } +/** + * Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS. + * @see KLS_Conf + */ +KLS_Conf kls_conf_init(int autoset_regions, int alloc_backend, ptrdiff_t reglist_kls_size, int autoset_temp_regions, int collect_stats, int verbose_lvl, int block_while_has_temp, FILE* log_fp, const char* log_filepath) +{ + KLS_Err_Handlers err_handlers = KLS_DEFAULT_ERR_HANDLERS; + return kls_conf_init_handled(autoset_regions, alloc_backend, reglist_kls_size, autoset_temp_regions, collect_stats, verbose_lvl, block_while_has_temp, log_fp, log_filepath, err_handlers); +} + /** * Prints enabled Koliseo features to stderr. */ @@ -210,11 +253,6 @@ void kls_dbg_features(void) #else bool kls_locate = false; #endif -#ifdef KOLISEO_HAS_CURSES - bool kls_ncurses = true; -#else - bool kls_ncurses = false; -#endif #ifdef KOLISEO_HAS_GULP bool kls_gulp = true; #else @@ -225,11 +263,6 @@ void kls_dbg_features(void) #else bool kls_region = false; #endif -#ifdef KOLISEO_HAS_TITLE - bool kls_title = true; -#else - bool kls_title = false; -#endif #ifdef KLS_DEBUG_CORE bool kls_debug = true; #else @@ -240,17 +273,15 @@ void kls_dbg_features(void) #else bool kls_exper = false; #endif - bool features[7] = { + bool features[5] = { [0] = kls_debug, [1] = kls_locate, - [2] = kls_title, - [3] = kls_ncurses, - [4] = kls_region, - [5] = kls_gulp, - [6] = kls_exper, + [2] = kls_region, + [3] = kls_gulp, + [4] = kls_exper, }; int total_enabled = 0; - for (int i=0; i<7; i++) { + for (int i=0; i<5; i++) { if (features[i]) { total_enabled += 1; } @@ -268,14 +299,6 @@ void kls_dbg_features(void) fprintf(stderr, "locate%s", (total_enabled > 1 ? ", " : "")); total_enabled -= 1; } - if (kls_title) { - fprintf(stderr, "title%s", (total_enabled > 1 ? ", " : "")); - total_enabled -= 1; - } - if (kls_ncurses) { - fprintf(stderr, "ncurses%s", (total_enabled > 1 ? ", " : "")); - total_enabled -= 1; - } if (kls_region) { fprintf(stderr, "region%s", (total_enabled > 1 ? ", " : "")); total_enabled -= 1; @@ -413,6 +436,7 @@ void kls_log(Koliseo *kls, const char *tag, const char *format, ...) * Sets the KLS_Conf field to KLS_DEFAULT_CONF. * Sets the fields with appropriate values if memory allocation was successful, goes to exit() otherwise. * @param size The size for Koliseo data field. + * @param alloc_func The allocation function to use to init the Koliseo. * @return A pointer to the initialised Koliseo struct. * @see Koliseo * @see Koliseo_Temp @@ -552,13 +576,15 @@ Koliseo *kls_new_conf_alloc(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_ * @param size The size for Koliseo data field. * @param output_path The filepath for log output. * @param alloc_func The allocation function to use. + * @param err_handlers The error handlers struct for errors in push calls. * @return A pointer to the initialised Koliseo struct, with wanted config. * @see Koliseo * @see KLS_Conf * @see kls_new_conf_alloc() */ -Koliseo *kls_new_traced_alloc(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func) +Koliseo *kls_new_traced_alloc_handled(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers) { + #ifndef KLS_DEBUG_CORE fprintf(stderr, "[WARN] %s(): KLS_DEBUG_CORE is not defined. No tracing allowed.\n", @@ -566,22 +592,48 @@ Koliseo *kls_new_traced_alloc(ptrdiff_t size, const char *output_path, kls_alloc #endif KLS_Conf k = (KLS_Conf) { .kls_collect_stats = 1,.kls_verbose_lvl = - 1,.kls_log_filepath = output_path + 1,.kls_log_filepath = output_path, +#ifndef KOLISEO_HAS_LOCATE + .err_handlers.OOM_handler = (err_handlers.OOM_handler != NULL ? err_handlers.OOM_handler : &KLS_OOM_default_handler__), + .err_handlers.PTRDIFF_MAX_handler = ( err_handlers.PTRDIFF_MAX_handler != NULL ? err_handlers.PTRDIFF_MAX_handler : &KLS_PTRDIFF_MAX_default_handler__), +#else + .err_handlers.OOM_handler = (err_handlers.OOM_handler != NULL ? err_handlers.OOM_handler : &KLS_OOM_default_handler_dbg__), + .err_handlers.PTRDIFF_MAX_handler = ( err_handlers.PTRDIFF_MAX_handler != NULL ? err_handlers.PTRDIFF_MAX_handler : &KLS_PTRDIFF_MAX_default_handler_dbg__), +#endif // KOLISEO_HAS_LOCATE }; return kls_new_conf_alloc(size, k, alloc_func); } +/** + * Takes a ptrdiff_t size, a filepath for the trace output file, and an allocation function pointer. + * Returns a pointer to the prepared Koliseo. + * Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a traced Koliseo, logging to the passed filepath. + * @param size The size for Koliseo data field. + * @param output_path The filepath for log output. + * @param alloc_func The allocation function to use. + * @return A pointer to the initialised Koliseo struct, with wanted config. + * @see Koliseo + * @see KLS_Conf + * @see kls_new_conf_alloc() + */ +Koliseo *kls_new_traced_alloc(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func) +{ + KLS_Err_Handlers err_handlers = KLS_DEFAULT_ERR_HANDLERS; + return kls_new_traced_alloc_handled(size, output_path, alloc_func, err_handlers); +} + /** * Takes a ptrdiff_t size and an allocation function pointer, and returns a pointer to the prepared Koliseo. * Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a debug Koliseo (printing to stderr). * @param size The size for Koliseo data field. * @param alloc_func The allocation function to use. + * @param err_handlers The error handlers for errors in push calls. * @return A pointer to the initialised Koliseo struct, with wanted config. * @see Koliseo * @see KLS_Conf * @see kls_new_conf() */ -Koliseo *kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func) +Koliseo *kls_new_dbg_alloc_handled(ptrdiff_t size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers) { #ifndef KLS_DEBUG_CORE fprintf(stderr, @@ -589,13 +641,36 @@ Koliseo *kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func) __func__); #endif KLS_Conf k = (KLS_Conf) { - .kls_collect_stats = 1,.kls_verbose_lvl = 0 + .kls_collect_stats = 1,.kls_verbose_lvl = 0, +#ifndef KOLISEO_HAS_LOCATE + .err_handlers.OOM_handler = ( err_handlers.OOM_handler != NULL ? err_handlers.OOM_handler : &KLS_OOM_default_handler__), + .err_handlers.PTRDIFF_MAX_handler = ( err_handlers.PTRDIFF_MAX_handler != NULL ? err_handlers.PTRDIFF_MAX_handler : &KLS_PTRDIFF_MAX_default_handler__), +#else + .err_handlers.OOM_handler = ( err_handlers.OOM_handler != NULL ? err_handlers.OOM_handler : &KLS_OOM_default_handler_dbg__), + .err_handlers.PTRDIFF_MAX_handler = ( err_handlers.PTRDIFF_MAX_handler != NULL ? err_handlers.PTRDIFF_MAX_handler : &KLS_PTRDIFF_MAX_default_handler_dbg__), +#endif // KOLIEO_HAS_LOCATE }; Koliseo * kls = kls_new_conf_alloc(size, k, alloc_func); kls->conf.kls_verbose_lvl = 1; return kls; } +/** + * Takes a ptrdiff_t size and an allocation function pointer, and returns a pointer to the prepared Koliseo. + * Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a debug Koliseo (printing to stderr). + * @param size The size for Koliseo data field. + * @param alloc_func The allocation function to use. + * @return A pointer to the initialised Koliseo struct, with wanted config. + * @see Koliseo + * @see KLS_Conf + * @see kls_new_conf() + */ +Koliseo *kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func) +{ + KLS_Err_Handlers err_handlers = KLS_DEFAULT_ERR_HANDLERS; + return kls_new_dbg_alloc_handled(size, alloc_func, err_handlers); +} + /** * Takes a ptrdiff_t size and a filepath for the trace output file, and the needed parameters for a successful init of the prepared Koliseo. * Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a traced Koliseo, logging to the passed filepath. @@ -603,13 +678,14 @@ Koliseo *kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func) * @param output_path The filepath for log output. * @param reglist_kls_size The size to use for the inner reglist Koliseo. * @param alloc_func The allocation function to use. + * @param err_handlers The error handlers for errors in push calls. * @return A pointer to the initialised Koliseo struct, with wanted config. * @see Koliseo * @see KLS_Conf * @see kls_new_conf_alloc() */ -Koliseo *kls_new_traced_AR_KLS_alloc(ptrdiff_t size, const char *output_path, - ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func) +Koliseo *kls_new_traced_AR_KLS_alloc_handled(ptrdiff_t size, const char *output_path, + ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers) { #ifndef KLS_DEBUG_CORE fprintf(stderr, @@ -626,10 +702,39 @@ Koliseo *kls_new_traced_AR_KLS_alloc(ptrdiff_t size, const char *output_path, .kls_autoset_regions = 1, .kls_autoset_temp_regions = 1, #endif // KOLISEO_HAS_REGION + .err_handlers = (KLS_Err_Handlers) { +#ifndef KOLISEO_HAS_LOCATE + .OOM_handler = (err_handlers.OOM_handler != NULL ? err_handlers.OOM_handler : &KLS_OOM_default_handler__), + .PTRDIFF_MAX_handler = (err_handlers.PTRDIFF_MAX_handler != NULL ? err_handlers.PTRDIFF_MAX_handler : &KLS_PTRDIFF_MAX_default_handler__), +#else + .OOM_handler = (err_handlers.OOM_handler != NULL ? err_handlers.OOM_handler : &KLS_OOM_default_handler_dbg__), + .PTRDIFF_MAX_handler = (err_handlers.PTRDIFF_MAX_handler != NULL ? err_handlers.PTRDIFF_MAX_handler : &KLS_PTRDIFF_MAX_default_handler_dbg__), +#endif // KOLISEO_HAS_LOCATE + }, }; return kls_new_conf_alloc(size, k, alloc_func); } +/** + * Takes a ptrdiff_t size and a filepath for the trace output file, and the needed parameters for a successful init of the prepared Koliseo. + * Calls kls_new_conf_alloc() to initialise the Koliseo with the proper config for a traced Koliseo, logging to the passed filepath. + * @param size The size for Koliseo data field. + * @param output_path The filepath for log output. + * @param reglist_kls_size The size to use for the inner reglist Koliseo. + * @param alloc_func The allocation function to use. + * @return A pointer to the initialised Koliseo struct, with wanted config. + * @see Koliseo + * @see KLS_Conf + * @see kls_new_conf_alloc() + */ +Koliseo *kls_new_traced_AR_KLS_alloc(ptrdiff_t size, const char *output_path, + ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func) +{ + KLS_Err_Handlers err_handlers = KLS_DEFAULT_ERR_HANDLERS; + return kls_new_traced_AR_KLS_alloc_handled(size, output_path, + reglist_kls_size, alloc_func, err_handlers); +} + /** * Updates the KLS_Conf for the passed Koliseo pointer. Internal usage. * @param kls The Koliseo pointer to update. @@ -653,6 +758,42 @@ bool kls_set_conf(Koliseo *kls, KLS_Conf conf) "[%s()]: Preliminary set of conf.kls_log_fp to stderr.", __func__); #endif +#endif // KLS_DEBUG_CORE + } + + if (conf.err_handlers.OOM_handler == NULL) { + fprintf(stderr, + "[ERROR] at %s(): passed OOM_handler is NULL. Using default.\n", + __func__); +#ifdef KLS_DEBUG_CORE +#ifdef KLS_SETCONF_DEBUG + kls_log(kls, "KLS", + "[%s()]: Passed OOM_handler was NULL, using default.", + __func__); +#endif +#endif // KLS_DEBUG_CORE +#ifndef KOLISEO_HAS_LOCATE + kls->conf.err_handlers.OOM_handler = &KLS_OOM_default_handler__; +#else + kls->conf.err_handlers.OOM_handler = &KLS_OOM_default_handler_dbg__; +#endif + } + + if (conf.err_handlers.PTRDIFF_MAX_handler == NULL) { + fprintf(stderr, + "[ERROR] at %s(): passed PTRDIFF_MAX_handler is NULL. Using default.\n", + __func__); +#ifdef KLS_DEBUG_CORE +#ifdef KLS_SETCONF_DEBUG + kls_log(kls, "KLS", + "[%s()]: Passed PTRDIFF_MAX_handler was NULL, using default.", + __func__); +#endif +#endif // KLS_DEBUG_CORE +#ifndef KOLISEO_HAS_LOCATE + kls->conf.err_handlers.PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler__; +#else + kls->conf.err_handlers.PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__; #endif } @@ -795,44 +936,60 @@ static inline void kls__check_available_dbg(Koliseo* kls, ptrdiff_t size, ptrdif #endif // KOLISEO_HAS_LOCATE { assert(kls != NULL); - ptrdiff_t available = kls->size - kls->offset; - ptrdiff_t padding = -kls->offset & (align - 1); + const ptrdiff_t available = kls->size - kls->offset; + const ptrdiff_t padding = -kls->offset & (align - 1); if (count > PTRDIFF_MAX / size || available - padding < size * count) { if (count > PTRDIFF_MAX / size) { + if (kls->conf.err_handlers.PTRDIFF_MAX_handler != NULL) { +#ifndef KOLISEO_HAS_LOCATE + kls->conf.err_handlers.PTRDIFF_MAX_handler(kls, size, count); +#else + kls->conf.err_handlers.PTRDIFF_MAX_handler(kls, size, count, loc); +#endif // KOLISEO_HAS_LOCATE + } else { // Let's keep this here for now? It's the original part before adding KLS_PTRDIFF_MAX_default_handler__() #ifndef _WIN32 #ifndef KOLISEO_HAS_LOCATE - fprintf(stderr, - "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%li].\n", - count, PTRDIFF_MAX / size); + fprintf(stderr, + "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%li].\n", + count, PTRDIFF_MAX / size); #else - fprintf(stderr, - "[KLS] " KLS_Loc_Fmt "count [%td] was bigger than PTRDIFF_MAX/size [%li].\n", - KLS_Loc_Arg(loc), - count, PTRDIFF_MAX / size); + fprintf(stderr, + "[KLS] " KLS_Loc_Fmt "count [%td] was bigger than PTRDIFF_MAX/size [%li].\n", + KLS_Loc_Arg(loc), + count, PTRDIFF_MAX / size); #endif // KOLISEO_HAS_LOCATE #else #ifndef KOLISEO_HAS_LOCATE - fprintf(stderr, - "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n", - count, PTRDIFF_MAX / size); + fprintf(stderr, + "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n", + count, PTRDIFF_MAX / size); #else - fprintf(stderr, - "[KLS] " KLS_Loc_Fmt "count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n", - KLS_Loc_Arg(loc), - count, PTRDIFF_MAX / size); + fprintf(stderr, + "[KLS] " KLS_Loc_Fmt "count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n", + KLS_Loc_Arg(loc), + count, PTRDIFF_MAX / size); #endif // KOLISEO_HAS_LOCATE #endif // _WIN32 + } } else { + if (kls->conf.err_handlers.OOM_handler != NULL) { #ifndef KOLISEO_HAS_LOCATE - fprintf(stderr, - "[KLS] Out of memory. size*count [%td] was bigger than available-padding [%td].\n", - size * count, available - padding); + kls->conf.err_handlers.OOM_handler(kls, available, padding, size, count); #else - fprintf(stderr, - "[KLS] " KLS_Loc_Fmt "Out of memory. size*count [%td] was bigger than available-padding [%td].\n", - KLS_Loc_Arg(loc), - size * count, available - padding); + kls->conf.err_handlers.OOM_handler(kls, available, padding, size, count, loc); #endif // KOLISEO_HAS_LOCATE + } else { // Let's keep this here for now? It's the original part before adding KLS_OOM_default_handler__() +#ifndef KOLISEO_HAS_LOCATE + fprintf(stderr, + "[KLS] Out of memory. size*count [%td] was bigger than available-padding [%td].\n", + size * count, available - padding); +#else + fprintf(stderr, + "[KLS] " KLS_Loc_Fmt "Out of memory. size*count [%td] was bigger than available-padding [%td].\n", + KLS_Loc_Arg(loc), + size * count, available - padding); +#endif // KOLISEO_HAS_LOCATE + } } #ifndef KOLISEO_HAS_LOCATE fprintf(stderr, "[KLS] Failed %s() call.\n", __func__); @@ -1876,373 +2033,6 @@ void kls_formatSize(ptrdiff_t size, char *outputBuffer, size_t bufferSize) snprintf(outputBuffer, bufferSize, "%.2f %s", sizeValue, units[unitIndex]); } -#ifdef KOLISEO_HAS_CURSES -/** - * Prints fields and eventually KLS_Region_List from the passed Koliseo pointer, to the passed WINDOW pointer. - * @param kls The Koliseo at hand. - * @param win The Window at hand. - */ -void kls_show_toWin(Koliseo *kls, WINDOW *win) -{ - if (kls == NULL) { - fprintf(stderr, "kls_show_toWin(): passed Koliseo was null."); - exit(EXIT_FAILURE); - } - if (win == NULL) { -#ifdef KLS_DEBUG_CORE - kls_log(kls, "ERROR", "kls_show_toWin(): passed WINDOW was null."); -#else - fprintf(stderr, "kls_show_toWin(): passed WINDOW was null."); -#endif - exit(EXIT_FAILURE); - } - wclear(win); - box(win, 0, 0); - wrefresh(win); - int y = 2; - int x = 2; - mvwprintw(win, y++, x, "Koliseo data:"); - mvwprintw(win, y++, x, "API Level: { %i }", int_koliseo_version()); -#ifndef _WIN32 - mvwprintw(win, y++, x, "Size: { %li }", kls->size); -#else - mvwprintw(win, y++, x, "Size: { %lli }", kls->size); -#endif - char h_size[200]; - kls_formatSize(kls->size, h_size, sizeof(h_size)); - mvwprintw(win, y++, x, "Human size: { %s }", h_size); - char curr_size[200]; - kls_formatSize(kls->offset, curr_size, sizeof(curr_size)); - mvwprintw(win, y++, x, "Used (Human): { %s }", curr_size); -#ifndef _WIN32 - mvwprintw(win, y++, x, "Offset: { %li }", kls->offset); -#else - mvwprintw(win, y++, x, "Offset: { %lli }", kls->offset); -#endif -#ifndef _WIN32 - mvwprintw(win, y++, x, "Prev_Offset: { %li }", kls->prev_offset); -#else - mvwprintw(win, y++, x, "Prev_Offset: { %lli }", kls->prev_offset); -#endif -#ifdef KOLISEO_HAS_REGION - mvwprintw(win, y++, x, "KLS_Region_List len: { %i }", - kls_rl_length(kls->regs)); -#endif - mvwprintw(win, y++, x, "Current usage: { %.3f%% }", - (kls->offset * 100.0) / kls->size); - mvwprintw(win, y++, x, "%s", ""); - mvwprintw(win, y++, x, "q or Enter to quit."); - /* - KLS_Region_List rl = kls_copy(kls->regs); - while (!kls_empty(rl)) { - mvwprintw(win, y, x, "Prev_Offset: [%i]",kls->prev_offset); - } - */ - wrefresh(win); - int ch = '?'; - int quit = -1; - do { - quit = 0; - ch = wgetch(win); - switch (ch) { - case 10: - case 'q': { - quit = 1; - } - break; - default: { - quit = 0; - } - break; - } - } while (!quit); -} - -/** - * Takes a Koliseo_Temp pointer and prints fields and eventually KLS_Region_List from the referred Koliseo pointer, to the passed WINDOW pointer. - * @param t_kls The Koliseo_Temp at hand. - * @param win The Window at hand. - */ -void kls_temp_show_toWin(Koliseo_Temp *t_kls, WINDOW *win) -{ - if (t_kls == NULL) { - fprintf(stderr, "kls_temp_show_toWin(): passed Koliseo_Temp was null."); - exit(EXIT_FAILURE); - } - Koliseo *kls = t_kls->kls; - if (kls == NULL) { - fprintf(stderr, "kls_temp_show_toWin(): referred Koliseo was null."); - exit(EXIT_FAILURE); - } - if (win == NULL) { -#ifdef KLS_DEBUG_CORE - kls_log(kls, "ERROR", - "kls_temp_show_toWin(): passed WINDOW was null."); -#else - fprintf(stderr, "kls_temp_show_toWin(): passed WINDOW was null."); -#endif - exit(EXIT_FAILURE); - } - wclear(win); - box(win, 0, 0); - wrefresh(win); - int y = 2; - int x = 2; - mvwprintw(win, y++, x, "Koliseo_Temp data:"); - mvwprintw(win, y++, x, "API Level: { %i }", int_koliseo_version()); -#ifndef _WIN32 - mvwprintw(win, y++, x, "Temp Size: { %li }", kls->size - t_kls->offset); - mvwprintw(win, y++, x, "Refer Size: { %li }", kls->size); -#else - mvwprintw(win, y++, x, "Temp Size: { %lli }", kls->size - t_kls->offset); - mvwprintw(win, y++, x, "Refer Size: { %lli }", kls->size); -#endif - char h_size[200]; - char curr_size[200]; - kls_formatSize(kls->size - t_kls->offset, h_size, sizeof(h_size)); - mvwprintw(win, y++, x, "Temp Human size: { %s }", h_size); - kls_formatSize(kls->size, h_size, sizeof(h_size)); - mvwprintw(win, y++, x, "Inner Human size: { %s }", h_size); - kls_formatSize(kls->offset, curr_size, sizeof(curr_size)); - mvwprintw(win, y++, x, "Inner Used (Human): { %s }", curr_size); - kls_formatSize(t_kls->offset, curr_size, sizeof(curr_size)); - mvwprintw(win, y++, x, "Temp Used (Human): { %s }", curr_size); -#ifndef _WIN32 - mvwprintw(win, y++, x, "Inner Offset: { %li }", kls->offset); - mvwprintw(win, y++, x, "Temp Offset: { %li }", t_kls->offset); -#else - mvwprintw(win, y++, x, "Inner Offset: { %lli }", kls->offset); - mvwprintw(win, y++, x, "Temp Offset: { %lli }", t_kls->offset); -#endif -#ifndef _WIN32 - mvwprintw(win, y++, x, "Inner Prev_Offset: { %li }", kls->prev_offset); - mvwprintw(win, y++, x, "Temp Prev_Offset: { %li }", t_kls->prev_offset); -#else - mvwprintw(win, y++, x, "Inner Prev_Offset: { %lli }", kls->prev_offset); - mvwprintw(win, y++, x, "Temp Prev_Offset: { %lli }", t_kls->prev_offset); -#endif -#ifdef KOLISEO_HAS_REGION - mvwprintw(win, y++, x, "Refer KLS_Region_List len: { %i }", - kls_rl_length(kls->regs)); - mvwprintw(win, y++, x, "Temp KLS_Region_List len: { %i }", - kls_rl_length(t_kls->t_regs)); -#endif - mvwprintw(win, y++, x, "Current inner usage: { %.3f%% }", - (kls->offset * 100.0) / kls->size); - mvwprintw(win, y++, x, "Current refer usage: { %.3f%% }", - (t_kls->offset * 100.0) / kls->size); - mvwprintw(win, y++, x, "%s", ""); - mvwprintw(win, y++, x, "q or Enter to quit."); - /* - KLS_Region_List rl = kls_copy(kls->regs); - while (!kls_empty(rl)) { - mvwprintw(win, y, x, "Prev_Offset: [%i]",kls->prev_offset); - } - */ - wrefresh(win); - int ch = '?'; - int quit = -1; - do { - quit = 0; - ch = wgetch(win); - switch (ch) { - case 10: - case 'q': { - quit = 1; - } - break; - default: { - quit = 0; - } - break; - } - } while (!quit); -} - -#ifdef KOLISEO_HAS_REGION -/** - * Displays a slideshow of KLS_Region_List from passed Koliseo, to the passed WINDOW pointer. - * @param kls The Koliseo at hand. - * @param win The Window at hand. - */ -void kls_showList_toWin(Koliseo *kls, WINDOW *win) -{ - if (kls == NULL) { - fprintf(stderr, "kls_showList_toWin(): passed Koliseo was null."); - exit(EXIT_FAILURE); - } - if (win == NULL) { -#ifdef KLS_DEBUG_CORE - kls_log(kls, "ERROR", "kls_showList_toWin(): passed WINDOW was null."); -#else - fprintf(stderr, "kls_showList_toWin(): passed WINDOW was null."); -#endif - exit(EXIT_FAILURE); - } - wclear(win); - box(win, 0, 0); - wrefresh(win); - int y = 2; - int x = 2; - int quit = 0; - mvwprintw(win, y++, x, "KLS_Region_List data:"); - KLS_Region_List rl = kls->regs; - while (!quit && !kls_rl_empty(rl)) { - wclear(win); - y = 3; - KLS_list_element e = kls_rl_head(rl); - mvwprintw(win, y++, x, "Name: { %s }", e->name); - mvwprintw(win, y++, x, "Desc: { %s }", e->desc); -#ifndef _WIN32 - mvwprintw(win, y++, x, "Offsets: { %li } -> { %li }", e->begin_offset, - e->end_offset); - mvwprintw(win, y++, x, "Size: { %li }", e->size); - mvwprintw(win, y++, x, "Padding: { %li }", e->padding); -#else - mvwprintw(win, y++, x, "Offsets: { %lli } -> { %lli }", e->begin_offset, - e->end_offset); - mvwprintw(win, y++, x, "Size: { %lli }", e->size); - mvwprintw(win, y++, x, "Padding: { %lli }", e->padding); -#endif - mvwprintw(win, y++, x, "KLS_Region_List len: { %i }", - kls_rl_length(kls->regs)); - mvwprintw(win, y++, x, "Current usage: { %.3f%% }", - kls_usageShare(e, kls)); - char h_size[200]; - ptrdiff_t reg_size = e->end_offset - e->begin_offset; - kls_formatSize(reg_size, h_size, sizeof(h_size)); - mvwprintw(win, y++, x, "Human size: { %s }", h_size); - mvwprintw(win, y++, x, "%s", ""); - mvwprintw(win, y++, x, "q to quit, Right arrow to go forward."); - /* - KLS_Region_List rl = kls_copy(kls->regs); - while (!kls_empty(rl)) { - mvwprintw(win, y, x, "Prev_Offset: [%i]",kls->prev_offset); - } - */ - box(win, 0, 0); - wrefresh(win); - int ch = '?'; - int picked = -1; - do { - picked = 0; - ch = wgetch(win); - switch (ch) { - case KEY_RIGHT: { - rl = kls_rl_tail(rl); - picked = 1; - } - break; - case 'q': { - quit = 1; - picked = 1; - } - break; - default: { - picked = 0; - } - break; - } - } while (!quit && !picked); - } -} - -/** - * Displays a slideshow of KLS_Region_List from passed Koliseo_Temp, to the passed WINDOW pointer. - * @param t_kls The Koliseo_Temp at hand. - * @param win The Window at hand. - */ -void kls_temp_showList_toWin(Koliseo_Temp *t_kls, WINDOW *win) -{ - if (t_kls == NULL) { - fprintf(stderr, - "kls_temp_showList_toWin(): passed Koliseo_Temp was null.\n"); - exit(EXIT_FAILURE); - } - Koliseo *kls_ref = t_kls->kls; - if (kls_ref == NULL) { - fprintf(stderr, - "kls_temp_showList_toWin(): referred Koliseo was null.\n"); - exit(EXIT_FAILURE); - } - if (win == NULL) { -#ifdef KLS_DEBUG_CORE - kls_log(kls_ref, "ERROR", - "kls_temp_showList_toWin(): passed WINDOW was null."); -#else - fprintf(stderr, "kls_temp_showList_toWin(): passed WINDOW was null.\n"); -#endif - exit(EXIT_FAILURE); - } - wclear(win); - box(win, 0, 0); - wrefresh(win); - int y = 2; - int x = 2; - int quit = 0; - mvwprintw(win, y++, x, "KLS_Region_List data:"); - KLS_Region_List rl = t_kls->t_regs; - while (!quit && !kls_rl_empty(rl)) { - wclear(win); - y = 3; - KLS_list_element e = kls_rl_head(rl); - mvwprintw(win, y++, x, "Name: { %s }", e->name); - mvwprintw(win, y++, x, "Desc: { %s }", e->desc); -#ifndef _WIN32 - mvwprintw(win, y++, x, "Offsets: { %li } -> { %li }", e->begin_offset, - e->end_offset); - mvwprintw(win, y++, x, "Size: { %li }", e->size); - mvwprintw(win, y++, x, "Padding: { %li }", e->padding); -#else - mvwprintw(win, y++, x, "Offsets: { %lli } -> { %lli }", e->begin_offset, - e->end_offset); - mvwprintw(win, y++, x, "Size: { %lli }", e->size); - mvwprintw(win, y++, x, "Padding: { %lli }", e->padding); -#endif - mvwprintw(win, y++, x, "KLS_Region_List len: { %i }", - kls_rl_length(t_kls->t_regs)); - //mvwprintw(win, y++, x, "Current usage: { %.3f%% }", kls_usageShare(e,kls)); - char h_size[200]; - ptrdiff_t reg_size = e->end_offset - e->begin_offset; - kls_formatSize(reg_size, h_size, sizeof(h_size)); - mvwprintw(win, y++, x, "Human size: { %s }", h_size); - mvwprintw(win, y++, x, "%s", ""); - mvwprintw(win, y++, x, "q to quit, Right arrow to go forward."); - /* - KLS_Region_List rl = kls_copy(kls->regs); - while (!kls_empty(rl)) { - mvwprintw(win, y, x, "Prev_Offset: [%i]",kls->prev_offset); - } - */ - box(win, 0, 0); - wrefresh(win); - int ch = '?'; - int picked = -1; - do { - picked = 0; - ch = wgetch(win); - switch (ch) { - case KEY_RIGHT: { - rl = kls_rl_tail(rl); - picked = 1; - } - break; - case 'q': { - quit = 1; - picked = 1; - } - break; - default: { - picked = 0; - } - break; - } - } while (!quit && !picked); - } -} -#endif // KOLISEO_HAS_REGION -#endif //KOLISEO_HAS_CURSES - /** * Resets the offset field for the passed Koliseo pointer. * Notably, it sets the prev_offset field to the previous offset, thus remembering where last allocation was before the clear. diff --git a/src/koliseo.h b/src/koliseo.h index 34fefe2..3161b2f 100644 --- a/src/koliseo.h +++ b/src/koliseo.h @@ -77,7 +77,7 @@ typedef struct Koliseo_Loc { #define KLS_MAJOR 0 /**< Represents current major release.*/ #define KLS_MINOR 4 /**< Represents current minor release.*/ -#define KLS_PATCH 5 /**< Represents current patch release.*/ +#define KLS_PATCH 6 /**< Represents current patch release.*/ typedef void*(kls_alloc_func)(size_t); /**< Used to select an allocation function for the arena's backing memory.*/ @@ -112,6 +112,137 @@ extern const char* kls_reglist_backend_strings[KLS_REGLIST_TOTAL_BACKENDS]; const char* kls_reglist_backend_string(KLS_RegList_Alloc_Backend kls_be); #endif // KOLISEO_HAS_REGION +/** + * Defines current API version number from KLS_MAJOR, KLS_MINOR and KLS_PATCH. + */ +static const int KOLISEO_API_VERSION_INT = + (KLS_MAJOR * 1000000 + KLS_MINOR * 10000 + KLS_PATCH * 100); +/**< Represents current version with numeric format.*/ + +/** + * Defines current API version string. + */ +static const char KOLISEO_API_VERSION_STRING[] = "0.4.6"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/ + +/** + * Returns current koliseo version as a string. + */ +const char *string_koliseo_version(void); + +/** + * Returns current koliseo version as an integer. + */ +int int_koliseo_version(void); + +#define KLS_DEFAULT_SIZE (16*1024) /**< Represents a simple default size for demo purposes.*/ + +#ifndef KLS_DEFAULT_ALIGNMENT +#define KLS_DEFAULT_ALIGNMENT (2*sizeof(void *)) /**< Represents a default alignment value. Not used.*/ +#endif + +/** + * Represents a type index for Regions. + * @see KLS_PUSH_TYPED() + */ +typedef enum KLS_Region_Type { + KLS_None = 0, + Temp_KLS_Header = 1, + KLS_Header = 2, +} KLS_Region_Type; + +/** + * Defines max index for Koliseo's own Region_Type values. + * @see Region_Type + */ +#define KLS_REGIONTYPE_MAX KLS_Header + +/** + * Defines max size for KLS_Region's name field. + * @see KLS_Region + */ +#define KLS_REGION_MAX_NAME_SIZE 15 +/** + * Defines max size for KLS_Region's desc field. + * @see KLS_Region + */ +#define KLS_REGION_MAX_DESC_SIZE 20 + +#ifdef KOLISEO_HAS_REGION + +/** + * Represents an allocated memory region in a Koliseo. + * @see KLS_PUSH() + * @see KLS_PUSH_NAMED() + */ +typedef struct KLS_Region { + ptrdiff_t begin_offset; /**< Starting offset of memory region.*/ + ptrdiff_t end_offset; /**< Ending offset of memory region.*/ + ptrdiff_t size; /**< Size of memory for the KLS_Region.*/ + ptrdiff_t padding; /**< Size of padding for the KLS_Region.*/ + char name[KLS_REGION_MAX_NAME_SIZE + 1]; /**< Name field for the KLS_Region.*/ + char desc[KLS_REGION_MAX_DESC_SIZE + 1]; /**< Description field for the KLS_Region.*/ + int type; /**< Used to identify which type the KLS_Region holds.*/ +} KLS_Region; + +static const char KOLISEO_DEFAULT_REGION_NAME[] = "No Name"; /**< Represents default Region name, used for kls_push_zero().*/ +static const char KOLISEO_DEFAULT_REGION_DESC[] = "No Desc"; /**< Represents default Region desc, used for kls_push_zero().*/ + +typedef KLS_Region *KLS_list_element; /**< Redundant typedef to better denote the actual value field of a KLS_region_list_item.*/ + +/** + * Defines the node for a KLS_Region_List. + * @see KLS_list_element + */ +typedef struct KLS_list_region { + KLS_list_element value; /**< The KLS_Region value.*/ + struct KLS_list_region *next; /**< Pointer to the next node int the list.*/ +} KLS_region_list_item; + +typedef KLS_region_list_item *KLS_Region_List; +#endif // KOLISEO_HAS_REGION + +struct Koliseo_Temp; //Forward declaration for Koliseo itself +struct Koliseo; //Forward declaration for KLS_OOM_Handler + +#ifndef KOLISEO_HAS_LOCATE +typedef void(KLS_OOM_Handler)(struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count); /**< Used to pass an error handler for Out-Of-Memory error.*/ +#else +typedef void(KLS_OOM_Handler)(struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc); /**< Used to pass an error handler for Out-Of-Memory error.*/ +#endif + +#ifndef KOLISEO_HAS_LOCATE +typedef void(KLS_PTRDIFF_MAX_Handler)(struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count); /**< Used to pass an error handler for count > (PTRDIFF_MAX / size) error.*/ +#else +typedef void(KLS_PTRDIFF_MAX_Handler)(struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc); /**< Used to pass an error handler for count > (PTRDIFF_MAX / size) error.*/ +#endif + +#ifndef KOLISEO_HAS_LOCATE +void KLS_OOM_default_handler__(struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count); /**< Used by default when no handler is passed.*/ +#else +void KLS_OOM_default_handler_dbg__(struct Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc); /**< Used by default when no handler is passed.*/ +#endif + +#ifndef KOLISEO_HAS_LOCATE +void KLS_PTRDIFF_MAX_default_handler__(struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count); /**< Used by default when no handler is passed.*/ +#else +void KLS_PTRDIFF_MAX_default_handler_dbg__(struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc); /**< Used by default when no handler is passed.*/ +#endif + +/** + * Defines the handlers used for errors in push calls. + * @see KLS_Conf + */ +typedef struct KLS_Err_Handlers { + KLS_OOM_Handler* OOM_handler; /**< Pointer to handler for Out-Of-Memory errors in push caalls.*/ + KLS_PTRDIFF_MAX_Handler* PTRDIFF_MAX_handler; /**< Pointer to handler for count > (PTRDIFF_MAX / size) errors in push calls.*/ +} KLS_Err_Handlers; + +#ifndef KOLISEO_HAS_LOCATE +#define KLS_DEFAULT_ERR_HANDLERS (KLS_Err_Handlers) { .OOM_handler = &KLS_OOM_default_handler__, .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler__, } +#else +#define KLS_DEFAULT_ERR_HANDLERS (KLS_Err_Handlers) { .OOM_handler = &KLS_OOM_default_handler_dbg__, .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__, } +#endif // KOLISEO_HAS_LOCATE + /** * Defines flags for Koliseo. * @see Koliseo @@ -128,8 +259,11 @@ typedef struct KLS_Conf { FILE *kls_log_fp; /**< FILE pointer used by the Koliseo to print its kls_log() output.*/ const char *kls_log_filepath; /**< String representing the path to the Koliseo logfile.*/ int kls_block_while_has_temp; /**< If set to 1, make the Koliseo reject push calls while it has an open Koliseo_Temp.*/ + KLS_Err_Handlers err_handlers; /**< Used to pass custom error handlers for push calls.*/ } KLS_Conf; +KLS_Conf kls_conf_init_handled(int autoset_regions, int alloc_backend, ptrdiff_t reglist_kls_size, int autoset_temp_regions, int collect_stats, int verbose_lvl, int block_while_has_temp, FILE* log_fp, const char* log_filepath, KLS_Err_Handlers err_handlers); + KLS_Conf kls_conf_init(int autoset_regions, int alloc_backend, ptrdiff_t reglist_kls_size, int autoset_temp_regions, int collect_stats, int verbose_lvl, int block_while_has_temp, FILE* log_fp, const char* log_filepath); void kls_dbg_features(void); @@ -273,106 +407,6 @@ typedef struct KLS_Temp_Conf { */ #define KLS_Temp_Conf_Arg(conf) (conf.kls_autoset_regions),(conf.tkls_reglist_alloc_backend),(conf.kls_reglist_kls_size) -/** - * Defines current API version number from KLS_MAJOR, KLS_MINOR and KLS_PATCH. - */ -static const int KOLISEO_API_VERSION_INT = - (KLS_MAJOR * 1000000 + KLS_MINOR * 10000 + KLS_PATCH * 100); -/**< Represents current version with numeric format.*/ - -/** - * Defines current API version string. - */ -static const char KOLISEO_API_VERSION_STRING[] = "0.4.5"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/ - -/** - * Returns current koliseo version as a string. - */ -const char *string_koliseo_version(void); - -/** - * Returns current koliseo version as an integer. - */ -int int_koliseo_version(void); - -#ifdef KOLISEO_HAS_TITLE -#define KLS_TITLEROWS 33 /**< Defines how many rows the title banner has.*/ -extern char *kls_title[KLS_TITLEROWS + 1]; -/**< Contains title banner.*/ - -void kls_print_title_2file(FILE * fp);/**< Prints the title banner to the passed FILE.*/ -void kls_print_title(void); -#endif // KOLISEO_HAS_TITLE - -#define KLS_DEFAULT_SIZE (16*1024) /**< Represents a simple default size for demo purposes.*/ - -#ifndef KLS_DEFAULT_ALIGNMENT -#define KLS_DEFAULT_ALIGNMENT (2*sizeof(void *)) /**< Represents a default alignment value. Not used.*/ -#endif - -/** - * Represents a type index for Regions. - * @see KLS_PUSH_TYPED() - */ -typedef enum KLS_Region_Type { - KLS_None = 0, - Temp_KLS_Header = 1, - KLS_Header = 2, -} KLS_Region_Type; - -/** - * Defines max index for Koliseo's own Region_Type values. - * @see Region_Type - */ -#define KLS_REGIONTYPE_MAX KLS_Header - -/** - * Defines max size for KLS_Region's name field. - * @see KLS_Region - */ -#define KLS_REGION_MAX_NAME_SIZE 15 -/** - * Defines max size for KLS_Region's desc field. - * @see KLS_Region - */ -#define KLS_REGION_MAX_DESC_SIZE 20 - -#ifdef KOLISEO_HAS_REGION - -/** - * Represents an allocated memory region in a Koliseo. - * @see KLS_PUSH() - * @see KLS_PUSH_NAMED() - */ -typedef struct KLS_Region { - ptrdiff_t begin_offset; /**< Starting offset of memory region.*/ - ptrdiff_t end_offset; /**< Ending offset of memory region.*/ - ptrdiff_t size; /**< Size of memory for the KLS_Region.*/ - ptrdiff_t padding; /**< Size of padding for the KLS_Region.*/ - char name[KLS_REGION_MAX_NAME_SIZE + 1]; /**< Name field for the KLS_Region.*/ - char desc[KLS_REGION_MAX_DESC_SIZE + 1]; /**< Description field for the KLS_Region.*/ - int type; /**< Used to identify which type the KLS_Region holds.*/ -} KLS_Region; - -static const char KOLISEO_DEFAULT_REGION_NAME[] = "No Name"; /**< Represents default Region name, used for kls_push_zero().*/ -static const char KOLISEO_DEFAULT_REGION_DESC[] = "No Desc"; /**< Represents default Region desc, used for kls_push_zero().*/ - -typedef KLS_Region *KLS_list_element; /**< Redundant typedef to better denote the actual value field of a KLS_region_list_item.*/ - -/** - * Defines the node for a KLS_Region_List. - * @see KLS_list_element - */ -typedef struct KLS_list_region { - KLS_list_element value; /**< The KLS_Region value.*/ - struct KLS_list_region *next; /**< Pointer to the next node int the list.*/ -} KLS_region_list_item; - -typedef KLS_region_list_item *KLS_Region_List; -#endif // KOLISEO_HAS_REGION - -struct Koliseo_Temp; //Forward declaration for Koliseo itself - /** * Represents the initialised arena allocator struct. * @see kls_new() @@ -455,13 +489,20 @@ Koliseo *kls_new_alloc_dbg(ptrdiff_t size, kls_alloc_func alloc_func, Koliseo_Lo //bool kls_set_conf(Koliseo* kls, KLS_Conf conf); Koliseo *kls_new_conf_alloc(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func); #define kls_new_conf(size, conf) kls_new_conf_alloc((size), (conf), KLS_DEFAULT_ALLOCF) +Koliseo *kls_new_traced_alloc_handled(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers); Koliseo *kls_new_traced_alloc(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func); #define kls_new_traced(size, output_path) kls_new_traced_alloc((size), (output_path), KLS_DEFAULT_ALLOCF) +#define kls_new_traced_handled(size, output_path, err_handlers) kls_new_traced_alloc_handled((size), (output_path), KLS_DEFAULT_ALLOCF, (err_handlers)) +Koliseo *kls_new_dbg_alloc_handled(ptrdiff_t size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers); Koliseo *kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func); #define kls_new_dbg(size) kls_new_dbg_alloc((size), KLS_DEFAULT_ALLOCF) +#define kls_new_dbg_handled(size, err_handlers) kls_new_dbg_alloc_handled((size), KLS_DEFAULT_ALLOCF,(err_handlers)) +Koliseo *kls_new_traced_AR_KLS_alloc_handled(ptrdiff_t size, const char *output_path, + ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func, KLS_Err_Handlers err_handlers); Koliseo *kls_new_traced_AR_KLS_alloc(ptrdiff_t size, const char *output_path, ptrdiff_t reglist_kls_size, kls_alloc_func alloc_func); #define kls_new_traced_AR_KLS(size, output_path, reglist_kls_size) kls_new_traced_AR_KLS_alloc((size), (output_path), (reglist_kls_size), KLS_DEFAULT_ALLOCF) +#define kls_new_traced_AR_KLS_handled(size, output_path, reglist_kls_size, err_handlers) kls_new_traced_AR_KLS_alloc_handled((size), (output_path), (reglist_kls_size), KLS_DEFAULT_ALLOCF, (err_handlers)) //void* kls_push(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count); @@ -577,27 +618,6 @@ void print_kls_2file(FILE * fp, const Koliseo * kls); void print_dbg_kls(const Koliseo * kls); void kls_formatSize(ptrdiff_t size, char *outputBuffer, size_t bufferSize); -#ifdef KOLISEO_HAS_CURSES /**< This definition controls the inclusion of ncurses functions.*/ - -#ifndef KOLISEO_CURSES_H_ -#define KOLISEO_CURSES_H_ - -#ifndef _WIN32 -#include "ncurses.h" -#else -#include -#endif // _WIN32 - -void kls_show_toWin(Koliseo * kls, WINDOW * win); -void kls_temp_show_toWin(Koliseo_Temp * t_kls, WINDOW * win); -#ifdef KOLISEO_HAS_REGION -void kls_showList_toWin(Koliseo * kls, WINDOW * win); -void kls_temp_showList_toWin(Koliseo_Temp * t_kls, WINDOW * win); -#endif // KOLISEO_HAS_REGION -#endif //KOLISEO_CURSES_H_ - -#endif //KOLISEO_HAS_CURSES - #ifndef KOLISEO_HAS_LOCATE Koliseo_Temp *kls_temp_start(Koliseo * kls); #else diff --git a/static/demo.c b/static/demo.c index f7fd6b2..0432423 100644 --- a/static/demo.c +++ b/static/demo.c @@ -4,6 +4,7 @@ #include #include #include "../src/koliseo.h" +#include "./kls_banner.h" #include "amboso.h" void usage(char *progname) @@ -31,9 +32,7 @@ int main(int argc, char **argv) } } -#ifdef KOLISEO_HAS_TITLE kls_print_title(); -#endif // KOLISEO_HAS_TITLE printf("\n\nDemo for Koliseo, using API lvl [%i], version %s \n", @@ -210,34 +209,6 @@ int main(int argc, char **argv) kls_usageReport(kls); #endif // KOLISEO_HAS_REGION -#ifdef KOLISEO_HAS_CURSES - if (is_interactive == 1) { - WINDOW *win = NULL; - /* Initialize curses */ - setlocale(LC_ALL, ""); - initscr(); - clear(); - refresh(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - win = newwin(22, 60, 1, 2); - keypad(win, TRUE); - wclear(win); - wrefresh(win); - kls_show_toWin(kls, win); - kls_temp_show_toWin(temp_kls, win); - refresh(); -#ifdef KOLISEO_HAS_REGION - kls_showList_toWin(kls, win); - kls_temp_showList_toWin(temp_kls, win); -#endif // KOLISEO_HAS_REGION - delwin(win); - endwin(); - } -#endif - #ifdef KOLISEO_HAS_EXPER int *z = &minusone; printf("\n*z is [%i] before KLS_POP\n", *z); diff --git a/static/kls_banner.c b/static/kls_banner.c new file mode 100644 index 0000000..294dbee --- /dev/null +++ b/static/kls_banner.c @@ -0,0 +1,83 @@ +// jgabaut @ github.com/jgabaut +// SPDX-License-Identifier: GPL-3.0-only +/* + Copyright (C) 2023-2024 jgabaut + + 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, version 3 of the License. + + 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 "./kls_banner.h" +/** + * Defines title banner. + */ +char *kls_title[KLS_TITLEROWS + 1] = { + " .',,,. ", + " ...''',,;;:cl;. ", + " ..''''''.... .co, ", + " .'',,,'.. 'ol. ", + " ..''''.. .co. ", + " ..'.. cl. ", + " ..'... . . .:'... . . .. ..... ... ", + " .... . ..:c,'. .oc .ll. :dddxo. ld. 'x: .cxddx; :kxodo, .lddxx; ", + " .,.. .cl,.. .cxd:.. ;Ol;do. :Ol. c0c .kx. lO; ;0d..:: .xk' .xx' 'kx. ", + " .,.. 'dOl. .''......lKOkc. .kx. ;0l ;0l .xk. 'xk; 'Ok;'. l0; .xk. ", + " ''.;, .,;;............. .xKKO' ;0c c0: lO; 'Od. .lko. :0koo:. .xk. 'Od. ", + " ',.'c;. ....... 'Oo:ko. c0; .xk. .xx. :0c . ;Od. .oO, 'Od. c0: ", + " ,; ....... .::. :O; lO; :0l..okc. 'Od... .oO' .ld'.:Od. 'kk,... .kk,.:kd. ", + " ;xc,... . 'd: .:d; ;l. .l: .:dool''c. 'ddolc. .cc. 'ldooc. 'dxoll:. 'odoo:. ", + " .lx;. . ,d; .ll. .''. ;l:' ", + " :o. ;, cc .. . ,cc:::c, ", + " .c; .. .' ....',,;;;;;;;;;;,,,,,,,,,,;;;ox;........'cddoollcc:;,,'.. ", + " ,: ...',:clodxkO0KKXXXXXXKKK000000KKKKXXXXKKKXXXKKKKKKKKKXNNNNNNNNNNNXXKOxoc;'. ", + " .:. ..';cldkOKXXXXK0Okxxdolc::;,''.','......';clc::cloONNNNNNNNNNNNNNNNNNNNNNNNNNNNNNK0xl;. ", + " :xxxOKKK0kxoddl;,';od;. 'cl, .ckko. ,d00Ol. .xXNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNKkl;. ", + ".lKX0xoc,';;. .ll. ;xO; .oX0, ,ONXl ,0NNNK; .lKNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNX0o' ", + ".xk;. . .;. .:, .dc 'OK; .dNNo. ;0NNNXc ;kXNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNk.", + " :c .. .. .l, .k0, .xXXo ;0XNNXc .l0NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNO'", + " :; .'. .;:. .,cl;....,loddo;.. 'dKNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN0,", + ".c, ....',;;:cclllooddddddddddodxxxxxxxdddddddolllccccc:cxXNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNK;", + ".l:',:cloxxkkkOkkxxdollcc::;,,'''.............................',cONNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNXc", + ":00OOxdoc:;,'... .. .. . .oNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNXl", + ":o,..',. .. ';. .co' ;d, 'oOk; .o00kd; .oOkd, :KNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNXl", + ":; ,o' .. .l: ;0o .dXo. 'xNNk. 'ONNNNO' :KNNNd. cKNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNXo", + "c; .. .. '; 'ko. 'ONo. .kNNO' ,0NNNNK; :KNNXd. :0NNNNNNNNNNNNNNNNNNNNNNNNNNNNNXo", + "l, .. 'ko 'OXl ,0NNO' 'ONNNNK; ;KNNXl. ;ONNNNNNNNNNNNNNNNNNNNNNNNNNNNXl", + "cc.............';'...;do'...:k0c....:0XX0:...'xXXXX0c...:0XK0l.......c0NNNNNNNNNNNNNNNNNNNNXXXXXXKO,", + ".;:;;;;;;:::::::::cc:::::::::c:;;;;,;ccc:;,,,,:cccc:;;;;;ccc:;,,,,,;;;clloooooooooooooooooollcc:;,. " +}; + +/** + * Prints the title banner to the passed FILE pointer. + * @see kls_title + * @param fp The FILE to print to. + */ +void kls_print_title_2file(FILE *fp) +{ + if (fp == NULL) { + fprintf(stderr, + "[KLS] kls_print_title_2file(): Passed file pointer was NULL.\n"); + exit(EXIT_FAILURE); + } + for (int i = 0; i < KLS_TITLEROWS; i++) { + fprintf(fp, "%s\n", kls_title[i]); + } +} + +/** + * Prints the title banner to stdout. + * @see kls_title + */ +void kls_print_title(void) +{ + kls_print_title_2file(stdout); +} diff --git a/static/kls_banner.h b/static/kls_banner.h new file mode 100644 index 0000000..a3ffd32 --- /dev/null +++ b/static/kls_banner.h @@ -0,0 +1,30 @@ +// jgabaut @ github.com/jgabaut +// SPDX-License-Identifier: GPL-3.0-only +/* + Copyright (C) 2023-2024 jgabaut + + 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, version 3 of the License. + + 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 . +*/ + +#ifndef KLS_TITLE_H_ +#define KLS_TITLE_H_ +#include +#include + +#define KLS_TITLEROWS 33 /**< Defines how many rows the title banner has.*/ +extern char *kls_title[KLS_TITLEROWS + 1]; +/**< Contains title banner.*/ + +void kls_print_title_2file(FILE * fp);/**< Prints the title banner to the passed FILE.*/ +void kls_print_title(void); +#endif // KLS_TITLE_H_ diff --git a/stego.lock b/stego.lock index 6ebdd8e..e8960d9 100644 --- a/stego.lock +++ b/stego.lock @@ -66,3 +66,4 @@ testsdir = "ok" "0.4.3" = "Fix format specifiers for ptrdiff_t (thanks to khushal-banks), bump anvil to 2.0.6, invil to 0.2.13" "0.4.4" = "Drop list template from main header, add configurable block for Koliseo usage while a Koliseo_Temp is active on it, add --enable-locate to include caller location in some APIs, bump invil to 0.2.15" "0.4.5" = "Set block_on_active_temp on by default, refactor kls_dbg_features()" +"0.4.6" = "Support for user handlers for errors in push calls, drop ncurses and title features, bump amboso to 2.0.7, invil to 0.2.17"