This repository has been archived by the owner on May 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtility.cpp
139 lines (105 loc) · 2.66 KB
/
Utility.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define MDK_EXPORT_FUNCTIONS 1 /*Export the methods*/
#include "Utility.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
bool MDKDLLAPI strendswith(const char *buffer, const char *what)
{
size_t endsize = strlen(what), buffsize = strlen(buffer);
char *checkbuf = (char *)malloc(sizeof(char) * (endsize + 1));
for (; endsize > -1; buffsize--, endsize--)
{
checkbuf[endsize] = buffer[buffsize];
}
if (strcmp(checkbuf, what) == 0)
{
if (checkbuf)
free(checkbuf);
return true;
}
if (checkbuf)
free(checkbuf);
return false;
}
bool MDKDLLAPI strdelete(char *buffer, size_t buffersize, size_t number)
{
size_t counter = 0;
if (buffersize < number)
return false;
buffersize -= number;
for (; counter < buffersize; counter++, number++)
{
buffer[counter] = buffer[number];
}
buffer[counter] = '\0';
return true;
}
void MDKDLLAPI strrand(char *buffer, size_t buffersize, const char *table)
{
size_t table_len = strlen(table), i = 0;
for (; i < (buffersize - 1); i++)
{
int randnum = rand() % (table_len - 1);
buffer[i] = table[randnum];
}
buffer[i] = '\0';
}
bool MDKDLLAPI strfind(char *buffer, const char what)
{
while (*buffer != '\0')
{
if (*buffer == what)
return true;
buffer++;
}
return false;
}
bool MDKDLLAPI strstartswith(const char* buffer, const char* what)
{
size_t whatsize = strlen(what), count = 0;
char *checkbuf = (char *)malloc(sizeof(char) * (whatsize + 1));
if (whatsize > strlen(buffer))
return false;
for (; count < whatsize; count++)
{
checkbuf[count] = buffer[count];
}
checkbuf[count] = '\0';
if (strcmp(checkbuf, what) == 0)
{
if (checkbuf)
free(checkbuf);
return true;
}
if (checkbuf)
free(checkbuf);
return false;
}
void MDKDLLAPI CmdLoginInfoDisplay(const char *name, const char *type, const char *fmt, ...)
{
va_list vl;
if (!fmt)
return;
if (name)
printf("[%s] ", name);
if (type)
printf("[%s] ", type);
printf(">> ");
va_start(vl, fmt);
vprintf(fmt, vl);
va_end(vl);
printf("\n");
}