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 140 141 142 143 144
|
/********************************************************************
* Extra standard functions
*/
#include <stdio.h>
#include <ctype.h>
#include "misc.h"
/********************************************************************
* Case insensetive strcmp()
*/
int nocase_strcmp(char *s, char *t)
{
int i;
for(i = 0; tolower(s[i]) == tolower(t[i]); i++)
if(s[i] == '\0')
return(0);
return(tolower(s[i]) - tolower(t[i]));
}
/********************************************************************
* Case insensetive strncmp()
*/
int nocase_strncmp(char *s, char *t, int n)
{
int i;
for(i = 0; (tolower(s[i]) == tolower(t[i])); i++, n--)
if((s[i] == '\0') || (n == 1))
return(0);
return(tolower(s[i]) - tolower(t[i]));
}
/********************************************************************
* Case insensetive strstr()
*/
char *nocase_strstr(char *s, char *t)
{
int i = 0, j, found = False;
while((s[i] != '\0') && !found)
{
j = 0;
while(tolower(t[j]) == tolower(s[i + j]))
{
j++;
if(t[j] == '\0')
{
found = True;
break;
}
else if(s[i + j] == '\0')
break;
}
i++;
}
i--;
if(found)
return(&s[i]);
return(NULL);
}
/********************************************************************
* ascii to hex
* ignores "0x"
*/
int atox(char *s)
{
int i = 0, ret = 0;
while(s[i] != '\0')
{
ret <<= 4;
if((s[i] <= 'F') && (s[i] >= 'A'))
ret |= s[i] - 'A' + 10;
else if((s[i] <= 'f') && (s[i] >= 'a'))
ret |= s[i] - 'a' + 10;
else if((s[i] <= '9') && (s[i] >= '0'))
ret |= s[i] - '0';
i++;
}
return(ret);
}
/********************************************************************
* n ascii chars to int
*/
int atoi_n(char *s, int n)
{
int i = 0, ret = 0;
while((s[i] != '\0') && n)
{
ret = 10 * ret + (s[i] - '0');
i++;
n--;
}
return(ret);
}
/********************************************************************
* n ascii chars to hex
* 0 < n <= 8
* ignores "0x"
*/
int atox_n(char *s, int n)
{
int i = 0, ret = 0;
while((s[i] != '\0') && n)
{
ret <<= 4;
if((s[i] <= 'F') && (s[i] >= 'A'))
ret |= s[i] - 'A' + 10;
else if((s[i] <= 'f') && (s[i] >= 'a'))
ret |= s[i] - 'a' + 10;
else if((s[i] <= '9') && (s[i] >= '0'))
ret |= s[i] - '0';
i++;
n--;
}
return(ret);
}
|