19fc34f8763db78ec958d8d31b7d4e656090b0c8
6 #define TOKEN_MAX_LENGTH 50
7 #define TOKEN_LIST_MAX 500
9 FILE *source
= NULL
, *target
= NULL
;
12 char tokenValue
[TOKEN_MAX_LENGTH
];
21 const char* tokenTypestr
[] = { "MOTCLE", "SECTION", "SSECTION", "NPARA", "MOT", "FIN" };
22 const char* tokenList
[TOKEN_LIST_MAX
];
24 /* It looks silly to check for each characters but for debugging, it's just the way to go */
26 if (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
== 'A' || c
== 'B' || c
== 'C' || c
== 'D' || c
== 'E' || c
== 'F' || c
== 'G' || \
31 c
== 'H' || c
== 'I' || c
== 'J' || c
== 'K' || c
== 'L' || c
== 'M' || c
== 'N' || \
32 c
== 'O' || c
== 'P' || c
== 'Q' || c
== 'R' || c
== 'S' || c
== 'T' || c
== 'U' || \
33 c
== 'V' || c
== 'W' || c
== 'X' || c
== 'Y' || c
== 'Z' || \
34 c
== '.' || c
== '?' || c
== '!' || c
== ',' || c
== ';' || c
== ':' || c
== '-' || \
35 c
== '\''|| c
== '#' || \
36 c
== '0' || c
== '1' || c
== '2' || c
== '3' || c
== '4' || c
== '5' || c
== '6' || \
37 c
== '7' || c
== '8' || c
== '9') {
44 if (c
== '\t' || c
== ' ' || c
== '\n') {
51 const char* Titre
= "Titre";
52 const char* Auteur
= "Auteur";
55 // The main loop get the next character
57 if (c
== ' ' || c
== '\t') {
94 // FIXME: Partial match need a rewind in the characters extraction from the file
95 if (c
== Titre
[j
] && j
< strlen(Titre
) - 1) {
102 if (c
== Auteur
[j
] && j
< strlen(Auteur
) - 1) {
122 if (isSeparator() || c
== EOF
) {
127 if (isSeparator() || c
== EOF
) {
136 tokenType
= SSECTION
;
146 if (isSeparator() || c
== EOF
) {
151 if (c
== ' ' || c
== '\t') {
220 if (isSeparator() || c
== EOF
) {
237 int main (int argc
, char const *argv
[]) {
239 // Ouvre le fichier test.txt en lecture seulement (le fichier doit exister) :
240 source
= fopen("test.txt", "r");
241 // Cree et ouvre un fichier target.html en lecture/ecriture
242 // avec suppression du contenu au prealable :
243 target
= fopen("target.html", "w+");
245 if (source
== NULL
) {
246 printf("Impossible d'ouvrir le fichier source\n");
250 if (target
== NULL
) {
251 printf("Impossible d'ouvrir le fichier target\n");
258 c
= fgetc(source
); // lecture du caractere suivant du fichier source
261 int scanrt
= scanner();
263 printf ("Scanner error with token value: %s\n", tokenValue
);
267 printf ("Token type found: %s with value: %s\n", tokenTypestr
[tokenType
], tokenValue
);
269 printf ("Token type found: %s\n", tokenTypestr
[tokenType
]);
271 tokenList
[tokenFound
] = tokenTypestr
[tokenType
];
275 memset(tokenValue
, 0, sizeof(tokenValue
));
276 } while (c
!= EOF
); // tant que la fin du fichier n'est pas atteinte
278 if (source
!= NULL
) fclose(source
); // fermeture du fichier source
279 if (target
!= NULL
) fclose(target
); // fermeture du fichier target