Commit 6293ee89345319b63059631874883ed89e05715b

Thomas de Grivel 2024-08-05T15:12:40

misc/print_limits

diff --git a/.gitignore b/.gitignore
index f9190c2..56d0187 100644
--- a/.gitignore
+++ b/.gitignore
@@ -88,6 +88,7 @@ libkc3_window/sdl2/demo/macos/kc3_window_sdl2_demo_debug.app/
 macos/kc3-v*
 /misc/http_request_offsets
 /misc/http_response_offsets
+/misc/print_limits
 *.o
 release/
 .test
diff --git a/libkc3/io.c b/libkc3/io.c
index b85c2a8..9640ee7 100644
--- a/libkc3/io.c
+++ b/libkc3/io.c
@@ -197,38 +197,48 @@ sw io_write_str (const s_str *x)
   return r;
 }
 
-DEF_ERR_IO_INSPECT(array,       const s_array *)
-DEF_ERR_IO_INSPECT(call,        const s_call *)
-DEF_ERR_IO_INSPECT(character,   const character *)
-DEF_ERR_IO_INSPECT(f32,         const f32 *)
-DEF_ERR_IO_INSPECT(fact,        const s_fact *)
-DEF_ERR_IO_INSPECT(fn_pattern,  const s_list *)
-DEF_ERR_IO_INSPECT(ident,       const s_ident *)
-DEF_ERR_IO_INSPECT(list,        const s_list * const *)
-DEF_ERR_IO_INSPECT(map,         const s_map *)
-DEF_ERR_IO_INSPECT(pointer,     const void *)
-DEF_ERR_IO_INSPECT(ptr,         const u_ptr_w *)
-DEF_ERR_IO_INSPECT(s8,          const s8 *)
-DEF_ERR_IO_INSPECT(s8_decimal,  const s8 *)
-DEF_ERR_IO_INSPECT(s16,         const s16 *)
-DEF_ERR_IO_INSPECT(s16_decimal, const s16 *)
-DEF_ERR_IO_INSPECT(s32,         const s32 *)
-DEF_ERR_IO_INSPECT(s32_decimal, const s32 *)
-DEF_ERR_IO_INSPECT(s64,         const s64 *)
-DEF_ERR_IO_INSPECT(s64_decimal, const s64 *)
-DEF_ERR_IO_INSPECT(str,         const s_str *)
-DEF_ERR_IO_INSPECT(sw,          const sw *)
-DEF_ERR_IO_INSPECT(sw_decimal,  const sw *)
-DEF_ERR_IO_INSPECT(sym,         const s_sym * const *)
-DEF_ERR_IO_INSPECT(tag,         const s_tag *)
-DEF_ERR_IO_INSPECT(tuple,       const s_tuple *)
-DEF_ERR_IO_INSPECT(u8,          const u8 *)
-DEF_ERR_IO_INSPECT(u8_decimal,  const u8 *)
-DEF_ERR_IO_INSPECT(u16,         const u16 *)
-DEF_ERR_IO_INSPECT(u16_decimal, const u16 *)
-DEF_ERR_IO_INSPECT(u32,         const u32 *)
-DEF_ERR_IO_INSPECT(u32_decimal, const u32 *)
-DEF_ERR_IO_INSPECT(u64,         const u64 *)
-DEF_ERR_IO_INSPECT(u64_decimal, const u64 *)
-DEF_ERR_IO_INSPECT(uw,          const uw *)
-DEF_ERR_IO_INSPECT(uw_decimal,  const uw *)
+DEF_ERR_IO_INSPECT(array,           const s_array *)
+DEF_ERR_IO_INSPECT(call,            const s_call *)
+DEF_ERR_IO_INSPECT(character,       const character *)
+DEF_ERR_IO_INSPECT(f32,             const f32 *)
+DEF_ERR_IO_INSPECT(fact,            const s_fact *)
+DEF_ERR_IO_INSPECT(fn_pattern,      const s_list *)
+DEF_ERR_IO_INSPECT(ident,           const s_ident *)
+DEF_ERR_IO_INSPECT(list,            const s_list * const *)
+DEF_ERR_IO_INSPECT(map,             const s_map *)
+DEF_ERR_IO_INSPECT(pointer,         const void *)
+DEF_ERR_IO_INSPECT(ptr,             const u_ptr_w *)
+DEF_ERR_IO_INSPECT(s8,              const s8 *)
+DEF_ERR_IO_INSPECT(s8_decimal,      const s8 *)
+DEF_ERR_IO_INSPECT(s8_hexadecimal,  const s8 *)
+DEF_ERR_IO_INSPECT(s16,             const s16 *)
+DEF_ERR_IO_INSPECT(s16_decimal,     const s16 *)
+DEF_ERR_IO_INSPECT(s16_hexadecimal, const s16 *)
+DEF_ERR_IO_INSPECT(s32,             const s32 *)
+DEF_ERR_IO_INSPECT(s32_decimal,     const s32 *)
+DEF_ERR_IO_INSPECT(s32_hexadecimal, const s32 *)
+DEF_ERR_IO_INSPECT(s64,             const s64 *)
+DEF_ERR_IO_INSPECT(s64_decimal,     const s64 *)
+DEF_ERR_IO_INSPECT(s64_hexadecimal, const s64 *)
+DEF_ERR_IO_INSPECT(str,             const s_str *)
+DEF_ERR_IO_INSPECT(sw,              const sw *)
+DEF_ERR_IO_INSPECT(sw_decimal,      const sw *)
+DEF_ERR_IO_INSPECT(sw_hexadecimal,  const sw *)
+DEF_ERR_IO_INSPECT(sym,             const s_sym * const *)
+DEF_ERR_IO_INSPECT(tag,             const s_tag *)
+DEF_ERR_IO_INSPECT(tuple,           const s_tuple *)
+DEF_ERR_IO_INSPECT(u8,              const u8 *)
+DEF_ERR_IO_INSPECT(u8_decimal,      const u8 *)
+DEF_ERR_IO_INSPECT(u8_hexadecimal,  const u8 *)
+DEF_ERR_IO_INSPECT(u16,             const u16 *)
+DEF_ERR_IO_INSPECT(u16_decimal,     const u16 *)
+DEF_ERR_IO_INSPECT(u16_hexadecimal, const u16 *)
+DEF_ERR_IO_INSPECT(u32,             const u32 *)
+DEF_ERR_IO_INSPECT(u32_decimal,     const u32 *)
+DEF_ERR_IO_INSPECT(u32_hexadecimal, const u32 *)
+DEF_ERR_IO_INSPECT(u64,             const u64 *)
+DEF_ERR_IO_INSPECT(u64_decimal,     const u64 *)
+DEF_ERR_IO_INSPECT(u64_hexadecimal, const u64 *)
+DEF_ERR_IO_INSPECT(uw,              const uw *)
+DEF_ERR_IO_INSPECT(uw_decimal,      const uw *)
+DEF_ERR_IO_INSPECT(uw_hexadecimal,  const uw *)
diff --git a/libkc3/io.h b/libkc3/io.h
index db051b5..c58c860 100644
--- a/libkc3/io.h
+++ b/libkc3/io.h
@@ -41,48 +41,58 @@ sw io_write (const void *x, uw len);
 sw io_write_1 (const char *x);
 sw io_write_str (const s_str *x);
 
