add win32 (msvc) support

This commit is contained in:
2024-11-14 16:56:12 +00:00
parent c14c2e5500
commit d614e110df
35 changed files with 454 additions and 280 deletions

View File

@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.25)
project(bluelib C)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(b_modules core object term cmd)
set(b_system_name ${CMAKE_SYSTEM_NAME})
@@ -21,6 +23,8 @@ foreach (module ${b_modules})
misc/CuTest.h)
target_link_libraries(blue-${module}-units blue-${module})
target_include_directories(blue-${module}-units PRIVATE misc/)
set_target_properties(blue-${module}-units PROPERTIES FOLDER "Tests/${module}")
endif ()
file(GLOB test_sources ${module}-test/*.c)
@@ -30,6 +34,8 @@ foreach (module ${b_modules})
get_filename_component(test_name ${test_file} NAME_WE)
add_executable(blue-${module}-${test_name} ${test_file})
set_target_properties(blue-${module}-${test_name} PROPERTIES FOLDER "Tests/${module}")
target_link_libraries(blue-${module}-${test_name} blue-${module})
endforeach (test_file)
endif ()

View File

@@ -21,7 +21,7 @@ function(add_bluelib_module)
set(module_preproc_token BLUELIB_${module_preproc_token})
target_include_directories(blue-${module_name}-obj PUBLIC include/)
target_compile_definitions(blue-${module_name}-obj PUBLIC ${module_preproc_token})
target_compile_definitions(blue-${module_name}-obj PUBLIC ${module_preproc_token} BLUELIB_EXPORT=1)
foreach (dep ${arg_DEPENDENCIES})
target_link_libraries(blue-${module_name}-obj blue-${dep}-obj)
@@ -40,6 +40,10 @@ function(add_bluelib_module)
target_link_libraries(blue-${module_name}-s blue-${dep}-s)
endforeach (dep)
set_target_properties(blue-${module_name}-obj PROPERTIES FOLDER "Modules/${module_name}")
set_target_properties(blue-${module_name} PROPERTIES FOLDER "Binaries/${module_name}")
set_target_properties(blue-${module_name}-s PROPERTIES FOLDER "Binaries/${module_name}")
install(TARGETS blue-${module_name} blue-${module_name}-s)
install(FILES ${root_header} DESTINATION include/blue)
install(FILES ${headers} DESTINATION include/blue/${module_name})

View File

@@ -100,42 +100,42 @@ struct b_arglist {
struct b_btree list_options;
};
extern struct b_command *b_command_get_subcommand_with_name(
BLUE_API struct b_command *b_command_get_subcommand_with_name(
struct b_command *cmd, const char *name);
extern struct b_command *b_command_get_subcommand_with_long_name(
BLUE_API struct b_command *b_command_get_subcommand_with_long_name(
struct b_command *cmd, const char *long_name);
extern struct b_command *b_command_get_subcommand_with_short_name(
BLUE_API struct b_command *b_command_get_subcommand_with_short_name(
struct b_command *cmd, char short_name);
extern struct b_command_option *b_command_get_option_with_long_name(
BLUE_API struct b_command_option *b_command_get_option_with_long_name(
struct b_command *cmd, const char *long_name);
extern struct b_command_option *b_command_get_option_with_short_name(
BLUE_API struct b_command_option *b_command_get_option_with_short_name(
struct b_command *cmd, char short_name);
extern struct b_command_option *b_command_option_create(void);
extern void b_command_option_destroy(struct b_command_option *opt);
BLUE_API struct b_command_option *b_command_option_create(void);
BLUE_API void b_command_option_destroy(struct b_command_option *opt);
extern struct b_command_arg *b_command_arg_create(void);
extern void b_command_arg_destroy(struct b_command_arg *arg);
BLUE_API struct b_command_arg *b_command_arg_create(void);
BLUE_API void b_command_arg_destroy(struct b_command_arg *arg);
extern struct b_arglist *b_arglist_create(void);
extern b_status b_arglist_parse(
BLUE_API struct b_arglist *b_arglist_create(void);
BLUE_API b_status b_arglist_parse(
struct b_arglist *args, struct b_command **cmd, int argc,
const char **argv);
extern void b_arglist_destroy(struct b_arglist *args);
BLUE_API void b_arglist_destroy(struct b_arglist *args);
extern struct b_string *z__b_command_default_usage_string(
BLUE_API struct b_string *z__b_command_default_usage_string(
struct b_command *cmd, struct b_command_option *with_opt);
extern void z__b_get_arg_usage_string(
BLUE_API void z__b_get_arg_usage_string(
struct b_command_arg *arg, bool colour, struct b_string *out);
extern void z__b_get_arg_description(
BLUE_API void z__b_get_arg_description(
struct b_command_arg *arg, struct b_string *out);
extern void z__b_get_option_usage_string(
BLUE_API void z__b_get_option_usage_string(
struct b_command_option *opt, enum cmd_string_flags flags,
struct b_string *out);
extern void z__b_get_option_description(
BLUE_API void z__b_get_option_description(
struct b_command_option *opt, struct b_string *out);
#endif

View File

@@ -172,59 +172,59 @@ typedef struct b_arglist b_arglist;
typedef int (*b_command_callback)(
const b_command *, const b_arglist *, const b_array *);
extern b_command *b_command_create(unsigned int id);
extern void b_command_destroy(b_command *cmd);
extern b_status b_command_register(b_command *cmd);
extern int b_command_dispatch(unsigned int cmd_id, int argc, const char **argv);
BLUE_API b_command *b_command_create(unsigned int id);
BLUE_API void b_command_destroy(b_command *cmd);
BLUE_API b_status b_command_register(b_command *cmd);
BLUE_API int b_command_dispatch(unsigned int cmd_id, int argc, const char **argv);
extern b_status b_command_set_name(b_command *cmd, const char *name);
extern b_status b_command_set_long_name(b_command *cmd, const char *name);
extern b_status b_command_set_short_name(b_command *cmd, char name);
extern b_status b_command_set_flags(b_command *cmd, b_command_flags flags);
extern b_status b_command_set_description(b_command *cmd, const char *description);
extern b_status b_command_set_callback(b_command *cmd, b_command_callback callback);
extern b_status b_command_set_parent(b_command *cmd, unsigned int parent_id);
extern b_command_option *b_command_add_option(b_command *cmd, int id);
extern b_command_arg *b_command_add_arg(b_command *cmd, int id);
extern b_command_usage *b_command_add_usage(b_command *cmd);
BLUE_API b_status b_command_set_name(b_command *cmd, const char *name);
BLUE_API b_status b_command_set_long_name(b_command *cmd, const char *name);
BLUE_API b_status b_command_set_short_name(b_command *cmd, char name);
BLUE_API b_status b_command_set_flags(b_command *cmd, b_command_flags flags);
BLUE_API b_status b_command_set_description(b_command *cmd, const char *description);
BLUE_API b_status b_command_set_callback(b_command *cmd, b_command_callback callback);
BLUE_API b_status b_command_set_parent(b_command *cmd, unsigned int parent_id);
BLUE_API b_command_option *b_command_add_option(b_command *cmd, int id);
BLUE_API b_command_arg *b_command_add_arg(b_command *cmd, int id);
BLUE_API b_command_usage *b_command_add_usage(b_command *cmd);
extern b_status b_command_option_set_long_name(
BLUE_API b_status b_command_option_set_long_name(
b_command_option *opt, const char *name);
extern b_status b_command_option_set_short_name(b_command_option *opt, char name);
extern b_status b_command_option_set_description(
BLUE_API b_status b_command_option_set_short_name(b_command_option *opt, char name);
BLUE_API b_status b_command_option_set_description(
b_command_option *opt, const char *description);
extern b_command_arg *b_command_option_add_arg(b_command_option *opt, int id);
BLUE_API b_command_arg *b_command_option_add_arg(b_command_option *opt, int id);
extern b_status b_command_arg_set_name(b_command_arg *arg, const char *name);
extern b_status b_command_arg_set_description(
BLUE_API b_status b_command_arg_set_name(b_command_arg *arg, const char *name);
BLUE_API b_status b_command_arg_set_description(
b_command_arg *arg, const char *description);
extern b_status b_command_arg_set_nr_values(
BLUE_API b_status b_command_arg_set_nr_values(
b_command_arg *arg, b_command_arg_value_count nr_values);
extern b_status b_command_arg_set_allowed_values(
BLUE_API b_status b_command_arg_set_allowed_values(
b_command_arg *arg, const char **allowed_values);
extern b_status b_command_usage_add_option(
BLUE_API b_status b_command_usage_add_option(
b_command_usage *usage, b_command_option *opt);
extern b_status b_command_usage_add_arg(b_command_usage *usage, b_command_arg *opt);
extern b_status b_command_usage_add_command(
BLUE_API b_status b_command_usage_add_arg(b_command_usage *usage, b_command_arg *opt);
BLUE_API b_status b_command_usage_add_command(
b_command_usage *usage, unsigned int cmd_id);
extern b_status b_arglist_get_string(
BLUE_API b_status b_arglist_get_string(
const b_arglist *args, unsigned int opt_id, unsigned int arg_id,
unsigned int index, const char **out);
extern b_status b_arglist_get_int(
BLUE_API b_status b_arglist_get_int(
const b_arglist *args, unsigned int opt_id, unsigned int arg_id,
unsigned int index, long long *out);
extern b_status b_arglist_get_uint(
BLUE_API b_status b_arglist_get_uint(
const b_arglist *args, unsigned int opt_id, unsigned int arg_id,
unsigned int index, unsigned long long *out);
extern size_t b_arglist_get_count(
BLUE_API size_t b_arglist_get_count(
const b_arglist *args, unsigned int opt_id, unsigned int arg_id);
extern int b_arglist_iterator_begin(
BLUE_API int b_arglist_iterator_begin(
const b_arglist *args, unsigned int opt_filter, unsigned int arg_filter,
b_arglist_iterator *it);
extern bool b_arglist_iterator_next(b_arglist_iterator *it);
extern bool b_arglist_iterator_is_valid(const b_arglist_iterator *it);
BLUE_API bool b_arglist_iterator_next(b_arglist_iterator *it);
BLUE_API bool b_arglist_iterator_is_valid(const b_arglist_iterator *it);
#endif

View File

@@ -0,0 +1,10 @@
#ifndef BLUELIB_CORE_BITOP_H_
#define BLUELIB_CORE_BITOP_H_
#include <blue/core/misc.h>
BLUE_API int b_popcountl(long v);
BLUE_API int b_ctzl(long v);
BLUE_API int b_clzl(long v);
#endif

View File

@@ -267,34 +267,34 @@ typedef struct b_btree_iterator {
@param tree the tree to re-balance.
@param node the node that was just inserted into the tree.
*/
extern void b_btree_insert_fixup(b_btree *tree, b_btree_node *node);
BLUE_API void b_btree_insert_fixup(b_btree *tree, b_btree_node *node);
/* delete a node from a binary tree and re-balance the tree afterwards.
@param tree the tree to delete from
@param node the node to delete.
*/
extern void b_btree_delete(b_btree *tree, b_btree_node *node);
BLUE_API void b_btree_delete(b_btree *tree, b_btree_node *node);
/* get the first node in a binary tree.
this will be the node with the smallest key (i.e. the node that is
furthest-left from the root)
*/
extern b_btree_node *b_btree_first(const b_btree *tree);
BLUE_API b_btree_node *b_btree_first(const b_btree *tree);
/* get the last node in a binary tree.
this will be the node with the largest key (i.e. the node that is
furthest-right from the root)
*/
extern b_btree_node *b_btree_last(const b_btree *tree);
BLUE_API b_btree_node *b_btree_last(const b_btree *tree);
/* for any binary tree node, this function returns the node with the
* next-largest key value */
extern b_btree_node *b_btree_next(const b_btree_node *node);
BLUE_API b_btree_node *b_btree_next(const b_btree_node *node);
/* for any binary tree node, this function returns the node with the
* next-smallest key value */
extern b_btree_node *b_btree_prev(const b_btree_node *node);
BLUE_API b_btree_node *b_btree_prev(const b_btree_node *node);
/* return true if the btree is empty, false otherwise */
static inline bool b_btree_empty(const b_btree *tree)
{
@@ -345,10 +345,10 @@ static inline unsigned short b_btree_height(b_btree_node *node)
return node->b_height;
}
extern int b_btree_iterator_begin(const b_btree *tree, b_btree_iterator *it);
extern bool b_btree_iterator_next(b_btree_iterator *it);
extern b_status b_btree_iterator_erase(b_btree_iterator *it);
extern bool b_btree_iterator_is_valid(const b_btree_iterator *it);
BLUE_API int b_btree_iterator_begin(const b_btree *tree, b_btree_iterator *it);
BLUE_API bool b_btree_iterator_next(b_btree_iterator *it);
BLUE_API b_status b_btree_iterator_erase(b_btree_iterator *it);
BLUE_API bool b_btree_iterator_is_valid(const b_btree_iterator *it);
#ifdef __cplusplus
}

