From cce71ee7d1568534293ff2fc377e404b6b0f5335 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 20 Sep 2024 13:54:04 +0200 Subject: [PATCH] misc: adopt M_ prefix for private functions --- src/benchmark.c | 4 +- src/config/config_file.c | 42 ++-- src/engine/audio.c | 7 +- src/engine/audio_sample.c | 44 ++--- src/engine/audio_stream.c | 48 +++-- src/engine/image.c | 37 ++-- src/filesystem.c | 28 +-- src/game/console/commands/config.c | 38 ++-- src/game/console/commands/heal.c | 6 +- src/game/console/commands/pos.c | 6 +- src/game/console/commands/set_health.c | 6 +- src/gfx/3d/3d_renderer.c | 14 +- src/gfx/3d/vertex_stream.c | 22 +-- src/gfx/context.c | 15 +- src/gfx/renderers/fbo_renderer.c | 44 ++--- src/gfx/renderers/legacy_renderer.c | 6 +- src/json/bson_parse.c | 182 +++++++++-------- src/json/bson_write.c | 258 ++++++++++++------------- src/json/json_parse.c | 77 ++++---- src/json/json_write.c | 139 ++++++------- src/log_linux.c | 20 +- src/log_windows.c | 18 +- src/vector.c | 24 +-- 23 files changed, 520 insertions(+), 565 deletions(-) diff --git a/src/benchmark.c b/src/benchmark.c index 5423433..c29ca5a 100644 --- a/src/benchmark.c +++ b/src/benchmark.c @@ -5,7 +5,7 @@ #include -static void Benchmark_Log( +static void M_Log( BENCHMARK *const b, const char *file, int32_t line, const char *func, Uint64 current, const char *message) { @@ -49,7 +49,7 @@ void Benchmark_Tick_Impl( const char *const func, const char *const message) { const Uint64 current = SDL_GetPerformanceCounter(); - Benchmark_Log(b, file, line, func, current, message); + M_Log(b, file, line, func, current, message); b->last = current; } diff --git a/src/config/config_file.c b/src/config/config_file.c index eac1dec..0405c21 100644 --- a/src/config/config_file.c +++ b/src/config/config_file.c @@ -6,13 +6,12 @@ #include -static bool Config_ReadFromJSON( +static bool M_ReadFromJSON( const char *json, void (*load)(struct json_object_s *root_obj)); -static char *Config_WriteToJSON(void (*dump)(struct json_object_s *root_obj)); +static char *M_WriteToJSON(void (*dump)(struct json_object_s *root_obj)); +static const char *M_ResolveOptionName(const char *option_name); -static const char *ConfigFile_ResolveOptionName(const char *option_name); - -static bool Config_ReadFromJSON( +static bool M_ReadFromJSON( const char *cfg_data, void (*load)(struct json_object_s *root_obj)) { bool result = false; @@ -42,7 +41,7 @@ static bool Config_ReadFromJSON( return result; } -static char *Config_WriteToJSON(void (*dump)(struct json_object_s *root_obj)) +static char *M_WriteToJSON(void (*dump)(struct json_object_s *root_obj)) { struct json_object_s *root_obj = json_object_new(); @@ -56,7 +55,7 @@ static char *Config_WriteToJSON(void (*dump)(struct json_object_s *root_obj)) return data; } -static const char *ConfigFile_ResolveOptionName(const char *option_name) +static const char *M_ResolveOptionName(const char *option_name) { const char *dot = strrchr(option_name, '.'); if (dot) { @@ -73,9 +72,9 @@ bool ConfigFile_Read( if (!File_Load(path, &cfg_data, NULL)) { LOG_WARNING("'%s' not loaded - default settings will apply", path); - result = Config_ReadFromJSON("{}", load); + result = M_ReadFromJSON("{}", load); } else { - result = Config_ReadFromJSON(cfg_data, load); + result = M_ReadFromJSON(cfg_data, load); } Memory_FreePointer(&cfg_data); @@ -92,7 +91,7 @@ bool ConfigFile_Write( return false; } - char *data = Config_WriteToJSON(dump); + char *data = M_WriteToJSON(dump); File_WriteData(fp, data, strlen(data)); File_Close(fp); Memory_FreePointer(&data); @@ -108,31 +107,31 @@ void ConfigFile_LoadOptions( switch (opt->type) { case COT_BOOL: *(bool *)opt->target = json_object_get_bool( - root_obj, ConfigFile_ResolveOptionName(opt->name), + root_obj, M_ResolveOptionName(opt->name), *(bool *)opt->default_value); break; case COT_INT32: *(int32_t *)opt->target = json_object_get_int( - root_obj, ConfigFile_ResolveOptionName(opt->name), + root_obj, M_ResolveOptionName(opt->name), *(int32_t *)opt->default_value); break; case COT_FLOAT: *(float *)opt->target = json_object_get_double( - root_obj, ConfigFile_ResolveOptionName(opt->name), + root_obj, M_ResolveOptionName(opt->name), *(float *)opt->default_value); break; case COT_DOUBLE: *(double *)opt->target = json_object_get_double( - root_obj, ConfigFile_ResolveOptionName(opt->name), + root_obj, M_ResolveOptionName(opt->name), *(double *)opt->default_value); break; case COT_ENUM: *(int *)opt->target = ConfigFile_ReadEnum( - root_obj, ConfigFile_ResolveOptionName(opt->name), + root_obj, M_ResolveOptionName(opt->name), *(int *)opt->default_value, (const ENUM_STRING_MAP *)opt->param); } @@ -148,32 +147,31 @@ void ConfigFile_DumpOptions( switch (opt->type) { case COT_BOOL: json_object_append_bool( - root_obj, ConfigFile_ResolveOptionName(opt->name), - *(bool *)opt->target); + root_obj, M_ResolveOptionName(opt->name), *(bool *)opt->target); break; case COT_INT32: json_object_append_int( - root_obj, ConfigFile_ResolveOptionName(opt->name), + root_obj, M_ResolveOptionName(opt->name), *(int32_t *)opt->target); break; case COT_FLOAT: json_object_append_double( - root_obj, ConfigFile_ResolveOptionName(opt->name), + root_obj, M_ResolveOptionName(opt->name), *(float *)opt->target); break; case COT_DOUBLE: json_object_append_double( - root_obj, ConfigFile_ResolveOptionName(opt->name), + root_obj, M_ResolveOptionName(opt->name), *(double *)opt->target); break; case COT_ENUM: ConfigFile_WriteEnum( - root_obj, ConfigFile_ResolveOptionName(opt->name), - *(int *)opt->target, (const ENUM_STRING_MAP *)opt->param); + root_obj, M_ResolveOptionName(opt->name), *(int *)opt->target, + (const ENUM_STRING_MAP *)opt->param); break; } opt++; diff --git a/src/engine/audio.c b/src/engine/audio.c index 4761381..87429ae 100644 --- a/src/engine/audio.c +++ b/src/engine/audio.c @@ -15,10 +15,9 @@ static size_t m_MixBufferCapacity = 0; static float *m_MixBuffer = NULL; static Uint8 m_Silence = 0; -static void Audio_MixerCallback( - void *userdata, Uint8 *stream_data, int32_t len); +static void M_MixerCallback(void *userdata, Uint8 *stream_data, int32_t len); -static void Audio_MixerCallback(void *userdata, Uint8 *stream_data, int32_t len) +static void M_MixerCallback(void *userdata, Uint8 *stream_data, int32_t len) { memset(m_MixBuffer, m_Silence, len); Audio_Stream_Mix(m_MixBuffer, len); @@ -46,7 +45,7 @@ bool Audio_Init(void) desired.format = AUDIO_WORKING_FORMAT; desired.channels = AUDIO_WORKING_CHANNELS; desired.samples = AUDIO_SAMPLES; - desired.callback = Audio_MixerCallback; + desired.callback = M_MixerCallback; desired.userdata = NULL; SDL_AudioSpec delivered; diff --git a/src/engine/audio_sample.c b/src/engine/audio_sample.c index fd54b85..cc7648a 100644 --- a/src/engine/audio_sample.c +++ b/src/engine/audio_sample.c @@ -61,20 +61,18 @@ static int32_t m_LoadedSamplesCount = 0; static AUDIO_SAMPLE m_LoadedSamples[AUDIO_MAX_SAMPLES] = { 0 }; static AUDIO_SAMPLE_SOUND m_Samples[AUDIO_MAX_ACTIVE_SAMPLES] = { 0 }; -static double Audio_Sample_DecibelToMultiplier(double db_gain); -static bool Audio_Sample_RecalculateChannelVolumes(int32_t sound_id); -static int32_t Audio_Sample_ReadAVBuffer( - void *opaque, uint8_t *dst, int32_t dst_size); -static int64_t Audio_Sample_SeekAVBuffer( - void *opaque, int64_t offset, int32_t whence); -static bool Audio_Sample_Convert(const int32_t sample_id); - -static double Audio_Sample_DecibelToMultiplier(double db_gain) +static double M_DecibelToMultiplier(double db_gain); +static bool M_RecalculateChannelVolumes(int32_t sound_id); +static int32_t M_ReadAVBuffer(void *opaque, uint8_t *dst, int32_t dst_size); +static int64_t M_SeekAVBuffer(void *opaque, int64_t offset, int32_t whence); +static bool M_Convert(const int32_t sample_id); + +static double M_DecibelToMultiplier(double db_gain) { return pow(2.0, db_gain / 600.0); } -static bool Audio_Sample_RecalculateChannelVolumes(int32_t sound_id) +static bool M_RecalculateChannelVolumes(int32_t sound_id) { if (!g_AudioDeviceID || sound_id < 0 || sound_id >= AUDIO_MAX_ACTIVE_SAMPLES) { @@ -82,16 +80,15 @@ static bool Audio_Sample_RecalculateChannelVolumes(int32_t sound_id) } AUDIO_SAMPLE_SOUND *sound = &m_Samples[sound_id]; - sound->volume_l = Audio_Sample_DecibelToMultiplier( + sound->volume_l = M_DecibelToMultiplier( sound->volume - (sound->pan > 0 ? sound->pan : 0)); - sound->volume_r = Audio_Sample_DecibelToMultiplier( + sound->volume_r = M_DecibelToMultiplier( sound->volume + (sound->pan < 0 ? sound->pan : 0)); return true; } -static int32_t Audio_Sample_ReadAVBuffer( - void *opaque, uint8_t *dst, int32_t dst_size) +static int32_t M_ReadAVBuffer(void *opaque, uint8_t *dst, int32_t dst_size) { assert(opaque != NULL); assert(dst != NULL); @@ -106,8 +103,7 @@ static int32_t Audio_Sample_ReadAVBuffer( return read; } -static int64_t Audio_Sample_SeekAVBuffer( - void *opaque, int64_t offset, int32_t whence) +static int64_t M_SeekAVBuffer(void *opaque, int64_t offset, int32_t whence) { assert(opaque != NULL); AUDIO_AV_BUFFER *src = opaque; @@ -140,7 +136,7 @@ static int64_t Audio_Sample_SeekAVBuffer( return src->ptr - src->data; } -static bool Audio_Sample_Convert(const int32_t sample_id) +static bool M_Convert(const int32_t sample_id) { assert(sample_id >= 0 && sample_id < m_LoadedSamplesCount); @@ -201,8 +197,8 @@ static bool Audio_Sample_Convert(const int32_t sample_id) }; av.avio_context = avio_alloc_context( - read_buffer, av.read_buffer_size, 0, &av_buf, Audio_Sample_ReadAVBuffer, - NULL, Audio_Sample_SeekAVBuffer); + read_buffer, av.read_buffer_size, 0, &av_buf, M_ReadAVBuffer, NULL, + M_SeekAVBuffer); av.format_ctx = avformat_alloc_context(); av.format_ctx->pb = av.avio_context; @@ -559,7 +555,7 @@ int32_t Audio_Sample_Play( continue; } - Audio_Sample_Convert(sample_id); + M_Convert(sample_id); sound->is_used = true; sound->is_playing = true; @@ -570,7 +566,7 @@ int32_t Audio_Sample_Play( sound->current_sample = 0.0f; sound->sample = &m_LoadedSamples[sample_id]; - Audio_Sample_RecalculateChannelVolumes(sound_id); + M_RecalculateChannelVolumes(sound_id); result = sound_id; break; @@ -696,7 +692,7 @@ bool Audio_Sample_SetPan(int32_t sound_id, int32_t pan) SDL_LockAudioDevice(g_AudioDeviceID); m_Samples[sound_id].pan = pan; - Audio_Sample_RecalculateChannelVolumes(sound_id); + M_RecalculateChannelVolumes(sound_id); SDL_UnlockAudioDevice(g_AudioDeviceID); return true; @@ -711,7 +707,7 @@ bool Audio_Sample_SetVolume(int32_t sound_id, int32_t volume) SDL_LockAudioDevice(g_AudioDeviceID); m_Samples[sound_id].volume = volume; - Audio_Sample_RecalculateChannelVolumes(sound_id); + M_RecalculateChannelVolumes(sound_id); SDL_UnlockAudioDevice(g_AudioDeviceID); return true; @@ -726,7 +722,7 @@ bool Audio_Sample_SetPitch(int32_t sound_id, float pitch) SDL_LockAudioDevice(g_AudioDeviceID); m_Samples[sound_id].pitch = pitch; - Audio_Sample_RecalculateChannelVolumes(sound_id); + M_RecalculateChannelVolumes(sound_id); SDL_UnlockAudioDevice(g_AudioDeviceID); return true; diff --git a/src/engine/audio_stream.c b/src/engine/audio_stream.c index 794a506..4001298 100644 --- a/src/engine/audio_stream.c +++ b/src/engine/audio_stream.c @@ -75,14 +75,13 @@ static float m_MixBuffer[AUDIO_SAMPLES * AUDIO_WORKING_CHANNELS] = { 0 }; static size_t m_DecodeBufferCapacity = 0; static float *m_DecodeBuffer = NULL; -static void Audio_Stream_SeekToStart(AUDIO_STREAM_SOUND *stream); -static bool Audio_Stream_DecodeFrame(AUDIO_STREAM_SOUND *stream); -static bool Audio_Stream_EnqueueFrame(AUDIO_STREAM_SOUND *stream); -static bool Audio_Stream_InitialiseFromPath( - int32_t sound_id, const char *file_path); -static void Audio_Stream_Clear(AUDIO_STREAM_SOUND *stream); - -static void Audio_Stream_SeekToStart(AUDIO_STREAM_SOUND *stream) +static void M_SeekToStart(AUDIO_STREAM_SOUND *stream); +static bool M_DecodeFrame(AUDIO_STREAM_SOUND *stream); +static bool M_EnqueueFrame(AUDIO_STREAM_SOUND *stream); +static bool M_InitialiseFromPath(int32_t sound_id, const char *file_path); +static void M_Clear(AUDIO_STREAM_SOUND *stream); + +static void M_SeekToStart(AUDIO_STREAM_SOUND *stream) { assert(stream != NULL); @@ -101,14 +100,14 @@ static void Audio_Stream_SeekToStart(AUDIO_STREAM_SOUND *stream) } } -static bool Audio_Stream_DecodeFrame(AUDIO_STREAM_SOUND *stream) +static bool M_DecodeFrame(AUDIO_STREAM_SOUND *stream) { assert(stream != NULL); if (stream->stop_at > 0.0 && stream->timestamp >= stream->stop_at) { if (stream->is_looped) { - Audio_Stream_SeekToStart(stream); - return Audio_Stream_DecodeFrame(stream); + M_SeekToStart(stream); + return M_DecodeFrame(stream); } else { return false; } @@ -118,8 +117,8 @@ static bool Audio_Stream_DecodeFrame(AUDIO_STREAM_SOUND *stream) av_read_frame(stream->av.format_ctx, stream->av.packet); if (error_code == AVERROR_EOF && stream->is_looped) { - Audio_Stream_SeekToStart(stream); - return Audio_Stream_DecodeFrame(stream); + M_SeekToStart(stream); + return M_DecodeFrame(stream); } if (error_code < 0) { @@ -142,7 +141,7 @@ static bool Audio_Stream_DecodeFrame(AUDIO_STREAM_SOUND *stream) return true; } -static bool Audio_Stream_EnqueueFrame(AUDIO_STREAM_SOUND *stream) +static bool M_EnqueueFrame(AUDIO_STREAM_SOUND *stream) { assert(stream != NULL); @@ -245,8 +244,7 @@ static bool Audio_Stream_EnqueueFrame(AUDIO_STREAM_SOUND *stream) return true; } -static bool Audio_Stream_InitialiseFromPath( - int32_t sound_id, const char *file_path) +static bool M_InitialiseFromPath(int32_t sound_id, const char *file_path) { assert(file_path != NULL); @@ -323,7 +321,7 @@ static bool Audio_Stream_InitialiseFromPath( goto cleanup; } - Audio_Stream_DecodeFrame(stream); + M_DecodeFrame(stream); int32_t sdl_sample_rate = stream->av.codec_ctx->sample_rate; int32_t sdl_channels = stream->av.codec_ctx->channels; @@ -350,7 +348,7 @@ static bool Audio_Stream_InitialiseFromPath( } ret = true; - Audio_Stream_EnqueueFrame(stream); + M_EnqueueFrame(stream); cleanup: if (error_code) { @@ -368,7 +366,7 @@ static bool Audio_Stream_InitialiseFromPath( return ret; } -static void Audio_Stream_Clear(AUDIO_STREAM_SOUND *stream) +static void M_Clear(AUDIO_STREAM_SOUND *stream) { assert(stream != NULL); @@ -388,7 +386,7 @@ void Audio_Stream_Init(void) { for (int32_t sound_id = 0; sound_id < AUDIO_MAX_ACTIVE_STREAMS; sound_id++) { - Audio_Stream_Clear(&m_Streams[sound_id]); + M_Clear(&m_Streams[sound_id]); } } @@ -454,7 +452,7 @@ int32_t Audio_Stream_CreateFromFile(const char *file_path) continue; } - if (!Audio_Stream_InitialiseFromPath(sound_id, file_path)) { + if (!M_InitialiseFromPath(sound_id, file_path)) { return AUDIO_NO_SOUND; } @@ -510,7 +508,7 @@ bool Audio_Stream_Close(int32_t sound_id) void (*finish_callback)(int32_t, void *) = stream->finish_callback; void *finish_callback_user_data = stream->finish_callback_user_data; - Audio_Stream_Clear(stream); + M_Clear(stream); SDL_UnlockAudioDevice(g_AudioDeviceID); @@ -581,8 +579,8 @@ void Audio_Stream_Mix(float *dst_buffer, size_t len) while ((SDL_AudioStreamAvailable(stream->sdl.stream) < (int32_t)len) && !stream->is_read_done) { - if (Audio_Stream_DecodeFrame(stream)) { - Audio_Stream_EnqueueFrame(stream); + if (M_DecodeFrame(stream)) { + M_EnqueueFrame(stream); } else { stream->is_read_done = true; } @@ -598,7 +596,7 @@ void Audio_Stream_Mix(float *dst_buffer, size_t len) stream->is_read_done = true; } else if (bytes_gotten == 0) { // legit end of stream. looping is handled in - // Audio_Stream_DecodeFrame + // M_DecodeFrame stream->is_playing = false; stream->is_used = false; stream->is_read_done = true; diff --git a/src/engine/image.c b/src/engine/image.c index 5793c4c..424c0a0 100644 --- a/src/engine/image.c +++ b/src/engine/image.c @@ -40,17 +40,16 @@ typedef struct { AVPacket *packet; } IMAGE_READER_CONTEXT; -static bool Image_Reader_Init(const char *path, IMAGE_READER_CONTEXT *ctx); -static void Image_Reader_Free(IMAGE_READER_CONTEXT *ctx); -static IMAGE *Image_Reader_ConstructImage( +static bool M_Init(const char *path, IMAGE_READER_CONTEXT *ctx); +static void M_Free(IMAGE_READER_CONTEXT *ctx); +static IMAGE *M_ConstructImage( IMAGE_READER_CONTEXT *ctx, int32_t target_width, int32_t target_height, IMAGE_FIT_MODE fit_mode); -static IMAGE_BLIT Image_GetBlit( +static IMAGE_BLIT M_GetBlit( int32_t source_width, int32_t source_height, int32_t target_width, int32_t target_height, IMAGE_FIT_MODE fit_mode); -static bool Image_Reader_Init( - const char *const path, IMAGE_READER_CONTEXT *const ctx) +static bool M_Init(const char *const path, IMAGE_READER_CONTEXT *const ctx) { assert(ctx != NULL); ctx->format_ctx = NULL; @@ -149,14 +148,14 @@ static bool Image_Reader_Init( if (error_code != 0) { LOG_ERROR( "Error while opening image %s: %s", path, av_err2str(error_code)); - Image_Reader_Free(ctx); + M_Free(ctx); return false; } return true; } -static void Image_Reader_Free(IMAGE_READER_CONTEXT *const ctx) +static void M_Free(IMAGE_READER_CONTEXT *const ctx) { if (ctx->packet != NULL) { av_packet_free(&ctx->packet); @@ -186,7 +185,7 @@ IMAGE *Image_Create(const int width, const int height) return image; } -static IMAGE *Image_Reader_ConstructImage( +static IMAGE *M_ConstructImage( IMAGE_READER_CONTEXT *const ctx, const int32_t target_width, const int32_t target_height, IMAGE_FIT_MODE fit_mode) { @@ -194,7 +193,7 @@ static IMAGE *Image_Reader_ConstructImage( assert(target_width > 0); assert(target_height > 0); - IMAGE_BLIT blit = Image_GetBlit( + IMAGE_BLIT blit = M_GetBlit( ctx->frame->width, ctx->frame->height, target_width, target_height, fit_mode); @@ -230,7 +229,7 @@ static IMAGE *Image_Reader_ConstructImage( return target_image; } -static IMAGE_BLIT Image_GetBlit( +static IMAGE_BLIT M_GetBlit( const int32_t source_width, const int32_t source_height, const int32_t target_width, const int32_t target_height, IMAGE_FIT_MODE fit_mode) @@ -315,14 +314,14 @@ IMAGE *Image_CreateFromFile(const char *const path) assert(path != NULL); IMAGE_READER_CONTEXT ctx; - if (!Image_Reader_Init(path, &ctx)) { + if (!M_Init(path, &ctx)) { return NULL; } - IMAGE *target_image = Image_Reader_ConstructImage( + IMAGE *target_image = M_ConstructImage( &ctx, ctx.frame->width, ctx.frame->height, IMAGE_FIT_STRETCH); - Image_Reader_Free(&ctx); + M_Free(&ctx); return target_image; } @@ -334,14 +333,14 @@ IMAGE *Image_CreateFromFileInto( assert(path != NULL); IMAGE_READER_CONTEXT ctx; - if (!Image_Reader_Init(path, &ctx)) { + if (!M_Init(path, &ctx)) { return NULL; } - IMAGE *target_image = Image_Reader_ConstructImage( - &ctx, target_width, target_height, fit_mode); + IMAGE *target_image = + M_ConstructImage(&ctx, target_width, target_height, fit_mode); - Image_Reader_Free(&ctx); + M_Free(&ctx); return target_image; } @@ -514,7 +513,7 @@ IMAGE *Image_Scale( assert(target_width > 0); assert(target_height > 0); - IMAGE_BLIT blit = Image_GetBlit( + IMAGE_BLIT blit = M_GetBlit( source_image->width, source_image->height, target_width, target_height, fit_mode); diff --git a/src/filesystem.c b/src/filesystem.c index 2393678..47e27df 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -24,30 +24,30 @@ struct MYFILE { const char *m_GameDir = NULL; -static void File_PathAppendSeparator(char *path); -static void File_PathAppendPart(char *path, const char *part); -static char *File_CasePath(char const *path); -static bool File_ExistsRaw(const char *path); +static void M_PathAppendSeparator(char *path); +static void M_PathAppendPart(char *path, const char *part); +static char *M_CasePath(char const *path); +static bool M_ExistsRaw(const char *path); -static void File_PathAppendSeparator(char *path) +static void M_PathAppendSeparator(char *path) { if (!String_EndsWith(path, PATH_SEPARATOR)) { strcat(path, PATH_SEPARATOR); } } -static void File_PathAppendPart(char *path, const char *part) +static void M_PathAppendPart(char *path, const char *part) { - File_PathAppendSeparator(path); + M_PathAppendSeparator(path); strcat(path, part); } -static char *File_CasePath(char const *path) +static char *M_CasePath(char const *path) { assert(path); char *path_copy = Memory_DupStr(path); - if (File_ExistsRaw(path)) { + if (M_ExistsRaw(path)) { return path_copy; } @@ -82,7 +82,7 @@ static char *File_CasePath(char const *path) struct dirent *cur_file = readdir(path_dir); while (cur_file) { if (String_Equivalent(path_piece, cur_file->d_name)) { - File_PathAppendPart(current_path, cur_file->d_name); + M_PathAppendPart(current_path, cur_file->d_name); break; } cur_file = readdir(path_dir); @@ -90,7 +90,7 @@ static char *File_CasePath(char const *path) closedir(path_dir); if (!cur_file) { - File_PathAppendPart(current_path, path_piece); + M_PathAppendPart(current_path, path_piece); } if (delim) { @@ -115,7 +115,7 @@ static char *File_CasePath(char const *path) return result; } -static bool File_ExistsRaw(const char *path) +static bool M_ExistsRaw(const char *path) { FILE *fp = fopen(path, "rb"); if (fp) { @@ -162,7 +162,7 @@ bool File_DirExists(const char *path) bool File_Exists(const char *path) { char *full_path = File_GetFullPath(path); - bool ret = File_ExistsRaw(full_path); + bool ret = M_ExistsRaw(full_path); Memory_FreePointer(&full_path); return ret; } @@ -181,7 +181,7 @@ char *File_GetFullPath(const char *path) full_path = Memory_DupStr(path); } - char *case_path = File_CasePath(full_path); + char *case_path = M_CasePath(full_path); if (case_path) { Memory_FreePointer(&full_path); return case_path; diff --git a/src/game/console/commands/config.c b/src/game/console/commands/config.c index 8759628..502f9bb 100644 --- a/src/game/console/commands/config.c +++ b/src/game/console/commands/config.c @@ -10,18 +10,18 @@ #include #include -static const char *Console_Cmd_Config_Resolve(const char *option_name); -static bool Console_Cmd_Config_SameKey(const char *key1, const char *key2); -static char *Console_Cmd_Config_NormalizeKey(const char *key); +static const char *M_Resolve(const char *option_name); +static bool M_SameKey(const char *key1, const char *key2); +static char *M_NormalizeKey(const char *key); -static bool Console_Cmd_Config_GetCurrentValue( +static bool M_GetCurrentValue( const CONFIG_OPTION *option, char *target, size_t target_size); -static bool Console_Cmd_Config_SetCurrentValue( +static bool M_SetCurrentValue( const CONFIG_OPTION *option, const char *new_value); static COMMAND_RESULT Console_Cmd_Set(const char *args); -static const char *Console_Cmd_Config_Resolve(const char *const option_name) +static const char *M_Resolve(const char *const option_name) { const char *dot = strrchr(option_name, '.'); if (dot) { @@ -30,10 +30,10 @@ static const char *Console_Cmd_Config_Resolve(const char *const option_name) return option_name; } -static bool Console_Cmd_Config_SameKey(const char *key1, const char *key2) +static bool M_SameKey(const char *key1, const char *key2) { - key1 = Console_Cmd_Config_Resolve(key1); - key2 = Console_Cmd_Config_Resolve(key2); + key1 = M_Resolve(key1); + key2 = M_Resolve(key2); const size_t len1 = strlen(key1); const size_t len2 = strlen(key2); if (len1 != len2) { @@ -55,7 +55,7 @@ static bool Console_Cmd_Config_SameKey(const char *key1, const char *key2) return true; } -static char *Console_Cmd_Config_NormalizeKey(const char *key) +static char *M_NormalizeKey(const char *key) { // TODO: Once we support arbitrary glyphs, this conversion should // no longer be necessary. @@ -68,7 +68,7 @@ static char *Console_Cmd_Config_NormalizeKey(const char *key) return result; } -static bool Console_Cmd_Config_GetCurrentValue( +static bool M_GetCurrentValue( const CONFIG_OPTION *const option, char *target, const size_t target_size) { if (option == NULL) { @@ -103,7 +103,7 @@ static bool Console_Cmd_Config_GetCurrentValue( return true; } -static bool Console_Cmd_Config_SetCurrentValue( +static bool M_SetCurrentValue( const CONFIG_OPTION *const option, const char *const new_value) { if (option == NULL) { @@ -167,7 +167,7 @@ const CONFIG_OPTION *Console_Cmd_Config_GetOptionFromKey(const char *const key) { for (const CONFIG_OPTION *option = Config_GetOptionMap(); option->name != NULL; option++) { - if (Console_Cmd_Config_SameKey(option->name, key)) { + if (M_SameKey(option->name, key)) { return option; } } @@ -193,24 +193,24 @@ COMMAND_RESULT Console_Cmd_Config_Helper( { assert(option != NULL); - char *normalized_name = Console_Cmd_Config_NormalizeKey(option->name); + char *normalized_name = M_NormalizeKey(option->name); COMMAND_RESULT result = CR_BAD_INVOCATION; if (new_value == NULL || String_IsEmpty(new_value)) { char cur_value[128]; - if (Console_Cmd_Config_GetCurrentValue(option, cur_value, 128)) { + if (M_GetCurrentValue(option, cur_value, 128)) { Console_Log(GS(OSD_CONFIG_OPTION_GET), normalized_name, cur_value); result = CR_SUCCESS; } } - if (Console_Cmd_Config_SetCurrentValue(option, new_value)) { + if (M_SetCurrentValue(option, new_value)) { Config_Sanitize(); Config_Write(); Config_ApplyChanges(); char final_value[128]; - assert(Console_Cmd_Config_GetCurrentValue(option, final_value, 128)); + assert(M_GetCurrentValue(option, final_value, 128)); Console_Log(GS(OSD_CONFIG_OPTION_SET), normalized_name, final_value); result = CR_SUCCESS; } @@ -220,7 +220,7 @@ COMMAND_RESULT Console_Cmd_Config_Helper( return result; } -static COMMAND_RESULT Console_Cmd_Config(const char *const args) +static COMMAND_RESULT M_Entrypoint(const char *const args) { COMMAND_RESULT result = CR_BAD_INVOCATION; @@ -248,5 +248,5 @@ static COMMAND_RESULT Console_Cmd_Config(const char *const args) CONSOLE_COMMAND g_Console_Cmd_Config = { .prefix = "set", - .proc = Console_Cmd_Config, + .proc = M_Entrypoint, }; diff --git a/src/game/console/commands/heal.c b/src/game/console/commands/heal.c index f687947..86191d2 100644 --- a/src/game/console/commands/heal.c +++ b/src/game/console/commands/heal.c @@ -5,7 +5,9 @@ #include "game/lara/common.h" #include "game/lara/misc.h" -static COMMAND_RESULT Console_Cmd_Heal(const char *const args) +static COMMAND_RESULT M_Entrypoint(const char *args); + +static COMMAND_RESULT M_Entrypoint(const char *const args) { if (!Game_IsPlayable()) { return CR_UNAVAILABLE; @@ -25,5 +27,5 @@ static COMMAND_RESULT Console_Cmd_Heal(const char *const args) CONSOLE_COMMAND g_Console_Cmd_Heal = { .prefix = "heal", - .proc = Console_Cmd_Heal, + .proc = M_Entrypoint, }; diff --git a/src/game/console/commands/pos.c b/src/game/console/commands/pos.c index 46301bf..c68fcdf 100644 --- a/src/game/console/commands/pos.c +++ b/src/game/console/commands/pos.c @@ -6,9 +6,9 @@ #include "game/lara/common.h" #include "game/objects/common.h" -static COMMAND_RESULT Console_Cmd_Pos(const char *args); +static COMMAND_RESULT M_Entrypoint(const char *args); -static COMMAND_RESULT Console_Cmd_Pos(const char *const args) +static COMMAND_RESULT M_Entrypoint(const char *const args) { const OBJECT_INFO *const object = Object_GetObject(O_LARA); if (!object->loaded) { @@ -34,5 +34,5 @@ static COMMAND_RESULT Console_Cmd_Pos(const char *const args) CONSOLE_COMMAND g_Console_Cmd_Pos = { .prefix = "pos", - .proc = Console_Cmd_Pos, + .proc = M_Entrypoint, }; diff --git a/src/game/console/commands/set_health.c b/src/game/console/commands/set_health.c index 45a928b..133d16a 100644 --- a/src/game/console/commands/set_health.c +++ b/src/game/console/commands/set_health.c @@ -8,9 +8,9 @@ #include "strings.h" #include "utils.h" -static COMMAND_RESULT Console_Cmd_SetHealth(const char *args); +static COMMAND_RESULT M_Entrypoint(const char *args); -static COMMAND_RESULT Console_Cmd_SetHealth(const char *const args) +static COMMAND_RESULT M_Entrypoint(const char *const args) { if (!Game_IsPlayable()) { return CR_UNAVAILABLE; @@ -35,5 +35,5 @@ static COMMAND_RESULT Console_Cmd_SetHealth(const char *const args) CONSOLE_COMMAND g_Console_Cmd_SetHealth = { .prefix = "hp", - .proc = Console_Cmd_SetHealth, + .proc = M_Entrypoint, }; diff --git a/src/gfx/3d/3d_renderer.c b/src/gfx/3d/3d_renderer.c index a028dd1..64904b5 100644 --- a/src/gfx/3d/3d_renderer.c +++ b/src/gfx/3d/3d_renderer.c @@ -7,11 +7,9 @@ #include #include -static void GFX_3D_Renderer_SelectTextureImpl( - GFX_3D_Renderer *renderer, int texture_num); +static void M_SelectTextureImpl(GFX_3D_Renderer *renderer, int texture_num); -static void GFX_3D_Renderer_SelectTextureImpl( - GFX_3D_Renderer *renderer, int texture_num) +static void M_SelectTextureImpl(GFX_3D_Renderer *renderer, int texture_num) { assert(renderer); @@ -189,7 +187,7 @@ bool GFX_3D_Renderer_UnregisterEnvironmentMap( // unbind texture if currently bound if (renderer->selected_texture_num == texture_num) { - GFX_3D_Renderer_SelectTextureImpl(renderer, GFX_NO_TEXTURE); + M_SelectTextureImpl(renderer, GFX_NO_TEXTURE); renderer->selected_texture_num = GFX_NO_TEXTURE; } @@ -248,7 +246,7 @@ bool GFX_3D_Renderer_UnregisterTexturePage( // unbind texture if currently bound if (texture_num == renderer->selected_texture_num) { - GFX_3D_Renderer_SelectTextureImpl(renderer, GFX_NO_TEXTURE); + M_SelectTextureImpl(renderer, GFX_NO_TEXTURE); renderer->selected_texture_num = GFX_NO_TEXTURE; } @@ -287,13 +285,13 @@ void GFX_3D_Renderer_SelectTexture(GFX_3D_Renderer *renderer, int texture_num) assert(renderer); GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream); renderer->selected_texture_num = texture_num; - GFX_3D_Renderer_SelectTextureImpl(renderer, texture_num); + M_SelectTextureImpl(renderer, texture_num); } void GFX_3D_Renderer_RestoreTexture(GFX_3D_Renderer *renderer) { assert(renderer); - GFX_3D_Renderer_SelectTextureImpl(renderer, renderer->selected_texture_num); + M_SelectTextureImpl(renderer, renderer->selected_texture_num); } void GFX_3D_Renderer_SetPrimType( diff --git a/src/gfx/3d/vertex_stream.c b/src/gfx/3d/vertex_stream.c index d844bf1..1fbef64 100644 --- a/src/gfx/3d/vertex_stream.c +++ b/src/gfx/3d/vertex_stream.c @@ -10,10 +10,10 @@ static const GLenum GL_PRIM_MODES[] = { GL_TRIANGLES, // GFX_3D_PRIM_TRI }; -static void GFX_3D_VertexStream_PushVertex( +static void M_PushVertex( GFX_3D_VertexStream *vertex_stream, GFX_3D_Vertex *vertex); -static void GFX_3D_VertexStream_PushVertex( +static void M_PushVertex( GFX_3D_VertexStream *vertex_stream, GFX_3D_Vertex *vertex) { if (vertex_stream->pending_vertices.count + 1 @@ -80,14 +80,14 @@ bool GFX_3D_VertexStream_PushPrimStrip( if (count <= 2) { for (int i = 0; i < count; i++) { - GFX_3D_VertexStream_PushVertex(vertex_stream, &vertices[i]); + M_PushVertex(vertex_stream, &vertices[i]); } } else { // convert strip to raw triangles for (int i = 2; i < count; i++) { - GFX_3D_VertexStream_PushVertex(vertex_stream, &vertices[i - 2]); - GFX_3D_VertexStream_PushVertex(vertex_stream, &vertices[i - 1]); - GFX_3D_VertexStream_PushVertex(vertex_stream, &vertices[i]); + M_PushVertex(vertex_stream, &vertices[i - 2]); + M_PushVertex(vertex_stream, &vertices[i - 1]); + M_PushVertex(vertex_stream, &vertices[i]); } } @@ -104,14 +104,14 @@ bool GFX_3D_VertexStream_PushPrimFan( if (count <= 2) { for (int i = 0; i < count; i++) { - GFX_3D_VertexStream_PushVertex(vertex_stream, &vertices[i]); + M_PushVertex(vertex_stream, &vertices[i]); } } else { // convert fan to raw triangles for (int i = 2; i < count; i++) { - GFX_3D_VertexStream_PushVertex(vertex_stream, &vertices[0]); - GFX_3D_VertexStream_PushVertex(vertex_stream, &vertices[i - 1]); - GFX_3D_VertexStream_PushVertex(vertex_stream, &vertices[i]); + M_PushVertex(vertex_stream, &vertices[0]); + M_PushVertex(vertex_stream, &vertices[i - 1]); + M_PushVertex(vertex_stream, &vertices[i]); } } @@ -122,7 +122,7 @@ bool GFX_3D_VertexStream_PushPrimList( GFX_3D_VertexStream *vertex_stream, GFX_3D_Vertex *vertices, int count) { for (int i = 0; i < count; i++) { - GFX_3D_VertexStream_PushVertex(vertex_stream, &vertices[i]); + M_PushVertex(vertex_stream, &vertices[i]); } return true; } diff --git a/src/gfx/context.c b/src/gfx/context.c index 732c49b..8a005ed 100644 --- a/src/gfx/context.c +++ b/src/gfx/context.c @@ -31,10 +31,10 @@ typedef struct GFX_CONTEXT { static GFX_CONTEXT m_Context = { 0 }; -static bool GFX_Context_IsExtensionSupported(const char *name); -static void GFX_Context_CheckExtensionSupport(const char *name); +static bool M_IsExtensionSupported(const char *name); +static void M_CheckExtensionSupport(const char *name); -static bool GFX_Context_IsExtensionSupported(const char *name) +static bool M_IsExtensionSupported(const char *name) { int number_of_extensions; @@ -52,11 +52,10 @@ static bool GFX_Context_IsExtensionSupported(const char *name) return false; } -static void GFX_Context_CheckExtensionSupport(const char *name) +static void M_CheckExtensionSupport(const char *name) { LOG_INFO( - "%s supported: %s", name, - GFX_Context_IsExtensionSupported(name) ? "yes" : "no"); + "%s supported: %s", name, M_IsExtensionSupported(name) ? "yes" : "no"); } void GFX_Context_SwitchToWindowViewport(void) @@ -150,8 +149,8 @@ void GFX_Context_Attach(void *window_handle) // Check the availability of non-Core Profile extensions for OpenGL 2.1 if (GFX_GL_DEFAULT_BACKEND == GFX_GL_21) { - GFX_Context_CheckExtensionSupport("GL_ARB_explicit_attrib_location"); - GFX_Context_CheckExtensionSupport("GL_EXT_gpu_shader4"); + M_CheckExtensionSupport("GL_ARB_explicit_attrib_location"); + M_CheckExtensionSupport("GL_EXT_gpu_shader4"); } glClearColor(0, 0, 0, 0); diff --git a/src/gfx/renderers/fbo_renderer.c b/src/gfx/renderers/fbo_renderer.c index b4dc987..da9460d 100644 --- a/src/gfx/renderers/fbo_renderer.c +++ b/src/gfx/renderers/fbo_renderer.c @@ -32,17 +32,16 @@ typedef struct { GFX_GL_Program program; } GFX_Renderer_FBO_Context; -static void GFX_Renderer_FBO_SwapBuffers(GFX_Renderer *renderer); -static void GFX_Renderer_FBO_Init( - GFX_Renderer *renderer, const GFX_CONFIG *config); -static void GFX_Renderer_FBO_Shutdown(GFX_Renderer *renderer); -static void GFX_Renderer_FBO_Reset(GFX_Renderer *renderer); +static void M_SwapBuffers(GFX_Renderer *renderer); +static void M_Init(GFX_Renderer *renderer, const GFX_CONFIG *config); +static void M_Shutdown(GFX_Renderer *renderer); +static void M_Reset(GFX_Renderer *renderer); -static void GFX_Renderer_FBO_Render(GFX_Renderer *renderer); -static void GFX_Renderer_FBO_Bind(const GFX_Renderer *renderer); -static void GFX_Renderer_FBO_Unbind(const GFX_Renderer *renderer); +static void M_Render(GFX_Renderer *renderer); +static void M_Bind(const GFX_Renderer *renderer); +static void M_Unbind(const GFX_Renderer *renderer); -static void GFX_Renderer_FBO_SwapBuffers(GFX_Renderer *renderer) +static void M_SwapBuffers(GFX_Renderer *renderer) { if (GFX_Context_GetScheduledScreenshotPath()) { GFX_Screenshot_CaptureToFile(GFX_Context_GetScheduledScreenshotPath()); @@ -50,21 +49,20 @@ static void GFX_Renderer_FBO_SwapBuffers(GFX_Renderer *renderer) } GFX_Context_SwitchToWindowViewportAR(); - GFX_Renderer_FBO_Render(renderer); + M_Render(renderer); SDL_GL_SwapWindow(GFX_Context_GetWindowHandle()); GFX_Context_SwitchToWindowViewport(); - GFX_Renderer_FBO_Unbind(renderer); + M_Unbind(renderer); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GFX_GL_CheckError(); - GFX_Renderer_FBO_Bind(renderer); + M_Bind(renderer); GFX_Context_SwitchToDisplayViewport(); } -static void GFX_Renderer_FBO_Init( - GFX_Renderer *const renderer, const GFX_CONFIG *const config) +static void M_Init(GFX_Renderer *const renderer, const GFX_CONFIG *const config) { LOG_INFO(""); @@ -146,7 +144,7 @@ static void GFX_Renderer_FBO_Init( } } -static void GFX_Renderer_FBO_Shutdown(GFX_Renderer *renderer) +static void M_Shutdown(GFX_Renderer *renderer) { LOG_INFO(""); @@ -169,7 +167,7 @@ static void GFX_Renderer_FBO_Shutdown(GFX_Renderer *renderer) Memory_FreePointer(&renderer->priv); } -static void GFX_Renderer_FBO_Reset(GFX_Renderer *renderer) +static void M_Reset(GFX_Renderer *renderer) { GFX_Renderer_FBO_Context *const priv = renderer->priv; const GFX_CONFIG *const config = priv->config; @@ -178,7 +176,7 @@ static void GFX_Renderer_FBO_Reset(GFX_Renderer *renderer) renderer->init(renderer, config); } -static void GFX_Renderer_FBO_Render(GFX_Renderer *renderer) +static void M_Render(GFX_Renderer *renderer) { assert(renderer != NULL); GFX_Renderer_FBO_Context *priv = renderer->priv; @@ -227,7 +225,7 @@ static void GFX_Renderer_FBO_Render(GFX_Renderer *renderer) GFX_GL_CheckError(); } -static void GFX_Renderer_FBO_Bind(const GFX_Renderer *renderer) +static void M_Bind(const GFX_Renderer *renderer) { assert(renderer != NULL); GFX_Renderer_FBO_Context *priv = renderer->priv; @@ -235,14 +233,14 @@ static void GFX_Renderer_FBO_Bind(const GFX_Renderer *renderer) glBindFramebuffer(GL_FRAMEBUFFER, priv->fbo); } -static void GFX_Renderer_FBO_Unbind(const GFX_Renderer *renderer) +static void M_Unbind(const GFX_Renderer *renderer) { glBindFramebuffer(GL_FRAMEBUFFER, 0); } GFX_Renderer g_GFX_Renderer_FBO = { - .swap_buffers = &GFX_Renderer_FBO_SwapBuffers, - .init = &GFX_Renderer_FBO_Init, - .shutdown = &GFX_Renderer_FBO_Shutdown, - .reset = &GFX_Renderer_FBO_Reset, + .swap_buffers = &M_SwapBuffers, + .init = &M_Init, + .shutdown = &M_Shutdown, + .reset = &M_Reset, }; diff --git a/src/gfx/renderers/legacy_renderer.c b/src/gfx/renderers/legacy_renderer.c index 830001c..3df02bd 100644 --- a/src/gfx/renderers/legacy_renderer.c +++ b/src/gfx/renderers/legacy_renderer.c @@ -7,9 +7,9 @@ #include #include -static void GFX_Renderer_Legacy_SwapBuffers(GFX_Renderer *renderer); +static void M_SwapBuffers(GFX_Renderer *renderer); -static void GFX_Renderer_Legacy_SwapBuffers(GFX_Renderer *renderer) +static void M_SwapBuffers(GFX_Renderer *renderer) { assert(renderer != NULL); @@ -28,7 +28,7 @@ static void GFX_Renderer_Legacy_SwapBuffers(GFX_Renderer *renderer) GFX_Renderer g_GFX_Renderer_Legacy = { .priv = NULL, - .swap_buffers = &GFX_Renderer_Legacy_SwapBuffers, + .swap_buffers = &M_SwapBuffers, .init = NULL, .reset = NULL, .shutdown = NULL, diff --git a/src/json/bson_parse.c b/src/json/bson_parse.c index 9d37ce4..4c5703a 100644 --- a/src/json/bson_parse.c +++ b/src/json/bson_parse.c @@ -22,53 +22,50 @@ struct bson_parse_state_s { size_t error; }; -static bool bson_parse_get_object_key_size(struct bson_parse_state_s *state); -static bool bson_parse_get_null_value_size(struct bson_parse_state_s *state); -static bool bson_parse_get_bool_value_size(struct bson_parse_state_s *state); -static bool bson_parse_get_int32_value_size(struct bson_parse_state_s *state); -static bool bson_parse_get_double_value_size(struct bson_parse_state_s *state); -static bool bson_parse_get_string_value_size(struct bson_parse_state_s *state); -static bool bson_parse_get_array_element_wrapped_size( - struct bson_parse_state_s *state); -static bool bson_parse_get_array_size(struct bson_parse_state_s *state); -static bool bson_parse_get_array_value_size(struct bson_parse_state_s *state); -static bool bson_parse_get_object_element_wrapped_size( - struct bson_parse_state_s *state); -static bool bson_parse_get_object_size(struct bson_parse_state_s *state); -static bool bson_parse_get_object_value_size(struct bson_parse_state_s *state); -static bool bson_parse_get_value_size( - struct bson_parse_state_s *state, uint8_t marker); -static bool bson_parse_get_root_size(struct bson_parse_state_s *state); - -static void bson_parse_object_key( +static bool M_GetObjectKeySize(struct bson_parse_state_s *state); +static bool M_GetNullValueSize(struct bson_parse_state_s *state); +static bool M_GetBoolValueSize(struct bson_parse_state_s *state); +static bool M_GetInt32ValueSize(struct bson_parse_state_s *state); +static bool M_GetDoubleValueSize(struct bson_parse_state_s *state); +static bool M_GetStringValueSize(struct bson_parse_state_s *state); +static bool M_GetArrayElementWrappedSize(struct bson_parse_state_s *state); +static bool M_GetArraySize(struct bson_parse_state_s *state); +static bool M_GetArrayValueSize(struct bson_parse_state_s *state); +static bool M_GetObjectElementWrappedSize(struct bson_parse_state_s *state); +static bool M_GetObjectSize(struct bson_parse_state_s *state); +static bool M_GetObjectValueSize(struct bson_parse_state_s *state); +static bool M_GetValueSize(struct bson_parse_state_s *state, uint8_t marker); +static bool m_GetRootSize(struct bson_parse_state_s *state); + +static void M_HandleObjectKey( struct bson_parse_state_s *state, struct json_string_s *string); -static void bson_parse_null_value( +static void M_HandleNullValue( struct bson_parse_state_s *state, struct json_value_s *value); -static void bson_parse_bool_value( +static void M_HandleBoolValue( struct bson_parse_state_s *state, struct json_value_s *value); -static void bson_parse_int32_value( +static void M_HandleInt32Value( struct bson_parse_state_s *state, struct json_value_s *value); -static void bson_parse_double_value( +static void M_HandleDoubleValue( struct bson_parse_state_s *state, struct json_value_s *value); -static void bson_parse_string_value( +static void M_HandleStringValue( struct bson_parse_state_s *state, struct json_value_s *value); -static void bson_parse_array_element_wrapped( +static void M_HandleArrayElementWrapped( struct bson_parse_state_s *state, struct json_array_element_s *element); -static void bson_parse_array( +static void M_HandleArray( struct bson_parse_state_s *state, struct json_array_s *array); -static void bson_parse_array_value( +static void M_HandleArrayValue( struct bson_parse_state_s *state, struct json_value_s *value); -static void bson_parse_object_element_wrapped( +static void M_HandleObjectElementWrapped( struct bson_parse_state_s *state, struct json_object_element_s *element); -static void bson_parse_object( +static void M_HandleObject( struct bson_parse_state_s *state, struct json_object_s *object); -static void bson_parse_object_value( +static void M_HandleObjectValue( struct bson_parse_state_s *state, struct json_value_s *value); -static void bson_parse_value( +static void M_HandleValue( struct bson_parse_state_s *state, struct json_value_s *value, uint8_t marker); -static bool bson_parse_get_object_key_size(struct bson_parse_state_s *state) +static bool M_GetObjectKeySize(struct bson_parse_state_s *state) { assert(state); while (state->src[state->offset]) { @@ -80,13 +77,13 @@ static bool bson_parse_get_object_key_size(struct bson_parse_state_s *state) return true; } -static bool bson_parse_get_null_value_size(struct bson_parse_state_s *state) +static bool M_GetNullValueSize(struct bson_parse_state_s *state) { assert(state); return true; } -static bool bson_parse_get_bool_value_size(struct bson_parse_state_s *state) +static bool M_GetBoolValueSize(struct bson_parse_state_s *state) { assert(state); if (state->offset + sizeof(uint8_t) > state->size) { @@ -108,7 +105,7 @@ static bool bson_parse_get_bool_value_size(struct bson_parse_state_s *state) return true; } -static bool bson_parse_get_int32_value_size(struct bson_parse_state_s *state) +static bool M_GetInt32ValueSize(struct bson_parse_state_s *state) { assert(state); @@ -124,7 +121,7 @@ static bool bson_parse_get_int32_value_size(struct bson_parse_state_s *state) return true; } -static bool bson_parse_get_double_value_size(struct bson_parse_state_s *state) +static bool M_GetDoubleValueSize(struct bson_parse_state_s *state) { assert(state); @@ -140,7 +137,7 @@ static bool bson_parse_get_double_value_size(struct bson_parse_state_s *state) return true; } -static bool bson_parse_get_string_value_size(struct bson_parse_state_s *state) +static bool M_GetStringValueSize(struct bson_parse_state_s *state) { assert(state); @@ -164,8 +161,7 @@ static bool bson_parse_get_string_value_size(struct bson_parse_state_s *state) return true; } -static bool bson_parse_get_array_element_wrapped_size( - struct bson_parse_state_s *state) +static bool M_GetArrayElementWrappedSize(struct bson_parse_state_s *state) { assert(state); @@ -178,15 +174,15 @@ static bool bson_parse_get_array_element_wrapped_size( // BSON arrays always use keys state->dom_size += sizeof(struct json_string_s); - if (!bson_parse_get_object_key_size(state)) { + if (!M_GetObjectKeySize(state)) { return false; } state->dom_size += sizeof(struct json_value_s); - return bson_parse_get_value_size(state, marker); + return M_GetValueSize(state, marker); } -static bool bson_parse_get_array_size(struct bson_parse_state_s *state) +static bool M_GetArraySize(struct bson_parse_state_s *state) { assert(state); @@ -200,7 +196,7 @@ static bool bson_parse_get_array_size(struct bson_parse_state_s *state) while (state->offset < start_offset + size - 1) { state->dom_size += sizeof(struct json_array_element_s); - if (!bson_parse_get_array_element_wrapped_size(state)) { + if (!M_GetArrayElementWrappedSize(state)) { return false; } } @@ -217,15 +213,14 @@ static bool bson_parse_get_array_size(struct bson_parse_state_s *state) return true; } -static bool bson_parse_get_array_value_size(struct bson_parse_state_s *state) +static bool M_GetArrayValueSize(struct bson_parse_state_s *state) { assert(state); state->dom_size += sizeof(struct json_array_s); - return bson_parse_get_array_size(state); + return M_GetArraySize(state); } -static bool bson_parse_get_object_element_wrapped_size( - struct bson_parse_state_s *state) +static bool M_GetObjectElementWrappedSize(struct bson_parse_state_s *state) { assert(state); @@ -237,15 +232,15 @@ static bool bson_parse_get_object_element_wrapped_size( state->offset++; state->dom_size += sizeof(struct json_string_s); - if (!bson_parse_get_object_key_size(state)) { + if (!M_GetObjectKeySize(state)) { return false; } state->dom_size += sizeof(struct json_value_s); - return bson_parse_get_value_size(state, marker); + return M_GetValueSize(state, marker); } -static bool bson_parse_get_object_size(struct bson_parse_state_s *state) +static bool M_GetObjectSize(struct bson_parse_state_s *state) { assert(state); @@ -259,7 +254,7 @@ static bool bson_parse_get_object_size(struct bson_parse_state_s *state) while (state->offset < start_offset + size - 1) { state->dom_size += sizeof(struct json_object_element_s); - if (!bson_parse_get_object_element_wrapped_size(state)) { + if (!M_GetObjectElementWrappedSize(state)) { return false; } } @@ -276,46 +271,45 @@ static bool bson_parse_get_object_size(struct bson_parse_state_s *state) return true; } -static bool bson_parse_get_object_value_size(struct bson_parse_state_s *state) +static bool M_GetObjectValueSize(struct bson_parse_state_s *state) { assert(state); state->dom_size += sizeof(struct json_object_s); - return bson_parse_get_object_size(state); + return M_GetObjectSize(state); } -static bool bson_parse_get_value_size( - struct bson_parse_state_s *state, uint8_t marker) +static bool M_GetValueSize(struct bson_parse_state_s *state, uint8_t marker) { assert(state); switch (marker) { case 0x01: - return bson_parse_get_double_value_size(state); + return M_GetDoubleValueSize(state); case 0x02: - return bson_parse_get_string_value_size(state); + return M_GetStringValueSize(state); case 0x03: - return bson_parse_get_object_value_size(state); + return M_GetObjectValueSize(state); case 0x04: - return bson_parse_get_array_value_size(state); + return M_GetArrayValueSize(state); case 0x0A: - return bson_parse_get_null_value_size(state); + return M_GetNullValueSize(state); case 0x08: - return bson_parse_get_bool_value_size(state); + return M_GetBoolValueSize(state); case 0x10: - return bson_parse_get_int32_value_size(state); + return M_GetInt32ValueSize(state); default: state->error = bson_parse_error_invalid_value; return false; } } -static bool bson_parse_get_root_size(struct bson_parse_state_s *state) +static bool m_GetRootSize(struct bson_parse_state_s *state) { // assume the root element to be an object state->dom_size += sizeof(struct json_value_s); - return bson_parse_get_object_value_size(state); + return M_GetObjectValueSize(state); } -static void bson_parse_object_key( +static void M_HandleObjectKey( struct bson_parse_state_s *state, struct json_string_s *string) { assert(state); @@ -331,7 +325,7 @@ static void bson_parse_object_key( state->data += size; } -static void bson_parse_null_value( +static void M_HandleNullValue( struct bson_parse_state_s *state, struct json_value_s *value) { assert(state); @@ -340,7 +334,7 @@ static void bson_parse_null_value( value->payload = json_null; } -static void bson_parse_bool_value( +static void M_HandleBoolValue( struct bson_parse_state_s *state, struct json_value_s *value) { assert(state); @@ -361,7 +355,7 @@ static void bson_parse_bool_value( state->offset++; } -static void bson_parse_int32_value( +static void M_HandleInt32Value( struct bson_parse_state_s *state, struct json_value_s *value) { assert(state); @@ -384,7 +378,7 @@ static void bson_parse_int32_value( value->payload = number; } -static void bson_parse_double_value( +static void M_HandleDoubleValue( struct bson_parse_state_s *state, struct json_value_s *value) { assert(state); @@ -416,7 +410,7 @@ static void bson_parse_double_value( value->payload = number; } -static void bson_parse_string_value( +static void M_HandleStringValue( struct bson_parse_state_s *state, struct json_value_s *value) { assert(state); @@ -441,7 +435,7 @@ static void bson_parse_string_value( value->payload = string; } -static void bson_parse_array_element_wrapped( +static void M_HandleArrayElementWrapped( struct bson_parse_state_s *state, struct json_array_element_s *element) { assert(state); @@ -455,7 +449,7 @@ static void bson_parse_array_element_wrapped( struct json_string_s *key = (struct json_string_s *)state->dom; key->ref_count = 1; state->dom += sizeof(struct json_string_s); - bson_parse_object_key(state, key); + M_HandleObjectKey(state, key); struct json_value_s *value = (struct json_value_s *)state->dom; value->ref_count = 1; @@ -463,10 +457,10 @@ static void bson_parse_array_element_wrapped( element->value = value; - bson_parse_value(state, value, marker); + M_HandleValue(state, value, marker); } -static void bson_parse_array( +static void M_HandleArray( struct bson_parse_state_s *state, struct json_array_s *array) { assert(state); @@ -490,7 +484,7 @@ static void bson_parse_array( previous->next = element; } previous = element; - bson_parse_array_element_wrapped(state, element); + M_HandleArrayElementWrapped(state, element); count++; } if (previous) { @@ -506,7 +500,7 @@ static void bson_parse_array( state->offset++; } -static void bson_parse_array_value( +static void M_HandleArrayValue( struct bson_parse_state_s *state, struct json_value_s *value) { assert(state); @@ -516,13 +510,13 @@ static void bson_parse_array_value( array->ref_count = 1; state->dom += sizeof(struct json_array_s); - bson_parse_array(state, array); + M_HandleArray(state, array); value->type = json_type_array; value->payload = array; } -static void bson_parse_object_element_wrapped( +static void M_HandleObjectElementWrapped( struct bson_parse_state_s *state, struct json_object_element_s *element) { assert(state); @@ -535,7 +529,7 @@ static void bson_parse_object_element_wrapped( struct json_string_s *key = (struct json_string_s *)state->dom; key->ref_count = 1; state->dom += sizeof(struct json_string_s); - bson_parse_object_key(state, key); + M_HandleObjectKey(state, key); struct json_value_s *value = (struct json_value_s *)state->dom; value->ref_count = 1; @@ -544,10 +538,10 @@ static void bson_parse_object_element_wrapped( element->name = key; element->value = value; - bson_parse_value(state, value, marker); + M_HandleValue(state, value, marker); } -static void bson_parse_object( +static void M_HandleObject( struct bson_parse_state_s *state, struct json_object_s *object) { assert(state); @@ -571,7 +565,7 @@ static void bson_parse_object( previous->next = element; } previous = element; - bson_parse_object_element_wrapped(state, element); + M_HandleObjectElementWrapped(state, element); count++; } if (previous) { @@ -587,7 +581,7 @@ static void bson_parse_object( state->offset++; } -static void bson_parse_object_value( +static void M_HandleObjectValue( struct bson_parse_state_s *state, struct json_value_s *value) { assert(state); @@ -597,13 +591,13 @@ static void bson_parse_object_value( object->ref_count = 1; state->dom += sizeof(struct json_object_s); - bson_parse_object(state, object); + M_HandleObject(state, object); value->type = json_type_object; value->payload = object; } -static void bson_parse_value( +static void M_HandleValue( struct bson_parse_state_s *state, struct json_value_s *value, uint8_t marker) { @@ -611,25 +605,25 @@ static void bson_parse_value( assert(value); switch (marker) { case 0x01: - bson_parse_double_value(state, value); + M_HandleDoubleValue(state, value); break; case 0x02: - bson_parse_string_value(state, value); + M_HandleStringValue(state, value); break; case 0x03: - bson_parse_object_value(state, value); + M_HandleObjectValue(state, value); break; case 0x04: - bson_parse_array_value(state, value); + M_HandleArrayValue(state, value); break; case 0x0A: - bson_parse_null_value(state, value); + M_HandleNullValue(state, value); break; case 0x08: - bson_parse_bool_value(state, value); + M_HandleBoolValue(state, value); break; case 0x10: - bson_parse_int32_value(state, value); + M_HandleInt32Value(state, value); break; default: assert(0); @@ -665,7 +659,7 @@ struct json_value_s *bson_parse_ex( state.dom_size = 0; state.data_size = 0; - if (bson_parse_get_root_size(&state)) { + if (m_GetRootSize(&state)) { if (state.offset != state.size) { state.error = bson_parse_error_unexpected_trailing_bytes; } @@ -693,7 +687,7 @@ struct json_value_s *bson_parse_ex( value = (struct json_value_s *)state.dom; value->ref_count = 0; state.dom += sizeof(struct json_value_s); - bson_parse_object_value(&state, value); + M_HandleObjectValue(&state, value); assert(state.dom == allocation + state.dom_size); assert(state.data == allocation + state.dom_size + state.data_size); diff --git a/src/json/bson_write.c b/src/json/bson_write.c index 34cd7fe..7cc7a63 100644 --- a/src/json/bson_write.c +++ b/src/json/bson_write.c @@ -11,59 +11,53 @@ #include #include -static bool bson_write_get_marker_size(size_t *size, const char *key); -static bool bson_write_get_null_wrapped(size_t *size, const char *key); -static bool bson_write_get_boolean_wrapped_size(size_t *size, const char *key); -static bool bson_write_get_int32_size(size_t *size); -static bool bson_write_get_int32_wrapped_size(size_t *size, const char *key); -static bool bson_write_get_double_size(size_t *size); -static bool bson_write_get_double_wrapped_size(size_t *size, const char *key); -static bool bson_write_get_number_wrapped_size( +static bool M_GetMarkerSize(size_t *size, const char *key); +static bool M_GetNullWrappedSize(size_t *size, const char *key); +static bool M_GetBoolWrappedSize(size_t *size, const char *key); +static bool M_GetInt32Size(size_t *size); +static bool M_GetInt32WrappedSize(size_t *size, const char *key); +static bool M_GetDoubleSize(size_t *size); +static bool M_GetDoubleWrappedSize(size_t *size, const char *key); +static bool M_GetNumberWrappedSize( size_t *size, const char *key, const struct json_number_s *number); -static bool bson_write_get_string_size( - size_t *size, const struct json_string_s *string); -static bool bson_write_get_string_wrapped_size( +static bool M_GetStringSize(size_t *size, const struct json_string_s *string); +static bool M_GetStringWrappedSize( size_t *size, const char *key, const struct json_string_s *string); -static bool bson_write_get_array_size( - size_t *size, const struct json_array_s *array); -static bool bson_write_get_array_wrapped_size( +static bool M_GetArraySize(size_t *size, const struct json_array_s *array); +static bool M_GetArrayWrappedSize( size_t *size, const char *key, const struct json_array_s *array); -static bool bson_write_get_object_size( - size_t *size, const struct json_object_s *object); -static bool bson_write_get_object_wrapped_size( +static bool M_GetObjectSize(size_t *size, const struct json_object_s *object); +static bool M_GetObjectWrappedSize( size_t *size, const char *key, const struct json_object_s *object); -static bool bson_write_get_value_size( - size_t *size, const struct json_value_s *value); -static bool bson_write_get_value_wrapped_size( +static bool M_GetValueSize(size_t *size, const struct json_value_s *value); +static bool M_GetValueWrappedSize( size_t *size, const char *key, const struct json_value_s *value); -static char *bson_write_marker( - char *data, const char *key, const uint8_t marker); -static char *bson_write_null_wrapped(char *data, const char *key); -static char *bson_write_boolean_wrapped( - char *data, const char *key, bool value); -static char *bson_write_int32(char *data, const int32_t value); -static char *bson_write_int32_wrapped( +static char *M_WriteMarker(char *data, const char *key, const uint8_t marker); +static char *M_WriteNullWrapped(char *data, const char *key); +static char *M_WriteBoolWrapped(char *data, const char *key, bool value); +static char *M_WriteInt32(char *data, const int32_t value); +static char *M_WriteInt32Wrapped( char *data, const char *key, const int32_t value); -static char *bson_write_double(char *data, const double value); -static char *bson_write_double_wrapped( +static char *M_WriteDouble(char *data, const double value); +static char *M_WriteDoubleWrapped( char *data, const char *key, const double value); -static char *bson_write_number_wrapped( +static char *M_WriteNumberWrapped( char *data, const char *key, const struct json_number_s *number); -static char *bson_write_string(char *data, const struct json_string_s *string); -static char *bson_write_string_wrapped( +static char *M_WriteString(char *data, const struct json_string_s *string); +static char *M_WriteStringWrapped( char *data, const char *key, const struct json_string_s *string); -static char *bson_write_array(char *data, const struct json_array_s *array); -static char *bson_write_array_wrapped( +static char *M_WriteArray(char *data, const struct json_array_s *array); +static char *M_WriteArrayWrapped( char *data, const char *key, const struct json_array_s *array); -static char *bson_write_object(char *data, const struct json_object_s *object); -static char *bson_write_object_wrapped( +static char *M_WriteObject(char *data, const struct json_object_s *object); +static char *M_WriteObjectWrapped( char *data, const char *key, const struct json_object_s *object); -static char *bson_write_value(char *data, const struct json_value_s *value); -static char *bson_write_value_wrapped( +static char *M_WriteValue(char *data, const struct json_value_s *value); +static char *M_WriteValueWrapped( char *data, const char *key, const struct json_value_s *value); -static bool bson_write_get_marker_size(size_t *size, const char *key) +static bool M_GetMarkerSize(size_t *size, const char *key) { assert(size); assert(key); @@ -73,65 +67,65 @@ static bool bson_write_get_marker_size(size_t *size, const char *key) return true; } -static bool bson_write_get_null_wrapped_size(size_t *size, const char *key) +static bool M_GetNullWrappedSize(size_t *size, const char *key) { assert(size); assert(key); - return bson_write_get_marker_size(size, key); + return M_GetMarkerSize(size, key); } -static bool bson_write_get_boolean_wrapped_size(size_t *size, const char *key) +static bool M_GetBoolWrappedSize(size_t *size, const char *key) { assert(size); assert(key); - if (!bson_write_get_marker_size(size, key)) { + if (!M_GetMarkerSize(size, key)) { return false; } *size += 1; return true; } -static bool bson_write_get_int32_size(size_t *size) +static bool M_GetInt32Size(size_t *size) { assert(size); *size += sizeof(int32_t); return true; } -static bool bson_write_get_int32_wrapped_size(size_t *size, const char *key) +static bool M_GetInt32WrappedSize(size_t *size, const char *key) { assert(size); assert(key); - if (!bson_write_get_marker_size(size, key)) { + if (!M_GetMarkerSize(size, key)) { return false; } - if (!bson_write_get_int32_size(size)) { + if (!M_GetInt32Size(size)) { return false; } return true; } -static bool bson_write_get_double_size(size_t *size) +static bool M_GetDoubleSize(size_t *size) { assert(size); *size += sizeof(double); return true; } -static bool bson_write_get_double_wrapped_size(size_t *size, const char *key) +static bool M_GetDoubleWrappedSize(size_t *size, const char *key) { assert(size); assert(key); - if (!bson_write_get_marker_size(size, key)) { + if (!M_GetMarkerSize(size, key)) { return false; } - if (!bson_write_get_double_size(size)) { + if (!M_GetDoubleSize(size)) { return false; } return true; } -static bool bson_write_get_number_wrapped_size( +static bool M_GetNumberWrappedSize( size_t *size, const char *key, const struct json_number_s *number) { assert(size); @@ -142,7 +136,7 @@ static bool bson_write_get_number_wrapped_size( // hexadecimal numbers if (number->number_size >= 2 && (str[1] == 'x' || str[1] == 'X')) { - return bson_write_get_int32_wrapped_size(size, key); + return M_GetInt32WrappedSize(size, key); } // skip leading sign @@ -153,21 +147,20 @@ static bool bson_write_get_number_wrapped_size( if (!strcmp(str, "Infinity")) { // BSON does not support Infinity. - return bson_write_get_double_wrapped_size(size, key); + return M_GetDoubleWrappedSize(size, key); } else if (!strcmp(str, "NaN")) { // BSON does not support NaN. - return bson_write_get_int32_wrapped_size(size, key); + return M_GetInt32WrappedSize(size, key); } else if (strchr(str, '.')) { - return bson_write_get_double_wrapped_size(size, key); + return M_GetDoubleWrappedSize(size, key); } else { - return bson_write_get_int32_wrapped_size(size, key); + return M_GetInt32WrappedSize(size, key); } return false; } -static bool bson_write_get_string_size( - size_t *size, const struct json_string_s *string) +static bool M_GetStringSize(size_t *size, const struct json_string_s *string) { assert(size); assert(string); @@ -177,23 +170,22 @@ static bool bson_write_get_string_size( return true; } -static bool bson_write_get_string_wrapped_size( +static bool M_GetStringWrappedSize( size_t *size, const char *key, const struct json_string_s *string) { assert(size); assert(key); assert(string); - if (!bson_write_get_marker_size(size, key)) { + if (!M_GetMarkerSize(size, key)) { return false; } - if (!bson_write_get_string_size(size, string)) { + if (!M_GetStringSize(size, string)) { return false; } return true; } -static bool bson_write_get_array_size( - size_t *size, const struct json_array_s *array) +static bool M_GetArraySize(size_t *size, const struct json_array_s *array) { assert(size); assert(array); @@ -204,7 +196,7 @@ static bool bson_write_get_array_size( element != json_null; element = element->next) { sprintf(key, "%d", idx); idx++; - if (!bson_write_get_value_wrapped_size(size, key, element->value)) { + if (!M_GetValueWrappedSize(size, key, element->value)) { return false; } } @@ -212,30 +204,29 @@ static bool bson_write_get_array_size( return true; } -static bool bson_write_get_array_wrapped_size( +static bool M_GetArrayWrappedSize( size_t *size, const char *key, const struct json_array_s *array) { assert(size); assert(key); assert(array); - if (!bson_write_get_marker_size(size, key)) { + if (!M_GetMarkerSize(size, key)) { return false; } - if (!bson_write_get_array_size(size, array)) { + if (!M_GetArraySize(size, array)) { return false; } return true; } -static bool bson_write_get_object_size( - size_t *size, const struct json_object_s *object) +static bool M_GetObjectSize(size_t *size, const struct json_object_s *object) { assert(size); assert(object); *size += sizeof(int32_t); // object size for (struct json_object_element_s *element = object->start; element != json_null; element = element->next) { - if (!bson_write_get_value_wrapped_size( + if (!M_GetValueWrappedSize( size, element->name->string, element->value)) { return false; } @@ -244,40 +235,37 @@ static bool bson_write_get_object_size( return true; } -static bool bson_write_get_object_wrapped_size( +static bool M_GetObjectWrappedSize( size_t *size, const char *key, const struct json_object_s *object) { assert(size); assert(key); assert(object); - if (!bson_write_get_marker_size(size, key)) { + if (!M_GetMarkerSize(size, key)) { return false; } - if (!bson_write_get_object_size(size, object)) { + if (!M_GetObjectSize(size, object)) { return false; } return true; } -static bool bson_write_get_value_size( - size_t *size, const struct json_value_s *value) +static bool M_GetValueSize(size_t *size, const struct json_value_s *value) { assert(size); assert(value); switch (value->type) { case json_type_array: - return bson_write_get_array_size( - size, (struct json_array_s *)value->payload); + return M_GetArraySize(size, (struct json_array_s *)value->payload); case json_type_object: - return bson_write_get_object_size( - size, (struct json_object_s *)value->payload); + return M_GetObjectSize(size, (struct json_object_s *)value->payload); default: LOG_ERROR("Bad BSON root element: %d", value->type); } return false; } -static bool bson_write_get_value_wrapped_size( +static bool M_GetValueWrappedSize( size_t *size, const char *key, const struct json_value_s *value) { assert(size); @@ -285,22 +273,22 @@ static bool bson_write_get_value_wrapped_size( assert(value); switch (value->type) { case json_type_null: - return bson_write_get_null_wrapped_size(size, key); + return M_GetNullWrappedSize(size, key); case json_type_true: - return bson_write_get_boolean_wrapped_size(size, key); + return M_GetBoolWrappedSize(size, key); case json_type_false: - return bson_write_get_boolean_wrapped_size(size, key); + return M_GetBoolWrappedSize(size, key); case json_type_number: - return bson_write_get_number_wrapped_size( + return M_GetNumberWrappedSize( size, key, (struct json_number_s *)value->payload); case json_type_string: - return bson_write_get_string_wrapped_size( + return M_GetStringWrappedSize( size, key, (struct json_string_s *)value->payload); case json_type_array: - return bson_write_get_array_wrapped_size( + return M_GetArrayWrappedSize( size, key, (struct json_array_s *)value->payload); case json_type_object: - return bson_write_get_object_wrapped_size( + return M_GetObjectWrappedSize( size, key, (struct json_object_s *)value->payload); default: LOG_ERROR("Unknown JSON element: %d", value->type); @@ -308,8 +296,7 @@ static bool bson_write_get_value_wrapped_size( } } -static char *bson_write_marker( - char *data, const char *key, const uint8_t marker) +static char *M_WriteMarker(char *data, const char *key, const uint8_t marker) { assert(data); assert(key); @@ -320,23 +307,23 @@ static char *bson_write_marker( return data; } -static char *bson_write_null_wrapped(char *data, const char *key) +static char *M_WriteNullWrapped(char *data, const char *key) { assert(data); assert(key); - return bson_write_marker(data, key, '\x0A'); + return M_WriteMarker(data, key, '\x0A'); } -static char *bson_write_boolean_wrapped(char *data, const char *key, bool value) +static char *M_WriteBoolWrapped(char *data, const char *key, bool value) { assert(data); assert(key); - data = bson_write_marker(data, key, '\x08'); + data = M_WriteMarker(data, key, '\x08'); *(int8_t *)data++ = (int8_t)value; return data; } -static char *bson_write_int32(char *data, const int32_t value) +static char *M_WriteInt32(char *data, const int32_t value) { assert(data); *(int32_t *)data = value; @@ -344,16 +331,16 @@ static char *bson_write_int32(char *data, const int32_t value) return data; } -static char *bson_write_int32_wrapped( +static char *M_WriteInt32Wrapped( char *data, const char *key, const int32_t value) { assert(data); assert(key); - data = bson_write_marker(data, key, '\x10'); - return bson_write_int32(data, value); + data = M_WriteMarker(data, key, '\x10'); + return M_WriteInt32(data, value); } -static char *bson_write_double(char *data, const double value) +static char *M_WriteDouble(char *data, const double value) { assert(data); *(double *)data = value; @@ -361,16 +348,16 @@ static char *bson_write_double(char *data, const double value) return data; } -static char *bson_write_double_wrapped( +static char *M_WriteDoubleWrapped( char *data, const char *key, const double value) { assert(data); assert(key); - data = bson_write_marker(data, key, '\x01'); - return bson_write_double(data, value); + data = M_WriteMarker(data, key, '\x01'); + return M_WriteDouble(data, value); } -static char *bson_write_number_wrapped( +static char *M_WriteNumberWrapped( char *data, const char *key, const struct json_number_s *number) { assert(data); @@ -380,7 +367,7 @@ static char *bson_write_number_wrapped( // hexadecimal numbers if (number->number_size >= 2 && (str[1] == 'x' || str[1] == 'X')) { - return bson_write_int32_wrapped( + return M_WriteInt32Wrapped( data, key, json_strtoumax(number->number, json_null, 0)); } @@ -392,20 +379,20 @@ static char *bson_write_number_wrapped( if (!strcmp(str, "Infinity")) { // BSON does not support Infinity. - return bson_write_double_wrapped(data, key, DBL_MAX); + return M_WriteDoubleWrapped(data, key, DBL_MAX); } else if (!strcmp(str, "NaN")) { // BSON does not support NaN. - return bson_write_int32_wrapped(data, key, 0); + return M_WriteInt32Wrapped(data, key, 0); } else if (strchr(str, '.')) { - return bson_write_double_wrapped(data, key, atof(number->number)); + return M_WriteDoubleWrapped(data, key, atof(number->number)); } else { - return bson_write_int32_wrapped(data, key, atoi(number->number)); + return M_WriteInt32Wrapped(data, key, atoi(number->number)); } return data; } -static char *bson_write_string(char *data, const struct json_string_s *string) +static char *M_WriteString(char *data, const struct json_string_s *string) { assert(data); assert(string); @@ -417,18 +404,18 @@ static char *bson_write_string(char *data, const struct json_string_s *string) return data; } -static char *bson_write_string_wrapped( +static char *M_WriteStringWrapped( char *data, const char *key, const struct json_string_s *string) { assert(data); assert(key); assert(string); - data = bson_write_marker(data, key, '\x02'); - data = bson_write_string(data, string); + data = M_WriteMarker(data, key, '\x02'); + data = M_WriteString(data, string); return data; } -static char *bson_write_array(char *data, const struct json_array_s *array) +static char *M_WriteArray(char *data, const struct json_array_s *array) { assert(data); assert(array); @@ -440,25 +427,25 @@ static char *bson_write_array(char *data, const struct json_array_s *array) element != json_null; element = element->next) { sprintf(key, "%d", idx); idx++; - data = bson_write_value_wrapped(data, key, element->value); + data = M_WriteValueWrapped(data, key, element->value); } *data++ = '\0'; *(int32_t *)old = data - old; return data; } -static char *bson_write_array_wrapped( +static char *M_WriteArrayWrapped( char *data, const char *key, const struct json_array_s *array) { assert(data); assert(key); assert(array); - data = bson_write_marker(data, key, '\x04'); - data = bson_write_array(data, array); + data = M_WriteMarker(data, key, '\x04'); + data = M_WriteArray(data, array); return data; } -static char *bson_write_object(char *data, const struct json_object_s *object) +static char *M_WriteObject(char *data, const struct json_object_s *object) { assert(data); assert(object); @@ -466,35 +453,34 @@ static char *bson_write_object(char *data, const struct json_object_s *object) data += sizeof(int32_t); for (struct json_object_element_s *element = object->start; element != json_null; element = element->next) { - data = bson_write_value_wrapped( - data, element->name->string, element->value); + data = M_WriteValueWrapped(data, element->name->string, element->value); } *data++ = '\0'; *(int32_t *)old = data - old; return data; } -static char *bson_write_object_wrapped( +static char *M_WriteObjectWrapped( char *data, const char *key, const struct json_object_s *object) { assert(data); assert(key); assert(object); - data = bson_write_marker(data, key, '\x03'); - data = bson_write_object(data, object); + data = M_WriteMarker(data, key, '\x03'); + data = M_WriteObject(data, object); return data; } -static char *bson_write_value(char *data, const struct json_value_s *value) +static char *M_WriteValue(char *data, const struct json_value_s *value) { assert(data); assert(value); switch (value->type) { case json_type_array: - data = bson_write_array(data, (struct json_array_s *)value->payload); + data = M_WriteArray(data, (struct json_array_s *)value->payload); break; case json_type_object: - data = bson_write_object(data, (struct json_object_s *)value->payload); + data = M_WriteObject(data, (struct json_object_s *)value->payload); break; default: assert(0); @@ -502,7 +488,7 @@ static char *bson_write_value(char *data, const struct json_value_s *value) return data; } -static char *bson_write_value_wrapped( +static char *M_WriteValueWrapped( char *data, const char *key, const struct json_value_s *value) { assert(data); @@ -510,22 +496,22 @@ static char *bson_write_value_wrapped( assert(value); switch (value->type) { case json_type_null: - return bson_write_null_wrapped(data, key); + return M_WriteNullWrapped(data, key); case json_type_true: - return bson_write_boolean_wrapped(data, key, true); + return M_WriteBoolWrapped(data, key, true); case json_type_false: - return bson_write_boolean_wrapped(data, key, false); + return M_WriteBoolWrapped(data, key, false); case json_type_number: - return bson_write_number_wrapped( + return M_WriteNumberWrapped( data, key, (struct json_number_s *)value->payload); case json_type_string: - return bson_write_string_wrapped( + return M_WriteStringWrapped( data, key, (struct json_string_s *)value->payload); case json_type_array: - return bson_write_array_wrapped( + return M_WriteArrayWrapped( data, key, (struct json_array_s *)value->payload); case json_type_object: - return bson_write_object_wrapped( + return M_WriteObjectWrapped( data, key, (struct json_object_s *)value->payload); default: return json_null; @@ -541,12 +527,12 @@ void *bson_write(const struct json_value_s *value, size_t *out_size) } size_t size = 0; - if (!bson_write_get_value_size(&size, value)) { + if (!M_GetValueSize(&size, value)) { return json_null; } char *data = Memory_Alloc(size); - char *data_end = bson_write_value(data, value); + char *data_end = M_WriteValue(data, value); assert((size_t)(data_end - data) == size); if (out_size != json_null) { diff --git a/src/json/json_parse.c b/src/json/json_parse.c index 4750b31..409062b 100644 --- a/src/json/json_parse.c +++ b/src/json/json_parse.c @@ -16,13 +16,13 @@ struct json_parse_state_s { size_t error; }; -static int json_hexadecimal_digit(const char c); -static int json_hexadecimal_value( +static int M_HexDigit(const char c); +static int M_HexValue( const char *c, const unsigned long size, unsigned long *result); -static int json_skip_whitespace(struct json_parse_state_s *state); -static int json_skip_c_style_comments(struct json_parse_state_s *state); -static int json_skip_all_skippables(struct json_parse_state_s *state); +static int M_SkipWhitespace(struct json_parse_state_s *state); +static int M_SkipCStyleComments(struct json_parse_state_s *state); +static int M_SkipAllSkippables(struct json_parse_state_s *state); static int json_get_value_size( struct json_parse_state_s *state, int is_global_object); @@ -50,7 +50,7 @@ static void json_parse_array( static void json_parse_number( struct json_parse_state_s *state, struct json_number_s *number); -static int json_hexadecimal_digit(const char c) +static int M_HexDigit(const char c) { if ('0' <= c && c <= '9') { return c - '0'; @@ -64,7 +64,7 @@ static int json_hexadecimal_digit(const char c) return -1; } -static int json_hexadecimal_value( +static int M_HexValue( const char *c, const unsigned long size, unsigned long *result) { const char *p; @@ -77,7 +77,7 @@ static int json_hexadecimal_value( *result = 0; for (p = c; (unsigned long)(p - c) < size; ++p) { *result <<= 4; - digit = json_hexadecimal_digit(*p); + digit = M_HexDigit(*p); if (digit < 0 || digit > 15) { return 0; } @@ -86,7 +86,7 @@ static int json_hexadecimal_value( return 1; } -static int json_skip_whitespace(struct json_parse_state_s *state) +static int M_SkipWhitespace(struct json_parse_state_s *state) { size_t offset = state->offset; const size_t size = state->size; @@ -128,7 +128,7 @@ static int json_skip_whitespace(struct json_parse_state_s *state) return 1; } -static int json_skip_c_style_comments(struct json_parse_state_s *state) +static int M_SkipCStyleComments(struct json_parse_state_s *state) { /* do we have a comment?. */ if ('/' == state->src[state->offset]) { @@ -192,11 +192,11 @@ static int json_skip_c_style_comments(struct json_parse_state_s *state) return 0; } -static int json_skip_all_skippables(struct json_parse_state_s *state) +static int M_SkipAllSkippables(struct json_parse_state_s *state) { /* skip all whitespace and other skippables until there are none left. note * that the previous version suffered from read past errors should. the - * stream end on json_skip_c_style_comments eg. '{"a" ' with comments flag. + * stream end on M_SkipCStyleComments eg. '{"a" ' with comments flag. */ int did_consume = 0; @@ -209,7 +209,7 @@ static int json_skip_all_skippables(struct json_parse_state_s *state) return 1; } - did_consume = json_skip_whitespace(state); + did_consume = M_SkipWhitespace(state); /* This should really be checked on access, not in front of every * call. @@ -219,7 +219,7 @@ static int json_skip_all_skippables(struct json_parse_state_s *state) return 1; } - did_consume |= json_skip_c_style_comments(state); + did_consume |= M_SkipCStyleComments(state); } while (0 != did_consume); } else { do { @@ -228,7 +228,7 @@ static int json_skip_all_skippables(struct json_parse_state_s *state) return 1; } - did_consume = json_skip_whitespace(state); + did_consume = M_SkipWhitespace(state); } while (0 != did_consume); } @@ -320,7 +320,7 @@ static int json_get_string_size(struct json_parse_state_s *state, size_t is_key) } codepoint = 0; - if (!json_hexadecimal_value(&src[offset + 1], 4, &codepoint)) { + if (!M_HexValue(&src[offset + 1], 4, &codepoint)) { /* escaped unicode sequences must contain 4 hexadecimal * digits! */ state->error = @@ -501,8 +501,7 @@ static int json_get_object_size( if (is_global_object) { /* if we found an opening '{' of an object, we actually have a normal * JSON object at the root of the DOM... */ - if (!json_skip_all_skippables(state) - && '{' == state->src[state->offset]) { + if (!M_SkipAllSkippables(state) && '{' == state->src[state->offset]) { /* . and we don't actually have a global object after all! */ is_global_object = 0; } @@ -527,7 +526,7 @@ static int json_get_object_size( do { if (!is_global_object) { - if (json_skip_all_skippables(state)) { + if (M_SkipAllSkippables(state)) { state->error = json_parse_error_premature_end_of_buffer; return 1; } @@ -544,7 +543,7 @@ static int json_get_object_size( } else { /* we don't require brackets, so that means the object ends when the * input stream ends! */ - if (json_skip_all_skippables(state)) { + if (M_SkipAllSkippables(state)) { break; } } @@ -570,7 +569,7 @@ static int json_get_object_size( if (json_parse_flags_allow_trailing_comma & flags_bitset) { continue; } else { - if (json_skip_all_skippables(state)) { + if (M_SkipAllSkippables(state)) { state->error = json_parse_error_premature_end_of_buffer; return 1; } @@ -583,7 +582,7 @@ static int json_get_object_size( return 1; } - if (json_skip_all_skippables(state)) { + if (M_SkipAllSkippables(state)) { state->error = json_parse_error_premature_end_of_buffer; return 1; } @@ -604,7 +603,7 @@ static int json_get_object_size( /* skip colon. */ state->offset++; - if (json_skip_all_skippables(state)) { + if (M_SkipAllSkippables(state)) { state->error = json_parse_error_premature_end_of_buffer; return 1; } @@ -649,7 +648,7 @@ static int json_get_array_size(struct json_parse_state_s *state) state->dom_size += sizeof(struct json_array_s); while (state->offset < size) { - if (json_skip_all_skippables(state)) { + if (M_SkipAllSkippables(state)) { state->error = json_parse_error_premature_end_of_buffer; return 1; } @@ -680,7 +679,7 @@ static int json_get_array_size(struct json_parse_state_s *state) allow_comma = 0; continue; } else { - if (json_skip_all_skippables(state)) { + if (M_SkipAllSkippables(state)) { state->error = json_parse_error_premature_end_of_buffer; return 1; } @@ -925,7 +924,7 @@ static int json_get_value_size( if (is_global_object) { return json_get_object_size(state, /* is_global_object = */ 1); } else { - if (json_skip_all_skippables(state)) { + if (M_SkipAllSkippables(state)) { state->error = json_parse_error_premature_end_of_buffer; return 1; } @@ -1045,7 +1044,7 @@ static void json_parse_string( return; /* we cannot ever reach here. */ case 'u': { codepoint = 0; - if (!json_hexadecimal_value(&src[offset], 4, &codepoint)) { + if (!M_HexValue(&src[offset], 4, &codepoint)) { return; /* this shouldn't happen as the value was already * validated. */ @@ -1230,7 +1229,7 @@ static void json_parse_object( state->offset++; } - (void)json_skip_all_skippables(state); + M_SkipAllSkippables(state); /* reset elements. */ elements = 0; @@ -1241,7 +1240,7 @@ static void json_parse_object( struct json_value_s *value = json_null; if (!is_global_object) { - (void)json_skip_all_skippables(state); + M_SkipAllSkippables(state); if ('}' == src[state->offset]) { /* skip trailing '}'. */ @@ -1251,7 +1250,7 @@ static void json_parse_object( break; } } else { - if (json_skip_all_skippables(state)) { + if (M_SkipAllSkippables(state)) { /* global object ends when the file ends! */ break; } @@ -1300,12 +1299,12 @@ static void json_parse_object( (void)json_parse_key(state, string); - (void)json_skip_all_skippables(state); + M_SkipAllSkippables(state); /* skip colon or equals. */ state->offset++; - (void)json_skip_all_skippables(state); + M_SkipAllSkippables(state); if (json_parse_flags_allow_location_information & flags_bitset) { struct json_value_ex_s *value_ex = @@ -1336,7 +1335,7 @@ static void json_parse_object( previous->next = json_null; } - if (0 == elements) { + if (elements == 0) { object->start = json_null; } @@ -1356,7 +1355,7 @@ static void json_parse_array( /* skip leading '['. */ state->offset++; - (void)json_skip_all_skippables(state); + M_SkipAllSkippables(state); /* reset elements. */ elements = 0; @@ -1365,7 +1364,7 @@ static void json_parse_array( struct json_array_element_s *element = json_null; struct json_value_s *value = json_null; - (void)json_skip_all_skippables(state); + M_SkipAllSkippables(state); if (']' == src[state->offset]) { /* skip trailing ']'. */ @@ -1428,7 +1427,7 @@ static void json_parse_array( previous->next = json_null; } - if (0 == elements) { + if (elements == 0) { array->start = json_null; } @@ -1538,7 +1537,7 @@ static void json_parse_value( const size_t size = state->size; size_t offset; - (void)json_skip_all_skippables(state); + M_SkipAllSkippables(state); /* cache offset now. */ offset = state->offset; @@ -1684,8 +1683,8 @@ struct json_value_s *json_parse_ex( &state, (int)(json_parse_flags_allow_global_object & state.flags_bitset)); - if (0 == input_error) { - json_skip_all_skippables(&state); + if (input_error == 0) { + M_SkipAllSkippables(&state); if (state.offset != state.size) { /* our parsing didn't have an error, but there are characters diff --git a/src/json/json_write.c b/src/json/json_write.c index 2817a34..cbde566 100644 --- a/src/json/json_write.c +++ b/src/json/json_write.c @@ -2,45 +2,42 @@ #include "memory.h" -static int json_write_minified_get_value_size( +static int M_GetValueSize_Minified( const struct json_value_s *value, size_t *size); -static int json_write_get_number_size( - const struct json_number_s *number, size_t *size); -static int json_write_get_string_size( - const struct json_string_s *string, size_t *size); -static int json_write_minified_get_array_size( +static int M_GetNumberSize(const struct json_number_s *number, size_t *size); +static int M_GetStringSize(const struct json_string_s *string, size_t *size); +static int M_GetArraySize_Minified( const struct json_array_s *array, size_t *size); -static int json_write_minified_get_object_size( +static int M_GetObjectSize_Minified( const struct json_object_s *object, size_t *size); -static char *json_write_minified_value( +static char *M_WriteValue_Minified( const struct json_value_s *value, char *data); -static char *json_write_number(const struct json_number_s *number, char *data); -static char *json_write_string(const struct json_string_s *string, char *data); -static char *json_write_minified_array( +static char *M_WriteNumber(const struct json_number_s *number, char *data); +static char *M_WriteString(const struct json_string_s *string, char *data); +static char *M_WriteArray_Minified( const struct json_array_s *array, char *data); -static char *json_write_minified_object( +static char *M_WriteObject_Minified( const struct json_object_s *object, char *data); -static int json_write_pretty_get_value_size( +static int M_GetValueSize_Pretty( const struct json_value_s *value, size_t depth, size_t indent_size, size_t newline_size, size_t *size); -static int json_write_pretty_get_array_size( +static int M_GetArraySize_Pretty( const struct json_array_s *array, size_t depth, size_t indent_size, size_t newline_size, size_t *size); -static int json_write_pretty_get_object_size( +static int M_GetObjectSize_Pretty( const struct json_object_s *object, size_t depth, size_t indent_size, size_t newline_size, size_t *size); -static char *json_write_pretty_value( +static char *M_WriteValue_Pretty( const struct json_value_s *value, size_t depth, const char *indent, const char *newline, char *data); -static char *json_write_pretty_array( +static char *M_WriteArray_Pretty( const struct json_array_s *array, size_t depth, const char *indent, const char *newline, char *data); -static char *json_write_pretty_object( +static char *M_WriteObject_Pretty( const struct json_object_s *object, size_t depth, const char *indent, const char *newline, char *data); -static int json_write_get_number_size( - const struct json_number_s *number, size_t *size) +static int M_GetNumberSize(const struct json_number_s *number, size_t *size) { json_uintmax_t parsed_number; size_t i; @@ -162,8 +159,7 @@ static int json_write_get_number_size( return 0; } -static int json_write_get_string_size( - const struct json_string_s *string, size_t *size) +static int M_GetStringSize(const struct json_string_s *string, size_t *size) { size_t i; for (i = 0; i < string->string_size; i++) { @@ -188,7 +184,7 @@ static int json_write_get_string_size( return 0; } -static int json_write_minified_get_array_size( +static int M_GetArraySize_Minified( const struct json_array_s *array, size_t *size) { struct json_array_element_s *element; @@ -201,7 +197,7 @@ static int json_write_minified_get_array_size( for (element = array->start; json_null != element; element = element->next) { - if (json_write_minified_get_value_size(element->value, size)) { + if (M_GetValueSize_Minified(element->value, size)) { /* value was malformed! */ return 1; } @@ -210,7 +206,7 @@ static int json_write_minified_get_array_size( return 0; } -static int json_write_minified_get_object_size( +static int M_GetObjectSize_Minified( const struct json_object_s *object, size_t *size) { struct json_object_element_s *element; @@ -225,12 +221,12 @@ static int json_write_minified_get_object_size( for (element = object->start; json_null != element; element = element->next) { - if (json_write_get_string_size(element->name, size)) { + if (M_GetStringSize(element->name, size)) { /* string was malformed! */ return 1; } - if (json_write_minified_get_value_size(element->value, size)) { + if (M_GetValueSize_Minified(element->value, size)) { /* value was malformed! */ return 1; } @@ -239,7 +235,7 @@ static int json_write_minified_get_object_size( return 0; } -static int json_write_minified_get_value_size( +static int M_GetValueSize_Minified( const struct json_value_s *value, size_t *size) { switch (value->type) { @@ -247,16 +243,14 @@ static int json_write_minified_get_value_size( /* unknown value type found! */ return 1; case json_type_number: - return json_write_get_number_size( - (struct json_number_s *)value->payload, size); + return M_GetNumberSize((struct json_number_s *)value->payload, size); case json_type_string: - return json_write_get_string_size( - (struct json_string_s *)value->payload, size); + return M_GetStringSize((struct json_string_s *)value->payload, size); case json_type_array: - return json_write_minified_get_array_size( + return M_GetArraySize_Minified( (struct json_array_s *)value->payload, size); case json_type_object: - return json_write_minified_get_object_size( + return M_GetObjectSize_Minified( (struct json_object_s *)value->payload, size); case json_type_true: *size += 4; /* the string "true". */ @@ -270,7 +264,7 @@ static int json_write_minified_get_value_size( } } -static char *json_write_number(const struct json_number_s *number, char *data) +static char *M_WriteNumber(const struct json_number_s *number, char *data) { json_uintmax_t parsed_number, backup; size_t i; @@ -455,7 +449,7 @@ static char *json_write_number(const struct json_number_s *number, char *data) return data; } -static char *json_write_string(const struct json_string_s *string, char *data) +static char *M_WriteString(const struct json_string_s *string, char *data) { size_t i; @@ -502,8 +496,7 @@ static char *json_write_string(const struct json_string_s *string, char *data) return data; } -static char *json_write_minified_array( - const struct json_array_s *array, char *data) +static char *M_WriteArray_Minified(const struct json_array_s *array, char *data) { struct json_array_element_s *element = json_null; @@ -515,7 +508,7 @@ static char *json_write_minified_array( *data++ = ','; /* ','s seperate each element. */ } - data = json_write_minified_value(element->value, data); + data = M_WriteValue_Minified(element->value, data); if (json_null == data) { /* value was malformed! */ @@ -528,7 +521,7 @@ static char *json_write_minified_array( return data; } -static char *json_write_minified_object( +static char *M_WriteObject_Minified( const struct json_object_s *object, char *data) { struct json_object_element_s *element = json_null; @@ -541,7 +534,7 @@ static char *json_write_minified_object( *data++ = ','; /* ','s seperate each element. */ } - data = json_write_string(element->name, data); + data = M_WriteString(element->name, data); if (json_null == data) { /* string was malformed! */ @@ -550,7 +543,7 @@ static char *json_write_minified_object( *data++ = ':'; /* ':'s seperate each name/value pair. */ - data = json_write_minified_value(element->value, data); + data = M_WriteValue_Minified(element->value, data); if (json_null == data) { /* value was malformed! */ @@ -563,22 +556,21 @@ static char *json_write_minified_object( return data; } -static char *json_write_minified_value( - const struct json_value_s *value, char *data) +static char *M_WriteValue_Minified(const struct json_value_s *value, char *data) { switch (value->type) { default: /* unknown value type found! */ return json_null; case json_type_number: - return json_write_number((struct json_number_s *)value->payload, data); + return M_WriteNumber((struct json_number_s *)value->payload, data); case json_type_string: - return json_write_string((struct json_string_s *)value->payload, data); + return M_WriteString((struct json_string_s *)value->payload, data); case json_type_array: - return json_write_minified_array( + return M_WriteArray_Minified( (struct json_array_s *)value->payload, data); case json_type_object: - return json_write_minified_object( + return M_WriteObject_Minified( (struct json_object_s *)value->payload, data); case json_type_true: data[0] = 't'; @@ -612,7 +604,7 @@ void *json_write_minified(const struct json_value_s *value, size_t *out_size) return json_null; } - if (json_write_minified_get_value_size(value, &size)) { + if (M_GetValueSize_Minified(value, &size)) { /* value was malformed! */ return json_null; } @@ -626,7 +618,7 @@ void *json_write_minified(const struct json_value_s *value, size_t *out_size) return json_null; } - data_end = json_write_minified_value(value, data); + data_end = M_WriteValue_Minified(value, data); if (json_null == data_end) { /* bad chi occurred! */ @@ -644,7 +636,7 @@ void *json_write_minified(const struct json_value_s *value, size_t *out_size) return data; } -static int json_write_pretty_get_array_size( +static int M_GetArraySize_Pretty( const struct json_array_s *array, size_t depth, size_t indent_size, size_t newline_size, size_t *size) { @@ -663,7 +655,7 @@ static int json_write_pretty_get_array_size( /* each element gets an indent. */ *size += (depth + 1) * indent_size; - if (json_write_pretty_get_value_size( + if (M_GetValueSize_Pretty( element->value, depth + 1, indent_size, newline_size, size)) { /* value was malformed! */ @@ -686,7 +678,7 @@ static int json_write_pretty_get_array_size( return 0; } -static int json_write_pretty_get_object_size( +static int M_GetObjectSize_Pretty( const struct json_object_s *object, size_t depth, size_t indent_size, size_t newline_size, size_t *size) { @@ -705,14 +697,14 @@ static int json_write_pretty_get_object_size( *size += (depth + 1) * indent_size; *size += newline_size; - if (json_write_get_string_size(element->name, size)) { + if (M_GetStringSize(element->name, size)) { /* string was malformed! */ return 1; } *size += 3; /* seperate each name/value pair with " : ". */ - if (json_write_pretty_get_value_size( + if (M_GetValueSize_Pretty( element->value, depth + 1, indent_size, newline_size, size)) { /* value was malformed! */ @@ -728,7 +720,7 @@ static int json_write_pretty_get_object_size( return 0; } -static int json_write_pretty_get_value_size( +static int M_GetValueSize_Pretty( const struct json_value_s *value, size_t depth, size_t indent_size, size_t newline_size, size_t *size) { @@ -737,17 +729,15 @@ static int json_write_pretty_get_value_size( /* unknown value type found! */ return 1; case json_type_number: - return json_write_get_number_size( - (struct json_number_s *)value->payload, size); + return M_GetNumberSize((struct json_number_s *)value->payload, size); case json_type_string: - return json_write_get_string_size( - (struct json_string_s *)value->payload, size); + return M_GetStringSize((struct json_string_s *)value->payload, size); case json_type_array: - return json_write_pretty_get_array_size( + return M_GetArraySize_Pretty( (struct json_array_s *)value->payload, depth, indent_size, newline_size, size); case json_type_object: - return json_write_pretty_get_object_size( + return M_GetObjectSize_Pretty( (struct json_object_s *)value->payload, depth, indent_size, newline_size, size); case json_type_true: @@ -762,7 +752,7 @@ static int json_write_pretty_get_value_size( } } -static char *json_write_pretty_array( +static char *M_WriteArray_Pretty( const struct json_array_s *array, size_t depth, const char *indent, const char *newline, char *data) { @@ -792,7 +782,7 @@ static char *json_write_pretty_array( } } - data = json_write_pretty_value( + data = M_WriteValue_Pretty( element->value, depth + 1, indent, newline, data); if (json_null == data) { @@ -817,7 +807,7 @@ static char *json_write_pretty_array( return data; } -static char *json_write_pretty_object( +static char *M_WriteObject_Pretty( const struct json_object_s *object, size_t depth, const char *indent, const char *newline, char *data) { @@ -847,7 +837,7 @@ static char *json_write_pretty_object( } } - data = json_write_string(element->name, data); + data = M_WriteString(element->name, data); if (json_null == data) { /* string was malformed! */ @@ -859,7 +849,7 @@ static char *json_write_pretty_object( *data++ = ':'; *data++ = ' '; - data = json_write_pretty_value( + data = M_WriteValue_Pretty( element->value, depth + 1, indent, newline, data); if (json_null == data) { @@ -884,7 +874,7 @@ static char *json_write_pretty_object( return data; } -static char *json_write_pretty_value( +static char *M_WriteValue_Pretty( const struct json_value_s *value, size_t depth, const char *indent, const char *newline, char *data) { @@ -893,15 +883,15 @@ static char *json_write_pretty_value( /* unknown value type found! */ return json_null; case json_type_number: - return json_write_number((struct json_number_s *)value->payload, data); + return M_WriteNumber((struct json_number_s *)value->payload, data); case json_type_string: - return json_write_string((struct json_string_s *)value->payload, data); + return M_WriteString((struct json_string_s *)value->payload, data); case json_type_array: - return json_write_pretty_array( + return M_WriteArray_Pretty( (struct json_array_s *)value->payload, depth, indent, newline, data); case json_type_object: - return json_write_pretty_object( + return M_WriteObject_Pretty( (struct json_object_s *)value->payload, depth, indent, newline, data); case json_type_true: @@ -956,8 +946,7 @@ void *json_write_pretty( ++newline_size; /* skip non-null terminating characters. */ } - if (json_write_pretty_get_value_size( - value, 0, indent_size, newline_size, &size)) { + if (M_GetValueSize_Pretty(value, 0, indent_size, newline_size, &size)) { /* value was malformed! */ return json_null; } @@ -971,7 +960,7 @@ void *json_write_pretty( return json_null; } - data_end = json_write_pretty_value(value, 0, indent, newline, data); + data_end = M_WriteValue_Pretty(value, 0, indent, newline, data); if (json_null == data_end) { /* bad chi occurred! */ diff --git a/src/log_linux.c b/src/log_linux.c index ae838b5..6af46b3 100644 --- a/src/log_linux.c +++ b/src/log_linux.c @@ -6,18 +6,18 @@ #include #include -static void Log_ErrorCallback(void *data, const char *msg, int errnum); -static int Log_StackTrace( +static void M_ErrorCallback(void *data, const char *msg, int errnum); +static int M_StackTrace( void *data, uintptr_t pc, const char *filename, int lineno, const char *func_name); -static void Log_SignalHandler(int sig); +static void M_SignalHandler(int sig); -static void Log_ErrorCallback(void *data, const char *msg, int errnum) +static void M_ErrorCallback(void *data, const char *msg, int errnum) { LOG_ERROR("%s", msg); } -static int Log_StackTrace( +static int M_StackTrace( void *data, uintptr_t pc, const char *filename, int lineno, const char *func_name) { @@ -31,21 +31,21 @@ static int Log_StackTrace( return 0; } -static void Log_SignalHandler(int sig) +static void M_SignalHandler(int sig) { LOG_ERROR("== CRASH REPORT =="); LOG_INFO("SIGNAL: %d", sig); LOG_INFO("STACK TRACE:"); struct backtrace_state *state = backtrace_create_state( - NULL, BACKTRACE_SUPPORTS_THREADS, Log_ErrorCallback, NULL); - backtrace_full(state, 0, Log_StackTrace, Log_ErrorCallback, NULL); + NULL, BACKTRACE_SUPPORTS_THREADS, M_ErrorCallback, NULL); + backtrace_full(state, 0, M_StackTrace, M_ErrorCallback, NULL); exit(EXIT_FAILURE); } void Log_Init_Extra(const char *path) { - signal(SIGSEGV, Log_SignalHandler); - signal(SIGFPE, Log_SignalHandler); + signal(SIGSEGV, M_SignalHandler); + signal(SIGFPE, M_SignalHandler); } void Log_Shutdown_Extra(void) diff --git a/src/log_windows.c b/src/log_windows.c index 69601be..f31916a 100644 --- a/src/log_windows.c +++ b/src/log_windows.c @@ -12,13 +12,13 @@ #include static char *m_MiniDumpPath = NULL; -static char *Log_GetMiniDumpPath(const char *log_path); -static void Log_CreateMiniDump(EXCEPTION_POINTERS *ex, const char *path); -static void Log_StackTrace( +static char *M_GetMiniDumpPath(const char *log_path); +static void M_CreateMiniDump(EXCEPTION_POINTERS *ex, const char *path); +static void M_StackTrace( uint64_t addr, const char *filename, int line_no, const char *func_name, void *context, int column_no); -static char *Log_GetMiniDumpPath(const char *const log_path) +static char *M_GetMiniDumpPath(const char *const log_path) { char *dot = strrchr(log_path, '.'); if (dot == NULL) { @@ -34,7 +34,7 @@ static char *Log_GetMiniDumpPath(const char *const log_path) return minidump_path; } -static void Log_StackTrace( +static void M_StackTrace( const uint64_t addr, const char *filename, const int line_no, const char *const func_name, void *const context, const int column_no) { @@ -68,7 +68,7 @@ static void Log_StackTrace( } } -static void Log_CreateMiniDump( +static void M_CreateMiniDump( EXCEPTION_POINTERS *const ex, const char *const path) { HANDLE handle = CreateFile( @@ -94,9 +94,9 @@ LONG WINAPI Log_CrashHandler(EXCEPTION_POINTERS *ex) LOG_INFO("STACK TRACE:"); int32_t count = 0; - dwstOfException(ex->ContextRecord, &Log_StackTrace, &count); + dwstOfException(ex->ContextRecord, &M_StackTrace, &count); - Log_CreateMiniDump(ex, m_MiniDumpPath); + M_CreateMiniDump(ex, m_MiniDumpPath); return EXCEPTION_EXECUTE_HANDLER; } @@ -104,7 +104,7 @@ LONG WINAPI Log_CrashHandler(EXCEPTION_POINTERS *ex) void Log_Init_Extra(const char *log_path) { if (log_path != NULL) { - m_MiniDumpPath = Log_GetMiniDumpPath(log_path); + m_MiniDumpPath = M_GetMiniDumpPath(log_path); SetUnhandledExceptionFilter(Log_CrashHandler); } } diff --git a/src/vector.c b/src/vector.c index 3fd8c22..ac0c963 100644 --- a/src/vector.c +++ b/src/vector.c @@ -16,7 +16,16 @@ struct VECTOR_PRIV { char *items; }; -static void Vector_EnsureCapacity(VECTOR *vector, int32_t n); +static void M_EnsureCapacity(VECTOR *vector, int32_t n); + +static void M_EnsureCapacity(VECTOR *const vector, const int32_t n) +{ + while (vector->count + n > vector->capacity) { + vector->capacity *= VECTOR_GROWTH_RATE; + P(vector).items = Memory_Realloc( + P(vector).items, vector->item_size * vector->capacity); + } +} VECTOR *Vector_Create(const size_t item_size) { @@ -42,15 +51,6 @@ void Vector_Free(VECTOR *vector) Memory_FreePointer(&vector); } -static void Vector_EnsureCapacity(VECTOR *const vector, const int32_t n) -{ - while (vector->count + n > vector->capacity) { - vector->capacity *= VECTOR_GROWTH_RATE; - P(vector).items = Memory_Realloc( - P(vector).items, vector->item_size * vector->capacity); - } -} - int32_t Vector_IndexOf(const VECTOR *const vector, const void *const item) { for (int32_t i = 0; i < vector->count; i++) { @@ -90,14 +90,14 @@ void *Vector_Get(VECTOR *const vector, const int32_t index) void Vector_Add(VECTOR *const vector, void *const item) { - Vector_EnsureCapacity(vector, 1); + M_EnsureCapacity(vector, 1); Vector_Insert(vector, vector->count, item); } void Vector_Insert(VECTOR *const vector, const int32_t index, void *const item) { assert(index >= 0 && index <= vector->count); - Vector_EnsureCapacity(vector, 1); + M_EnsureCapacity(vector, 1); char *const items = P(vector).items; if (index < vector->count) { memmove(