14 struct token_s token
[TOKEN_MAX
] = {NULL
, 0};
16 FILE *source
= NULL
, *target
= NULL
;
18 unsigned int tokenFound
= 0;
27 const char* tokenTypestr
[] = { "MOTCLE", "SECTION", "SSECTION", "NPARA", "MOT", "FIN" };
29 /* It looks silly to check for each characters but for debugging, it's just the way to go */
31 if (c
== L
'a' || c
== L
'b' || c
== L
'c' || c
== L
'd' || c
== L
'e' || c
== L
'f' || c
== L
'g' || \
32 c
== L
'h' || c
== L
'i' || c
== L
'j' || c
== L
'k' || c
== L
'l' || c
== L
'm' || c
== L
'n' || \
33 c
== L
'o' || c
== L
'p' || c
== L
'q' || c
== L
'r' || c
== L
's' || c
== L
't' || c
== L
'u' || \
34 c
== L
'v' || c
== L
'w' || c
== L
'x' || c
== L
'y' || c
== L
'z' || \
35 c
== L
'A' || c
== L
'B' || c
== L
'C' || c
== L
'D' || c
== L
'E' || c
== L
'F' || c
== L
'G' || \
36 c
== L
'H' || c
== L
'I' || c
== L
'J' || c
== L
'K' || c
== L
'L' || c
== L
'M' || c
== L
'N' || \
37 c
== L
'O' || c
== L
'P' || c
== L
'Q' || c
== L
'R' || c
== L
'S' || c
== L
'T' || c
== L
'U' || \
38 c
== L
'V' || c
== L
'W' || c
== L
'X' || c
== L
'Y' || c
== L
'Z' || \
39 c
== L
'.' || c
== L
'?' || c
== L
'!' || c
== L
',' || c
== L
';' || c
== L
':' || c
== L
'-' || \
40 c
== L
'\''|| c
== L
'#' || \
41 c
== L
'0' || c
== L
'1' || c
== L
'2' || c
== L
'3' || c
== L
'4' || c
== L
'5' || c
== L
'6' || \
42 c
== L
'7' || c
== L
'8' || c
== L
'9' || \
43 c
== L
'à' || c
== L
'â' || c
== L
'ç' || c
== L
'è' || c
== L
'é' || c
== L
'î' || c
== L
'ô' || \
44 c
== L
'ù' || c
== L
'û' || \
45 c
== L
'À' || c
== L
'Â' || c
== L
'Ç' || c
== L
'È' || c
== L
'É' || c
== L
'Î' || c
== L
'Ô' || \
46 c
== L
'Ù' || c
== L
'Û') {
53 if (c
== L
'\t' || c
== L
' ' || c
== L
'\n') {
64 if (c
== L
' ' || c
== L
'\t') {
81 token
[tokenFound
].value
[i
] = c
;
92 if (c
== L
'A' && !wcscmp(fgetws(m
, 6, source
), L
"uteur")) {
93 wcscpy((wchar_t*)token
[tokenFound
].value
, L
">Auteur");
97 if (c
== L
'T' && !wcscmp(fgetws(m
, 5, source
), L
"itre")) {
98 wcscpy((wchar_t*)token
[tokenFound
].value
, L
">Titre");
109 if (isSeparator() || c
== WEOF
) {
115 if (isSeparator() || c
== WEOF
) {
125 tokenType
= SSECTION
;
130 token
[tokenFound
].value
[i
] = c
;
135 if (isSeparator() || c
== WEOF
) {
141 if (c
== L
' ' || c
== L
'\t') {
150 token
[tokenFound
].value
[i
] = c
;
198 if (isSeparator() || c
== WEOF
) {
217 // Ouvre le fichier test.txt en lecture seulement (le fichier doit exister) :
218 source
= fopen("test.txt", "r+");
219 // Cree et ouvre un fichier target.html en lecture/ecriture
220 // avec suppression du contenu au prealable :
221 target
= fopen("target.html", "w+");
223 if (source
== NULL
) {
224 printf("Impossible d'ouvrir le fichier source\n");
228 if (target
== NULL
) {
229 printf("Impossible d'ouvrir le fichier target\n");
233 c
= fgetwc(source
); // lecture du premier caractere
235 int scanrt
= scanner();
236 if (scanrt
== EXIT_FAILURE
) {
237 wprintf(L
"Scanner error with token value: %ls\n", token
[tokenFound
].value
);
240 if (tokenType
== MOT
|| tokenType
== MOTCLE
) {
241 wprintf(L
"%20s: %ls\n", tokenTypestr
[tokenType
], token
[tokenFound
].value
);
243 wprintf(L
"%20s\n", tokenTypestr
[tokenType
]);
245 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
247 } while (tokenType
!= FIN
); // tant que la fin du fichier n'est pas atteinte
249 if (source
!= NULL
) fclose(source
); // fermeture du fichier source
250 if (target
!= NULL
) fclose(target
); // fermeture du fichier target