demake 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/bin/demake +199 -6
  3. data/lib/apps/example/Makefile +0 -0
  4. data/lib/apps/example/demake/auto_bits.rb +59 -0
  5. data/lib/apps/example/demake/auto_list.rb +60 -0
  6. data/lib/apps/example/src/Makefile +6 -0
  7. data/lib/apps/example/src/goodbye.c +0 -0
  8. data/lib/apps/example/src/hello.c +0 -0
  9. data/lib/apps/example/src/string/string.c +0 -0
  10. data/lib/apps/example/src/string/string.h +0 -0
  11. data/lib/apps/oreo/Makefile +0 -0
  12. data/lib/apps/oreo/src/Makefile +6 -0
  13. data/lib/apps/oreo/src/defines.h +0 -0
  14. data/lib/apps/oreo/src/fast_read_file.h +0 -0
  15. data/lib/apps/oreo/src/oreo.c +0 -0
  16. data/lib/apps/oreo/src/typedefs.h +0 -0
  17. data/lib/data/libsrc/auto_bits.c +41 -0
  18. data/lib/data/libsrc/auto_bits.h +212 -4
  19. data/lib/data/libsrc/auto_bits.rb +9 -0
  20. data/lib/data/libsrc/auto_list.rb +9 -0
  21. data/lib/data/libsrc/auto_string.c +300 -0
  22. data/lib/data/libsrc/auto_string.h +1023 -0
  23. data/lib/data/libsrc/auto_string_clamp_test.c +52 -0
  24. data/lib/data/libsrc/base.h +0 -0
  25. data/lib/data/libsrc/cpu_mark_check.h +0 -0
  26. data/lib/data/libsrc/defines.h +29 -3
  27. data/lib/data/libsrc/fast_read_file.h +0 -0
  28. data/lib/data/libsrc/fast_sha2.h +0 -0
  29. data/lib/data/libsrc/memory_arena.c +32 -0
  30. data/lib/data/libsrc/memory_arena.h +345 -0
  31. data/lib/data/libsrc/memory_arena_test.c +173 -0
  32. data/lib/data/libsrc/parse_arguments.h +0 -0
  33. data/lib/data/libsrc/rb_library.c +0 -0
  34. data/lib/data/libsrc/simple_linked_list.c +42 -22
  35. data/lib/data/libsrc/simple_linked_list.h +140 -56
  36. data/lib/data/libsrc/typedefs.h +5 -3
  37. data/lib/to_plural.rb +126 -0
  38. metadata +24 -13
  39. data/lib/data/libsrc/simple_linked_list +0 -0
  40. data/lib/data/libsrc/smart_alloc.h +0 -45
@@ -2,32 +2,240 @@
2
2
 
3
3
  auto_bits.h -- *Full Library* Header File
4
4
 
5
- For auto bits
5
+ For creating and managing bits / flags
6
+
7
+ Note: Some of this code is easiest to write using Ruby and meta
8
+ programming. See the note in the example for more details.
6
9
 
7
10
  See the end of this file for an example.
8
11
 
12
+ Useful macros:
13
+
14
+ #define IS_SET(bits, bit) ((bits) & (bit))
15
+ #define SET_BIT(bits, bit) ((bits) |= (bit))
16
+ #define REMOVE_BIT(bits, bit) ((bits) &= ~(bit))
17
+ #define TOGGLE_BIT(bits, bit) ((bits) ^= (bit))
18
+
9
19
  Public Functions:
10
20
 
21
+ void auto_bits_print(cc8 *list[], b8 bits);
22
+ void auto_bits_show(cc8 *list[], b8 bits, cc8 *separator);
23
+
11
24
  */
12
25
 
13
- #ifndef AUTO_BITS_H_Minaswan /* Prevent multiple inclusions */
26
+ #ifndef AUTO_BITS_H_Minaswan /* Prevent multiple inclusions */
14
27
  #define AUTO_BITS_H_Minaswan
15
- #ifndef TYPEDEFS_H_Minaswan /* Header guard for typedefs.h */
28
+ #define AUTO_BITS_VERSION "0.1.0"
29
+ #ifndef TYPEDEFS_H_Minaswan /* Header guard for typedefs.h */
16
30
  #define TYPEDEFS_H_Minaswan
