|
|
@ -11,6 +11,42 @@ int testBit(char *bits, int n) |
|
|
|
return bits[n/8] & (1 << n%8); |
|
|
|
} |
|
|
|
|
|
|
|
int isEscapedChar(char char1, char char2){ |
|
|
|
if( char1=='\n'){ |
|
|
|
return 10; |
|
|
|
} |
|
|
|
if( char1=='\a'){ |
|
|
|
return 7; |
|
|
|
} |
|
|
|
if( char1=='\b'){ |
|
|
|
return 8; |
|
|
|
} |
|
|
|
if( char1=='\e'){ |
|
|
|
return 27; |
|
|
|
} |
|
|
|
if( char1=='\f'){ |
|
|
|
return 12; |
|
|
|
} |
|
|
|
if( char1=='\r'){ |
|
|
|
return 13; |
|
|
|
} |
|
|
|
else if( char1=='\t'){ |
|
|
|
return 9; |
|
|
|
} |
|
|
|
if( char1=='\v'){ |
|
|
|
return 1; |
|
|
|
} |
|
|
|
else if( char1=='\\' && char2=='-'){ |
|
|
|
return 45; |
|
|
|
} |
|
|
|
else if ( char1=='\\'){ |
|
|
|
return 92; |
|
|
|
} |
|
|
|
else return ; |
|
|
|
//if(character==92 || character==7 || character==8 || character==27 || character==12 || character==10 || character==13 || character==13 |
|
|
|
// || character==9 || character==11) |
|
|
|
} |
|
|
|
|
|
|
|
char *classify(char *spec) |
|
|
|
{ |
|
|
|
char *class= malloc(32); // 256 bits indicating if character N (bit position N) is in the class or not |
|
|
@ -39,12 +75,14 @@ char *classify(char *spec) |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
printf("Error, aekzaepaz"); |
|
|
|
printf("Error, bad use of range"); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
if(spec[index-1]>spec[index+1]){ |
|
|
|
printf("Error, first char greater than the second one"); |
|
|
|
printf("Error, first char greater than the second one\n"); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
else if(spec[index-1]>=65 && spec[index-1]<=90 && spec[index+1]>=65 && spec[index+1]<=90 ){ |
|
|
|
for(int j=spec[index-1]; j<=spec[index+1] ; j++){ |
|
|
@ -61,12 +99,22 @@ char *classify(char *spec) |
|
|
|
} |
|
|
|
index++; |
|
|
|
} |
|
|
|
else{ |
|
|
|
printf("Bad use of char range"); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else if((spec[index]>=65 && spec[index]<=90) || (spec[index]>=97 && spec[index]<=122)){ |
|
|
|
setBit(class,spec[index]); |
|
|
|
printf("added char : %c\n",spec[index]); |
|
|
|
} |
|
|
|
else if(isEscapedChar(spec[index],spec[index+1])!=0){ |
|
|
|
if(isEscapedChar(spec[index],spec[index+1])==45){ |
|
|
|
index++; |
|
|
|
} |
|
|
|
setBit(class,isEscapedChar(spec[index],spec[index+1])); |
|
|
|
} |
|
|
|
printf("%c\n",spec[index]); |
|
|
|
printf("%i\n",index); |
|
|
@ -87,7 +135,7 @@ int main() |
|
|
|
ssize_t line_len=0; |
|
|
|
char a='a'; |
|
|
|
printf("%i\n",(int)a); |
|
|
|
printf("%s",classify("a-cA-Z")); |
|
|
|
printf("%s",classify("fgmfa\\-c")); |
|
|
|
while ((line_len= getline(&line,&line_max,stdin)) >= 0) { |
|
|
|
if (line_len>0 && line[line_len-1]=='\n') { |
|
|
|
line[line_len-1]=0; |
|
|
|