1 |
/* |
2 |
main.c - JSCoverage main routine |
3 |
Copyright (C) 2007, 2008 siliconforks.com |
4 |
|
5 |
This program is free software; you can redistribute it and/or modify |
6 |
it under the terms of the GNU General Public License as published by |
7 |
the Free Software Foundation; either version 2 of the License, or |
8 |
(at your option) any later version. |
9 |
|
10 |
This program is distributed in the hope that it will be useful, |
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
GNU General Public License for more details. |
14 |
|
15 |
You should have received a copy of the GNU General Public License along |
16 |
with this program; if not, write to the Free Software Foundation, Inc., |
17 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
18 |
*/ |
19 |
|
20 |
#include <stdio.h> |
21 |
#include <stdlib.h> |
22 |
#include <string.h> |
23 |
|
24 |
#include "config.h" |
25 |
#include "instrument.h" |
26 |
#include "instrument-js.h" |
27 |
#include "resource-manager.h" |
28 |
#include "util.h" |
29 |
|
30 |
int main(int argc, char ** argv) { |
31 |
int verbose = 0; |
32 |
|
33 |
// program = argv[0]; |
34 |
program = "jscoverage"; |
35 |
|
36 |
char * source = NULL; |
37 |
char * destination = NULL; |
38 |
|
39 |
char ** no_instrument = xmalloc((argc - 1) * sizeof(char *)); |
40 |
int num_no_instrument = 0; |
41 |
|
42 |
char ** exclude = xmalloc((argc - 1) * sizeof(char *)); |
43 |
int num_exclude = 0; |
44 |
|
45 |
for (int i = 1; i < argc; i++) { |
46 |
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { |
47 |
copy_resource_to_stream("help.txt", stdout); |
48 |
exit(EXIT_SUCCESS); |
49 |
} |
50 |
else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) { |
51 |
printf("jscoverage %s\n", VERSION); |
52 |
exit(EXIT_SUCCESS); |
53 |
} |
54 |
else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) { |
55 |
verbose = 1; |
56 |
} |
57 |
else if (strcmp(argv[i], "--no-instrument") == 0) { |
58 |
i++; |
59 |
if (i == argc) { |
60 |
fatal("--no-instrument: option requires an argument"); |
61 |
} |
62 |
no_instrument[num_no_instrument] = argv[i]; |
63 |
num_no_instrument++; |
64 |
} |
65 |
else if (strncmp(argv[i], "--no-instrument=", 16) == 0) { |
66 |
no_instrument[num_no_instrument] = argv[i] + 16; |
67 |
num_no_instrument++; |
68 |
} |
69 |
else if (strcmp(argv[i], "--exclude") == 0) { |
70 |
i++; |
71 |
if (i == argc) { |
72 |
fatal("--exclude: option requires an argument"); |
73 |
} |
74 |
exclude[num_exclude] = argv[i]; |
75 |
num_exclude++; |
76 |
} |
77 |
else if (strncmp(argv[i], "--exclude=", 10) == 0) { |
78 |
exclude[num_exclude] = argv[i] + 10; |
79 |
num_exclude++; |
80 |
} |
81 |
else if (strncmp(argv[i], "-", 1) == 0) { |
82 |
fatal("unrecognized option `%s'", argv[i]); |
83 |
} |
84 |
else if (source == NULL) { |
85 |
source = argv[i]; |
86 |
} |
87 |
else if (destination == NULL) { |
88 |
destination = argv[i]; |
89 |
} |
90 |
else { |
91 |
fatal("too many arguments"); |
92 |
} |
93 |
} |
94 |
|
95 |
if (source == NULL || destination == NULL) { |
96 |
fatal("missing argument"); |
97 |
} |
98 |
|
99 |
source = make_canonical_path(source); |
100 |
destination = make_canonical_path(destination); |
101 |
|
102 |
jscoverage_init(); |
103 |
jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument); |
104 |
jscoverage_cleanup(); |
105 |
|
106 |
free(source); |
107 |
free(destination); |
108 |
free(exclude); |
109 |
free(no_instrument); |
110 |
|
111 |
exit(EXIT_SUCCESS); |
112 |
} |