31
+ #define TYPEDEFS_VERSION "0.1.1"
32
+ #include <stdint.h>
33
+
34
+ typedef uint8_t b8; /* Booleans */
35
+ typedef uint16_t b16;
36
+ typedef uint32_t b32;
37
+ typedef uint64_t b64;
38
+
39
+ typedef char c8; /* Characters */
40
+ typedef const char cc8;
41
+ typedef unsigned char uc8;
42
+ typedef char as8; /* Auto string */
43
+
44
+ typedef uint8_t u8; /* Unsigned Numbers */
45
+ typedef uint16_t u16;
46
+ typedef uint32_t u32;
47
+ typedef uint64_t u64;
48
+
49
+ typedef int8_t i8; /* Signed Numbers */
50
+ typedef int16_t i16;
51
+ typedef int32_t i32;
52
+ typedef int64_t i64;
53
+
54
+ typedef float f32; /* Floating Point Numbers */
55
+ typedef double f64;
56
+ #endif /* TYPEDEFS_H_Minaswan */
57
+
58
+ #ifndef DEFINES_H_Minaswan /* Prevent multiple inclusions */
59
+ #define DEFINES_H_Minaswan
60
+ #define DEFINES_VERSION "0.1.1"
61
+ #ifndef NULL
62
+ #define NULL ((void *) 0)
63
+ #endif
64
+ #ifndef FALSE
65
+ #define FALSE 0
66
+ #endif
67
+ #ifndef TRUE
68
+ #define TRUE 1
69
+ #endif
70
+ #ifndef NO
71
+ #define NO 0
72
+ #endif
73
+ #ifndef YES
74
+ #define YES 1
75
+ #endif
76
+ #ifndef OFF
77
+ #define OFF 0
78
+ #endif
79
+ #ifndef ON
80
+ #define ON 1
81
+ #endif
82
+ #ifndef MIN
83
+ #define MIN(x, y) (x) < (y) ? (x) : (y)
84
+ #endif
85
+ #ifndef MAX
86
+ #define MAX(x, y) (x) > (y) ? (x) : (y)
87
+ #endif
88
+ #ifndef KB
89
+ #define KB(x) ((u64)(x) * 1024)
90
+ #endif
91
+ #ifndef MB
92
+ #define MB(x) ((u64)(x) * 1024 * 1024)
93
+ #endif
94
+ #ifndef GB
95
+ #define GB(x) ((u64)(x) * 1024 * 1024 * 1024)
96
+ #endif
97
+ #ifndef TO_UPPER_CASE
98
+ #define TO_UPPER_CASE(x) (((uc8)(x) >= (uc8)'a' && (uc8)(x) <= (uc8)'z') ? \
99
+ (uc8)((uc8)(x) - (uc8)'a' + (uc8)'A') : (uc8)(x))
100
+ #endif
101
+ #ifndef TO_LOWER_CASE
102
+ #define TO_LOWER_CASE(x) (((uc8)(x) >= (uc8)'A' && (uc8)(x) <= (uc8)'Z') ? \
103
+ (uc8)((uc8)(x) - (uc8)'A' + (uc8)'a') : (uc8)(x))
104
+ #endif
105
+ #ifndef IS_WHITE_SPACE
106
+ #define IS_WHITE_SPACE(x) ((uc8)(x) == ' ' || (uc8)(x) - (uc8)'\t' < 5)
107
+ #endif
108
+ #endif /* DEFINES_H_Minaswan */
109
+
110
+ #ifndef _SCOPE_ /* _SCOPE_ is short and can be easily redefined */
111
+ #define _SCOPE_WAS_NOT_PREDEFINED_
112
+ /*
113
+ #define _SCOPE_ extern
114
+ #define _SCOPE_ static
115
+ */
116
+ #if defined(__GNUC__) || defined(__clang__)
117
+ #define _SCOPE_ static __inline__
118
+ #elif defined(_MSC_VER)
119
+ #define _SCOPE_ static __inline
120
+ #else
121
+ #define _SCOPE_ static inline
122
+ #endif
123
+ #endif
124
+
125
+ #include <stdio.h>
17
126
 
