6 FILE *source
, *target
= NULL
;
18 const char* tokenTypestr
[] = { "MOTCLE", "SECTION", "SSECTION", "NPARA", "MOT", "FIN" };
20 /* It looks silly to check for each characters but for debugging, it's just the way to go */
22 if (c
== 'a' || c
== 'b' || c
== 'c' || c
== 'd' || c
== 'e' || c
== 'f' || c
== 'g' || \
23 c
== 'h' || c
== 'i' || c
== 'j' || c
== 'k' || c
== 'l' || c
== 'm' || c
== 'n' || \
24 c
== 'o' || c
== 'p' || c
== 'q' || c
== 'r' || c
== 's' || c
== 't' || c
== 'u' || \
25 c
== 'v' || c
== 'w' || c
== 'x' || c
== 'y' || c
== 'z' || \
26 c
== 'A' || c
== 'B' || c
== 'C' || c
== 'D' || c
== 'E' || c
== 'F' || c
== 'G' || \
27 c
== 'H' || c
== 'I' || c
== 'J' || c
== 'K' || c
== 'L' || c
== 'M' || c
== 'N' || \
28 c
== 'O' || c
== 'P' || c
== 'Q' || c
== 'R' || c
== 'S' || c
== 'T' || c
== 'U' || \
29 c
== 'V' || c
== 'W' || c
== 'X' || c
== 'Y' || c
== 'Z' || \
30 c
== '.' || c
== '?' || c
== '!' || c
== ',' || c
== ';' || c
== ':' || c
== '-' || \
31 c
== '\''|| c
== '#' || \
32 c
== '0' || c
== '1' || c
== '2' || c
== '3' || c
== '4' || c
== '5' || c
== '6' || \
33 c
== '7' || c
== '8' || c
== '9') {
40 if (c
== '\t' || c
== ' ' || c
== '\n') {
47 const char* Titre
= "Titre";
48 const char* Auteur
= "Auteur";
51 // The main loop get the next character
53 if (c
== ' ' || c
== '\t') {
90 // FIXME: Partial match need a rewind in the characters extraction from the file
91 if (c
== Titre
[j
] && j
< strlen(Titre
) - 1) {
98 if (c
== Auteur
[j
] && j
< strlen(Auteur
) - 1) {
118 if (isSeparator() || c
== EOF
) {
123 if (isSeparator() || c
== EOF
) {
132 tokenType
= SSECTION
;
142 if (isSeparator() || c
== EOF
) {
147 if (c
== ' ' || c
== '\t') {
216 if (isSeparator() || c
== EOF
) {
233 int main (int argc
, char const *argv
[]) {
235 // Ouvre le fichier test.txt en lecture seulement (le fichier doit exister) :
236 source
= fopen("test.txt", "r");
237 // Cree et ouvre un fichier target.html en lecture/ecriture
238 // avec suppression du contenu au prealable :
239 target
= fopen("target.html", "w+");
241 if (source
== NULL
) {
242 printf("Impossible d'ouvrir le fichier source\n");
246 if (target
== NULL
) {
247 printf("Impossible d'ouvrir le fichier target\n");
252 c
= fgetc(source
); // lecture du caractere suivant du fichier source
255 int scanrt
= scanner();
257 printf ("Scanner error with token value: %s\n", tokenValue
);
261 printf ("Token type found: %s with value: %s\n", tokenTypestr
[tokenType
], tokenValue
);
263 printf ("Token type found: %s\n", tokenTypestr
[tokenType
]);
267 memset(tokenValue
, 0, sizeof(tokenValue
));
268 } while (c
!= EOF
); // tant que la fin du fichier n'est pas atteinte
270 if (source
!= NULL
) fclose(source
); // fermeture du fichier source
271 if (target
!= NULL
) fclose(target
); // fermeture du fichier target