diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2025-04-16 21:23:54 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2025-04-16 21:23:54 +0200 |
commit | a24258441ecf47528267500770812f432fa701de (patch) | |
tree | a9e25bf501be2e51ba2a31472209984f4080b22d | |
parent | 7ef9023e88a174998b4542a52a54d31f8a04af20 (diff) | |
download | reduced_system_layer-a24258441ecf47528267500770812f432fa701de.zip |
Update logging
-rw-r--r-- | index.htm | 23 | ||||
-rwxr-xr-x | reduced_system_layer.c | 258 |
2 files changed, 163 insertions, 118 deletions
@@ -46,11 +46,22 @@ fd_seek : () => { throw new Error("Unexpected fd_seek call"); }, }, env : { - log_error_impl : (file_len, file, line, func_len, func, text_len, text) => { - let s_file = String.fromCharCode.apply(null, new Uint8Array(this.memory_buffer, file, file_len)); - let s_func = String.fromCharCode.apply(null, new Uint8Array(this.memory_buffer, func, func_len)); - let s_text = String.fromCharCode.apply(null, new Uint8Array(this.memory_buffer, text, text_len)); - console.error(`${s_file}:${line}, ${s_func}: ${s_text}`); + log_impl : (mode, file_len, file, line, func_len, func, text_len, text) => { + if (text_len == 0) { + let s_file = String.fromCharCode.apply(null, new Uint8Array(this.memory_buffer, file, file_len)); + let s_func = String.fromCharCode.apply(null, new Uint8Array(this.memory_buffer, func, func_len)); + + console.log(`${s_file}:${line}, ${s_func}`); + } else { + let s_file = String.fromCharCode.apply(null, new Uint8Array(this.memory_buffer, file, file_len)); + let s_func = String.fromCharCode.apply(null, new Uint8Array(this.memory_buffer, func, func_len)); + let s_text = String.fromCharCode.apply(null, new Uint8Array(this.memory_buffer, text, text_len)); + + if (mode == 0) + console.log(`${s_file}:${line}, ${s_func}: ${s_text}`); + else + console.error(`${s_file}:${line}, ${s_func}: ${s_text}`); + } }, write_clipboard_text_impl : (size, text) => { let text_buffer = new ArrayBuffer(size); @@ -290,7 +301,7 @@ wasm, { env : { - log_error_impl : () => {}, + log_impl : () => {}, write_clipboard_impl : () => {}, current_utc_time_in_milliseconds : () => {}, diff --git a/reduced_system_layer.c b/reduced_system_layer.c index ace2963..794f511 100755 --- a/reduced_system_layer.c +++ b/reduced_system_layer.c @@ -814,14 +814,38 @@ static i64 max2_i64_(i64 x, i64 y) { // // ================================================================ -// TODO: Use print formatting after we implement it. +// TODO: +// - Use print formatting after we implement it. +// - Print time. + #if defined(__wasm__) -void log_error_impl(i32 file_len, c8 const *file, i32 line, i32 func_len, c8 const *func, i32 text_len, c8 const *text); -#define LOG_ERROR(text_, ...) \ +void log_impl(i32 mode, i32 file_len, c8 const *file, i32 line, i32 func_len, c8 const *func, i32 text_len, c8 const *text); +#define LOG_trace() \ + do { \ + log_impl( \ + 0, \ + sizeof(__FILE__) - 1, __FILE__, \ + __LINE__, \ + sizeof(__func__) - 1, __func__, \ + 0, NULL); \ + } while (0) +#define LOG_print(text_, ...) \ + do { \ + i32 len = 0; \ + while ((text_)[len] != '\0') ++len; \ + log_impl( \ + 0, \ + sizeof(__FILE__) - 1, __FILE__, \ + __LINE__, \ + sizeof(__func__) - 1, __func__, \ + len, text_); \ + } while (0) +#define LOG_error(text_, ...) \ do { \ i32 len = 0; \ while ((text_)[len] != '\0') ++len; \ - log_error_impl( \ + log_impl( \ + 1, \ sizeof(__FILE__) - 1, __FILE__, \ __LINE__, \ sizeof(__func__) - 1, __func__, \ @@ -829,7 +853,17 @@ void log_error_impl(i32 file_len, c8 const *file, i32 line, i32 func_len, c8 con } while (0) #else #include <stdio.h> -#define LOG_ERROR(...) \ +#define LOG_trace() \ + do { \ + fprintf(stdout, "%s:%d, %s\n", __FILE__, __LINE__, __func__); \ + } while (0) +#define LOG_print(...) \ + do { \ + fprintf(stdout, "%s:%d, %s: ", __FILE__, __LINE__, __func__); \ + fprintf(stdout, __VA_ARGS__); \ + fprintf(stdout, "\n"); \ + } while (0) +#define LOG_error(...) \ do { \ fprintf(stderr, "%s:%d, %s: ", __FILE__, __LINE__, __func__); \ fprintf(stderr, __VA_ARGS__); \ @@ -1298,12 +1332,12 @@ static i64 memory_buffer_occupied_len_(i64 buffer_size) { static void *memory_buffer_allocate_from_(i64 memory_buffer_size, u8 *memory_buffer, i64 size, i64 alignment, i64 previous_size, void *previous_data) { if (memory_buffer_size <= 0) { - LOG_ERROR("Invalid memory buffer size."); + LOG_error("Invalid memory buffer size."); return NULL; } if (memory_buffer == NULL) { - LOG_ERROR("Invalid memory buffer."); + LOG_error("Invalid memory buffer."); return NULL; } @@ -1318,27 +1352,27 @@ static void *memory_buffer_allocate_from_(i64 memory_buffer_size, u8 *memory_buf u64 *occupied = (u64 *) memory_buffer; if (memory_buffer_size <= occupied_len_bytes) { - LOG_ERROR("Memory buffer too small."); + LOG_error("Memory buffer too small."); goto _finish; } if (alignment <= 0) { - LOG_ERROR("Invalid alignment: %lld", alignment); + LOG_error("Invalid alignment: %lld", alignment); goto _finish; } if (size < 0) { - LOG_ERROR("Invalid size: %lld", size); + LOG_error("Invalid size: %lld", size); goto _finish; } if (previous_size < 0) { - LOG_ERROR("Invalid previous size: %lld", previous_size); + LOG_error("Invalid previous size: %lld", previous_size); goto _finish; } if (previous_size > 0 && previous_data == NULL) { - LOG_ERROR("Invalid previous data."); + LOG_error("Invalid previous data."); goto _finish; } @@ -1394,7 +1428,7 @@ static void *memory_buffer_allocate_from_(i64 memory_buffer_size, u8 *memory_buf // Check if out of memory dst = data + chunk * MEMORY_CHUNK_SIZE; if (dst + size > memory_buffer + memory_buffer_size) { - LOG_ERROR("Out of memory: %lld bytes", size - previous_size); + LOG_error("Out of memory: %lld bytes", size - previous_size); return NULL; } @@ -1445,7 +1479,7 @@ void *memory_buffer_allocate(i64 size, i64 alignment, i64 previous_size, void *p void resize_dynamic_array_exact(i64 *num, void **data, i64 element_size, i64 new_num) { if (num == NULL || data == NULL) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -1474,7 +1508,7 @@ void resize_dynamic_array_exact(i64 *num, void **data, i64 element_size, i64 new void resize_dynamic_array_capacity(i64 *num, i64 *capacity, void **data, i64 element_size, i64 new_num) { if (num == NULL || capacity == NULL || data == NULL) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -1513,7 +1547,7 @@ void PROFILER_init(u32 slot, c8 *name) { resize_dynamic_array_exact(&_profiler_num_slots, (void **) &_profiler_slots, sizeof *_profiler_slots, (i64) (u64) slot + 1); if ((i64) (u64) slot >= _profiler_num_slots) { - LOG_ERROR("Invalid slot: %d", (i32) slot); + LOG_error("Invalid slot: %d", (i32) slot); return; } @@ -1528,12 +1562,12 @@ void PROFILER_begin(u32 slot) { return; if ((i64) (u64) slot >= _profiler_num_slots) { - LOG_ERROR("Invalid slot: %d", (i32) slot); + LOG_error("Invalid slot: %d", (i32) slot); return; } if (_profiler_slots[slot].count < 0) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -1551,7 +1585,7 @@ void PROFILER_begin(u32 slot) { static void normalize_time_(i64 *sec, i64 *nsec) { if (sec == NULL || nsec == NULL) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -1573,7 +1607,7 @@ void PROFILER_end(u32 slot) { return; if (_profiler_slots[slot].count <= 0) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -1708,7 +1742,7 @@ static b8 pixel_size_update_(i64 real_width, i64 real_height) { resize_dynamic_array_exact(&g_platform.num_pixels, (void **) &g_platform.pixels, sizeof *g_platform.pixels, width * height); if (g_platform.num_pixels < width * height) - LOG_ERROR("Failed to allocate %lld x %lld pixel buffer.", width, height); + LOG_error("Failed to allocate %lld x %lld pixel buffer.", width, height); height = width <= 0 ? 0 : g_platform.num_pixels / width; if (g_platform.frame_width != width || g_platform.frame_height != height) { @@ -1722,11 +1756,11 @@ static b8 pixel_size_update_(i64 real_width, i64 real_height) { resize_dynamic_array_exact(&_internal_pixels_len, (void **) &_internal_pixels, sizeof *_internal_pixels, internal_width * internal_height); if (_internal_pixels_len < internal_width * internal_height) - LOG_ERROR("Failed to allocate %lld x %lld internal pixel buffer.", internal_width, internal_height); + LOG_error("Failed to allocate %lld x %lld internal pixel buffer.", internal_width, internal_height); resize_dynamic_array_exact(&_internal_row_len, (void **) &_internal_row, sizeof *_internal_row, internal_width); if (_internal_row_len < internal_width) - LOG_ERROR("Failed to allocate %lld internal immediate pixel buffer.", internal_width); + LOG_error("Failed to allocate %lld internal immediate pixel buffer.", internal_width); _internal_width = real_width; _internal_height = real_width <= 0 ? 0 : min2_i32_(_internal_pixels_len / real_width, real_height); @@ -1738,7 +1772,7 @@ static void convert_pixels_for_window_(void) { u32 aa_scale = g_platform.antialiasing_scale; if (aa_scale == 0 || aa_scale > 1024) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -1751,17 +1785,17 @@ static void convert_pixels_for_window_(void) { u32 src_width = g_platform.frame_width; if (g_platform.num_pixels < src_width * g_platform.frame_height) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } if (_internal_pixels_len < dst_width * dst_height) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } if (_internal_row_len < dst_width) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -1809,12 +1843,12 @@ static void convert_pixels_for_window_(void) { i64 dst_len = dst_width * dst_height; if (_internal_pixels_len < src_len) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } if (_internal_pixels_len < dst_len) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -1919,7 +1953,7 @@ static void drop_files_clean_(void) { static void drop_files_set_num_(i64 num) { if (num <= g_platform.num_drop_files) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -1928,12 +1962,12 @@ static void drop_files_set_num_(i64 num) { static void drop_files_set_name_(i64 index, i64 name_len, c8 *name) { if (g_platform.drop_files == NULL) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } if (index < 0 || index >= g_platform.num_drop_files) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -1946,12 +1980,12 @@ static void drop_files_set_name_(i64 index, i64 name_len, c8 *name) { static void drop_files_set_data_(i64 index, i64 data_size) { if (g_platform.drop_files == NULL) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } if (index < 0 || index >= g_platform.num_drop_files) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -2000,7 +2034,7 @@ static Dynamic_Libraries_ _dynamic_libraries = {0}; void dynamic_library_open(u16 slot, c8 *name) { if (name == NULL) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return; } @@ -2008,7 +2042,7 @@ void dynamic_library_open(u16 slot, c8 *name) { resize_dynamic_array_exact(&_dynamic_libraries.num_slots, (void **) &_dynamic_libraries.slots, sizeof *_dynamic_libraries.slots, (i64) slot + 1); if ((i64) (u64) slot >= _dynamic_libraries.num_slots) { - LOG_ERROR("Invalid slot: %d", (i32) slot); + LOG_error("Invalid slot: %d", (i32) slot); return; } @@ -2020,8 +2054,8 @@ void dynamic_library_open(u16 slot, c8 *name) { void *h = dlopen(name, RTLD_LAZY); if (h == NULL) { - LOG_ERROR("Failed to open: %s", name); - LOG_ERROR("%s", dlerror()); + LOG_error("Failed to open: %s", name); + LOG_error("%s", dlerror()); return; } @@ -2030,25 +2064,25 @@ void dynamic_library_open(u16 slot, c8 *name) { void *dynamic_library_get_proc_address(u16 slot, c8 *proc) { if ((i64) (u64) slot >= _dynamic_libraries.num_slots) { - LOG_ERROR("Invalid slot: %d", (i32) slot); + LOG_error("Invalid slot: %d", (i32) slot); return NULL; } if (proc == NULL) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); return NULL; } if (_dynamic_libraries.slots[slot].handle == NULL) { - LOG_ERROR("Slot is closed: %d", (i32) slot); + LOG_error("Slot is closed: %d", (i32) slot); return NULL; } void *proc_address = dlsym(_dynamic_libraries.slots[slot].handle, proc); if (proc_address == NULL) { - LOG_ERROR("Failed to get: %s", proc); - LOG_ERROR("%s", dlerror()); + LOG_error("Failed to get: %s", proc); + LOG_error("%s", dlerror()); } return proc_address; @@ -2067,14 +2101,14 @@ void dynamic_library_open(u16 slot, c8 *name) { (void) slot; (void) name; - LOG_ERROR("Dynamic library not found: %s", name); + LOG_error("Dynamic library not found: %s", name); } void *dynamic_library_get_proc_address(u16 slot, c8 *proc) { (void) slot; (void) proc; - LOG_ERROR("Proc address not found: %s", proc); + LOG_error("Proc address not found: %s", proc); return NULL; } #endif // defined(__wasm__) @@ -2181,7 +2215,7 @@ b8 network_open(u16 slot, Network_Address address, u16 *local_port) { network_init_(slot); if ((i64) (u64) slot >= _num_sockets) { - LOG_ERROR("Invalid slot: %d", (i32) slot); + LOG_error("Invalid slot: %d", (i32) slot); return 0; } @@ -2215,7 +2249,7 @@ b8 network_open(u16 slot, Network_Address address, u16 *local_port) { _sockets[slot].socket = socket(address.protocol == IPv4_UDP ? AF_INET : AF_INET6, SOCK_DGRAM, IPPROTO_UDP); if (_sockets[slot].socket == -1) { - LOG_ERROR("socket failed (errno %d).", errno); + LOG_error("socket failed (errno %d).", errno); return 0; } @@ -2232,14 +2266,14 @@ b8 network_open(u16 slot, Network_Address address, u16 *local_port) { if (bind(_sockets[slot].socket, p, p_len) == -1) { close(_sockets[slot].socket); - LOG_ERROR("bind failed (errno %d).", errno); + LOG_error("bind failed (errno %d).", errno); return 0; } if (getsockname(_sockets[slot].socket, p, &(socklen_t) {p_len}) == -1) { close(_sockets[slot].socket); - LOG_ERROR("getsockname failed (errno %d).", errno); + LOG_error("getsockname failed (errno %d).", errno); return 0; } @@ -2260,7 +2294,7 @@ b8 network_open(u16 slot, Network_Address address, u16 *local_port) { i64 network_recv(u16 slot, Network_Address address, i64 size, u8 *data, u16 *local_port, Network_Address *remote_address) { if (address.protocol != IPv4_UDP && address.protocol != IPv6_UDP) { - LOG_ERROR("Invalid address protocol: %d", (i32) (u32) address.protocol); + LOG_error("Invalid address protocol: %d", (i32) (u32) address.protocol); return -1; } @@ -2296,7 +2330,7 @@ i64 network_recv(u16 slot, Network_Address address, i64 size, u8 *data, u16 *loc if (errno == EAGAIN || errno == EWOULDBLOCK) return 0; - LOG_ERROR("recvfrom failed (errno %d).", errno); + LOG_error("recvfrom failed (errno %d).", errno); return -1; } @@ -2318,7 +2352,7 @@ i64 network_recv(u16 slot, Network_Address address, i64 size, u8 *data, u16 *loc i64 network_send(u16 slot, Network_Address address, i64 size, u8 *data, u16 *local_port) { if (address.protocol != IPv4_UDP && address.protocol != IPv6_UDP) { - LOG_ERROR("Invalid address protocol: %d", (i32) (u32) address.protocol); + LOG_error("Invalid address protocol: %d", (i32) (u32) address.protocol); return -1; } @@ -2365,7 +2399,7 @@ i64 network_send(u16 slot, Network_Address address, i64 size, u8 *data, u16 *loc if (errno == EAGAIN || errno == EWOULDBLOCK) return 0; - LOG_ERROR("sendto failed (errno %d).", errno); + LOG_error("sendto failed (errno %d).", errno); return -1; } @@ -2395,7 +2429,7 @@ static void sound_init_(void) { s = snd_pcm_open(&_sound_out, "default", SND_PCM_STREAM_PLAYBACK, 0); if (s < 0) { - LOG_ERROR("snd_pcm_open failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_open failed: %s", snd_strerror(s)); return; } @@ -2406,45 +2440,45 @@ static void sound_init_(void) { s = snd_pcm_hw_params_any(_sound_out, hw_params); if (s < 0) - LOG_ERROR("snd_pcm_hw_params_any failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_hw_params_any failed: %s", snd_strerror(s)); s = snd_pcm_hw_params_set_access(_sound_out, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); if (s < 0) - LOG_ERROR("snd_pcm_hw_params_set_access failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_hw_params_set_access failed: %s", snd_strerror(s)); s = snd_pcm_hw_params_set_format(_sound_out, hw_params, SND_PCM_FORMAT_FLOAT_LE); if (s < 0) - LOG_ERROR("snd_pcm_hw_params_set_format failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_hw_params_set_format failed: %s", snd_strerror(s)); s = snd_pcm_hw_params_set_rate(_sound_out, hw_params, PRIMARY_SOUND_SAMPLE_RATE, 0); if (s < 0) - LOG_ERROR("snd_pcm_hw_params_set_rate failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_hw_params_set_rate failed: %s", snd_strerror(s)); s = snd_pcm_hw_params_set_channels(_sound_out, hw_params, NUM_PRIMARY_SOUND_CHANNELS); if (s < 0) - LOG_ERROR("snd_pcm_hw_params_set_channels failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_hw_params_set_channels failed: %s", snd_strerror(s)); s = snd_pcm_hw_params(_sound_out, hw_params); if (s < 0) - LOG_ERROR("snd_pcm_hw_params failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_hw_params failed: %s", snd_strerror(s)); snd_pcm_sw_params_alloca(&sw_params); s = snd_pcm_sw_params_current(_sound_out, sw_params); if (s < 0) - LOG_ERROR("snd_pcm_sw_params_current failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_sw_params_current failed: %s", snd_strerror(s)); s = snd_pcm_sw_params_set_avail_min(_sound_out, sw_params, PRIMARY_SOUND_AVAIL_MIN); if (s < 0) - LOG_ERROR("snd_pcm_sw_params_set_avail_min failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_sw_params_set_avail_min failed: %s", snd_strerror(s)); s = snd_pcm_sw_params(_sound_out, sw_params); if (s < 0) - LOG_ERROR("snd_pcm_sw_params failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_sw_params failed: %s", snd_strerror(s)); s = snd_pcm_prepare(_sound_out); if (s < 0) - LOG_ERROR("snd_pcm_prepare failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_prepare failed: %s", snd_strerror(s)); _sound_ready = 1; } @@ -2457,11 +2491,11 @@ static void sound_cleanup_(void) { s = snd_pcm_nonblock(_sound_out, 0); if (s < 0) - LOG_ERROR("snd_pcm_nonblock failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_nonblock failed: %s", snd_strerror(s)); s = snd_pcm_drain(_sound_out); if (s < 0) - LOG_ERROR("snd_pcm_drain failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_drain failed: %s", snd_strerror(s)); // FIXME: Memory leaks, seems to be an ALSA bug. // snd_pcm_close(_sound_out); @@ -2477,7 +2511,7 @@ void handle_primary_sound(void) { i64 num_frames = g_platform.num_sound_samples_elapsed * NUM_PRIMARY_SOUND_CHANNELS; if (num_frames > MAX_NUM_PRIMARY_SOUND_FRAMES) { - LOG_ERROR("Sound buffer overflow."); + LOG_error("Sound buffer overflow."); num_frames %= MAX_NUM_PRIMARY_SOUND_FRAMES; } @@ -2486,7 +2520,7 @@ void handle_primary_sound(void) { if (num_frames <= MAX_NUM_PRIMARY_SOUND_FRAMES - _sound_position) { s = snd_pcm_writei(_sound_out, _sound_ring + _sound_position, num_frames / NUM_PRIMARY_SOUND_CHANNELS); if (s < 0) - LOG_ERROR("snd_pcm_writei failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_writei failed: %s", snd_strerror(s)); mem_set_(_sound_ring + _sound_position, 0, num_frames * sizeof *_sound_ring); } else { @@ -2495,11 +2529,11 @@ void handle_primary_sound(void) { s = snd_pcm_writei(_sound_out, _sound_ring + _sound_position, part_one / NUM_PRIMARY_SOUND_CHANNELS); if (s < 0) - LOG_ERROR("snd_pcm_writei failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_writei failed: %s", snd_strerror(s)); s = snd_pcm_writei(_sound_out, _sound_ring, part_two / NUM_PRIMARY_SOUND_CHANNELS); if (s < 0) - LOG_ERROR("snd_pcm_writei failed: %s", snd_strerror(s)); + LOG_error("snd_pcm_writei failed: %s", snd_strerror(s)); mem_set_(_sound_ring + _sound_position, 0, part_one * sizeof *_sound_ring); mem_set_(_sound_ring, 0, part_two * sizeof *_sound_ring); @@ -2510,7 +2544,7 @@ void handle_primary_sound(void) { void queue_primary_sound(i64 delay_in_samples, i64 num_samples, f32 *frames) { if (num_samples < 0) - LOG_ERROR("Invalid num samples %lld.", num_samples); + LOG_error("Invalid num samples %lld.", num_samples); if (frames == NULL) return; @@ -2526,7 +2560,7 @@ void queue_primary_sound(i64 delay_in_samples, i64 num_samples, f32 *frames) { i64 num_frames = num_samples * NUM_PRIMARY_SOUND_CHANNELS; if (num_frames > MAX_NUM_PRIMARY_SOUND_FRAMES) { - LOG_ERROR("Sound buffer overflow."); + LOG_error("Sound buffer overflow."); return; } @@ -2753,7 +2787,7 @@ static i32 anonymous_shm_open(void) { break; } - LOG_ERROR("shm_open failed.\n"); + LOG_error("shm_open failed.\n"); return -1; } @@ -2766,7 +2800,7 @@ static i32 create_shm_file(off_t size) { if (ftruncate(fd, size) < 0) { close(fd); - LOG_ERROR("ftruncate failed.\n"); + LOG_error("ftruncate failed.\n"); return -1; } @@ -2785,7 +2819,7 @@ static WL_Buffer_ *create_buffer(struct wl_shm *shm, enum wl_shm_format format, if (data == MAP_FAILED) { close(fd); - LOG_ERROR("mmap failed.\n"); + LOG_error("mmap failed.\n"); return NULL; } @@ -2798,7 +2832,7 @@ static WL_Buffer_ *create_buffer(struct wl_shm *shm, enum wl_shm_format format, WL_Buffer_ *buffer = calloc(1, sizeof(WL_Buffer_)); if (buffer == NULL) { - LOG_ERROR("calloc failed.\n"); + LOG_error("calloc failed.\n"); return NULL; } @@ -2878,7 +2912,7 @@ static void screencopy_frame_handle_failed( WL_Output_ *output = data; output->state->ok = 0; - LOG_ERROR("Screenshot copy failed."); + LOG_error("Screenshot copy failed."); } static struct zwlr_screencopy_frame_v1_listener screencopy_frame_listener = { @@ -2957,7 +2991,7 @@ b8 wayland_screenshot_(i64 *width, i64 *height, i64 max_num_pixels, vec4_f32 *pi state.display = wl_display_connect(NULL); if (state.display == NULL) { - LOG_ERROR("wl_display_connect failed."); + LOG_error("wl_display_connect failed."); goto _finalize; } @@ -2970,17 +3004,17 @@ b8 wayland_screenshot_(i64 *width, i64 *height, i64 max_num_pixels, vec4_f32 *pi wl_display_roundtrip(state.display); if (state.shm == NULL) { - LOG_ERROR("Compositor does not support wl_shm."); + LOG_error("Compositor does not support wl_shm."); goto _finalize; } if (wl_list_empty(&state.outputs)) { - LOG_ERROR("No wl_output."); + LOG_error("No wl_output."); goto _finalize; } if (state.screencopy_manager == NULL) { - LOG_ERROR("Compositor does not support wlr-screencopy-unstable-v1."); + LOG_error("Compositor does not support wlr-screencopy-unstable-v1."); goto _finalize; } @@ -3003,7 +3037,7 @@ b8 wayland_screenshot_(i64 *width, i64 *height, i64 max_num_pixels, vec4_f32 *pi } if (n_pending == 0) { - LOG_ERROR("Supplied geometry did not intersect with any outputs."); + LOG_error("Supplied geometry did not intersect with any outputs."); goto _finalize; } @@ -3017,7 +3051,7 @@ b8 wayland_screenshot_(i64 *width, i64 *height, i64 max_num_pixels, vec4_f32 *pi } if (!done) { - LOG_ERROR("Failed to screenshoot all outputs."); + LOG_error("Failed to screenshoot all outputs."); goto _finalize; } @@ -3052,7 +3086,7 @@ b8 wayland_screenshot_(i64 *width, i64 *height, i64 max_num_pixels, vec4_f32 *pi if (!check_format_(buffer->format)) continue; if (*width != buffer->width) { - LOG_ERROR("Sanity"); + LOG_error("Sanity"); break; } @@ -3164,7 +3198,7 @@ static b8 sub_str_eq_(c8 *a, c8 *b, i64 len) { static i32 x11_error_handler_(Display *display, XErrorEvent *event) { XGetErrorText(display, event->error_code, _error_buffer, sizeof _error_buffer - 1); - LOG_ERROR("%s", _error_buffer); + LOG_error("%s", _error_buffer); return 0; } @@ -3204,7 +3238,7 @@ void init_main_window(void) { _display = XOpenDisplay(NULL); if (_display == NULL) { - LOG_ERROR("XOpenDisplay failed."); + LOG_error("XOpenDisplay failed."); return; } @@ -3319,7 +3353,7 @@ void init_main_window(void) { _gc = DefaultGC(_display, screen); if (_gc == NULL) { - LOG_ERROR("DefaultGC failed."); + LOG_error("DefaultGC failed."); return; } @@ -3350,21 +3384,21 @@ void init_main_window(void) { _window = XCreateWindow(_display, _root_window, x, y, g_platform.frame_width, g_platform.frame_height, 0, depth, InputOutput, visual, CWEventMask, &(XSetWindowAttributes) { .event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | VisibilityChangeMask | FocusChangeMask | StructureNotifyMask | SubstructureNotifyMask, }); if (_window == 0) { - LOG_ERROR("XCreateWindow failed."); + LOG_error("XCreateWindow failed."); return; } _im = XOpenIM(_display, NULL, NULL, NULL); if (_im == NULL) { - LOG_ERROR("XOpenIM failed."); + LOG_error("XOpenIM failed."); return; } _ic = XCreateIC(_im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, _window, NULL); if (_ic == NULL) { - LOG_ERROR("XCreateIC failed."); + LOG_error("XCreateIC failed."); return; } @@ -3657,13 +3691,13 @@ i32 handle_main_window_events(void) { ); } else if (ev.xselectionrequest.target == _image_bmp) { // TODO - LOG_ERROR("Send BMP image - not implemented."); + LOG_error("Send BMP image - not implemented."); } else if (ev.xselectionrequest.target == _image_ppm) { // TODO - LOG_ERROR("Send PPM image - not implemented."); + LOG_error("Send PPM image - not implemented."); } else if (ev.xselectionrequest.target == _audio_wav) { // TODO - LOG_ERROR("Send WAV audio - not implemented."); + LOG_error("Send WAV audio - not implemented."); } } @@ -3702,7 +3736,7 @@ i32 handle_main_window_events(void) { ); if (len == 0) { - LOG_ERROR("Unable to retrieve drag and drop info."); + LOG_error("Unable to retrieve drag and drop info."); break; } @@ -3810,19 +3844,19 @@ i32 handle_main_window_events(void) { } else if (ev.xselection.target == _image_bmp) { if (g_platform.enable_clipboard_image) { // TODO - LOG_ERROR("Receive BMP image - not implemented."); + LOG_error("Receive BMP image - not implemented."); } _requested_clipboard = 0; } else if (ev.xselection.target == _image_ppm) { if (g_platform.enable_clipboard_image) { // TODO - LOG_ERROR("Receive PPM image - not implemented."); + LOG_error("Receive PPM image - not implemented."); } _requested_clipboard = 0; } else if (ev.xselection.target == _audio_wav) { if (g_platform.enable_clipboard_sound) { // TODO - LOG_ERROR("Receive WAV audio - not implemented."); + LOG_error("Receive WAV audio - not implemented."); } _requested_clipboard = 0; } @@ -3908,13 +3942,13 @@ i32 handle_main_window_events(void) { XFlush(_display); } else if (ev.xclient.message_type == _dnd_drop) { if (g_platform.drop_files == NULL) - LOG_ERROR("No drop files."); + LOG_error("No drop files."); else for (i64 i = 0; i < g_platform.num_drop_files; ++i) { FILE *f = fopen(g_platform.drop_files[i].name, "rb"); if (f == NULL) - LOG_ERROR("Unable to open: %s", g_platform.drop_files[i].name); + LOG_error("Unable to open: %s", g_platform.drop_files[i].name); i64 size = 0; @@ -3923,7 +3957,7 @@ i32 handle_main_window_events(void) { if (fstat(fileno(f), &info) == 0 && S_ISREG(info.st_mode)) size = (i64) info.st_size; else - LOG_ERROR("Unable to get the file info: %s", g_platform.drop_files[i].name); + LOG_error("Unable to get the file info: %s", g_platform.drop_files[i].name); } if (size > 0) { @@ -3933,7 +3967,7 @@ i32 handle_main_window_events(void) { fclose(f); if (num != g_platform.drop_files[i].data_size) { - LOG_ERROR("Unable to read: %s", g_platform.drop_files[i].name); + LOG_error("Unable to read: %s", g_platform.drop_files[i].name); drop_files_set_data_(i, 0); } } @@ -4045,7 +4079,7 @@ b8 x11_get_root_(void) { b8 x11_screenshot_(i64 *width, i64 *height, i64 max_num_pixels, vec4_f32 *pixels) { if (_display == NULL) { - LOG_ERROR("No display."); + LOG_error("No display."); return 0; } @@ -4058,7 +4092,7 @@ b8 x11_screenshot_(i64 *width, i64 *height, i64 max_num_pixels, vec4_f32 *pixels XImage *image = XGetImage(_display, _root_window, 0, 0, display_width, display_height, AllPlanes, ZPixmap); if (image == NULL) { - LOG_ERROR("XGetImage failed."); + LOG_error("XGetImage failed."); return 0; } @@ -4094,7 +4128,7 @@ b8 x11_screenshot_(i64 *width, i64 *height, i64 max_num_pixels, vec4_f32 *pixels #if defined(__linux__) && (ENABLE_X11 || ENABLE_WAYLAND) void take_screenshot(i64 *width, i64 *height, i64 max_num_pixels, vec4_f32 *pixels) { if (width == NULL || height == NULL) { - LOG_ERROR("Invalid arguments."); + LOG_error("Invalid arguments."); return; } @@ -4269,17 +4303,17 @@ void shutdown_all_systems(void) { } b8 network_open(u16 slot, Network_Address address, u16 *local_port) { - LOG_ERROR("Web sockets are not implemented."); + LOG_error("Web sockets are not implemented."); return 0; } i64 network_recv(u16 slot, Network_Address address, i64 size, u8 *data, u16 *local_port, Network_Address *remote_address) { - LOG_ERROR("Web sockets are not implemented."); + LOG_error("Web sockets are not implemented."); return 0; } i64 network_send(u16 slot, Network_Address address, i64 size, u8 *data, u16 *local_port) { - LOG_ERROR("Web sockets are not implemented."); + LOG_error("Web sockets are not implemented."); return 0; } @@ -4384,7 +4418,7 @@ void write_clipboard_text(i64 size, c8 *data) { void take_screenshot(i64 max_num_pixels, i64 *width, i64 *height, vec4_f32 *pixels) { if (width == NULL || height == NULL) { - LOG_ERROR("Invalid arguments."); + LOG_error("Invalid arguments."); return; } @@ -4412,7 +4446,7 @@ void queue_primary_sound(i64 delay_in_samples, i64 num_samples, f32 *frames) { i64 num_frames = num_samples * NUM_PRIMARY_SOUND_CHANNELS; if (num_frames > MAX_NUM_PRIMARY_SOUND_FRAMES) { - LOG_ERROR("Sound buffer overflow."); + LOG_error("Sound buffer overflow."); return; } @@ -4585,7 +4619,7 @@ __attribute__((export_name("js_drop"))) i32 js_drop(i32 name_len, i32 data_size) drop_files_set_name_(n, 0, NULL); drop_files_set_data_(n, 0); drop_files_set_num_(n); - LOG_ERROR("File too big."); + LOG_error("File too big."); return 0; } @@ -4617,11 +4651,11 @@ __attribute__((export_name("js_drop_data"))) void *js_drop_data(void) { #if !defined(__linux__) || (!ENABLE_X11 && !ENABLE_WAYLAND) void init_main_window(void) { - LOG_ERROR("Not implemented."); + LOG_error("Not implemented."); } void update_and_render_frame(void) { - LOG_ERROR("Not implemented."); + LOG_error("Not implemented."); } void shutdown_all_systems(void) { |