Skip to content

Commit

Permalink
Merge pull request #27 from capnramses/fix/Wstrict-prototypes
Browse files Browse the repository at this point in the history
fixes to new script-prototypes compiler warnings
  • Loading branch information
capnramses authored Apr 19, 2023
2 parents 3fd143c + 7490e77 commit 325f2f1
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 90 deletions.
6 changes: 3 additions & 3 deletions apg/apg.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ LOG FILES
#endif

/** Open/refresh a new log file and print timestamp. */
void apg_start_log();
void apg_start_log( void );

/** Write a log entry. */
void apg_log( const char* message, ... ) ATTRIB_PRINTF( 1, 2 );
Expand Down Expand Up @@ -839,7 +839,7 @@ LOG FILES IMPLEMENTATION
=================================================================================================*/
#define APG_LOG_FILE "apg.log" /* file name for log */

void apg_start_log() {
void apg_start_log( void ) {
FILE* file = fopen( APG_LOG_FILE, "w" ); /* NOTE it was getting massive with "a" */
if ( !file ) {
fprintf( stderr, "ERROR: could not open APG_LOG_FILE log file %s for writing\n", APG_LOG_FILE );
Expand Down Expand Up @@ -973,7 +973,7 @@ void apg_print_trace( FILE* stream ) {
} /* endfunc apg_print_trace() */

/* to deliberately cause a sigsegv: call a function containing bad ptr: int *foo = (int*)-1; */
void apg_start_crash_handler() {
void apg_start_crash_handler( void ) {
signal( SIGSEGV, _crash_handler );
signal( SIGABRT, _crash_handler ); /* assert */
signal( SIGILL, _crash_handler );
Expand Down
2 changes: 1 addition & 1 deletion apg/tests/apg.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ LOG FILES IMPLEMENTATION
=================================================================================================*/
#define APG_LOG_FILE "apg.log" /* file name for log */

void apg_start_log() {
void apg_start_log( void ) {
FILE* file = fopen( APG_LOG_FILE, "w" ); /* NOTE it was getting massive with "a" */
if ( !file ) {
fprintf( stderr, "ERROR: could not open APG_LOG_FILE log file %s for writing\n", APG_LOG_FILE );
Expand Down
2 changes: 1 addition & 1 deletion apg/tests/hash_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Language: C99

#define N_STORE 666

int main() {
int main( void ) {
printf( "===========================================\n" );
{
apg_hash_table_t table = apg_hash_table_create( 128 );
Expand Down
2 changes: 1 addition & 1 deletion apg/tests/rle_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdio.h>
#include <string.h>

int main() {
int main( void ) {
const char* input_buffer = "ABBCCCDDDDEEEEEFFFFFFGGGGGGGHHHHHHHHIIIIIIIII";
char* decompressed_buffer = NULL;

Expand Down
18 changes: 8 additions & 10 deletions apg_console/apg_console.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* =======================================================================================================================
APG_C - A Quake-style Console mini-library
Author: Anton Gerdelan - @capnramses
Version: 0.13
Version: 0.13.1
Language: C99
Licence: See bottom of header file.
======================================================================================================================= */
Expand Down Expand Up @@ -64,8 +64,6 @@ static void apg_c_strncat( char* dst, const char* src, const int dest_max_len, c
int dst_len = apg_c_strnlen( dst, dest_max_len );
dst[dst_len] = '\0'; // just in case it wasn't already terminated before max length
int remaining_space = dest_max_len - dst_len;
if ( remaining_space <= 0 ) { return; }
if ( remaining_space <= 0 ) { return; }
const int n = remaining_space < src_max_copy ? remaining_space : src_max_copy; // use src_max if smaller
strncat( dst, src, n - 1 ); // strncat manual guarantees null termination.
}
Expand All @@ -80,17 +78,17 @@ static void _apg_c_command_hist_append( const char* c_user_entered_text ) {
if ( _c_command_history_n >= APG_C_MAX_COMMAND_HIST ) { _c_command_history_n = APG_C_MAX_COMMAND_HIST - 1; }
}

static void _help() {
static void _help( void ) {
apg_c_printf( "APG_C by Anton Gerdelan. Autocomplete supported. Built-in functions are:" );
for ( int i = 0; i < APG_C_N_BUILT_IN_COMMANDS; i++ ) { apg_c_printf( "%s", _c_built_in_commands[i] ); }
}

static void _list_c_vars() {
static void _list_c_vars( void ) {
apg_c_printf( "=====c_vars=====" );
for ( uint32_t i = 0; i < _n_c_vars; i++ ) { apg_c_printf( "%s", _c_vars[i].str ); }
}

static void _list_c_funcs() {
static void _list_c_funcs( void ) {
apg_c_printf( "=====c_funcs=====" );
for ( uint32_t i = 0; i < _n_c_funcs; i++ ) { apg_c_printf( "%s", _c_funcs[i].str ); }
}
Expand Down Expand Up @@ -281,13 +279,13 @@ void apg_c_reuse_hist( int hist_steps ) {
_c_redraw_required = true;
}

void apg_c_reuse_hist_back_one() {
void apg_c_reuse_hist_back_one( void ) {
_hist_curr_rewind_idx++;
if ( _hist_curr_rewind_idx >= _c_command_history_n ) { _hist_curr_rewind_idx = _c_command_history_n - 1; }
apg_c_reuse_hist( _hist_curr_rewind_idx );
}

void apg_c_reuse_hist_ahead_one() {
void apg_c_reuse_hist_ahead_one( void ) {
_hist_curr_rewind_idx--;
if ( _hist_curr_rewind_idx < 0 ) { _hist_curr_rewind_idx = 0; }
apg_c_reuse_hist( _hist_curr_rewind_idx );
Expand All @@ -308,7 +306,7 @@ void apg_c_clear_user_entered_text( void ) {
}

// WARNING(Anton) - assumes string is ASCII
void apg_c_autocomplete() {
void apg_c_autocomplete( void ) {
size_t len = strlen( _c_user_entered_text );
if ( 0 == len ) { return; }

Expand Down Expand Up @@ -521,4 +519,4 @@ bool apg_c_draw_to_image_mem( uint8_t* img_ptr, int w, int h, int n_channels, ui
return true;
}

bool apg_c_image_redraw_required() { return _c_redraw_required; }
bool apg_c_image_redraw_required( void ) { return _c_redraw_required; }
33 changes: 17 additions & 16 deletions apg_console/apg_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ Contact: <[email protected]>
Website: https://github.com/capnramses/apg - http://antongerdelan.net/
Licence: See bottom of this file.
Version History:
v0.13 - 2022/09/23 - Updated API to match new apg_pixfont.
v0.12 - 2021/10/03 - Fix to missing nul-terminator in long string copies.
v0.11 - 2021/06/09 - Fixes to warnings reported by MSVC.
v0.10 - 2021/06/05 - Fixed strncat warnings.
v0.9 - 2020/11/08 - Added functions to iteratively scroll through history like in BaSh.
v0.8 - 2020/09/13 - Removed assert on append empty string. Reduced max str len to suit shorter consoles.
v0.7 - 2020/08/09 - Fixed bug where counter of number of built in commands was too high by 1. Updated docs in this file.
v0.6 - 2020/08/08 - Fixed issue/bug where dumping to stdout didn't print current user entered text if history was empty.
v0.5 - 2020/08/08 - apc_c_printf_rgba() to set the colour of particular lines. History text is now grey by default, and cursor text is white.
v0.4 - 2020/08/08 - Added printf-style variadic arguments and renamed apc_c_print() to apc_c_printf().
v0.3 - 2020/06/07 - Doubled length of tmp strings to avoid truncation warnings.
v0.2 - 2020/01/04 - Moved to apg libraries repository. Minor tweaks from testing in a game integration.
v0.1 - 2020/01/06 - Reduced interface. Moved from stored float cvars to addresses of existing vars. Data type is also specified for bool/int/uint/float support.
v0.13.1 - 2023/04/19 - Small function prototype fixes.
v0.13 - 2022/09/23 - Updated API to match new apg_pixfont.
v0.12 - 2021/10/03 - Fix to missing nul-terminator in long string copies.
v0.11 - 2021/06/09 - Fixes to warnings reported by MSVC.
v0.10 - 2021/06/05 - Fixed strncat warnings.
v0.9 - 2020/11/08 - Added functions to iteratively scroll through history like in BaSh.
v0.8 - 2020/09/13 - Removed assert on append empty string. Reduced max str len to suit shorter consoles.
v0.7 - 2020/08/09 - Fixed bug where counter of number of built in commands was too high by 1. Updated docs in this file.
v0.6 - 2020/08/08 - Fixed issue/bug where dumping to stdout didn't print current user entered text if history was empty.
v0.5 - 2020/08/08 - apc_c_printf_rgba() to set the colour of particular lines. History text is now grey by default, and cursor text is white.
v0.4 - 2020/08/08 - Added printf-style variadic arguments and renamed apc_c_print() to apc_c_printf().
v0.3 - 2020/06/07 - Doubled length of tmp strings to avoid truncation warnings.
v0.2 - 2020/01/04 - Moved to apg libraries repository. Minor tweaks from testing in a game integration.
v0.1 - 2020/01/06 - Reduced interface. Moved from stored float cvars to addresses of existing vars. Data type is also specified for bool/int/uint/float support.
Instructions
============
Expand Down Expand Up @@ -125,10 +126,10 @@ PARAMS - hist is the number of entries back from the most recent command entered
void apg_c_reuse_hist( int hist_steps );

/* Call this function on i.e. user hitting cursor up arrow to replicate BaSh history scrolling. Calls apg_c_reuse_hist() with the appropriate history item. */
void apg_c_reuse_hist_back_one();
void apg_c_reuse_hist_back_one( void );

/* Call this function on i.e. user hitting cursor down arrow to replicate BaSh history scrolling. */
void apg_c_reuse_hist_ahead_one();
void apg_c_reuse_hist_ahead_one( void );

void apg_c_clear_user_entered_text( void );

Expand Down Expand Up @@ -195,7 +196,7 @@ rendering API
bool apg_c_draw_to_image_mem( uint8_t* img_ptr, int w, int h, int n_channels, uint8_t* background_colour );

// RETURNS true if console has changed since last call to apg_c_draw_to_image_mem() and can be painted again
bool apg_c_image_redraw_required();
bool apg_c_image_redraw_required( void );

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion apg_console/tests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bool anton_func( const char* arg_str ) {
return true;
}

int main() {
int main( void ) {

// resolving a prior bug where text wouldn't print until a \n was entered
apg_c_append_user_entered_text( "does this print without a slash n?" );
Expand Down
54 changes: 28 additions & 26 deletions apg_gldb/apg_gldb.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
OpenGL Debug Drawing Functions
OpenGL Debug Drawing Functions v0.4.1
https://github.com/capnramses/opengl_debug_draw
Anton Gerdelan <[email protected]>
LICENCE - See bottom of header file.
Expand Down Expand Up @@ -39,9 +39,9 @@ static const char* gl_db_lines_fs_str =
" gl_FragColor = fc;\n"
"}";

void apg_gldb_reset_lines() { _count_lines = 0; }
void apg_gldb_reset_lines( void ) { _count_lines = 0; }

bool apg_gldb_init() {
bool apg_gldb_init( void ) {
// vao for drawing properties of lines
glGenVertexArrays( 1, &_lines_vao );
glBindVertexArray( _lines_vao );
Expand Down Expand Up @@ -85,14 +85,14 @@ bool apg_gldb_init() {
return true;
}

void apg_gldb_free() {
void apg_gldb_free( void ) {
glDeleteBuffers( 1, &_lines_vbo );
glDeleteVertexArrays( 1, &_lines_vao );
// attached shaders have prev been flagged to delete so will also be deleted
glDeleteProgram( _lines_shader_program );
}

int apg_gldb_add_line( float* start_xyz, float* end_xyz, float* colour_rgba ) {
int apg_gldb_add_line( const float* start_xyz, const float* end_xyz, const float* colour_rgba ) {
if ( _count_lines >= APG_GLDB_MAX_LINES ) {
fprintf( stderr, "ERROR: too many apg_gldb lines\n" );
return -1;
Expand Down Expand Up @@ -122,7 +122,7 @@ int apg_gldb_add_line( float* start_xyz, float* end_xyz, float* colour_rgba ) {
return _count_lines++;
}

int apg_gldb_add_normal( float* n_xyz, float* pos_xyz, float scale, float* colour_rgba ) {
int apg_gldb_add_normal( const float* n_xyz, const float* pos_xyz, float scale, const float* colour_rgba ) {
if ( _count_lines >= APG_GLDB_MAX_LINES ) {
fprintf( stderr, "ERROR: too many apg_gldb lines\n" );
return -1;
Expand Down Expand Up @@ -156,7 +156,7 @@ int apg_gldb_add_normal( float* n_xyz, float* pos_xyz, float scale, float* colou
return _count_lines++;
}

int apg_gldb_add_pos( float* pos_xyz, float scale, float* colour_rgba ) {
int apg_gldb_add_pos( const float* pos_xyz, float scale, const float* colour_rgba ) {
int rid = -1;
float start[3], end[3];

Expand Down Expand Up @@ -185,7 +185,7 @@ int apg_gldb_add_pos( float* pos_xyz, float scale, float* colour_rgba ) {
return rid;
}

int apg_gldb_add_aabb( float* min_xyz, float* max_xyz, float* colour_rgba ) {
int apg_gldb_add_aabb( const float* min_xyz, const float* max_xyz, const float* colour_rgba ) {
int rid = -1;
float start[3], end[3];

Expand Down Expand Up @@ -244,7 +244,7 @@ int apg_gldb_add_aabb( float* min_xyz, float* max_xyz, float* colour_rgba ) {
return rid;
}

int apg_gldb_add_rad_circle( float* centre_xyz, float radius, float* colour_rgba ) {
int apg_gldb_add_rad_circle( const float* centre_xyz, float radius, const float* colour_rgba ) {
int rid = -1;
float start[3], end[3];
// 3 radius lines in a cross first
Expand Down Expand Up @@ -273,39 +273,40 @@ int apg_gldb_add_rad_circle( float* centre_xyz, float radius, float* colour_rgba
int segs = 12;
// x,y around z loop
for ( int i = 0; i < segs; i++ ) {
start[0] = centre_xyz[0] + radius * cos( 2.0f * APG_GLDB_PI * (float)i / (float)segs );
start[1] = centre_xyz[1] + radius * sin( 2.0f * APG_GLDB_PI * (float)i / (float)segs );
start[0] = centre_xyz[0] + radius * cosf( 2.0f * (float)APG_GLDB_PI * (float)i / (float)segs );
start[1] = centre_xyz[1] + radius * sinf( 2.0f * (float)APG_GLDB_PI * (float)i / (float)segs );
start[2] = centre_xyz[2];
end[0] = centre_xyz[0] + radius * cos( 2.0f * APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
end[1] = centre_xyz[1] + radius * sin( 2.0f * APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
end[0] = centre_xyz[0] + radius * cosf( 2.0f * (float)APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
end[1] = centre_xyz[1] + radius * sinf( 2.0f * (float)APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
end[2] = centre_xyz[2];
apg_gldb_add_line( start, end, colour_rgba );
}
// x,z around y loop
for ( int i = 0; i < segs; i++ ) {
start[0] = centre_xyz[0] + radius * cos( 2.0f * APG_GLDB_PI * (float)i / (float)segs );
start[0] = centre_xyz[0] + radius * cosf( 2.0f * (float)APG_GLDB_PI * (float)i / (float)segs );
start[1] = centre_xyz[1];
start[2] = centre_xyz[2] + radius * sin( 2.0f * APG_GLDB_PI * (float)i / (float)segs );
end[0] = centre_xyz[0] + radius * cos( 2.0f * APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
start[2] = centre_xyz[2] + radius * sinf( 2.0f * (float)APG_GLDB_PI * (float)i / (float)segs );
end[0] = centre_xyz[0] + radius * cosf( 2.0f * (float)APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
end[1] = centre_xyz[1];
end[2] = centre_xyz[2] + radius * sin( 2.0f * APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
end[2] = centre_xyz[2] + radius * sinf( 2.0f * (float)APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
apg_gldb_add_line( start, end, colour_rgba );
}
// y,z around xloop
for ( int i = 0; i < segs; i++ ) {
start[0] = centre_xyz[0];
start[1] = centre_xyz[1] + radius * cos( 2.0f * APG_GLDB_PI * (float)i / (float)segs );
start[2] = centre_xyz[2] + radius * sin( 2.0f * APG_GLDB_PI * (float)i / (float)segs );
start[1] = centre_xyz[1] + radius * cosf( 2.0f * (float)APG_GLDB_PI * (float)i / (float)segs );
start[2] = centre_xyz[2] + radius * sinf( 2.0f * (float)APG_GLDB_PI * (float)i / (float)segs );
end[0] = centre_xyz[0];
end[1] = centre_xyz[1] + radius * cos( 2.0f * APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
end[2] = centre_xyz[2] + radius * sin( 2.0f * APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
end[1] = centre_xyz[1] + radius * cosf( 2.0f * (float)APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
end[2] = centre_xyz[2] + radius * sinf( 2.0f * (float)APG_GLDB_PI * (float)( i + 1 ) / (float)segs );
apg_gldb_add_line( start, end, colour_rgba );
}

return rid;
}

int apg_gldb_add_frustum( float* ftl, float* ftr, float* fbl, float* fbr, float* ntl, float* ntr, float* nbl, float* nbr, float* colour_rgba ) {
int apg_gldb_add_frustum( const float* ftl, const float* ftr, const float* fbl, const float* fbr, const float* ntl, const float* ntr, const float* nbl,
const float* nbr, const float* colour_rgba ) {
int rid = -1;
float start[3], end[3];
start[0] = ftl[0];
Expand Down Expand Up @@ -397,7 +398,7 @@ int apg_gldb_add_frustum( float* ftl, float* ftr, float* fbl, float* fbr, float*
return rid;
}

bool apg_gldb_mod_line( uint32_t line_id, float* start_xyz, float* end_xyz, float* colour_rgba ) {
bool apg_gldb_mod_line( uint32_t line_id, const float* start_xyz, const float* end_xyz, const float* colour_rgba ) {
if ( line_id >= _count_lines ) {
fprintf( stderr, "ERROR: modifying apg_gldb line - bad ID\n" );
return false;
Expand Down Expand Up @@ -427,7 +428,7 @@ bool apg_gldb_mod_line( uint32_t line_id, float* start_xyz, float* end_xyz, floa
return true;
}

bool apg_gldb_mod_aabb( uint32_t line_id, float* min_xyz, float* max_xyz, float* colour_rgba ) {
bool apg_gldb_mod_aabb( uint32_t line_id, const float* min_xyz, const float* max_xyz, const float* colour_rgba ) {
if ( line_id + 12 > _count_lines ) {
fprintf( stderr, "ERROR: modifying apg_gldb AABB - bad line ID\n" );
return false;
Expand Down Expand Up @@ -491,7 +492,8 @@ bool apg_gldb_mod_aabb( uint32_t line_id, float* min_xyz, float* max_xyz, float*
return true;
}

bool apg_gldb_mod_frustum( uint32_t line_id, float* ftl, float* ftr, float* fbl, float* fbr, float* ntl, float* ntr, float* nbl, float* nbr, float* colour_rgba ) {
bool apg_gldb_mod_frustum( uint32_t line_id, const float* ftl, const float* ftr, const float* fbl, const float* fbr, const float* ntl, const float* ntr,
const float* nbl, const float* nbr, const float* colour_rgba ) {
if ( line_id + 12 > _count_lines ) {
fprintf( stderr, "ERROR: modifying apg_gldb frustum - bad line ID\n" );
return false;
Expand Down Expand Up @@ -588,7 +590,7 @@ bool apg_gldb_mod_frustum( uint32_t line_id, float* ftl, float* ftr, float* fbl,
return true;
}

void apg_gldb_update_cam( float* PV_mat4 ) {
void apg_gldb_update_cam( const float* PV_mat4 ) {
glUseProgram( _lines_shader_program );
glUniformMatrix4fv( _PV_loc, 1, GL_FALSE, PV_mat4 );
}
Expand Down
Loading

0 comments on commit 325f2f1

Please sign in to comment.