forked from metin2/server
Removed MIN/MAX/MINMAX functions, upgraded to C++17, code cleanup
This commit is contained in:
@ -162,7 +162,7 @@ void buffer_reset(LPBUFFER buffer)
|
||||
void buffer_write(LPBUFFER& buffer, const void *src, int length)
|
||||
{
|
||||
if (buffer->write_point_pos + length >= buffer->mem_size)
|
||||
buffer_realloc(buffer, buffer->mem_size + length + MIN(10240, length));
|
||||
buffer_realloc(buffer, buffer->mem_size + length + std::min(10240, length));
|
||||
|
||||
memcpy(buffer->write_point, src, length);
|
||||
buffer_write_proceed(buffer, length);
|
||||
|
@ -10,56 +10,6 @@
|
||||
|
||||
static struct timeval null_time = { 0, 0 };
|
||||
|
||||
#define ishprint(x) ((((x) & 0xE0) > 0x90) || isprint(x))
|
||||
|
||||
void printdata(const unsigned char *data, int bytes)
|
||||
{
|
||||
int i, j, k;
|
||||
const unsigned char *p;
|
||||
|
||||
fprintf(stderr, "------------------------------------------------------------------\n");
|
||||
j = bytes;
|
||||
while (1)
|
||||
{
|
||||
k = j >= 16 ? 16 : j;
|
||||
|
||||
p = data;
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
if (i >= k)
|
||||
fprintf(stderr, " ");
|
||||
else
|
||||
fprintf(stderr, "%02x ", *p);
|
||||
p++;
|
||||
}
|
||||
|
||||
fprintf(stderr, "| ");
|
||||
|
||||
p = data;
|
||||
for (i = 0; i < k; i++)
|
||||
{
|
||||
if (i >= k)
|
||||
fprintf(stderr, " ");
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "%c", ishprint(*p) && ishprint(*(p+1)) ? *p : '.');
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
j -= 16;
|
||||
data += 16;
|
||||
|
||||
if (j <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, "------------------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
|
||||
struct timeval * timediff(const struct timeval *a, const struct timeval *b)
|
||||
{
|
||||
static struct timeval rslt;
|
||||
@ -166,73 +116,6 @@ void trim_and_lower(const char * src, char * dest, size_t dest_size)
|
||||
}
|
||||
}
|
||||
|
||||
void lower_string(const char *src, char *dest, size_t dest_size)
|
||||
{
|
||||
const char* tmp = src;
|
||||
size_t len = 0;
|
||||
|
||||
if (!dest || dest_size == 0)
|
||||
return;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
*dest = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
// \0 Ȯ<><C8AE>
|
||||
--dest_size;
|
||||
|
||||
while (*tmp && len < dest_size)
|
||||
{
|
||||
*(dest++) = LOWER(*tmp); // LOWER<45><52> <20><>ũ<EFBFBD>ζ<EFBFBD> ++ <20><><EFBFBD><EFBFBD> <20>ȵ<EFBFBD>
|
||||
++tmp;
|
||||
++len;
|
||||
}
|
||||
|
||||
*dest = '\0';
|
||||
}
|
||||
|
||||
char *str_dup(const char *source)
|
||||
{
|
||||
char *new_line;
|
||||
|
||||
CREATE(new_line, char, strlen(source) + 1);
|
||||
return (strcpy(new_line, source));
|
||||
}
|
||||
|
||||
/* arg1 <20><> arg2 <20><> <20>մܰ<D5B4> <20><><EFBFBD><EFBFBD> <20><> 1 <20><> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>. */
|
||||
int is_abbrev(char *arg1, char *arg2)
|
||||
{
|
||||
if (!*arg1)
|
||||
return 0;
|
||||
|
||||
for (; *arg1 && *arg2; arg1++, arg2++)
|
||||
if (LOWER(*arg1) != LOWER(*arg2))
|
||||
return 0;
|
||||
|
||||
if (!*arg1)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int filesize(FILE *fp)
|
||||
{
|
||||
int pos;
|
||||
int size;
|
||||
|
||||
pos = ftell(fp);
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
size = ftell(fp);
|
||||
fseek(fp, pos, SEEK_SET);
|
||||
|
||||
return (size);
|
||||
}
|
||||
|
||||
|
||||
/* "Name : <20><><EFBFBD><EFBFBD>" <20><> <20><><EFBFBD><EFBFBD> "<22><EFBFBD> : <20><>" <20><><EFBFBD><EFBFBD> <20>̷<EFBFBD><CCB7><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><EFBFBD><D7B8><EFBFBD> token <20><><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> value <20><> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>. */
|
||||
void parse_token(char *src, char *token, char *value)
|
||||
@ -327,24 +210,6 @@ struct tm * tm_calc(const struct tm * curr_tm, int days)
|
||||
return (&new_tm);
|
||||
}
|
||||
|
||||
int MIN(int a, int b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
int MAX(int a, int b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
int MINMAX(int min, int value, int max)
|
||||
{
|
||||
register int tv;
|
||||
|
||||
tv = (min > value ? min : value);
|
||||
return (max < tv) ? max : tv;
|
||||
}
|
||||
|
||||
#ifndef __WIN32__
|
||||
void thecore_sleep(struct timeval* timeout)
|
||||
{
|
||||
|
Reference in New Issue
Block a user