Miscellaneous utility functions.
Usage: #include <swilib.h> or #include <swilib/utils.h>
|
| 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.
|
| |
|
| 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.
|
| |
|
| 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.
|
| |
◆ SEQKILLER()
| void SEQKILLER |
( |
void * | data, |
|
|
void(* | next_in_seq )(void *), |
|
|
void * | data_to_kill ) |
Free memory in the sequence.
- Parameters
-
| data | data passed to the next_in_seq |
| next_in_seq | destructor |
| data_to_kill | pointer 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);
}
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()
◆ StrToInt()
| int StrToInt |
( |
const char * | s, |
|
|
char ** | endp ) |
Convert string to int.
- Parameters
-
| s | string with number |
| endp | pointer 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
-
| s | mutable string with HEX |
| fallback | value 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
-
- 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_out | output for hex string (len * 2 + 1) |
| str | input string |
| len | input string length |
◆ GetLangMesIntoWS()
| void GetLangMesIntoWS |
( |
int | lgp_id, |
|
|
WSHDR * | str ) |
Convert string to int.
- Parameters
-
| lgp_id | langpack ID |
| [out] | str | output 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_file | path to .bcfg file |
| config | pointer to config structure |
| size | config 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_file | path to .bcfg file |
| config_begin | pointer to config section begin |
| config_end | pointer 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_file | path to .bcfg file |
| config | pointer to config structure |
| size | config 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_file | path to .bcfg file |
| config_begin | pointer to config section begin |
| config_end | pointer 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
-
| inbuf | input buffer |
| insize | input buffer length |
| [out] | outbuf | output string buffer for the base64-encoded string |
| outsize | output 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
-
| inbuf | input b64 string |
| insize | input b64 string size |
| [out] | outbuf | output buffer |
| outsize | output buffer size (max size) |
| _null | set to NULL |
| unk5 | pointer to the dummy int |
- Returns
- decoded buffer size or 0
uint8_t outbuf[1024];
int unk = 0;
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
-
| divisor | the number by which we divide. |
| divident | the number we are dividing |
- Returns
- divident / divisor
◆ udiv()
| uint32_t udiv |
( |
uint32_t | divisor, |
|
|
uint32_t | dividend ) |
Unsigned int div.
- Parameters
-
| divisor | the number by which we divide. |
| divident | the number we are dividing |
- Returns
- divident / divisor
◆ DivBy10()
| int DivBy10 |
( |
int | dividend | ) |
|
Signed int div by 10.
- Parameters
-
| divident | the number we are dividing |
- Returns
- divident / 10