@@ -333,41 +333,41 @@ typedef struct sargs_desc {
333333 sargs_allocator allocator ;
334334} sargs_desc ;
335335
336- /* setup sokol-args */
336+ // setup sokol-args
337337SOKOL_ARGS_API_DECL void sargs_setup (const sargs_desc * desc );
338- /* shutdown sokol-args */
338+ // shutdown sokol-args
339339SOKOL_ARGS_API_DECL void sargs_shutdown (void );
340- /* true between sargs_setup() and sargs_shutdown() */
340+ // true between sargs_setup() and sargs_shutdown()
341341SOKOL_ARGS_API_DECL bool sargs_isvalid (void );
342- /* test if an argument exists by key name */
342+ // test if an argument exists by key name
343343SOKOL_ARGS_API_DECL bool sargs_exists (const char * key );
344- /* get value by key name, return empty string if key doesn't exist or an existing key has no value */
344+ // get value by key name, return empty string if key doesn't exist or an existing key has no value
345345SOKOL_ARGS_API_DECL const char * sargs_value (const char * key );
346- /* get value by key name, return provided default if key doesn't exist or has no value */
346+ // get value by key name, return provided default if key doesn't exist or has no value
347347SOKOL_ARGS_API_DECL const char * sargs_value_def (const char * key , const char * def );
348- /* return true if val arg matches the value associated with key */
348+ // return true if val arg matches the value associated with key
349349SOKOL_ARGS_API_DECL bool sargs_equals (const char * key , const char * val );
350- /* return true if key's value is "true", "yes", "on" or an existing key has no value */
350+ // return true if key's value is "true", "yes", "on" or an existing key has no value
351351SOKOL_ARGS_API_DECL bool sargs_boolean (const char * key );
352- /* get index of arg by key name, return -1 if not exists */
352+ // get index of arg by key name, return -1 if not exists
353353SOKOL_ARGS_API_DECL int sargs_find (const char * key );
354- /* get number of parsed arguments */
354+ // get number of parsed arguments
355355SOKOL_ARGS_API_DECL int sargs_num_args (void );
356- /* get key name of argument at index, or empty string */
356+ // get key name of argument at index, or empty string
357357SOKOL_ARGS_API_DECL const char * sargs_key_at (int index );
358- /* get value string of argument at index, or empty string */
358+ // get value string of argument at index, or empty string
359359SOKOL_ARGS_API_DECL const char * sargs_value_at (int index );
360360
361361#ifdef __cplusplus
362- } /* extern "C" */
362+ } // extern "C"
363363
364- /* reference-based equivalents for c++ */
364+ // reference-based equivalents for c++
365365inline void sargs_setup (const sargs_desc & desc ) { return sargs_setup (& desc ); }
366366
367367#endif
368368#endif // SOKOL_ARGS_INCLUDED
369369
370- /* --- IMPLEMENTATION ---------------------------------------------------------*/
370+ // --- IMPLEMENTATION -----------------------------------------------------------
371371#ifdef SOKOL_ARGS_IMPL
372372#define SOKOL_ARGS_IMPL_INCLUDED (1)
373373
@@ -408,37 +408,37 @@ inline void sargs_setup(const sargs_desc& desc) { return sargs_setup(&desc); }
408408#define _SARGS_MAX_ARGS_DEF (16)
409409#define _SARGS_BUF_SIZE_DEF (16*1024)
410410
411- /* parser state */
411+ // parser state
412412#define _SARGS_EXPECT_KEY (1<<0)
413413#define _SARGS_EXPECT_SEP (1<<1)
414414#define _SARGS_EXPECT_VAL (1<<2)
415415#define _SARGS_PARSING_KEY (1<<3)
416416#define _SARGS_PARSING_VAL (1<<4)
417417#define _SARGS_ERROR (1<<5)
418418
419- /* a key/value pair struct */
419+ // a key/value pair struct
420420typedef struct {
421- int key ; /* index to start of key string in buf */
422- int val ; /* index to start of value string in buf */
421+ int key ; // index to start of key string in buf
422+ int val ; // index to start of value string in buf
423423} _sargs_kvp_t ;
424424
425- /* sokol-args state */
425+ // sokol-args state
426426typedef struct {
427- int max_args ; /* number of key/value pairs in args array */
428- int num_args ; /* number of valid items in args array */
429- _sargs_kvp_t * args ; /* key/value pair array */
430- int buf_size ; /* size of buffer in bytes */
431- int buf_pos ; /* current buffer position */
432- char * buf ; /* character buffer, first char is reserved and zero for 'empty string' */
427+ int max_args ; // number of key/value pairs in args array
428+ int num_args ; // number of valid items in args array
429+ _sargs_kvp_t * args ; // key/value pair array
430+ int buf_size ; // size of buffer in bytes
431+ int buf_pos ; // current buffer position
432+ char * buf ; // character buffer, first char is reserved and zero for 'empty string'
433433 bool valid ;
434434 uint32_t parse_state ;
435- char quote ; /* current quote char, 0 if not in a quote */
436- bool in_escape ; /* currently in an escape sequence */
435+ char quote ; // current quote char, 0 if not in a quote
436+ bool in_escape ; // currently in an escape sequence
437437 sargs_allocator allocator ;
438438} _sargs_state_t ;
439439static _sargs_state_t _sargs ;
440440
441- /* == PRIVATE IMPLEMENTATION FUNCTIONS ========================================*/
441+ // == PRIVATE IMPLEMENTATION FUNCTIONS ==========================================
442442_SOKOL_PRIVATE void _sargs_clear (void * ptr , size_t size ) {
443443 SOKOL_ASSERT (ptr && (size > 0 ));
444444 memset (ptr , 0 , size );
@@ -481,7 +481,7 @@ _SOKOL_PRIVATE const char* _sargs_str(int index) {
481481 return & _sargs .buf [index ];
482482}
483483
484- /* -- argument parser functions ------------------*/
484+ // -- argument parser functions --------------------
485485_SOKOL_PRIVATE void _sargs_expect_key (void ) {
486486 _sargs .parse_state = _SARGS_EXPECT_KEY ;
487487}
@@ -513,8 +513,7 @@ _SOKOL_PRIVATE bool _sargs_is_separator(char c) {
513513_SOKOL_PRIVATE bool _sargs_is_quote (char c ) {
514514 if (0 == _sargs .quote ) {
515515 return (c == '\'' ) || (c == '"' );
516- }
517- else {
516+ } else {
518517 return c == _sargs .quote ;
519518 }
520519}
@@ -601,51 +600,44 @@ _SOKOL_PRIVATE bool _sargs_parse_carg(const char* src) {
601600 if (_sargs_in_escape ()) {
602601 c = _sargs_escape (c );
603602 _sargs_end_escape ();
604- }
605- else if (_sargs_is_escape (c )) {
603+ } else if (_sargs_is_escape (c )) {
606604 _sargs_start_escape ();
607605 continue ;
608606 }
609607 if (_sargs_any_expected ()) {
610608 if (!_sargs_is_whitespace (c )) {
611- /* start of key, value or separator */
609+ // start of key, value or separator
612610 if (_sargs_is_separator (c )) {
613- /* skip separator and expect value */
611+ // skip separator and expect value
614612 _sargs_expect_val ();
615613 continue ;
616- }
617- else if (_sargs_key_expected ()) {
618- /* start of new key */
614+ } else if (_sargs_key_expected ()) {
615+ // start of new key
619616 _sargs_start_key ();
620- }
621- else if (_sargs_val_expected ()) {
622- /* start of value */
617+ } else if (_sargs_val_expected ()) {
618+ // start of value
623619 if (_sargs_is_quote (c )) {
624620 _sargs_begin_quote (c );
625621 continue ;
626622 }
627623 _sargs_start_val ();
628624 }
629- }
630- else {
631- /* skip white space */
625+ } else {
626+ // skip white space
632627 continue ;
633628 }
634- }
635- else if (_sargs_parsing_key ()) {
629+ } else if (_sargs_parsing_key ()) {
636630 if (_sargs_is_whitespace (c ) || _sargs_is_separator (c )) {
637- /* end of key string */
631+ // end of key string
638632 _sargs_end_key ();
639633 if (_sargs_is_separator (c )) {
640634 _sargs_expect_val ();
641- }
642- else {
635+ } else {
643636 _sargs_expect_sep_or_key ();
644637 }
645638 continue ;
646639 }
647- }
648- else if (_sargs_parsing_val ()) {
640+ } else if (_sargs_parsing_val ()) {
649641 if (_sargs_in_quotes ()) {
650642 /* when in quotes, whitespace is a normal character
651643 and a matching quote ends the value string
@@ -656,9 +648,8 @@ _SOKOL_PRIVATE bool _sargs_parse_carg(const char* src) {
656648 _sargs_expect_key ();
657649 continue ;
658650 }
659- }
660- else if (_sargs_is_whitespace (c )) {
661- /* end of value string (no quotes) */
651+ } else if (_sargs_is_whitespace (c )) {
652+ // end of value string (no quotes)
662653 _sargs_end_val ();
663654 _sargs_expect_key ();
664655 continue ;
@@ -669,8 +660,7 @@ _SOKOL_PRIVATE bool _sargs_parse_carg(const char* src) {
669660 if (_sargs_parsing_key ()) {
670661 _sargs_end_key ();
671662 _sargs_expect_sep_or_key ();
672- }
673- else if (_sargs_parsing_val () && !_sargs_in_quotes ()) {
663+ } else if (_sargs_parsing_val () && !_sargs_in_quotes ()) {
674664 _sargs_end_val ();
675665 _sargs_expect_key ();
676666 }
@@ -687,15 +677,15 @@ _SOKOL_PRIVATE bool _sargs_parse_cargs(int argc, const char** argv) {
687677 return retval ;
688678}
689679
690- /* -- EMSCRIPTEN IMPLEMENTATION -----------------------------------------------*/
680+ // -- EMSCRIPTEN IMPLEMENTATION -------------------------------------------------
691681#if defined(__EMSCRIPTEN__ )
692682
693683#ifdef __cplusplus
694684extern "C" {
695685#endif
696686
697687#if defined(EM_JS_DEPS )
698- EM_JS_DEPS (sokol_audio , "$withStackSave,$stringToUTF8OnStack" );
688+ EM_JS_DEPS (sokol_audio , "$withStackSave,$stringToUTF8OnStack" )
699689#endif
700690
701691EMSCRIPTEN_KEEPALIVE void _sargs_add_kvp (const char * key , const char * val ) {
@@ -713,7 +703,7 @@ EMSCRIPTEN_KEEPALIVE void _sargs_add_kvp(const char* key, const char* val) {
713703 }
714704 _sargs_putc (0 );
715705
716- /* copy value string */
706+ // copy value string
717707 _sargs .args [_sargs .num_args ].val = _sargs .buf_pos ;
718708 ptr = val ;
719709 while (0 != (c = * ptr ++ )) {
@@ -724,10 +714,10 @@ EMSCRIPTEN_KEEPALIVE void _sargs_add_kvp(const char* key, const char* val) {
724714 _sargs .num_args ++ ;
725715}
726716#ifdef __cplusplus
727- } /* extern "C" */
717+ } // extern "C"
728718#endif
729719
730- /* JS function to extract arguments from the page URL */
720+ // JS function to extract arguments from the page URL
731721EM_JS (void , sargs_js_parse_url , (void ) , {
732722 const params = new URLSearchParams (window .location .search ).entries ();
733723 for (let p = params .next (); !p .done ; p = params .next ()) {
@@ -739,11 +729,11 @@ EM_JS(void, sargs_js_parse_url, (void), {
739729 __sargs_add_kvp (key_cstr , val_cstr )
740730 });
741731 }
742- });
732+ })
743733
744- #endif /* EMSCRIPTEN */
734+ #endif // EMSCRIPTEN
745735
746- /* == PUBLIC IMPLEMENTATION FUNCTIONS =========================================*/
736+ // == PUBLIC IMPLEMENTATION FUNCTIONS ===========================================
747737SOKOL_API_IMPL void sargs_setup (const sargs_desc * desc ) {
748738 SOKOL_ASSERT (desc );
749739 _sargs_clear (& _sargs , sizeof (_sargs ));
@@ -752,16 +742,16 @@ SOKOL_API_IMPL void sargs_setup(const sargs_desc* desc) {
752742 SOKOL_ASSERT (_sargs .buf_size > 8 );
753743 _sargs .args = (_sargs_kvp_t * ) _sargs_malloc_clear ((size_t )_sargs .max_args * sizeof (_sargs_kvp_t ));
754744 _sargs .buf = (char * ) _sargs_malloc_clear ((size_t )_sargs .buf_size * sizeof (char ));
755- /* the first character in buf is reserved and always zero, this is the 'empty string' */
745+ // the first character in buf is reserved and always zero, this is the 'empty string'
756746 _sargs .buf_pos = 1 ;
757747 _sargs .allocator = desc -> allocator ;
758748 _sargs .valid = true;
759749
760- /* parse argc/argv */
750+ // parse argc/argv
761751 _sargs_parse_cargs (desc -> argc , (const char * * ) desc -> argv );
762752
763753 #if defined(__EMSCRIPTEN__ )
764- /* on emscripten, also parse the page URL*/
754+ // on emscripten, also parse the page URL
765755 sargs_js_parse_url ();
766756 #endif
767757}
@@ -802,9 +792,8 @@ SOKOL_API_IMPL const char* sargs_key_at(int index) {
802792 SOKOL_ASSERT (_sargs .valid );
803793 if ((index >= 0 ) && (index < _sargs .num_args )) {
804794 return _sargs_str (_sargs .args [index ].key );
805- }
806- else {
807- /* index 0 is always the empty string */
795+ } else {
796+ // index 0 is always the empty string
808797 return _sargs_str (0 );
809798 }
810799}
@@ -813,9 +802,8 @@ SOKOL_API_IMPL const char* sargs_value_at(int index) {
813802 SOKOL_ASSERT (_sargs .valid );
814803 if ((index >= 0 ) && (index < _sargs .num_args )) {
815804 return _sargs_str (_sargs .args [index ].val );
816- }
817- else {
818- /* index 0 is always the empty string */
805+ } else {
806+ // index 0 is always the empty string
819807 return _sargs_str (0 );
820808 }
821809}
@@ -841,8 +829,7 @@ SOKOL_API_IMPL const char* sargs_value_def(const char* key, const char* def) {
841829 } else {
842830 return res ;
843831 }
844- }
845- else {
832+ } else {
846833 return def ;
847834 }
848835}
@@ -864,4 +851,4 @@ SOKOL_API_IMPL bool sargs_boolean(const char* key) {
864851 }
865852}
866853
867- #endif /* SOKOL_ARGS_IMPL */
854+ #endif // SOKOL_ARGS_IMPL
0 commit comments