|
@ -1,5 +1,6 @@ |
|
|
#include <stdio.h> |
|
|
#include <stdio.h> |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
void setBit(char *bits, int n) |
|
|
void setBit(char *bits, int n) |
|
|
{ |
|
|
{ |
|
@ -45,6 +46,65 @@ int isEscapedChar(char char1, char char2){ |
|
|
else return ; //returning nothing for the moment, returning 0 printed weird character, no idea what to do |
|
|
else return ; //returning nothing for the moment, returning 0 printed weird character, no idea what to do |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int hexaToDecimal(char hex1,char hex2){ |
|
|
|
|
|
char hex[2]; |
|
|
|
|
|
hex[0]=hex1;hex[1]=hex2; |
|
|
|
|
|
long long decimal = 0, base = 1; |
|
|
|
|
|
int i = 0, value, length; |
|
|
|
|
|
|
|
|
|
|
|
length = 2; |
|
|
|
|
|
for(i = length--; i >= 0; i--) |
|
|
|
|
|
{ |
|
|
|
|
|
if(hex[i] >= '0' && hex[i] <= '9') |
|
|
|
|
|
{ |
|
|
|
|
|
decimal += (hex[i] - 48) * base; |
|
|
|
|
|
base *= 16; |
|
|
|
|
|
} |
|
|
|
|
|
else if(hex[i] >= 'A' && hex[i] <= 'F') |
|
|
|
|
|
{ |
|
|
|
|
|
decimal += (hex[i] - 55) * base; |
|
|
|
|
|
base *= 16; |
|
|
|
|
|
} |
|
|
|
|
|
else if(hex[i] >= 'a' && hex[i] <= 'f') |
|
|
|
|
|
{ |
|
|
|
|
|
decimal += (hex[i] - 87) * base; |
|
|
|
|
|
base *= 16; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return decimal; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int octalToDecimal(int octalNumber) |
|
|
|
|
|
{ |
|
|
|
|
|
int decimalNumber = 0, i = 0; |
|
|
|
|
|
|
|
|
|
|
|
while(octalNumber != 0) |
|
|
|
|
|
{ |
|
|
|
|
|
decimalNumber += (octalNumber%10) * pow(8,i); |
|
|
|
|
|
++i; |
|
|
|
|
|
octalNumber/=10; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
i = 1; |
|
|
|
|
|
|
|
|
|
|
|
return decimalNumber; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int isByte(char char1, char char2, char char3, char char4){ |
|
|
|
|
|
if( char1=='\\' && char2=='x' && (char3<=55 && char3>=48) && ((char4<=57 && char4>=48) || (char4<=70 && char4>=65))){ |
|
|
|
|
|
printf("ouaiiiiis"); |
|
|
|
|
|
return hexaToDecimal(char3,char4); |
|
|
|
|
|
} |
|
|
|
|
|
else if(char1=='\\' && (char2<=55 && char2>=48) && (char3<=55 && char3>=48) && (char4<=55 && char4>=48)){ |
|
|
|
|
|
int octal=((int)char2-48)*100+((int)char3-48)*10+(int)char4-48; |
|
|
|
|
|
return octalToDecimal(octal); |
|
|
|
|
|
} |
|
|
|
|
|
else return 0 ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *classify(char *spec) |
|
|
char *classify(char *spec) |
|
|
{ |
|
|
{ |
|
|
char *class= malloc(32); // 256 bits indicating if character N (bit position N) is in the class or not |
|
|
char *class= malloc(32); // 256 bits indicating if character N (bit position N) is in the class or not |
|
@ -108,12 +168,18 @@ char *classify(char *spec) |
|
|
setBit(class,spec[index]); |
|
|
setBit(class,spec[index]); |
|
|
printf("added char : %c\n",spec[index]); |
|
|
printf("added char : %c\n",spec[index]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else if(isByte(spec[index],spec[index+1],spec[index+2],spec[index+3])){ |
|
|
|
|
|
setBit(class,isByte(spec[index],spec[index+1],spec[index+2],spec[index+3])); |
|
|
|
|
|
index=index+4; |
|
|
|
|
|
} |
|
|
else if(isEscapedChar(spec[index],spec[index+1])!=0){ |
|
|
else if(isEscapedChar(spec[index],spec[index+1])!=0){ |
|
|
if(isEscapedChar(spec[index],spec[index+1])==45){ |
|
|
if(isEscapedChar(spec[index],spec[index+1])==45){ |
|
|
index++; |
|
|
index++; |
|
|
} |
|
|
} |
|
|
setBit(class,isEscapedChar(spec[index],spec[index+1])); |
|
|
setBit(class,isEscapedChar(spec[index],spec[index+1])); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
printf("%c\n",spec[index]); |
|
|
printf("%c\n",spec[index]); |
|
|
printf("%i\n",index); |
|
|
printf("%i\n",index); |
|
|
index++; |
|
|
index++; |
|
|