View File

@@ -12,7 +12,7 @@
}; \
static f##_t_ f##_; \
static void f(void)
#elif defined(_MSB_VER)
#elif defined(_MSC_VER)
#pragma section(".CRT$XCU", read)
#define B_INIT2_(f, p) \
static void f(void); \

View File

@@ -2,6 +2,7 @@
#define BLUELIB_CORE_ITERATOR_H_
#include <blue/core/status.h>
#include <blue/core/misc.h>
#include <stdbool.h>
struct b_iterator;
@@ -17,9 +18,9 @@ typedef struct b_iterator {
const b_iterator_ops *it_ops;
} b_iterator;
extern b_status b_iterator_close(b_iterator *it);
extern bool b_iterator_next(b_iterator *it);
extern b_status b_iterator_erase(b_iterator *it);
extern bool b_iterator_is_valid(const b_iterator *it);
BLUE_API b_status b_iterator_close(b_iterator *it);
BLUE_API bool b_iterator_next(b_iterator *it);
BLUE_API b_status b_iterator_erase(b_iterator *it);
BLUE_API bool b_iterator_is_valid(const b_iterator *it);
#endif

View File

@@ -14,4 +14,14 @@
#define z__b_numargs(arg_type, ...) \
(sizeof((arg_type[]) {__VA_ARGS__}) / sizeof(arg_type))
#ifdef _MSC_VER
#ifdef BLUELIB_EXPORT
#define BLUE_API extern __declspec(dllexport)
#else
#define BLUE_API extern __declspec(dllimport)
#endif
#else
#define BLUE_API extern
#endif
#endif // B_MISB_H_

View File

