-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharc_options.c
89 lines (78 loc) · 2.21 KB
/
arc_options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <getopt.h>
#include "arc_utils.h"
#include "preprocessor.h"
extern char *include_path;
extern char *exename;
extern int is_dbg_mode;
extern int print_tree;
extern int print_table;
extern int mem_size;
static void print_help()
{
fprintf(stderr, "Utilisation: arc [-o outfile] [-d | --debug] "\
"[--print-tree] [--print-table] [-I dir] infile\n");
fprintf(stderr, "Consultez le man pour plus d'informations\n");
}
void handle_options(int argc, char **argv)
{
int opt;
const struct option options[] = {
{"draw-tree", no_argument, NULL, 1},
{"draw-table", optional_argument, NULL, 2},
{"debug", no_argument, NULL, 'd'},
{"mem-size", required_argument, NULL, 3},
{NULL, 0, NULL, '\0'}
};
while((opt = getopt_long(argc, argv, "I:o:d", options, NULL)) != -1)
{
switch (opt)
{
case 'I':
include_path = (char *) malloc(sizeof(char) * (strlen(optarg) + 2));
check_alloc(include_path);
strcpy(include_path, optarg);
if (optarg[strlen(optarg) - 1] != '/') strcat(include_path, "/");
break;
case 'o':
exename = (char *) malloc(sizeof(char) * (strlen(optarg) + 1));
check_alloc(exename);
strcpy(exename, optarg);
break;
case 'd':
is_dbg_mode = 1;
break;
case 1:
print_tree = 1;
break;
case 2:
print_table = 1;
break;
case 3:
mem_size = atoi(optarg);
break;
default:
print_help();
exit(1);
break;
}
}
/* Le seul argument sans option doit être le fichier.algo */
if (optind >= argc)
{
fatal_error("pas de fichier en entrée");
exit(F_INPUT_ERROR);
}
src = (char *) malloc(sizeof(char) * (strlen(argv[optind]) + 1));
check_alloc(src);
strcpy(src, argv[optind]);
if (exename == NULL)
{
exename = (char *) malloc(sizeof(char) * (strlen("a.out") + 1));
check_alloc(exename);
strcpy(exename, "a.out");
}
}