-PROTOTYPES_ERR_IO_INSPECT(array,       const s_array *);
-PROTOTYPES_ERR_IO_INSPECT(bool,        const bool *);
-PROTOTYPES_ERR_IO_INSPECT(buf,         const s_buf *);
-PROTOTYPES_ERR_IO_INSPECT(call,        const s_call *);
-PROTOTYPES_ERR_IO_INSPECT(cfn,         const s_cfn *);
-PROTOTYPES_ERR_IO_INSPECT(character,   const character *);
-PROTOTYPES_ERR_IO_INSPECT(f32,         const f32 *);
-PROTOTYPES_ERR_IO_INSPECT(f64,         const f64 *);
-PROTOTYPES_ERR_IO_INSPECT(fact,        const s_fact *);
-PROTOTYPES_ERR_IO_INSPECT(facts_spec,  const p_facts_spec);
-PROTOTYPES_ERR_IO_INSPECT(fn,          const s_fn *);
-PROTOTYPES_ERR_IO_INSPECT(fn_pattern,  const s_list *);
-PROTOTYPES_ERR_IO_INSPECT(ident,       const s_ident *);
-PROTOTYPES_ERR_IO_INSPECT(integer,     const s_integer *);
-PROTOTYPES_ERR_IO_INSPECT(list,        const s_list * const *);
-PROTOTYPES_ERR_IO_INSPECT(map,         const s_map *);
-PROTOTYPES_ERR_IO_INSPECT(pointer,     const void *);
-PROTOTYPES_ERR_IO_INSPECT(ptr,         const u_ptr_w *);
-PROTOTYPES_ERR_IO_INSPECT(s8,          const s8 *);
-PROTOTYPES_ERR_IO_INSPECT(s8_decimal,  const s8 *);
-PROTOTYPES_ERR_IO_INSPECT(s16,         const s16 *);
-PROTOTYPES_ERR_IO_INSPECT(s16_decimal, const s16 *);
-PROTOTYPES_ERR_IO_INSPECT(s32,         const s32 *);
-PROTOTYPES_ERR_IO_INSPECT(s32_decimal, const s32 *);
-PROTOTYPES_ERR_IO_INSPECT(s64,         const s64 *);
-PROTOTYPES_ERR_IO_INSPECT(s64_decimal, const s64 *);
-PROTOTYPES_ERR_IO_INSPECT(str,         const s_str *);
-PROTOTYPES_ERR_IO_INSPECT(sw,          const sw *);
-PROTOTYPES_ERR_IO_INSPECT(sw_decimal,  const sw *);
-PROTOTYPES_ERR_IO_INSPECT(sym,         const s_sym * const *);
-PROTOTYPES_ERR_IO_INSPECT(tag,         const s_tag *);
-PROTOTYPES_ERR_IO_INSPECT(tag_type,    e_tag_type);
-PROTOTYPES_ERR_IO_INSPECT(tuple,       const s_tuple *);
-PROTOTYPES_ERR_IO_INSPECT(u8,          const u8 *);
-PROTOTYPES_ERR_IO_INSPECT(u8_decimal,  const u8 *);
-PROTOTYPES_ERR_IO_INSPECT(u16,         const u16 *);
-PROTOTYPES_ERR_IO_INSPECT(u16_decimal, const u16 *);
-PROTOTYPES_ERR_IO_INSPECT(u32,         const u32 *);
-PROTOTYPES_ERR_IO_INSPECT(u32_decimal, const u32 *);
-PROTOTYPES_ERR_IO_INSPECT(u64,         const u64 *);
-PROTOTYPES_ERR_IO_INSPECT(u64_decimal, const u64 *);
-PROTOTYPES_ERR_IO_INSPECT(uw,          const uw *);
-PROTOTYPES_ERR_IO_INSPECT(uw_decimal,  const uw *);
+PROTOTYPES_ERR_IO_INSPECT(array,           const s_array *);
+PROTOTYPES_ERR_IO_INSPECT(bool,            const bool *);
+PROTOTYPES_ERR_IO_INSPECT(buf,             const s_buf *);
+PROTOTYPES_ERR_IO_INSPECT(call,            const s_call *);
+PROTOTYPES_ERR_IO_INSPECT(cfn,             const s_cfn *);
+PROTOTYPES_ERR_IO_INSPECT(character,       const character *);
+PROTOTYPES_ERR_IO_INSPECT(f32,             const f32 *);
+PROTOTYPES_ERR_IO_INSPECT(f64,             const f64 *);
+PROTOTYPES_ERR_IO_INSPECT(fact,            const s_fact *);
+PROTOTYPES_ERR_IO_INSPECT(facts_spec,      const p_facts_spec);
+PROTOTYPES_ERR_IO_INSPECT(fn,              const s_fn *);
+PROTOTYPES_ERR_IO_INSPECT(fn_pattern,      const s_list *);
+PROTOTYPES_ERR_IO_INSPECT(ident,           const s_ident *);
+PROTOTYPES_ERR_IO_INSPECT(integer,         const s_integer *);
+PROTOTYPES_ERR_IO_INSPECT(list,            const s_list * const *);
+PROTOTYPES_ERR_IO_INSPECT(map,             const s_map *);
+PROTOTYPES_ERR_IO_INSPECT(pointer,         const void *);
+PROTOTYPES_ERR_IO_INSPECT(ptr,             const u_ptr_w *);
+PROTOTYPES_ERR_IO_INSPECT(s8,              const s8 *);
+PROTOTYPES_ERR_IO_INSPECT(s8_decimal,      const s8 *);
+PROTOTYPES_ERR_IO_INSPECT(s8_hexadecimal,  const s8 *);
+PROTOTYPES_ERR_IO_INSPECT(s16,             const s16 *);
+PROTOTYPES_ERR_IO_INSPECT(s16_decimal,     const s16 *);
+PROTOTYPES_ERR_IO_INSPECT(s16_hexadecimal, const s16 *);
+PROTOTYPES_ERR_IO_INSPECT(s32,             const s32 *);
+PROTOTYPES_ERR_IO_INSPECT(s32_decimal,     const s32 *);
+PROTOTYPES_ERR_IO_INSPECT(s32_hexadecimal, const s32 *);
+PROTOTYPES_ERR_IO_INSPECT(s64,             const s64 *);
+PROTOTYPES_ERR_IO_INSPECT(s64_decimal,     const s64 *);
+PROTOTYPES_ERR_IO_INSPECT(s64_hexadecimal, const s64 *);
+PROTOTYPES_ERR_IO_INSPECT(str,             const s_str *);
+PROTOTYPES_ERR_IO_INSPECT(sw,              const sw *);
+PROTOTYPES_ERR_IO_INSPECT(sw_decimal,      const sw *);
+PROTOTYPES_ERR_IO_INSPECT(sw_hexadecimal,  const sw *);
+PROTOTYPES_ERR_IO_INSPECT(sym,             const s_sym * const *);
+PROTOTYPES_ERR_IO_INSPECT(tag,             const s_tag *);
+PROTOTYPES_ERR_IO_INSPECT(tag_type,        e_tag_type);
+PROTOTYPES_ERR_IO_INSPECT(tuple,           const s_tuple *);
+PROTOTYPES_ERR_IO_INSPECT(u8,              const u8 *);
+PROTOTYPES_ERR_IO_INSPECT(u8_decimal,      const u8 *);
+PROTOTYPES_ERR_IO_INSPECT(u8_hexadecimal,  const u8 *);
+PROTOTYPES_ERR_IO_INSPECT(u16,             const u16 *);
+PROTOTYPES_ERR_IO_INSPECT(u16_decimal,     const u16 *);
+PROTOTYPES_ERR_IO_INSPECT(u16_hexadecimal, const u16 *);
+PROTOTYPES_ERR_IO_INSPECT(u32,             const u32 *);
+PROTOTYPES_ERR_IO_INSPECT(u32_decimal,     const u32 *);
+PROTOTYPES_ERR_IO_INSPECT(u32_hexadecimal, const u32 *);
+PROTOTYPES_ERR_IO_INSPECT(u64,             const u64 *);
+PROTOTYPES_ERR_IO_INSPECT(u64_decimal,     const u64 *);
+PROTOTYPES_ERR_IO_INSPECT(u64_hexadecimal, const u64 *);
+PROTOTYPES_ERR_IO_INSPECT(uw,              const uw *);
+PROTOTYPES_ERR_IO_INSPECT(uw_decimal,      const uw *);
+PROTOTYPES_ERR_IO_INSPECT(uw_hexadecimal,  const uw *);
 
 #endif /* LIBKC3_IO_H */
