src/error.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#ifndef HEX_H #include "hex.h" #endif //////////////////////////////////////// // Error & Debugging // //////////////////////////////////////// void hex_error(hex_context_t *ctx, const char *format, ...) { va_list args; va_start(args, format); vsnprintf(ctx->error, sizeof(ctx->error), format, args); if (ctx->settings.errors_enabled) /// FC { fprintf(stderr, "[error] "); fprintf(stderr, "%s\n", ctx->error); } va_end(args); } void hex_debug(hex_context_t *ctx, const char *format, ...) { if (ctx->settings.debugging_enabled) { va_list args; va_start(args, format); fprintf(stdout, "*** "); vfprintf(stdout, format, args); fprintf(stdout, "\n"); va_end(args); } } char *hex_type(hex_item_type_t type) { switch (type) { case HEX_TYPE_INTEGER: return "integer"; case HEX_TYPE_STRING: return "string"; case HEX_TYPE_QUOTATION: return "quotation"; case HEX_TYPE_NATIVE_SYMBOL: return "native-symbol"; case HEX_TYPE_USER_SYMBOL: return "user-symbol"; case HEX_TYPE_INVALID: return "invalid"; default: return "unknown"; } } void hex_debug_item(hex_context_t *ctx, const char *message, hex_item_t item) { if (ctx->settings.debugging_enabled) { fprintf(stdout, "*** %s: ", message); hex_print_item(stdout, item); fprintf(stdout, "\n"); } } |