18
- #endif /* TYPEDEFS_H_Minaswan */
127
+ #define IS_SET(bits, bit) ((bits) & (bit))
128
+ #define SET_BIT(bits, bit) ((bits) |= (bit))
129
+ #define REMOVE_BIT(bits, bit) ((bits) &= ~(bit))
130
+ #define TOGGLE_BIT(bits, bit) ((bits) ^= (bit))
131
+
132
+ #define BIT_IS_SET(bits, bit) ((bits) & (bit))
133
+ #define BIT_SET(bits, bit) ((bits) |= (bit))
134
+ #define BIT_REMOVE(bits, bit) ((bits) &= ~(bit))
135
+ #define BIT_TOGGLE(bits, bit) ((bits) ^= (bit))
19
136
 
20
137
  /* Public Functions */
138
+ _SCOPE_ void auto_bits_print(cc8 *list[], b8 bits);
139
+ _SCOPE_ void auto_bits_show(cc8 *list[], b8 bits, cc8 *separator);
21
140
 
22
141
  #ifdef AUTO_BITS_IMPLEMENTATION
142
+ _SCOPE_ void auto_bits_print(cc8 *list[], b8 bits)
143
+ {
144
+ u8 i = 0;
145
+ b8 found = FALSE;
146
+
147
+ while(list[i] != NULL) {
148
+ if(IS_SET(bits, (1 << i))) {
149
+ if(!found) {
150
+ printf("Set bits: ");
151
+ printf("%s", list[i]);
152
+ found = TRUE;
153
+ } else
154
+ printf(", %s", list[i]);
155
+ }
156
+ i++;
157
+ }
158
+ if(found)
159
+ printf("\n");
160
+ else
161
+ printf("No bits are set\n");
162
+ }
23
163
 
164
+ _SCOPE_ void auto_bits_show(cc8 *list[], b8 bits, cc8 *separator)
165
+ {
166
+ u8 i = 0;
167
+ b8 found = FALSE;
168
+
169
+ while(list[i] != NULL) {
170
+ if(IS_SET(bits, (1 << i))) {
171
+ if(!found) {
172
+ printf("%s", list[i]);
173
+ found = TRUE;
174
+ } else
175
+ printf("%s%s", separator, list[i]);
176
+ }
177
+ i++;
178
+ }
179
+ }
24
180
  #endif /* AUTO_BITS_IMPLEMENTATION */
25
181
  #endif /* AUTO_BITS_H_Minaswan */
26
182
 
27
183
  /*
28
184
  Example:
29
185
 
186
+ *** Note: BIT_ macros and *bit_list[] are easiest to create using demake:
187
+
188
+ To create exactly what you see below, create an auto-bits.rb file containing:
189
+
190
+ prefix = "bit"
191
+ list = [ "0", "1", "2", "3" ]
192
+ auto_bits_add(prefix, list)
193
+
194
+ Then use demake to auto generate auto_bits_generated.h:
195
+ > demake auto-bits auto-bits.rb
196
+
197
+ *** End of Note
198
+
30
199
  #define AUTO_BITS_IMPLEMENTATION
31
200
  #include "auto_bits.h"
32
201
 
202
+ #define BIT_0 (1 << 0)
203
+ #define BIT_1 (1 << 1)
204
+ #define BIT_2 (1 << 2)
205
+ #define BIT_3 (1 << 3)
206
+
207
+ cc8 *bit_list[] = {
208
+ "0",
209
+ "1",
210
+ "2",
211
+ "3",
212
+ NULL
213
+ };
214
+
215
+ i32 main(i32 argc, c8 *argv[])
216
+ {
217
+ b8 bits = 0;
218
+
219
+ printf("-- Set both bits 1 & 2:\n");
220
+ SET_BIT(bits, BIT_1|BIT_2);
221
+ auto_bits_print(bit_list, bits);
222
+ if(IS_SET(bits, BIT_2))
223
+ printf("Bit #2 is set.\n");
224
+ printf("Manual list set bits: ");
225
+ auto_bits_show(bit_list, bits, "|");
226
+ printf("\n\n-- Remove both bits 1 & 2:\n");
227
+ REMOVE_BIT(bits, BIT_1|BIT_2);
228
+ auto_bits_print(bit_list, bits);
229
+ printf("\n-- Set all 4 bits:\n");
230
+ SET_BIT(bits, BIT_0|BIT_1|BIT_2|BIT_3);
231
+ auto_bits_print(bit_list, bits);
232
+ printf("Manual list set bits: ");
233
+ auto_bits_show(bit_list, bits, " + ");
234
+ printf("\n\n-- Toggle both bits 1 & 2:\n");
235
+ TOGGLE_BIT(bits, BIT_1|BIT_2);
236
+ auto_bits_print(bit_list, bits);
237
+
238
+ return 0;
239
+ }
240
+
33
241
  */
