|
|
|
/**
|
|
|
|
* Author......: See docs/credits.txt
|
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "types_int.h"
|
|
|
|
#include "shared.h"
|
|
|
|
|
|
|
|
u32 get_random_num (const u32 min, const u32 max)
|
|
|
|
{
|
|
|
|
if (min == max) return (min);
|
|
|
|
|
|
|
|
return ((rand () % (max - min)) + min);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 mydivc32 (const u32 dividend, const u32 divisor)
|
|
|
|
{
|
|
|
|
u32 quotient = dividend / divisor;
|
|
|
|
|
|
|
|
if (dividend % divisor) quotient++;
|
|
|
|
|
|
|
|
return quotient;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 mydivc64 (const u64 dividend, const u64 divisor)
|
|
|
|
{
|
|
|
|
u64 quotient = dividend / divisor;
|
|
|
|
|
|
|
|
if (dividend % divisor) quotient++;
|
|
|
|
|
|
|
|
return quotient;
|
|
|
|
}
|
|
|
|
|
|
|
|
void naive_replace (char *s, const u8 key_char, const u8 replace_char)
|
|
|
|
{
|
|
|
|
const size_t len = strlen (s);
|
|
|
|
|
|
|
|
for (size_t in = 0; in < len; in++)
|
|
|
|
{
|
|
|
|
const u8 c = s[in];
|
|
|
|
|
|
|
|
if (c == key_char)
|
|
|
|
{
|
|
|
|
s[in] = replace_char;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void naive_escape (char *s, size_t s_max, const u8 key_char, const u8 escape_char)
|
|
|
|
{
|
|
|
|
char s_escaped[1024] = { 0 };
|
|
|
|
|
|
|
|
size_t s_escaped_max = sizeof (s_escaped);
|
|
|
|
|
|
|
|
const size_t len = strlen (s);
|
|
|
|
|
|
|
|
for (size_t in = 0, out = 0; in < len; in++, out++)
|
|
|
|
{
|
|
|
|
const u8 c = s[in];
|
|
|
|
|
|
|
|
if (c == key_char)
|
|
|
|
{
|
|
|
|
s_escaped[out] = escape_char;
|
|
|
|
|
|
|
|
out++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (out == s_escaped_max - 2) break;
|
|
|
|
|
|
|
|
s_escaped[out] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy (s, s_escaped, s_max - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hc_sleep (const int sec)
|
|
|
|
{
|
|
|
|
#if defined (_WIN)
|
|
|
|
#define sleep(x) Sleep ((x) * 1000)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sleep (sec);
|
|
|
|
}
|