- // Ouvre le fichier test.txt en lecture seulement (le fichier doit exister) :
- source = fopen("test.txt", "r");
- // Cree et ouvre un fichier target.html en lecture/ecriture
- // avec suppression du contenu au prealable :
- target = fopen("target.html", "w+");
+int main(int argc, char **argv) {
+ /* In and out files name */
+ const char* in_file = NULL;
+ const char* out_file = NULL;
+ static int hflag = 0;
+ static int lflag = 0;
+
+ /* getopt_long stores the option index here. */
+ int option_index = 0;
+
+ static struct option long_options[] =
+ {
+ {"help", no_argument, &hflag, 1},
+ {"input", optional_argument, NULL, 'i'},
+ {"lexical-only", no_argument, &lflag, 1},
+ {"output", optional_argument, NULL, 'o'},
+ {0, 0, 0, 0}
+ };
+
+ int c_in;
+
+ while ((c_in = getopt_long(argc, argv, "hi::lo::", long_options,
+ &option_index)) != -1) {
+ switch (c_in) {
+ case 'h':
+ hflag = 1;
+ break;
+ case 'i':
+ if (optarg != NULL) {
+ in_file = optarg;
+ }
+ break;
+ case 'l':
+ lflag = 1;
+ break;
+ case 'o':
+ if (optarg != NULL) {
+ out_file = optarg;
+ }
+ break;
+ case 0:
+ /* getopt_long() set a variable, just keep going */
+ break;
+ case ':':
+ /* missing option argument */
+ pr_error("%s: option '-%c' requires an argument\n",
+ argv[0], optopt);
+ break;
+ case '?':
+ default:
+ /* invalid option */
+ pr_error("%s: option '-%c' is invalid: ignored\n",
+ argv[0], optopt);
+ /* print the help message for invalid options */
+ hflag = 1;
+ break;
+ }
+ }