SWILIB API (X75)    
Loading...
Searching...
No Matches
Utils

Detailed Description

Miscellaneous utility functions.

Usage: #include <swilib.h> or #include <swilib/utils.h>

Functions

void SEQKILLER (void *data, void(*next_in_seq)(void *), void *data_to_kill)
 Free memory in the sequence.
 
void * SEQKILLER_ADR ()
 Pointer to the SEQKILLER.
 

String utils

int StrToInt (const char *s, char **endp)
 Convert string to int.
 
uint32_t HexToInt (char *s, uint32_t fallback)
 Convert HEX-string to int.
 
int HexCharToInt (char c)
 Convert HEX char to int.
 
void StrToHex (char *hex_out, const char *str, int len)
 Convert string to int.
 
void GetLangMesIntoWS (int lgp_id, WSHDR *str)
 Convert string to int.
 

Binary Configs (BCFG)

int BCFG_GetDefaultDisk (void)
 Get default disk for BCFG configs.
 
int BCFG_LoadConfig (const char *config_file, void *config, uint32_t size)
 Load .bcfg config from disk (structure)
 
static int BCFG_LoadConfigSection (const char *config_file, void *config_begin, void *config_end)
 Load .bcfg config from disk (section)
 
int BCFG_SaveConfig (const char *config_file, const void *config, uint32_t size)
 Save .bcfg config to disk (structure)
 
static int BCFG_SaveConfigSection (const char *config_file, const void *config_begin, const void *config_end)
 Save .bcfg config to disk (section)
 

Base64 encoding/decoding

int Base64Encode (void *inbuf, int insize, void *outbuf, int outsize)
 Encode binary data to the base64 string.
 
int Base64Decode (char *inbuf, int insize, void *outbuf, int outsize, char *_null, int *unk5)
 Decode string to the binary data.
 

Math

int sdiv (int divisor, int dividend)
 Signed int div.
 
uint32_t udiv (uint32_t divisor, uint32_t dividend)
 Unsigned int div.
 
int DivBy10 (int dividend)
 Signed int div by 10.
 

Function Documentation

◆ SEQKILLER()

void SEQKILLER ( void * data,
void(* next_in_seq )(void *),
void * data_to_kill )

Free memory in the sequence.

Parameters
datadata passed to the next_in_seq
next_in_seqdestructor
data_to_killpointer to be freed
Builtin on platforms:
ELKA, NSG, X75, SG

Strange function with unknown purpose.

void SEQKILLER(void *data, void(*next_in_seq)(void *), void *data_to_kill) {
next_in_seq(data);
mfree(data_to_kill);
}
void SEQKILLER(void *data, void(*next_in_seq)(void *), void *data_to_kill)
Free memory in the sequence.
void mfree(void *ptr)
Free previously allocated memory.

◆ SEQKILLER_ADR()

void * SEQKILLER_ADR ( )

Pointer to the SEQKILLER.

Returns
pointer

◆ StrToInt()

int StrToInt ( const char * s,
char ** endp )

Convert string to int.

Parameters
sstring with number
endppointer to the end of the number
Returns
int

◆ HexToInt()

uint32_t HexToInt ( char * s,
uint32_t fallback )

Convert HEX-string to int.

The input may contain up to eight hexadecimal digits. Lowercase digits are converted to uppercase in place.

Parameters
smutable string with HEX
fallbackvalue returned for an invalid digit or a string longer than eight characters
Returns
parsed value, or fallback on error

◆ HexCharToInt()

int HexCharToInt ( char c)

Convert HEX char to int.

Parameters
cHEX char, any case
Returns
0..15 or 0xFF if the char is not a HEX digit

◆ StrToHex()

void StrToHex ( char * hex_out,
const char * str,
int len )

Convert string to int.

Parameters
[out]hex_outoutput for hex string (len * 2 + 1)
strinput string
leninput string length

◆ GetLangMesIntoWS()

void GetLangMesIntoWS ( int lgp_id,
WSHDR * str )