diff --git a/misc/Makefile b/misc/Makefile
index 95118e3..359fe4e 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -10,11 +10,11 @@
 ## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
 ## THIS SOFTWARE.
 
-CLEANFILES = http_request_offsets http_response_offsets
+CLEANFILES = http_request_offsets http_response_offsets print_limits
 
 CPPFLAGS += -I/usr/local/include -I.. -W -Wall -Werror
 
-all: http_request_offsets http_response_offsets
+all: http_request_offsets http_response_offsets print_limits
 
 build: all
 
@@ -29,6 +29,9 @@ http_request_offsets: http_request_offsets.c
 http_response_offsets: http_response_offsets.c
 	${CC} ${CPPFLAGS} -I.. http_response_offsets.c -o http_response_offsets
 
+print_limits: print_limits.c
+	libtool --mode=link ${CC} ${CPPFLAGS} -I.. print_limits.c -L../libkc3 -lkc3 -o print_limits
+
 .PHONY: \
 	all \
 	build \
diff --git a/misc/display_min_max.c b/misc/display_min_max.c
deleted file mode 100644
index 1c501bd..0000000
--- a/misc/display_min_max.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include <stdio.h>
-#include "libkc3/types.h"
-
-void display_min_max() {
-    // Display minimum and maximum values for integer types
-    printf("Minimum and Maximum values for integer types:\n");
-    printf("S8_MIN: %d\n", S8_MIN);
-    printf("S8_MAX: %d\n", S8_MAX);
-    printf("S16_MIN: %d\n", S16_MIN);
-    printf("S16_MAX: %d\n", S16_MAX);
-    printf("S32_MIN: %d\n", S32_MIN);
-    printf("S32_MAX: %d\n", S32_MAX);
-    printf("S64_MIN: %ld\n", S64_MIN);
-    printf("S64_MAX: %ld\n", S64_MAX);
-    printf("SW_MIN: %ld\n", SW_MIN);
-    printf("SW_MAX: %ld\n", SW_MAX);
-}
-
-int main() {
-    display_min_max();
-    return 0;
-}
\ No newline at end of file
diff --git a/misc/print_limits.c b/misc/print_limits.c
new file mode 100644
index 0000000..4e4bf53
--- /dev/null
+++ b/misc/print_limits.c
@@ -0,0 +1,44 @@
+#include <libkc3/kc3.h>
+
+void display_min_max() {
+  s8 s8_min = S8_MIN;
+  s8 s8_max = S8_MAX;
+  s16 s16_min = S16_MIN;
+  s16 s16_max = S16_MAX;
+  s32 s32_min = S32_MIN;
+  s32 s32_max = S32_MAX;
+  s64 s64_min = S64_MIN;
+  s64 s64_max = S64_MAX;
+  sw sw_min = SW_MIN;
+  sw sw_max = SW_MAX;
+    // Display minimum and maximum values for integer types
+  io_puts("Minimum and Maximum values for integer types:");
+  io_write_1("S8_MIN:  ");
+  io_inspect_s8_hexadecimal(&s8_min);
+  io_write_1("\nS8_MAX:   ");
+  io_inspect_s8_hexadecimal(&s8_max);
+  io_write_1("\nS16_MIN: ");
+  io_inspect_s16_hexadecimal(&s16_min);
+  io_write_1("\nS16_MAX:  ");
+  io_inspect_s16_hexadecimal(&s16_max);
+  io_write_1("\nS32_MIN: ");
+  io_inspect_s32_hexadecimal(&s32_min);
+  io_write_1("\nS32_MAX:  ");
+  io_inspect_s32_hexadecimal(&s32_max);
+  io_write_1("\nS64_MIN: ");
+  io_inspect_s64_hexadecimal(&s64_min);
+  io_write_1("\nS64_MAX:  ");
+  io_inspect_s64_hexadecimal(&s64_max);
+  io_write_1("\nSW_MIN:  ");
+  io_inspect_sw_hexadecimal(&sw_min);
+  io_write_1("\nSW_MAX:   ");
+  io_inspect_sw_hexadecimal(&sw_max);
+  io_write_1("\n");
+}
+
+int main (int argc, char **argv) {
+  kc3_init(NULL, &argc, &argv);
+  display_min_max();
+  kc3_clean(NULL);
+  return 0;
+}