Removed MIN/MAX/MINMAX functions, upgraded to C++17, code cleanup

This commit is contained in:
2022-11-27 22:18:08 +02:00
parent 3a74dac29e
commit 148223340c
56 changed files with 230 additions and 404 deletions

View File

@ -5,20 +5,12 @@
#include "effolkronium/random.hpp"
using Random = effolkronium::random_static;
#define SAFE_FREE(p) { if (p) { free( (void *) p); (p) = NULL; } }
#define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } }
#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } }
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } }
#include <algorithm>
#define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c))
#define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c))
#define str_cmp strcasecmp
#define STRNCPY(dst, src, len) do {strncpy(dst, src, len); dst[len] = '\0'; } while(0)
extern char * str_dup(const char * source); // <20>޸<EFBFBD><DEB8><EFBFBD> <20>Ҵ<EFBFBD> <20>ؼ<EFBFBD> source <20><><EFBFBD><EFBFBD> <20>Ѱ<EFBFBD> <20><><EFBFBD><EFBFBD>
extern void printdata(const unsigned char * data, int bytes); // data<74><61> hex<65><78> ascii<69><69> <20><><EFBFBD><EFBFBD> (<28><>Ŷ <20>м<EFBFBD> <20><20><><EFBFBD><EFBFBD>)
extern int filesize(FILE * fp); // <20><><EFBFBD><EFBFBD> ũ<><C5A9> <20><><EFBFBD><EFBFBD>
#define core_dump() core_dump_unix(__FILE__, __LINE__)
extern void core_dump_unix(const char *who, WORD line); // <20>ھ<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
@ -29,12 +21,6 @@ using Random = effolkronium::random_static;
extern void trim_and_lower(const char * src, char * dest, size_t dest_size);
// <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20>ҹ<EFBFBD><D2B9>ڷ<EFBFBD>
extern void lower_string(const char * src, char * dest, size_t dest_len);
// arg1<67><31> arg2<67><32> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ°<CFB4>? (<28><><EFBFBD>ҹ<EFBFBD><D2B9><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)
extern int is_abbrev(char *arg1, char *arg2);
// a<><61> b<><62> <20>ð<EFBFBD><C3B0><EFBFBD> <20>󸶳<EFBFBD> <20><><EFBFBD>̳<EFBFBD><CCB3><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern struct timeval * timediff(const struct timeval *a, const struct timeval *b);
@ -44,10 +30,6 @@ using Random = effolkronium::random_static;
// <20><><EFBFBD><EFBFBD> <20>ð<EFBFBD> curr_tm<74><6D><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> days<79><73> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern struct tm * tm_calc(const struct tm *curr_tm, int days);
extern int MAX(int a, int b); // <20><><EFBFBD>߿<EFBFBD> ū <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern int MIN(int a, int b); // <20><><EFBFBD>߿<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
extern int MINMAX(int min, int value, int max); // <20>ּ<EFBFBD> <20>ִ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>Բ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD> <20><><EFBFBD><EFBFBD>
extern void thecore_sleep(struct timeval * timeout); // timeout<75><74>ŭ <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD> <20><><EFBFBD><EFBFBD>
extern float get_float_time();

View File

@ -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);

View File

@ -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)
{