@@ -60,26 +60,26 @@ static inline b_queue_entry *b_queue_prev(const b_queue_entry *entry)
return entry->qe_prev;
}
extern size_t b_queue_length(b_queue *q);
BLUE_API size_t b_queue_length(b_queue *q);
extern void b_queue_insert_before(
BLUE_API void b_queue_insert_before(
b_queue *q, b_queue_entry *entry, b_queue_entry *before);
extern void b_queue_insert_after(
BLUE_API void b_queue_insert_after(
b_queue *q, b_queue_entry *entry, b_queue_entry *after);
extern void b_queue_push_front(b_queue *q, b_queue_entry *entry);
extern void b_queue_push_back(b_queue *q, b_queue_entry *entry);
BLUE_API void b_queue_push_front(b_queue *q, b_queue_entry *entry);
BLUE_API void b_queue_push_back(b_queue *q, b_queue_entry *entry);
extern b_queue_entry *b_queue_pop_front(b_queue *q);
extern b_queue_entry *b_queue_pop_back(b_queue *q);
BLUE_API b_queue_entry *b_queue_pop_front(b_queue *q);
BLUE_API b_queue_entry *b_queue_pop_back(b_queue *q);
extern void b_queue_delete(b_queue *q, b_queue_entry *entry);
extern void b_queue_delete_all(b_queue *q);
BLUE_API void b_queue_delete(b_queue *q, b_queue_entry *entry);
BLUE_API void b_queue_delete_all(b_queue *q);
extern int b_queue_iterator_begin(const b_queue *q, b_queue_iterator *it);
extern bool b_queue_iterator_next(b_queue_iterator *it);
extern b_status b_queue_iterator_erase(b_queue_iterator *it);
extern bool b_queue_iterator_is_valid(const b_queue_iterator *it);
BLUE_API int b_queue_iterator_begin(const b_queue *q, b_queue_iterator *it);
BLUE_API bool b_queue_iterator_next(b_queue_iterator *it);
BLUE_API b_status b_queue_iterator_erase(b_queue_iterator *it);
BLUE_API bool b_queue_iterator_is_valid(const b_queue_iterator *it);
#ifdef __cplusplus
}

View File

@@ -26,12 +26,12 @@ typedef struct b_random_ctx {
};
} b_random_ctx;
extern b_random_ctx *b_random_global_ctx(void);
BLUE_API b_random_ctx *b_random_global_ctx(void);
extern b_status b_random_init(b_random_ctx *ctx, b_random_flags flags);
extern unsigned long long b_random_next_int64(b_random_ctx *ctx);
extern double b_random_next_double(b_random_ctx *ctx);
extern void b_random_next_bytes(
BLUE_API b_status b_random_init(b_random_ctx *ctx, b_random_flags flags);
BLUE_API unsigned long long b_random_next_int64(b_random_ctx *ctx);
BLUE_API double b_random_next_double(b_random_ctx *ctx);
BLUE_API void b_random_next_bytes(
b_random_ctx *ctx, unsigned char *out, size_t nbytes);
#endif

View File

@@ -1,6 +1,8 @@
#ifndef BLUELIB_CORE_STATUS_H_
#define BLUELIB_CORE_STATUS_H_
#include <blue/core/misc.h>
#define B_OK(status) ((status) == B_SUCCESS)
#define B_ERR(status) ((status) != B_SUCCESS)
@@ -18,6 +20,6 @@ typedef enum {
B_ERR_BAD_FORMAT,
} b_status;
extern const char *b_status_to_string(b_status status);
BLUE_API const char *b_status_to_string(b_status status);
#endif

View File

@@ -2,6 +2,7 @@
#define BLUELIB_CORE_STRINGSTREAM_H_
#include <blue/core/status.h>
#include <blue/core/misc.h>
#include <stddef.h>
typedef struct b_stringstream {
@@ -14,18 +15,18 @@ typedef struct b_stringstream {
size_t ss_istack_ptr, ss_istack_size;
} b_stringstream;
extern void b_stringstream_begin(b_stringstream *strv, char *buf, size_t max);
extern void b_stringstream_begin_dynamic(b_stringstream *strv);
BLUE_API void b_stringstream_begin(b_stringstream *strv, char *buf, size_t max);
BLUE_API void b_stringstream_begin_dynamic(b_stringstream *strv);
extern void b_stringstream_push_indent(b_stringstream *strv, int indent);
extern void b_stringstream_pop_indent(b_stringstream *strv);
BLUE_API void b_stringstream_push_indent(b_stringstream *strv, int indent);
BLUE_API void b_stringstream_pop_indent(b_stringstream *strv);
extern b_status b_stringstream_add(b_stringstream *strv, const char *str);
extern b_status b_stringstream_addf(b_stringstream *strv, const char *format, ...);
extern b_status b_stringstream_addv(b_stringstream *strv, const char **strs);
extern b_status b_stringstream_addvl(
BLUE_API b_status b_stringstream_add(b_stringstream *strv, const char *str);
BLUE_API b_status b_stringstream_addf(b_stringstream *strv, const char *format, ...);
BLUE_API b_status b_stringstream_addv(b_stringstream *strv, const char **strs);
BLUE_API b_status b_stringstream_addvl(
b_stringstream *strv, const char **strs, size_t count);
extern b_status b_stringstream_add_many(b_stringstream *strv, ...);
extern char *b_stringstream_end(b_stringstream *strv);
BLUE_API b_status b_stringstream_add_many(b_stringstream *strv, ...);
BLUE_API char *b_stringstream_end(b_stringstream *strv);
#endif

View File

@@ -4,7 +4,7 @@
#define GET_ALGORITHM_ID(flags) ((flags) & 0xFF)
extern struct b_random_algorithm z__b_gen_mt19937;
BLUE_API struct b_random_algorithm z__b_gen_mt19937;
static struct b_random_algorithm *generators[] = {
[B_RANDOM_MT19937] = &z__b_gen_mt19937,

View File

@@ -2,6 +2,7 @@
#define _BLUELIB_RANDOM_H_
#include <stdint.h>
#include <blue/core/misc.h>
struct b_random_ctx;
@@ -11,7 +12,7 @@ struct b_random_algorithm {
uint64_t(*gen_getrand)(struct b_random_ctx *);
};
extern uint64_t z__b_platform_random_seed();
extern uint64_t z__b_platform_random_seed_secure();
BLUE_API uint64_t z__b_platform_random_seed(void);
BLUE_API uint64_t z__b_platform_random_seed_secure(void);
#endif

54
core/sys/windows/bitop.c Normal file
View File

@@ -0,0 +1,54 @@
#include <blue/core/bitop.h>
#include <intrin.h>
#include <assert.h>
#define CPU_FEATURE_YES 1
#define CPU_FEATURE_NO -1
#define CPU_FEATURE_UNKNOWN 0
static int cpu_supports_popcnt = CPU_FEATURE_UNKNOWN;
static int check_popcnt_support()
{
int d[4];
__cpuid(d, 0x00000001);
return (d[2] & 0x800000) ? CPU_FEATURE_YES : CPU_FEATURE_NO;
}
int b_popcountl(long v)
{
if (cpu_supports_popcnt == CPU_FEATURE_UNKNOWN) {
cpu_supports_popcnt = check_popcnt_support();
}
if (cpu_supports_popcnt == CPU_FEATURE_YES) {
return __popcnt64(v);
}
assert(0 && "CPU does not support popcount!");
return 0;
}
int b_ctzl(long v)
{
unsigned long trailing_zero = 0;
if (_BitScanForward64(&trailing_zero, v)) {
return trailing_zero;
} else {
return 64;
}
}
int b_clzl(long v)
{
unsigned long leading_zero = 0;
if (_BitScanReverse64(&leading_zero, v)) {
return 64 - leading_zero;
} else {
// Same remarks as above
return 64;
}
}

30
core/sys/windows/random.c Normal file
View File

@@ -0,0 +1,30 @@
#include <fcntl.h>
#include <stdint.h>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <wincrypt.h>
uint64_t z__b_platform_random_seed_secure(void)
{
BOOL status;
HCRYPTPROV hCryptProv;
status = CryptAcquireContext(
&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
if (status == FALSE) {
return (uint64_t)-1;
}
uint64_t v = 0;
status = CryptGenRandom(hCryptProv, sizeof v, (BYTE *)&v);
CryptReleaseContext(hCryptProv, 0);
return status == TRUE ? v : (uint64_t)-1;
}
uint64_t z__b_platform_random_seed(void)
{
return z__b_platform_random_seed_secure();
}

View File

@@ -1,5 +1,6 @@
#include <string.h>
#include <blue/object/bitmap.h>
#include <blue/core/bitop.h>
void b_bitmap_zero(b_bitmap_word *map, unsigned long nbits)
{
@@ -38,7 +39,6 @@ bool b_bitmap_check(const b_bitmap_word *map, unsigned long bit)
unsigned long mask = 1ul << offset;
return (map[index] & mask) != 0;
}
unsigned int b_bitmap_count_set(const b_bitmap_word *map, unsigned long nbits)
@@ -47,7 +47,7 @@ unsigned int b_bitmap_count_set(const b_bitmap_word *map, unsigned long nbits)
unsigned int set_bits = 0;
for (unsigned long i = 0; i < words; i++) {
set_bits += __builtin_popcountl(map[i]);
set_bits += b_popcountl(map[i]);
}
if (set_bits > nbits) {
@@ -63,7 +63,7 @@ unsigned int b_bitmap_count_clear(const b_bitmap_word *map, unsigned long nbits)
unsigned int clear_bits = 0;
for (unsigned long i = 0; i < words; i++) {
clear_bits += __builtin_popcountl(~map[i]);
clear_bits += b_popcountl(~map[i]);
}
if (clear_bits > nbits) {
@@ -91,7 +91,7 @@ unsigned int b_bitmap_highest_set(const b_bitmap_word *map, unsigned long nbits)
return B_BITMAP_NPOS;
}
return bit_index + (Z__B_BITS_PER_WORD - __builtin_ctzl(last_word) - 1);
return bit_index + (Z__B_BITS_PER_WORD - b_ctzl(last_word) - 1);
}
unsigned int b_bitmap_highest_clear(const b_bitmap_word *map, unsigned long nbits)
@@ -115,7 +115,7 @@ unsigned int b_bitmap_highest_clear(const b_bitmap_word *map, unsigned long nbit
return bit_index + Z__B_BITS_PER_WORD - 1;
}
return bit_index + (Z__B_BITS_PER_WORD - __builtin_ctzl(~last_word)) - 1;
return bit_index + (Z__B_BITS_PER_WORD - b_ctzl(~last_word)) - 1;
}
unsigned int b_bitmap_lowest_set(const b_bitmap_word *map, unsigned long nbits)
@@ -137,7 +137,7 @@ unsigned int b_bitmap_lowest_set(const b_bitmap_word *map, unsigned long nbits)
return B_BITMAP_NPOS;
}
return bit_index + __builtin_clzl(last_word);
return bit_index + b_clzl(last_word);
}
unsigned int b_bitmap_lowest_clear(const b_bitmap_word *map, unsigned long nbits)
@@ -163,5 +163,5 @@ unsigned int b_bitmap_lowest_clear(const b_bitmap_word *map, unsigned long nbits
return B_BITMAP_NPOS;
}
return bit_index + __builtin_clzl(~last_word);
return bit_index + b_clzl(~last_word);
}

View File

@@ -64,7 +64,7 @@ typedef struct b_array_iterator {
*
* @return A pointer to the new array, or NULL if an error occurred.
*/
extern b_array *b_array_create(void);
BLUE_API b_array *b_array_create(void);
/**
* Creates an b_array initialised with the contents of the provided b_object
@@ -81,7 +81,7 @@ extern b_array *b_array_create(void);
* @param nr_values The size of the `values` array.
* @return A pointer to the new b_array, or NULL if an error occurred.
*/
extern b_array *b_array_create_with_values(
BLUE_API b_array *b_array_create_with_values(
b_object *const *values, size_t nr_values);
/**
@@ -110,7 +110,7 @@ static inline void b_array_release(b_array *array)
*
* @param array The b_array to clear.
*/
extern void b_array_clear(b_array *array);
BLUE_API void b_array_clear(b_array *array);
/**
* Inserts an object at the end of an b_array. The reference count of the object
@@ -120,7 +120,7 @@ extern void b_array_clear(b_array *array);
* @param value The object to append.
* @return B_SUCCESS if the object was appended successfully, or an error code if an error occurred.
*/
extern b_status b_array_append(b_array *array, b_object *value);
BLUE_API b_status b_array_append(b_array *array, b_object *value);
/**
* Inserts an object at the beginning of an b_array. The reference count of the object
@@ -131,7 +131,7 @@ extern b_status b_array_append(b_array *array, b_object *value);
* @param value The object to prepend.
* @return B_SUCCESS if the object was prepended successfully, or an error code if an error occurred.
*/
extern b_status b_array_prepend(b_array *array, b_object *value);
BLUE_API b_status b_array_prepend(b_array *array, b_object *value);
/**
* Inserts an object into an b_array at a given index. The reference count of the object
@@ -145,7 +145,7 @@ extern b_status b_array_prepend(b_array *array, b_object *value);
* be inserted at the end of the b_array.
* @return B_SUCCESS if the object was inserted, or a status code describing any error that occurred.
*/
extern b_status b_array_insert(b_array *array, b_object *value, size_t at);
BLUE_API b_status b_array_insert(b_array *array, b_object *value, size_t at);
/**
* Removes the object at the specified index from an b_array. The reference count
@@ -157,7 +157,7 @@ extern b_status b_array_insert(b_array *array, b_object *value, size_t at);
* @param at The index of the object to be removed.
* @return B_SUCCESS if the object was removed, or a status code describing any error that occurred.
*/
extern b_status b_array_remove(b_array *array, size_t at);
BLUE_API b_status b_array_remove(b_array *array, size_t at);
/**
* Removes the object at the beginning of an b_array. The reference count
@@ -167,7 +167,7 @@ extern b_status b_array_remove(b_array *array, size_t at);
* @param array The b_array to remove the object from.
* @return B_SUCCESS if the object was removed, or a status code describing any error that occurred.
*/
extern b_status b_array_remove_front(b_array *array);
BLUE_API b_status b_array_remove_front(b_array *array);
/**
* Removes the object at the end of an b_array. The reference count
@@ -176,7 +176,7 @@ extern b_status b_array_remove_front(b_array *array);
* @param array The b_array to remove the object from.
* @return B_SUCCESS if the object was removed, or a status code describing any error that occurred.
*/
extern b_status b_array_remove_back(b_array *array);
BLUE_API b_status b_array_remove_back(b_array *array);
/**
* Removes the object at the specified index of an b_array, and returns a
@@ -191,7 +191,7 @@ extern b_status b_array_remove_back(b_array *array);
* @return An pointer to the removed object. This pointer is owned by the
* caller. Returns NULL if an error occurred.
*/
extern b_object *b_array_pop(b_array *array, size_t at);
BLUE_API b_object *b_array_pop(b_array *array, size_t at);
/**
* Removes the object at the beginning of an b_array, and returns a pointer to
@@ -204,7 +204,7 @@ extern b_object *b_array_pop(b_array *array, size_t at);
* @return An pointer to the removed object. This pointer is owned by the
* caller. Returns NULL if an error occurred.
*/
extern b_object *b_array_pop_front(b_array *array);
BLUE_API b_object *b_array_pop_front(b_array *array);
/**
* Removes the object at the end of an b_array, and returns a pointer to it. The
@@ -215,7 +215,7 @@ extern b_object *b_array_pop_front(b_array *array);
* @return An pointer to the removed object. This pointer is owned by the
* caller. Returns NULL if an error occurred.
*/
extern b_object *b_array_pop_back(b_array *array);
BLUE_API b_object *b_array_pop_back(b_array *array);
/**
* Returns an unowned pointer to the object at the given index of an b_array.
@@ -226,7 +226,7 @@ extern b_object *b_array_pop_back(b_array *array);
* @return A pointer to the object at the given index. This pointer is NOT owned
* by the caller. Returns NULL if an error occurred.
*/
extern b_object *b_array_at(const b_array *array, size_t at);
BLUE_API b_object *b_array_at(const b_array *array, size_t at);
/**
* Returns an owned pointer to the object at the given index of an b_array. The caller owns
@@ -237,7 +237,7 @@ extern b_object *b_array_at(const b_array *array, size_t at);
* @return A pointer to the object at the given index. This pointer is owned by the caller.
* Returns NULL if an error occurred.
*/
extern b_object *b_array_get(b_array *array, size_t at);
BLUE_API b_object *b_array_get(b_array *array, size_t at);
/**
* Returns the number of objects contained in an b_array.
@@ -245,7 +245,7 @@ extern b_object *b_array_get(b_array *array, size_t at);
* @param array The b_array.
* @return The number of objects contained in the b_array.
*/
extern size_t b_array_size(const b_array *array);
BLUE_API size_t b_array_size(const b_array *array);
/**
* Returns the current maximum capacity of an b_array. This represents the
@@ -255,7 +255,7 @@ extern size_t b_array_size(const b_array *array);
* @param array The b_array.
* @return The maximum capacity of the b_array.
*/
extern size_t b_array_capacity(const b_array *array);
BLUE_API size_t b_array_capacity(const b_array *array);
/**
* Initialise an b_array_iterator to pointer to the first object in an b_array.
@@ -265,7 +265,7 @@ extern size_t b_array_capacity(const b_array *array);
* @param it
* @return Always returns 0.
*/
extern int b_array_iterator_begin(b_array *array, b_array_iterator *it);
BLUE_API int b_array_iterator_begin(b_array *array, b_array_iterator *it);
/**
* Advances an b_array_iterator to pointer to the next object in an b_array.
@@ -273,7 +273,7 @@ extern int b_array_iterator_begin(b_array *array, b_array_iterator *it);
* @return True if the iterator contains a valid reference to an object, or
* False if the iterator has gone past the end of the array.
*/
extern bool b_array_iterator_next(b_array_iterator *it);
BLUE_API bool b_array_iterator_next(b_array_iterator *it);
/**
* Removes the object pointed to by an b_array_iterator from its container
@@ -284,7 +284,7 @@ extern bool b_array_iterator_next(b_array_iterator *it);
* @param it The iterator whose object should be removed.
* @return B_SUCCESS if the object was removed, or a status code describing the error that occurred.
*/
extern b_status b_array_iterator_erase(b_array_iterator *it);
BLUE_API b_status b_array_iterator_erase(b_array_iterator *it);
/**
* Checks whether or not an iterator contains a valid reference to an object.
@@ -295,7 +295,7 @@ extern b_status b_array_iterator_erase(b_array_iterator *it);
* @param it The iterator to check.
* @return True if the iterator is valid. False otherwise.
*/
extern bool b_array_iterator_is_valid(const b_array_iterator *it);
BLUE_API bool b_array_iterator_is_valid(const b_array_iterator *it);
#ifdef __cplusplus
}

View File

@@ -1,6 +1,7 @@
#ifndef BLUELIB_BITMAP_H_
#define BLUELIB_BITMAP_H_
#include <blue/core/misc.h>
#include <stdbool.h>
typedef unsigned long b_bitmap_word;
@@ -12,19 +13,19 @@ typedef unsigned long b_bitmap_word;
#define B_DECLARE_BITMAP(name, nbits) b_bitmap_word name[B_BITMAP_WORDS(nbits)]
extern void b_bitmap_zero(b_bitmap_word *map, unsigned long nbits);
extern void b_bitmap_fill(b_bitmap_word *map, unsigned long nbits);
extern void b_bitmap_set(b_bitmap_word *map, unsigned long bit);
extern void b_bitmap_clear(b_bitmap_word *map, unsigned long bit);
extern bool b_bitmap_check(const b_bitmap_word *map, unsigned long bit);
BLUE_API void b_bitmap_zero(b_bitmap_word *map, unsigned long nbits);
BLUE_API void b_bitmap_fill(b_bitmap_word *map, unsigned long nbits);
BLUE_API void b_bitmap_set(b_bitmap_word *map, unsigned long bit);
BLUE_API void b_bitmap_clear(b_bitmap_word *map, unsigned long bit);
BLUE_API bool b_bitmap_check(const b_bitmap_word *map, unsigned long bit);
extern unsigned int b_bitmap_count_set(const b_bitmap_word *map, unsigned long nbits);
extern unsigned int b_bitmap_count_clear(const b_bitmap_word *map, unsigned long nbits);
BLUE_API unsigned int b_bitmap_count_set(const b_bitmap_word *map, unsigned long nbits);
BLUE_API unsigned int b_bitmap_count_clear(const b_bitmap_word *map, unsigned long nbits);
extern unsigned int b_bitmap_highest_set(const b_bitmap_word *map, unsigned long nbits);
extern unsigned int b_bitmap_highest_clear(const b_bitmap_word *map, unsigned long nbits);
extern unsigned int b_bitmap_lowest_set(const b_bitmap_word *map, unsigned long nbits);
extern unsigned int b_bitmap_lowest_clear(const b_bitmap_word *map, unsigned long nbits);
BLUE_API unsigned int b_bitmap_highest_set(const b_bitmap_word *map, unsigned long nbits);
BLUE_API unsigned int b_bitmap_highest_clear(const b_bitmap_word *map, unsigned long nbits);
BLUE_API unsigned int b_bitmap_lowest_set(const b_bitmap_word *map, unsigned long nbits);
BLUE_API unsigned int b_bitmap_lowest_clear(const b_bitmap_word *map, unsigned long nbits);
#ifdef __cplusplus
}

View File

@@ -3,31 +3,30 @@
#include <blue/object/type.h>
#include <blue/object/object.h>
#include <blue/object/status.h>
#include <stddef.h>
#define B_BUFFER(p) ((b_buffer *)(p))
typedef struct b_buffer b_buffer;
extern b_buffer *b_buffer_create(size_t item_sz);
extern b_buffer *b_buffer_create_from_bytes(const void *p, size_t len);
extern b_buffer *b_buffer_create_from_array(const void *p, size_t item_sz, size_t len);
BLUE_API b_buffer *b_buffer_create(size_t item_sz);
BLUE_API b_buffer *b_buffer_create_from_bytes(const void *p, size_t len);
BLUE_API b_buffer *b_buffer_create_from_array(const void *p, size_t item_sz, size_t len);
static inline b_buffer *b_buffer_retain(b_buffer *buf) { return B_BUFFER(b_retain(B_OBJECT(buf))); }
static inline void b_buffer_release(b_buffer *buf) { b_release(B_OBJECT(buf)); }
extern void *b_buffer_steal(b_buffer *buf);
extern b_status b_buffer_reserve(b_buffer *buf, size_t capacity);
BLUE_API void *b_buffer_steal(b_buffer *buf);
BLUE_API b_status b_buffer_reserve(b_buffer *buf, size_t capacity);
extern b_status b_buffer_append(b_buffer *dest, const void *p, size_t count);
extern b_status b_buffer_prepend(b_buffer *dest, const void *p, size_t count);
extern b_status b_buffer_insert(b_buffer *dest, const void *p, size_t count, size_t at);
extern b_status b_buffer_clear(b_buffer *str);
BLUE_API b_status b_buffer_append(b_buffer *dest, const void *p, size_t count);
BLUE_API b_status b_buffer_prepend(b_buffer *dest, const void *p, size_t count);
BLUE_API b_status b_buffer_insert(b_buffer *dest, const void *p, size_t count, size_t at);
BLUE_API b_status b_buffer_clear(b_buffer *str);
extern size_t b_buffer_get_size(const b_buffer *str);
extern size_t b_buffer_get_item_size(const b_buffer *str);
extern size_t b_buffer_get_capacity(const b_buffer *str);
BLUE_API size_t b_buffer_get_size(const b_buffer *str);
BLUE_API size_t b_buffer_get_item_size(const b_buffer *str);
BLUE_API size_t b_buffer_get_capacity(const b_buffer *str);
extern void *b_buffer_ptr(const b_buffer *str);
BLUE_API void *b_buffer_ptr(const b_buffer *str);
#endif

View File

@@ -41,8 +41,8 @@ typedef struct b_dict_item {
b_object *value;
} b_dict_item;
extern b_dict *b_dict_create(void);
extern b_dict *b_dict_create_with_items(const b_dict_item *items);
BLUE_API b_dict *b_dict_create(void);
BLUE_API b_dict *b_dict_create_with_items(const b_dict_item *items);
static inline b_dict *b_dict_retain(b_dict *dict)
{
@@ -53,17 +53,17 @@ static inline void b_dict_release(b_dict *dict)
b_release(B_OBJECT(dict));
}
extern b_status b_dict_put(b_dict *dict, const char *key, b_object *value);
extern b_object *b_dict_at(const b_dict *dict, const char *key);
extern b_object *b_dict_get(b_dict *dict, const char *key);
BLUE_API b_status b_dict_put(b_dict *dict, const char *key, b_object *value);
BLUE_API b_object *b_dict_at(const b_dict *dict, const char *key);
BLUE_API b_object *b_dict_get(b_dict *dict, const char *key);
extern bool b_dict_has_key(const b_dict *dict, const char *key);
extern size_t b_dict_get_size(const b_dict *dict);
extern bool b_dict_is_empty(const b_dict *dict);
BLUE_API bool b_dict_has_key(const b_dict *dict, const char *key);
BLUE_API size_t b_dict_get_size(const b_dict *dict);
BLUE_API bool b_dict_is_empty(const b_dict *dict);
extern int b_dict_iterator_begin(b_dict *dict, b_dict_iterator *it);
extern bool b_dict_iterator_next(b_dict_iterator *it);
extern b_status b_dict_iterator_erase(b_dict_iterator *it);
extern bool b_dict_iterator_is_valid(const b_dict_iterator *it);
BLUE_API int b_dict_iterator_begin(b_dict *dict, b_dict_iterator *it);
BLUE_API bool b_dict_iterator_next(b_dict_iterator *it);
BLUE_API b_status b_dict_iterator_erase(b_dict_iterator *it);
BLUE_API bool b_dict_iterator_is_valid(const b_dict_iterator *it);
#endif

View File

@@ -63,8 +63,8 @@ typedef struct b_hashmap_iterator {
b_queue_entry *_cqe;
} b_hashmap_iterator;
extern b_hashmap *b_hashmap_create(void);
extern b_hashmap *b_hashmap_create_with_items(const b_hashmap_item *items);
BLUE_API b_hashmap *b_hashmap_create(void);
BLUE_API b_hashmap *b_hashmap_create_with_items(const b_hashmap_item *items);
static inline b_hashmap *b_hashmap_retain(b_hashmap *hashmap)
{
@@ -75,18 +75,18 @@ static inline void b_hashmap_release(b_hashmap *hashmap)
b_release(B_OBJECT(hashmap));
}
extern b_status b_hashmap_put(
BLUE_API b_status b_hashmap_put(
b_hashmap *hashmap, const b_hashmap_key *key, const b_hashmap_value *value);
extern const b_hashmap_value *b_hashmap_get(
BLUE_API const b_hashmap_value *b_hashmap_get(
const b_hashmap *hashmap, const b_hashmap_key *key);
extern bool b_hashmap_has_key(const b_hashmap *hashmap, const b_hashmap_key *key);
extern size_t b_hashmap_get_size(const b_hashmap *hashmap);
extern bool b_hashmap_is_empty(const b_hashmap *hashmap);
BLUE_API bool b_hashmap_has_key(const b_hashmap *hashmap, const b_hashmap_key *key);
BLUE_API size_t b_hashmap_get_size(const b_hashmap *hashmap);
BLUE_API bool b_hashmap_is_empty(const b_hashmap *hashmap);
extern int b_hashmap_iterator_begin(b_hashmap *hashmap, b_hashmap_iterator *it);
extern bool b_hashmap_iterator_next(b_hashmap_iterator *it);
extern b_status b_hashmap_iterator_erase(b_hashmap_iterator *it);
extern bool b_hashmap_iterator_is_valid(const b_hashmap_iterator *it);
BLUE_API int b_hashmap_iterator_begin(b_hashmap *hashmap, b_hashmap_iterator *it);
BLUE_API bool b_hashmap_iterator_next(b_hashmap_iterator *it);
BLUE_API b_status b_hashmap_iterator_erase(b_hashmap_iterator *it);
BLUE_API bool b_hashmap_iterator_is_valid(const b_hashmap_iterator *it);
#endif

View File

@@ -90,7 +90,7 @@ typedef struct {
};
} b_i64;
extern b_number *b_number_create(b_number_type type, void *value_ptr);
BLUE_API b_number *b_number_create(b_number_type type, void *value_ptr);
static inline b_number *b_number_retain(b_number *number)
{
return B_NUMBER(b_retain(B_OBJECT(number)));
@@ -157,8 +157,8 @@ static inline b_number *b_number_create_size_t(size_t value)
return b_number_create(B_NUMBER_SIZE_T, &value);
}
extern b_number_type b_number_get_type(const b_number *number);
extern int b_number_get_value(
BLUE_API b_number_type b_number_get_type(const b_number *number);
BLUE_API int b_number_get_value(
const b_number *number, b_number_type type, void *value_ptr);
static inline int8_t b_number_get_int8(const b_number *number)
@@ -259,27 +259,27 @@ static inline size_t b_number_get_size_t(const b_number *number)
return v;
}
extern bool b_number_is_integer(const b_number *number);
extern bool b_number_is_float(const b_number *number);
BLUE_API bool b_number_is_integer(const b_number *number);
BLUE_API bool b_number_is_float(const b_number *number);
extern size_t b_number_data_size(const b_number *number);
BLUE_API size_t b_number_data_size(const b_number *number);
extern b_i16 b_i16_htob(uint16_t v);
extern b_i16 b_i16_htos(uint16_t v);
BLUE_API b_i16 b_i16_htob(uint16_t v);
BLUE_API b_i16 b_i16_htos(uint16_t v);
extern uint16_t b_i16_btoh(b_i16 v);
extern uint16_t b_i16_stoh(b_i16 v);
BLUE_API uint16_t b_i16_btoh(b_i16 v);
BLUE_API uint16_t b_i16_stoh(b_i16 v);
extern b_i32 b_i32_htob(uint32_t v);
extern b_i32 b_i32_htos(uint32_t v);
BLUE_API b_i32 b_i32_htob(uint32_t v);
BLUE_API b_i32 b_i32_htos(uint32_t v);
extern uint32_t b_i32_btoh(b_i32 v);
extern uint32_t b_i32_stoh(b_i32 v);
BLUE_API uint32_t b_i32_btoh(b_i32 v);
BLUE_API uint32_t b_i32_stoh(b_i32 v);
extern b_i64 b_i64_htob(uint64_t v);
extern b_i64 b_i64_htos(uint64_t v);
BLUE_API b_i64 b_i64_htob(uint64_t v);
BLUE_API b_i64 b_i64_htos(uint64_t v);
extern uint64_t b_i64_btoh(b_i64 v);
extern uint64_t b_i64_stoh(b_i64 v);
BLUE_API uint64_t b_i64_btoh(b_i64 v);
BLUE_API uint64_t b_i64_stoh(b_i64 v);
#endif

View File

@@ -25,14 +25,14 @@ typedef struct b_object {
const struct b_object_type *ob_type;
} b_object;
extern b_object *b_make_rvalue(b_object *obj);
BLUE_API b_object *b_make_rvalue(b_object *obj);
extern b_object *b_retain(b_object *obj);
extern void b_release(b_object *obj);
BLUE_API b_object *b_retain(b_object *obj);
BLUE_API void b_release(b_object *obj);
extern void b_to_string(b_object *obj, struct b_stringstream *out);
extern b_object_type_id b_typeid(const b_object *obj);
BLUE_API void b_to_string(b_object *obj, struct b_stringstream *out);
BLUE_API b_object_type_id b_typeid(const b_object *obj);
extern b_comparison_result_t b_compare(const b_object *a, const b_object *b);
BLUE_API b_comparison_result_t b_compare(const b_object *a, const b_object *b);
#endif

View File

@@ -24,9 +24,9 @@ typedef struct b_strv_builder {
unsigned char strv_alloc;
} b_strv_builder;
extern b_string *b_string_create(void);
extern b_string *b_string_create_from_cstr(const char *s);
extern b_string *b_string_create_from_c(char c, size_t count);
BLUE_API b_string *b_string_create(void);
BLUE_API b_string *b_string_create_from_cstr(const char *s);
BLUE_API b_string *b_string_create_from_c(char c, size_t count);
static inline b_string *b_string_retain(b_string *str)
{
@@ -36,42 +36,42 @@ static inline void b_string_release(b_string *str)
{
b_release(B_OBJECT(str));
}
extern char *b_string_steal(b_string *str);
extern b_status b_string_reserve(b_string *str, size_t capacity);
BLUE_API char *b_string_steal(b_string *str);
BLUE_API b_status b_string_reserve(b_string *str, size_t capacity);
extern void b_string_append_s(b_string *dest, const b_string *src);
extern void b_string_append_cstr(b_string *dest, const char *src);
extern void b_string_append_cstrf(b_string *dest, const char *format, ...);
extern void b_string_prepend_s(b_string *dest, const b_string *src);
extern void b_string_prepend_cstr(b_string *dest, const char *src);
extern void b_string_prepend_cstrf(b_string *dest, const char *format, ...);
extern void b_string_insert_s(b_string *dest, const b_string *src, size_t at);
extern void b_string_insert_cstr(b_string *dest, const char *src, size_t at);
extern void b_string_insert_cstrn(
BLUE_API void b_string_append_s(b_string *dest, const b_string *src);
BLUE_API void b_string_append_cstr(b_string *dest, const char *src);
BLUE_API void b_string_append_cstrf(b_string *dest, const char *format, ...);
BLUE_API void b_string_prepend_s(b_string *dest, const b_string *src);
BLUE_API void b_string_prepend_cstr(b_string *dest, const char *src);
BLUE_API void b_string_prepend_cstrf(b_string *dest, const char *format, ...);
BLUE_API void b_string_insert_s(b_string *dest, const b_string *src, size_t at);
BLUE_API void b_string_insert_cstr(b_string *dest, const char *src, size_t at);
BLUE_API void b_string_insert_cstrn(
b_string *dest, const char *src, size_t len, size_t at);
extern void b_string_insert_cstrf(
BLUE_API void b_string_insert_cstrf(
b_string *dest, size_t at, const char *format, ...);
extern void b_string_clear(b_string *str);
BLUE_API void b_string_clear(b_string *str);
extern size_t b_string_get_size(const b_string *str, b_strlen_flags flags);
extern size_t b_string_get_capacity(const b_string *str);
BLUE_API size_t b_string_get_size(const b_string *str, b_strlen_flags flags);
BLUE_API size_t b_string_get_capacity(const b_string *str);
extern const char *b_string_ptr(const b_string *str);
BLUE_API const char *b_string_ptr(const b_string *str);
extern void b_strv_builder_begin(b_strv_builder *strv, char *buf, size_t max);
extern void b_strv_builder_begin_dynamic(b_strv_builder *strv);
BLUE_API void b_strv_builder_begin(b_strv_builder *strv, char *buf, size_t max);
BLUE_API void b_strv_builder_begin_dynamic(b_strv_builder *strv);
extern b_status b_strv_builder_add(b_strv_builder *strv, const char *str);
extern b_status b_strv_builder_addf(b_strv_builder *strv, const char *format, ...);
extern b_status b_strv_builder_addv(b_strv_builder *strv, const char **strs);
extern b_status b_strv_builder_addvl(
BLUE_API b_status b_strv_builder_add(b_strv_builder *strv, const char *str);
BLUE_API b_status b_strv_builder_addf(b_strv_builder *strv, const char *format, ...);
BLUE_API b_status b_strv_builder_addv(b_strv_builder *strv, const char **strs);
BLUE_API b_status b_strv_builder_addvl(
b_strv_builder *strv, const char **strs, size_t count);
extern b_status b_strv_builder_add_many(b_strv_builder *strv, ...);
extern char *b_strv_builder_end(b_strv_builder *strv);
BLUE_API b_status b_strv_builder_add_many(b_strv_builder *strv, ...);
BLUE_API char *b_strv_builder_end(b_strv_builder *strv);
extern char *b_strdup(const char *s);
extern size_t b_strlen(const char *s, b_strlen_flags flags);
BLUE_API char *b_strdup(const char *s);
BLUE_API size_t b_strlen(const char *s, b_strlen_flags flags);
extern uint64_t b_cstr_hash(const char *s);
BLUE_API uint64_t b_cstr_hash(const char *s);
#endif

View File

@@ -6,20 +6,20 @@
typedef struct b_stringstream b_stringstream;
extern b_stringstream *b_stringstream_create(void);
extern b_string *b_stringstream_end(b_stringstream *f);
extern void b_stringstream_destroy(b_stringstream *f);
extern const b_string *b_stringstream_str(b_stringstream *f);
extern const char *b_stringstream_cstr(b_stringstream *f);
extern void b_stringstream_clear(b_stringstream *f);
BLUE_API b_stringstream *b_stringstream_create(void);
BLUE_API b_string *b_stringstream_end(b_stringstream *f);
BLUE_API void b_stringstream_destroy(b_stringstream *f);
BLUE_API const b_string *b_stringstream_str(b_stringstream *f);
BLUE_API const char *b_stringstream_cstr(b_stringstream *f);
BLUE_API void b_stringstream_clear(b_stringstream *f);
extern void b_stringstream_push_indent(b_stringstream *f, int indent);
extern void b_stringstream_push_indent_abs(b_stringstream *f, int indent);
extern void b_stringstream_pop_indent(b_stringstream *f);
BLUE_API void b_stringstream_push_indent(b_stringstream *f, int indent);
BLUE_API void b_stringstream_push_indent_abs(b_stringstream *f, int indent);
BLUE_API void b_stringstream_pop_indent(b_stringstream *f);
extern void b_stringstream_add(b_stringstream *f, const char *s);
extern void b_stringstream_addf(b_stringstream *f, const char *format, ...);
extern void b_stringstream_addvf(b_stringstream *f, const char *format, va_list arg);
extern void b_stringstream_add_str(b_stringstream *f, const b_string *str);
BLUE_API void b_stringstream_add(b_stringstream *f, const char *s);
BLUE_API void b_stringstream_addf(b_stringstream *f, const char *format, ...);
BLUE_API void b_stringstream_addvf(b_stringstream *f, const char *format, va_list arg);
BLUE_API void b_stringstream_add_str(b_stringstream *f, const b_string *str);
#endif

View File

@@ -41,7 +41,7 @@ typedef struct b_tree_iterator {
unsigned char _f01;
} b_tree_iterator;
extern b_tree *b_tree_create(void);
BLUE_API b_tree *b_tree_create(void);
static inline b_tree *b_tree_retain(b_tree *tree)
{
@@ -52,21 +52,21 @@ static inline void b_tree_release(b_tree *tree)
b_release(B_OBJECT(tree));
}
extern void b_tree_set_root(b_tree *tree, struct b_tree_node *node);
BLUE_API void b_tree_set_root(b_tree *tree, struct b_tree_node *node);
extern void b_tree_node_add_child(b_tree_node *parent, b_tree_node *child);
extern void b_tree_node_add_sibling(b_tree_node *node, b_tree_node *to_add);
BLUE_API void b_tree_node_add_child(b_tree_node *parent, b_tree_node *child);
BLUE_API void b_tree_node_add_sibling(b_tree_node *node, b_tree_node *to_add);
extern b_tree_node *b_tree_node_get_child(b_tree_node *node, size_t at);
extern b_tree_node *b_tree_node_get_parent(b_tree_node *node);
BLUE_API b_tree_node *b_tree_node_get_child(b_tree_node *node, size_t at);
BLUE_API b_tree_node *b_tree_node_get_parent(b_tree_node *node);
extern int b_tree_iterator_begin(b_tree *tree, b_tree_iterator *it);
extern int b_tree_iterator_begin_at_node(b_tree_node *node, b_tree_iterator *it);
extern int b_tree_iterator_begin_at_node_recursive(
BLUE_API int b_tree_iterator_begin(b_tree *tree, b_tree_iterator *it);
BLUE_API int b_tree_iterator_begin_at_node(b_tree_node *node, b_tree_iterator *it);
BLUE_API int b_tree_iterator_begin_at_node_recursive(
b_tree_node *node, b_tree_iterator *it);
extern bool b_tree_iterator_next(b_tree_iterator *it);
extern b_status b_tree_iterator_erase(b_tree_iterator *it);
extern bool b_tree_iterator_is_valid(const b_tree_iterator *it);
BLUE_API bool b_tree_iterator_next(b_tree_iterator *it);
BLUE_API b_status b_tree_iterator_erase(b_tree_iterator *it);
BLUE_API bool b_tree_iterator_is_valid(const b_tree_iterator *it);
#endif

View File

@@ -45,7 +45,7 @@ typedef struct b_object_type {
void (*t_to_string)(struct b_object *, struct b_stringstream *);
} b_object_type;
extern b_status b_object_type_register(b_object_type *type);
extern struct b_object *b_object_type_instantiate(const b_object_type *type);
BLUE_API b_status b_object_type_register(b_object_type *type);
BLUE_API struct b_object *b_object_type_instantiate(const b_object_type *type);
#endif

View File

@@ -19,17 +19,17 @@ typedef struct b_uuid_bytes {
unsigned char uuid_bytes[B_UUID_NBYTES];
} b_uuid_bytes;
extern b_uuid *b_uuid_create(void);
extern b_uuid *b_uuid_create_from_bytes(
BLUE_API b_uuid *b_uuid_create(void);
BLUE_API b_uuid *b_uuid_create_from_bytes(
unsigned char u00, unsigned char u01, unsigned char u02,
unsigned char u03, unsigned char u04, unsigned char u05,
unsigned char u06, unsigned char u07, unsigned char u08,
unsigned char u09, unsigned char u10, unsigned char u11, unsigned char u12,
unsigned char u13, unsigned char u14, unsigned char u15);
extern b_uuid *b_uuid_create_from_bytev(const unsigned char bytes[B_UUID_NBYTES]);
extern b_uuid *b_uuid_create_from_uuid_bytes(const b_uuid_bytes *bytes);
extern b_uuid *b_uuid_create_from_string(const struct b_string *string);
extern b_uuid *b_uuid_create_from_cstr(const char *s);
BLUE_API b_uuid *b_uuid_create_from_bytev(const unsigned char bytes[B_UUID_NBYTES]);
BLUE_API b_uuid *b_uuid_create_from_uuid_bytes(const b_uuid_bytes *bytes);
BLUE_API b_uuid *b_uuid_create_from_string(const struct b_string *string);
BLUE_API b_uuid *b_uuid_create_from_cstr(const char *s);
static inline b_uuid *b_uuid_retain(b_uuid *uuid)
{
@@ -40,13 +40,13 @@ static inline void b_uuid_release(b_uuid *uuid)
b_release(B_OBJECT(uuid));
}
extern b_status b_uuid_to_string(const b_uuid *uuid, struct b_string *out);
extern b_status b_uuid_to_cstr(const b_uuid *uuid, char out[B_UUID_STRING_MAX]);
extern b_status b_uuid_to_strv_builder(
BLUE_API b_status b_uuid_to_string(const b_uuid *uuid, struct b_string *out);
BLUE_API b_status b_uuid_to_cstr(const b_uuid *uuid, char out[B_UUID_STRING_MAX]);
BLUE_API b_status b_uuid_to_strv_builder(
const b_uuid *uuid, struct b_strv_builder *out);
extern void b_uuid_get_bytes(
BLUE_API void b_uuid_get_bytes(
const b_uuid *uuid, unsigned char bytes[B_UUID_NBYTES]);
extern void b_uuid_get_uuid_bytes(const b_uuid *uuid, b_uuid_bytes *bytes);
extern b_uuid_bytes *b_uuid_ptr(b_uuid *uuid);
BLUE_API void b_uuid_get_uuid_bytes(const b_uuid *uuid, b_uuid_bytes *bytes);
BLUE_API b_uuid_bytes *b_uuid_ptr(b_uuid *uuid);
#endif

View File

@@ -48,7 +48,7 @@ static char *string_ptr(struct b_string *str)
return str->s_data.d_inline;
}
return str->s_data.d_external;
return str->s_data.d_BLUE_APIal;
}
static int string_make_inline(struct b_string *str)
@@ -76,7 +76,7 @@ static int string_resize_large(struct b_string *str, size_t capacity)
}
str->s_max = capacity;
str->s_data.d_external = new_buffer;
str->s_data.d_BLUE_APIal = new_buffer;
return 0;
}
@@ -92,7 +92,7 @@ static int string_make_large(struct b_string *str, size_t capacity)
buffer[str->s_len] = '\0';
str->s_max = capacity;
str->s_data.d_external = buffer;
str->s_data.d_BLUE_APIal = buffer;
return 0;
}
@@ -178,7 +178,7 @@ char *b_string_steal(struct b_string *str)
dest = b_strdup(src);
} else {
dest = src;
str->s_data.d_external = NULL;
str->s_data.d_BLUE_APIal = NULL;
str->s_max = 0;
}
@@ -318,7 +318,7 @@ const char *b_string_ptr(const struct b_string *str)
return str->s_data.d_inline;
}
return str->s_data.d_external;
return str->s_data.d_BLUE_APIal;
}
static void string_release(struct b_object *obj)

View File

@@ -14,7 +14,7 @@ struct b_string {
unsigned int s_max;
union {
char d_inline[STRING_INLINE_CAPACITY + 1];
char *d_external;
char *d_BLUE_APIal;
} s_data;
};

View File

@@ -30,14 +30,14 @@ typedef enum b_print_format {
B_PRINT_ERR,
} b_print_format;
extern b_status b_term_get_dimensions(FILE *fp, unsigned int *w, unsigned int *h);
BLUE_API b_status b_term_get_dimensions(FILE *fp, unsigned int *w, unsigned int *h);
extern b_status b_print(b_print_format format, const char *str, ...);
extern b_status b_print_paragraph(
BLUE_API b_status b_print(b_print_format format, const char *str, ...);
BLUE_API b_status b_print_paragraph(
const char *str, FILE *fp, b_paragraph_format *format);
extern int b_fputs(const char *str, FILE *fp);
extern int b_printf(const char *format, ...);
extern int b_fprintf(FILE *fp, const char *format, ...);
BLUE_API int b_fputs(const char *str, FILE *fp);
BLUE_API int b_printf(const char *format, ...);
BLUE_API int b_fprintf(FILE *fp, const char *format, ...);
#endif

View File

@@ -1,12 +1,13 @@
#ifndef _BLUELIB_PRINT_H_
#define _BLUELIB_PRINT_H_
#include <blue/core/misc.h>
#include <blue/term.h>
#include <stdio.h>
extern int z__b_stream_is_tty(FILE *fp);
extern int z__b_stream_dimensions(FILE *fp, unsigned int *w, unsigned int *h);
extern int z__b_stream_cursorpos(
BLUE_API int z__b_stream_is_tty(FILE *fp);
BLUE_API int z__b_stream_dimensions(FILE *fp, unsigned int *w, unsigned int *h);
BLUE_API int z__b_stream_cursorpos(
FILE *in, FILE *out, unsigned int *x, unsigned int *y);
#endif

54
term/sys/windows/print.c Normal file
View File

@@ -0,0 +1,54 @@
#include <stdio.h>
#include <string.h>
#include <Windows.h>
int z__b_stream_is_tty(FILE *fp)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE console = (HANDLE)_get_osfhandle(fileno(fp));
BOOL status = GetConsoleScreenBufferInfo(console, &csbi);
return status == TRUE ? 1 : 0;
}
int z__b_stream_dimensions(FILE *fp, unsigned int *w, unsigned int *h)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE console = (HANDLE)_get_osfhandle(fileno(fp));
BOOL status = GetConsoleScreenBufferInfo(console, &csbi);
if (status == FALSE) {
return -1;
}
if (w) {
*w = csbi.dwMaximumWindowSize.X;
}
if (h) {
*h = csbi.dwMaximumWindowSize.Y;
}
return 0;
}
int z__b_stream_cursorpos(FILE *in, FILE *out, unsigned int *x, unsigned int *y)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE console = (HANDLE)_get_osfhandle(fileno(in));
BOOL status = GetConsoleScreenBufferInfo(console, &csbi);
if (status == FALSE) {
return -1;
}
if (x) {
*x = csbi.dwCursorPosition.X;
}
if (y) {
*y = csbi.dwCursorPosition.Y;
}
return 0;
}