@@ -0,0 +1,9 @@
1
+ #file = "auto_bits_generated.h"
2
+ prefix = "bit"
3
+ list = [ "0", "1", "2", "3" ]
4
+ auto_bits_add(prefix, list)
5
+ #auto_bits_add(prefix, list, file)
6
+
7
+ @prespace = 2
8
+ @target_tab_column = 5
9
+ notify("|g|[check mark]|n auto_bits.rb found - generating code")
@@ -0,0 +1,9 @@
1
+ #file = "auto_list_generated.h"
2
+ prefix = "color"
3
+ list = [ "blue", "green", "red", "purple" ]
4
+ auto_bits_add(prefix, list)
5
+ #auto_bits_add(prefix, list, file)
6
+
7
+ @prespace = 2
8
+ @target_tab_column = 5
9
+ notify("|g|[check mark]|n auto_list.rb found - generating code")
@@ -0,0 +1,300 @@
1
+ /*
2
+ !!! IMPORTANT NOTE ON CLAMP !!!
3
+
4
+ This works:
5
+
6
+ c8 my_string[] = "This will work. Pretty cool, right?";
7
+
8
+ !!! ** You can't clamp on: *char literals !!!
9
+ !!! !!!
10
+ !!! ** Only clamp on: char[] and heap !!!
11
+ !!! !!!
12
+ !!! This will segfault: !!!
13
+
14
+ c8 *my_string2 = "This will segfault. Unfortunately.";
15
+
16
+ view2 = auto_view(my_string2);
17
+ auto_view_chop_right(&view2, 15);
18
+
19
+ This will segfault:
20
+
21
+ auto_view_clamp(&view2));
22
+
23
+ */
24
+
25
+ #define AUTO_STRING_IMPLEMENTATION
26
+ #include "auto_string.h"
27
+
28
+ #define BUF_STRING_LENGTH 1024
29
+
30
+ as8 *make_test_scratch(u64 *test_num, c8 *test_name);
31
+ void test_scratch(u64 *test_num, c8 *test_name, c8 *data1, c8 *data2,
32
+ b8 result, c8 *expected_result);
33
+ void test_scratch_view(u64 *test_num, c8 *test_name, AutoView *view, c8 *data2,
34
+ b8 result, c8 *expected_result);
35
+ void test_scratch_views(u64 *test_num, c8 *test_name, AutoView *view,
36
+ AutoView *view2, b8 result, c8 *expected_result);
37
+
38
+ i32 main(i32 argc, c8 *argv[])
39
+ {
40
+ AutoView view = { 0 }, view2 = { 0 };
41
+ u64 length = 0, available = 0, i = 0, test_num = 0;
42
+ i32 auto_string_identifier = 0;
43
+ c8 buf[BUF_STRING_LENGTH + 1] = {0};
44
+ as8 *data = NULL, *substring = NULL;
45
+ b8 result = FALSE;
46
+
47
+ printf("\nCreating test auto string data in arena 1:\n\n");
48
+ data = auto_string_by_id_extra(1, "hello", 8); /* 8 = include space for , world! */
49
+ data = auto_string_add(data, ", world!");
50
+ length = auto_string_length(data);
51
+ available = auto_string_available(data);
52
+ printf("%p %s = %ld (%ld available)\n", data, data, length, available);
53
+ data = auto_string_by_id_extra(1, "hello", -2); /* -2 = 2 x 5 (hello) extra space */
54
+ data = auto_string_add(data, ", world!");
55
+ length = auto_string_length(data);
56
+ available = auto_string_available(data);
57
+ printf("%p %s = %ld (%ld available)\n", data, data, length, available);
58
+ data = auto_string_by_id_new(1, "hello", FALSE); /* Default - 512 bytes */
59
+ data = auto_string_add(data, ", world!");
60
+ data = auto_string_add(data, " What's happening with your cool vibes?");
61
+ length = auto_string_length(data);
62
+ available = auto_string_available(data);
63
+ printf("%p %s = %ld (%ld available)\n", data, data, length, available);
64
+ for(i = 0; i < BUF_STRING_LENGTH; i++)
65
+ buf[i] = 'a' + i % 26;
66
+ buf[BUF_STRING_LENGTH + 1] = '\0';
67
+ data = auto_string_by_id_new(1, buf, FALSE); /* Default based on size - 1024 bytes */
68
+ length = auto_string_length(data);
69
+ available = auto_string_available(data);
70
+ printf("%p %-50.50s ... = %ld (%ld available)\n", data, data, length, available);
71
+ data = auto_string_add(data, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
72
+ length = auto_string_length(data);
73
+ available = auto_string_available(data);
74
+ printf("%p ... %-50.50s = %ld (%ld available)\n\n", data + length - 50,
75
+ data + length - 50, length, available);
76
+
77
+ auto_string_show();
78
+
79
+ /* Arena 2 */
80
+ printf("\nCreating dynamic new auto string arena (2) with 1 KB:\n\n");
81
+ auto_string_identifier = auto_string_init(KB(1));
82
+ auto_string_show();
83
+
84
+ /* Arena 3 */
85
+ printf("\nCreating auto string arena (3) with 1 KB:\n\n");
86
+ data = auto_string_by_id_extra(3, NULL, -2); /* -2 = 2 x 512 (default) space */
87
+ data = auto_string_add(data, "hello, world!");
88
+ length = auto_string_length(data);
89
+ available = auto_string_available(data);
90
+ printf("%p %s = %ld (%ld available)\n", data, data, length, available);
91
+ auto_string_show();
92
+
93
+ /* Arena 2 (using auto_string_identifier) */
94
+ printf("\nUsing dynamic auto string arena (2):\n\n");
95
+ data = auto_string_by_id_new(auto_string_identifier, "hello, world!", TRUE); /* 0 extra */
96
+ length = auto_string_length(data);
97
+ available = auto_string_available(data);
98
+ printf("%p %s = %ld (%ld available)\n", data, data, length, available);
99
+ auto_string_show();
100
+
101
+ /* Arena 4 - should be the same result as arena 3 above */
102
+ printf("\nCreating auto string arena (4) with 1 KB:\n\n");
103
+ auto_string_identifier = auto_string_init(KB(1));
104
+ data = auto_string_by_id_extra(auto_string_identifier, "hello, world!", 0);
105
+ length = auto_string_length(data);
106
+ available = auto_string_available(data);
107
+ printf("%p %s = %ld (%ld available)\n", data, data, length, available);
108
+ auto_string_show();
109
+
110
+ printf("\nReset auto string arena (3):\n\n");
111
+ auto_string_by_id_reset(3);
112
+ auto_string_show();
113
+
114
+ printf("\nFree auto string arena (2):\n\n");
115
+ auto_string_by_id_free(2);
116
+ auto_string_show();
117
+
118
+ printf("\nFind auto string arena identifier for current data pointer (4):\n");
119
+ auto_string_identifier = find_auto_string_identifier(data);
120
+ printf(" data is currently pointing at arena %d\n", auto_string_identifier);
121
+
122
+ printf("\nPerform tests:\n--------------\n");
123
+
124
+ result = auto_string_match(data, "hello, world!");
125
+ test_scratch(&test_num, "match", data, "hello, world!", result, "TRUE");
126
+
127
+ result = auto_string_match_no_case(data, "hello, WORLD!");
128
+ test_scratch(&test_num, "match no case", data, "hello, WORLD!", result, "TRUE");
129
+
130
+ result = auto_string_contains(data, "world");
131
+ test_scratch(&test_num, "contains", data, "world", result, "TRUE");
132
+
133
+ result = auto_string_match(data, "hell");
134
+ test_scratch(&test_num, "match", data, "hell", result, "FALSE");
135
+
136
+ result = auto_string_match_no_case(data, "HELL");
137
+ test_scratch(&test_num, "match no case", data, "HELL", result, "FALSE");
138
+
139
+ result = auto_string_contains(data, "HELLO");
140
+ test_scratch(&test_num, "contains", data, "HELLO", result, "FALSE");
141
+
142
+ result = auto_string_match(data, "world");
143
+ test_scratch(&test_num, "match", data, "world", result, "FALSE");
144
+
145
+ result = auto_string_match_no_case(data, "WORLD");
146
+ test_scratch(&test_num, "match no case", data, "WORLD", result, "FALSE");
147
+
148
+ result = auto_string_prefixed(data, "hell");
149
+ test_scratch(&test_num, "prefixed", data, "hell", result, "TRUE");
150
+
151
+ result = auto_string_prefixed(data, "HELL");
152
+ test_scratch(&test_num, "prefixed", data, "HELL", result, "FALSE");
153
+
154
+ result = auto_string_prefixed_no_case(data, "HELL");
155
+ test_scratch(&test_num, "prefixed no case", data, "HELL", result, "TRUE");
156
+
157
+ result = auto_string_prefixed_no_case(data, "EL");
158
+ test_scratch(&test_num, "prefixed no case", data, "EL", result, "FALSE");
159
+
160
+ view = a_view(" \n\t\r\v- world! -\n\t\r\v\t ");
161
+ view2 = a_view("world");
162
+ av_trim(&view);
163
+ av_chop_right(&view, 1);
164
+ av_chop_left(&view, 1);
165
+ av_trim(&view);
166
+ av_slice(&view, 1, 4);
167
+
168
+ result = auto_view_match(&view, "world");
169
+ test_scratch_view(&test_num, "view match", &view, "world", result, "FALSE");
170
+
171
+ result = av_match(&view, "orld");
172
+ test_scratch_view(&test_num, "view match", &view, "orld", result, "TRUE");
173
+
174
+ result = av_match_no_case(&view, "ORLD");
175
+ test_scratch_view(&test_num, "view match no case", &view, "ORLD", result, "TRUE");
176
+
177
+ result = av_match_no_case(&view, "OrLd");
178
+ test_scratch_view(&test_num, "view match no case", &view, "OrLd", result, "TRUE");
179
+
180
+ result = av_match_no_case(&view, "WORLD");
181
+ test_scratch_view(&test_num, "view match no case", &view, "WORLD", result, "FALSE");
182
+
183
+ result = auto_view_prefixed(&view, "orl");
184
+ test_scratch_view(&test_num, "view prefixed", &view, "orl", result, "TRUE");
185
+
186
+ result = auto_view_prefixed(&view2, "orl");
187
+ test_scratch_view(&test_num, "view prefixed", &view, "orl", result, "FALSE");
188
+
189
+ result = auto_views_match(&view, &view);
190
+ test_scratch_views(&test_num, "views match", &view, &view, result, "TRUE");
191
+
192
+ result = auto_views_match(&view, &view2);
193
+ test_scratch_views(&test_num, "views match", &view, &view2, result, "FALSE");
194
+
195
+ av_chop_left(&view2, 1);
196
+ result = auto_views_match(&view, &view2);
197
+ test_scratch_views(&test_num, "views match", &view, &view2, result, "TRUE");
198
+
199
+ view2 = a_view("ORLD");
200
+ result = auto_views_match_no_case(&view, &view2);
201
+ test_scratch_views(&test_num, "views match no case", &view, &view2, result, "TRUE");
202
+
203
+ view2 = a_view("OrlD");
204
+ result = auto_views_match_no_case(&view, &view2);
205
+ test_scratch_views(&test_num, "views match no case", &view, &view2, result, "TRUE");
206
+
207
+ view2 = a_view("0rlD");
208
+ result = auto_views_match_no_case(&view, &view2);
209
+ test_scratch_views(&test_num, "views match no case", &view, &view2, result, "FALSE");
210
+
211
+ printf("\n");
212
+ auto_string_show();
213
+
214
+ printf("\nFreeing scratch arena (420):\n");
215
+ auto_string_by_id_free(420);
216
+ auto_string_show();
217
+
218
+ printf("\nPerform thick (default extra capacity) substring: (world)\n");
219
+ substring = auto_string_by_id_substring(1, data, 6, 5, FALSE);
220
+ length = auto_string_length(substring);
221
+ available = auto_string_available(substring);
222
+ printf("%p %s = %ld (%ld available)\n", substring, substring, length, available);
223
+ printf("Perform thin (0 extra capacity) substring: (world)\n");
224
+ substring = auto_string_by_id_substring(1, data, 6, 5, TRUE);
225
+ length = auto_string_length(substring);
226
+ available = auto_string_available(substring);
227
+ printf("%p %s = %ld (%ld available)\n\n", substring, substring, length, available);
228
+ auto_string_show();
229
+
230
+ view = auto_view(data + 7);
231
+ printf("View: %.*s\n", AUTO_VIEW(view));
232
+
233
+ printf("\nReset all auto string arenas:\n\n");
234
+ auto_string_reset_all();
235
+ auto_string_show();
236
+
237
+ printf("\nFree all auto string arenas:\n\n");
238
+ auto_string_free_all();
239
+ auto_string_show();
240
+
241
+ view = a_view(" \n\t\r\v- world! -\n\t\r\v\t ");
242
+ view2 = a_view("world");
243
+ printf("\nUntrimmed View: |%.*s|\n", A_VIEW(view));
244
+ av_trim(&view);
245
+ printf("Trimmed View: |"VIEW"|\n", A_VIEW(view));
246
+ av_chop_right(&view, 1);
247
+ printf("Chop right 1: |"VIEW"|\n", A_VIEW(view));
248
+ av_chop_left(&view, 1);
249
+ printf("Chop left 1: |"VIEW"|\n", A_VIEW(view));
250
+ av_trim(&view);
251
+ printf("Trimmed View: |"VIEW"|\n", A_VIEW(view));
252
+ av_slice(&view, 1, 4);
253
+ printf("Sliced View: |"VIEW"|\n", A_VIEW(view));
254
+ printf("View2: |"VIEW"|\n", A_VIEW(view2));
255
+
256
+ as_show();
257
+
258
+ return 0;
259
+ }
260
+
261
+ /* Uses auto string arena 420 as scratch */
262
+ as8 *make_test_scratch(u64 *test_num, c8 *test_name)
263
+ {
264
+ i32 i = 0;
265
+ as8 *string = NULL;
266
+
267
+ *test_num += 1;
268
+ i = snprintf(NULL, 0, "Test %lu - %s", *test_num, test_name);
269
+ string = auto_string_by_id_extra(420, NULL, i); /* scratch arena / i bytes */
270
+ sprintf(string, "Test %lu - %s", *test_num, test_name);
271
+ auto_string_update(string); /* update position and capacity */
272
+ return string;
273
+ }
274
+
275
+ void test_scratch(u64 *test_num, c8 *test_name, c8 *data1, c8 *data2,
276
+ b8 result, c8 *expected_result)
277
+ {
278
+ as8 *string = make_test_scratch(test_num, test_name);
279
+
280
+ printf("%-30.30s %-15.15s %-15.15s %s | %s\n", string, data1, data2,
281
+ result ? " TRUE" : "FALSE", expected_result);
282
+ }
283
+
284
+ void test_scratch_view(u64 *test_num, c8 *test_name, AutoView *view, c8 *data2,
285
+ b8 result, c8 *expected_result)
286
+ {
287
+ as8 *string = make_test_scratch(test_num, test_name);
288
+
289
+ printf("%-30.30s %-15.*s %-15.15s %s | %s\n", string, A_PVIEW(view), data2,
290
+ result ? " TRUE" : "FALSE", expected_result);
291
+ }
292
+
293
+ void test_scratch_views(u64 *test_num, c8 *test_name, AutoView *view,
294
+ AutoView *view2, b8 result, c8 *expected_result)
295
+ {
296
+ as8 *string = make_test_scratch(test_num, test_name);
297
+
298
+ printf("%-30.30s "VIEW_WIDTH(-15)" "VIEW_WIDTH(-15)" %s | %s\n", string,
299
+ A_PVIEW(view), A_PVIEW(view2), result ? " TRUE" : "FALSE", expected_result);
300
+ }