7 #include "global_vars.h"
8 #include "lexical_analyzer.h"
9 #include "syntactic_analyzer.h"
10 #include "print_helper.h"
12 void do_lexical_analysis() {
13 c
= fgetwc(source
); // lecture du premier caractere
17 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
18 wcscpy((wchar_t*)tokenValue
, (wchar_t*)token
[tokenFound
].value
);
20 } while (tokenType
!= FIN
); // tant que la fin du fichier n'est pas atteinte
23 void do_syntactic_analysis() {
24 fputws(L
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr_FR\" lang=\"fr_FR\">\n",
26 c
= fgetwc(source
); // lecture du premier caractere
29 fputws(L
"</html>\n", target
);
32 void print_usage(const char* name
) {
33 fprintf(stdout
,"Usage: %s [options]\n"
34 "Where [options] are:\n"
35 " -h, --help: display this help message\n"
36 " -l, --lexical-only: do only the lexical analysis\n"
37 " -i, --input<filename>: use <filename> as input file instead of standard input\n"
38 " -o, --output<filename>: use <filename> as output file instead of standard output\n",
43 int main(int argc
, char **argv
) {
44 /* In and out files name */
45 const char* in_file
= NULL
;
46 const char* out_file
= NULL
;
50 /* getopt_long stores the option index here. */
53 static struct option long_options
[] =
55 {"help", no_argument
, &hflag
, 1},
56 {"input", optional_argument
, NULL
, 'i'},
57 {"lexical-only", no_argument
, &lflag
, 1},
58 {"output", optional_argument
, NULL
, 'o'},
64 while ((c_in
= getopt_long(argc
, argv
, "hi::lo::", long_options
,
65 &option_index
)) != -1) {
84 /* getopt_long() set a variable, just keep going */
87 /* missing option argument */
88 pr_error("%s: option '-%c' requires an argument\n",
94 pr_error("%s: option '-%c' is invalid: ignored\n",
96 /* print the help message for invalid options */
102 if (in_file
!= NULL
) {
103 // Ouvre le fichier source en lecture seulement (le fichier doit exister) :
104 source
= fopen(in_file
, "r+");
105 if (source
== NULL
) {
106 pr_error("Fail to open file %s\n", in_file
);
113 if (out_file
!= NULL
) {
114 // Cree et ouvre le fichier cible en lecture/ecriture
115 // avec suppression du contenu au prealable :
116 target
= fopen(out_file
, "w+");
117 if (target
== NULL
) {
118 pr_error("Fail to open file %s\n", out_file
);
126 print_usage(argv
[0]);
128 do_lexical_analysis();
130 do_syntactic_analysis();
133 if (source
!= NULL
) fclose(source
); // fermeture du fichier source
134 if (target
!= NULL
) fclose(target
); // fermeture du fichier target