Convert string to int.

Parameters
lgp_idlangpack ID
[out]stroutput for LGP string value

◆ BCFG_GetDefaultDisk()

int BCFG_GetDefaultDisk ( void )

Get default disk for BCFG configs.

Returns
disk number
Builtin on platforms:
ELKA, NSG, X75, SG

◆ BCFG_LoadConfig()

int BCFG_LoadConfig ( const char * config_file,
void * config,
uint32_t size )

Load .bcfg config from disk (structure)

Parameters
[out]config_filepath to .bcfg file
configpointer to config structure
sizeconfig structure size
Returns
0 if success, -1 if error
Builtin on platforms:
ELKA, NSG, X75, SG

◆ BCFG_LoadConfigSection()

static int BCFG_LoadConfigSection ( const char * config_file,
void * config_begin,
void * config_end )
inlinestatic

Load .bcfg config from disk (section)

Parameters
[out]config_filepath to .bcfg file
config_beginpointer to config section begin
config_endpointer to config section end
Returns
0 if success, -1 if error
Builtin on platforms:
ELKA, NSG, X75, SG

Definition at line 135 of file utils.h.

◆ BCFG_SaveConfig()

int BCFG_SaveConfig ( const char * config_file,
const void * config,
uint32_t size )

Save .bcfg config to disk (structure)

Parameters
[out]config_filepath to .bcfg file
configpointer to config structure
sizeconfig structure size
Returns
0 if success, -1 if error
Builtin on platforms:
ELKA, NSG, X75, SG

◆ BCFG_SaveConfigSection()

static int BCFG_SaveConfigSection ( const char * config_file,
const void * config_begin,
const void * config_end )
inlinestatic

Save .bcfg config to disk (section)

Parameters
[out]config_filepath to .bcfg file
config_beginpointer to config section begin
config_endpointer to config section end
Returns
0 if success, -1 if error
Builtin on platforms:
ELKA, NSG, X75, SG

Definition at line 160 of file utils.h.

◆ Base64Encode()

int Base64Encode ( void * inbuf,
int insize,
void * outbuf,
int outsize )

Encode binary data to the base64 string.

Parameters
inbufinput buffer
insizeinput buffer length
[out]outbufoutput string buffer for the base64-encoded string
outsizeoutput string buffer size (max size)
Returns
encoded string length or 0
char outbuf[1024];
int outbuf_len = Base64Encode(inbuf, inbuf_len, outbuf, sizeof(outbuf));
int Base64Encode(void *inbuf, int insize, void *outbuf, int outsize)
Encode binary data to the base64 string.

◆ Base64Decode()

int Base64Decode ( char * inbuf,
int insize,
void * outbuf,
int outsize,
char * _null,
int * unk5 )

Decode string to the binary data.

Parameters
inbufinput b64 string
insizeinput b64 string size
[out]outbufoutput buffer
outsizeoutput buffer size (max size)
_nullset to NULL
unk5pointer to the dummy int
Returns
decoded buffer size or 0
uint8_t outbuf[1024];
int unk = 0;
int decoded_len = Base64Decode(inbuf, strlen(inbuf), outbuf, sizeof(outbuf), NULL, &unk);
int Base64Decode(char *inbuf, int insize, void *outbuf, int outsize, char *_null, int *unk5)
Decode string to the binary data.
size_t strlen(const char *str)
Get string length.

◆ sdiv()

int sdiv ( int divisor,
int dividend )

Signed int div.

Parameters
divisorthe number by which we divide.
dividentthe number we are dividing
Returns
divident / divisor

◆ udiv()

uint32_t udiv ( uint32_t divisor,
uint32_t dividend )

Unsigned int div.

Parameters
divisorthe number by which we divide.
dividentthe number we are dividing
Returns
divident / divisor

◆ DivBy10()

int DivBy10 ( int dividend)

Signed int div by 10.

Parameters
dividentthe number we are dividing
Returns
divident / 10