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
| #include <stdio.h>
#include <stdlib.h>
typedef enum {
zero, un, deux, trois, quatre, cinq, six, sept, huit, neuf
} etats;
int main(int argc, char const *argv[])
{
FILE *fichier;
etats courrant = zero;
if(fichier = fopen("test.html", "r"))
{
char c = fgetc(fichier);
while (c!=EOF)
{
switch(courrant)
{
case zero:
if (c == '<') { courrant = un; c = fgetc(fichier); break; }
else c = fgetc(fichier);
case un:
if ((c >= 'a') && (c <= 'z')) { printf("Etat quatre\n"); courrant = quatre; c = fgetc(fichier); break; }
if (c == '/') { printf("etat deux\n"); courrant = deux; c = fgetc(fichier); break; }
else { printf("Syntax Error\n"); return 1; }
case deux:
if ((c >= 'a') && (c <= 'z')) { printf("Etat trois\n"); courrant = trois; c = fgetc(fichier); break; }
else { printf("Syntax Error\n"); return 1; }
case trois:
if (c == '>') { printf("fin de la balise"); return 1;}
if (c == ' ') {printf("Syntax error\n"); return 1;}
else { printf("Etat trois\n"); courrant = trois; c = fgetc(fichier); break; }
case quatre:
if (c == ' ') { printf("Etat cinq\n"); courrant = cinq; c = fgetc(fichier); break; }
if (c == '>') { printf("fin de la balise"); return 1;}
else { printf("Etat quatre\n"); courrant = quatre; c = fgetc(fichier); break; }
case cinq:
if (c == ' ') { printf("Etat cinq\n"); courrant = cinq; c = fgetc(fichier); break;}
if ( c == '>'|| c == '<'|| c == '=') { printf("Syntax Error\n"); return 1;}
else { printf("Etat six\n"); courrant = six; c = fgetc(fichier); break; }
case six:
if (c == '=') { printf("Etat sept\n"); courrant = sept; c = fgetc(fichier); break;}
else { printf("Etat six\n"); courrant = six; c = fgetc(fichier); break; }
case sept:
if (c == '"'|| c =='\'') { printf("Etat huit\n"); courrant = huit; c = fgetc(fichier); break;}
else { printf("Etat quatre\n"); courrant = quatre; c = fgetc(fichier); break; }
case huit:
if (c == '"'|| c =='\'') { printf("Etat neuf\n"); courrant = neuf; c = fgetc(fichier); break;}
else { printf("Etat huit\n"); courrant = huit; c = fgetc(fichier); break; }
case neuf:
if (c == ' ') { printf("Etat cinq\n"); courrant = cinq; c = fgetc(fichier); break;}
if (c == '>') { printf("fin de la balise"); return 1;}
else { printf("Syntax Error\n"); return 1; }
}
}
}
else printf("Couldn't open the file.\n");
printf("Operation terminated");
fclose(fichier);
return 0;
} |
Partager