forked from REDPOWAR/glDoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
doomlib.c
75 lines (58 loc) · 1.39 KB
/
doomlib.c
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
// doomlib.c
//
// This source file contains functions that are not supported by the
// ANSI 'C' specification but which appear in some form in most
// implementations. These are provided to make the software more
// portable by using only ANSI standard library functions.
char *D_strupper (char *str)
{
char *c, t;
t = 'a' - 'A';
c = str;
while (*c)
{
*c = ((*c >= 'a') && (*c <= 'z')) ? *c - t : *c;
c++;
}
return str;
}
char *D_strlower (char *str)
{
char *c, t;
t = 'A' - 'a';
c = str;
while (*c)
{
*c = ((*c >= 'A') && (*c <= 'Z')) ? *c - t : *c;
c++;
}
return str;
}
int D_strncasecmp(char *s1, char *s2, int count)
{
unsigned char c1, c2, c3;
c3 = 'a' - 'A';
while (1)
{
c1 = (unsigned char)*s1++;
c2 = (unsigned char)*s2++;
if (!count--)
return 0; // strings are equal until end point
if (c1 != c2)
{
if (c1 >= 'a' && c1 <= 'z')
c1 -= c3;
if (c2 >= 'a' && c2 <= 'z')
c2 -= c3;
if (c1 != c2)
return (int)(c1 - c2); // strings not equal
}
if (!c1)
return 0; // strings are equal
}
return -1;
}
int D_strcasecmp(char *s1, char *s2)
{
return(D_strncasecmp(s1, s2, 99999));
}