Debian Codegraph @

src/winfunctions.cpp

raw symbols SCIP
1 #ifdef WIN32
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include "winfunctions.h"
6
7 char *my_strcasestr(char *haystack, char *needle)
8 {
9 int length, index;
10 char *up_haystack, *up_needle;
11 char *result, *my_substr;
12
13 if ( (!haystack) || (! needle) )
14 return NULL;
15
16 // create buffers
17 up_haystack = (char *) calloc( strlen(haystack) + 1, sizeof(char));
18 if (! up_haystack)
19 return NULL;
20 up_needle = (char *) calloc( strlen(needle) + 1, sizeof(char) );
21 if (! up_needle)
22 {
23 free(up_haystack);
24 return NULL;
25 }
26
27 length = strlen(haystack);
28 for (index = 0; index < length; index++)
29 up_haystack[index] = toupper(haystack[index]);
30 length = strlen(needle);
31 for (index = 0; index < length; index++)
32 up_needle[index] = toupper(needle[index]);
33
34 result = strstr(up_haystack, up_needle);
35 if (result)
36 my_substr = (result - up_haystack) + haystack;
37 else
38 my_substr = NULL;
39
40 // free buffers
41 free(up_needle);
42 free(up_haystack);
43 return my_substr;
44 }
45
46
47
48 int my_strncasecmp(char *str1, char *str2, int letters)
49 {
50 int index = 0;
51 int letter1, letter2;
52 int result = FALSE;
53
54 while ( (index < letters) && (! result) )
55 {
56 letter1 = toupper(str1[index]);
57 letter2 = toupper(str2[index]);
58 if (letter1 == letter2)
59 index++;
60 else if (letter1 < letter2)
61 result = -1;
62 else if (letter1 > letter2)
63 result = 1;
64
65 }
66 return result;
67 }
68
69
70
71 #endif
72