a187f8ebb3fd88456aa01653418f00abd66e87c8
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
16 wprint_token_target();
17 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
19 } while (tokenType
!= FIN
); // tant que la fin du fichier n'est pas atteinte
22 void do_syntactic_analysis() {
23 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",
25 c
= fgetwc(source
); // lecture du premier caractere
27 fputws(L
"</html>\n", target
);
30 void print_usage(const char* name
) {
31 fprintf(stdout
,"Usage: %s [options]\n"
32 "Where [options] are:\n"
33 " -h, --help: display this help message\n"
34 " -l, --lexical-only: do only the lexical analysis\n"
35 " -i, --input<filename>: use <filename> as input file instead of standard input\n"
36 " -o, --output<filename>: use <filename> as output file instead of standard output\n",
41 int main(int argc
, char **argv
) {
42 /* In and out files name */
43 const char* in_file
= NULL
;
44 const char* out_file
= NULL
;
48 /* getopt_long stores the option index here. */
51 static struct option long_options
[] =
53 {"help", no_argument
, &hflag
, 1},
54 {"input", optional_argument
, NULL
, 'i'},
55 {"lexical-only", no_argument
, &lflag
, 1},
56 {"output", optional_argument
, NULL
, 'o'},
62 while ((c_in
= getopt_long(argc
, argv
, "hi::lo::", long_options
,
63 &option_index
)) != -1) {
82 /* getopt_long() set a variable, just keep going */
85 /* missing option argument */
86 pr_error("%s: option '-%c' requires an argument\n",
92 pr_error("%s: option '-%c' is invalid: ignored\n",
98 if (in_file
!= NULL
) {
99 // Ouvre le fichier source en lecture seulement (le fichier doit exister) :
100 source
= fopen(in_file
, "r+");
101 if (source
== NULL
) {
102 pr_error("Fail to open file %s\n", in_file
);
109 if (out_file
!= NULL
) {
110 // Cree et ouvre le fichier cible en lecture/ecriture
111 // avec suppression du contenu au prealable :
112 target
= fopen(out_file
, "w+");
113 if (target
== NULL
) {
114 pr_error("Fail to open file %s\n", out_file
);
122 print_usage(argv
[0]);
124 do_lexical_analysis();
126 do_syntactic_analysis();
129 if (source
!= NULL
) fclose(source
); // fermeture du fichier source
130 if (target
!= NULL
) fclose(target
); // fermeture du fichier target