-
Notifications
You must be signed in to change notification settings - Fork 0
/
a_common.cpp
104 lines (80 loc) · 1.37 KB
/
a_common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/****************************************************************
xerxes engine
a_common.cpp
****************************************************************/
#include "xerxes.h"
/***************************** data *****************************/
FILE *logf;
bool log_on = false;
/***************************** code *****************************/
void log_Init(bool on)
{
remove(LOGFILE);
log_on = on;
}
void log(char *text, ...)
{
va_list argptr;
char msg[256];
va_start(argptr, text);
vsprintf(msg, text, argptr);
va_end(argptr);
if (!log_on) return;
logf = fopen(LOGFILE,"aw");
fprintf(logf,"%s\n",msg);
fflush(logf);
fclose(logf);
}
char *va(char* format, ...)
{
va_list argptr;
static char string[1024];
va_start(argptr, format);
vsprintf(string, format, argptr);
va_end(argptr);
return string;
}
int strcasecmp(char *s1, char *s2)
{
while (true)
{
if (tolower(*s1) != tolower(*s2))
return -1;
if (!*s1)
return 0;
s1++;
s2++;
}
return -1;
}
bool isletter(char c)
{
if (tolower(c) < 'a' || tolower(c) > 'z') return false;
return true;
}
void strclean(char *s)
{
while (*s)
{
if (*s == 10 || *s == 13)
{
*s = 0;
return;
}
s++;
}
}
int sgn(int a)
{
if (a<0)
return -1;
else if (a>0)
return +1;
return 0;
}
int rnd(int lo, int hi)
{
int range = hi - lo + 1;
int i = rand() % range;
return i + lo;
}