1 |
siliconforks |
2 |
/* |
2 |
|
|
main.c - JSCoverage main routine |
3 |
siliconforks |
87 |
Copyright (C) 2007, 2008 siliconforks.com |
4 |
siliconforks |
2 |
|
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 |
siliconforks |
88 |
#include <config.h> |
21 |
|
|
|
22 |
siliconforks |
2 |
#include <stdio.h> |
23 |
|
|
#include <stdlib.h> |
24 |
|
|
#include <string.h> |
25 |
|
|
|
26 |
|
|
#include "instrument.h" |
27 |
|
|
#include "instrument-js.h" |
28 |
|
|
#include "resource-manager.h" |
29 |
|
|
#include "util.h" |
30 |
|
|
|
31 |
|
|
int main(int argc, char ** argv) { |
32 |
|
|
int verbose = 0; |
33 |
|
|
|
34 |
|
|
// program = argv[0]; |
35 |
|
|
program = "jscoverage"; |
36 |
|
|
|
37 |
|
|
char * source = NULL; |
38 |
|
|
char * destination = NULL; |
39 |
|
|
|
40 |
|
|
char ** no_instrument = xmalloc((argc - 1) * sizeof(char *)); |
41 |
|
|
int num_no_instrument = 0; |
42 |
|
|
|
43 |
|
|
char ** exclude = xmalloc((argc - 1) * sizeof(char *)); |
44 |
|
|
int num_exclude = 0; |
45 |
|
|
|
46 |
|
|
for (int i = 1; i < argc; i++) { |
47 |
|
|
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { |
48 |
|
|
copy_resource_to_stream("help.txt", stdout); |
49 |
|
|
exit(EXIT_SUCCESS); |
50 |
|
|
} |
51 |
|
|
else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) { |
52 |
|
|
printf("jscoverage %s\n", VERSION); |
53 |
|
|
exit(EXIT_SUCCESS); |
54 |
|
|
} |
55 |
|
|
else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) { |
56 |
|
|
verbose = 1; |
57 |
|
|
} |
58 |
|
|
else if (strcmp(argv[i], "--no-instrument") == 0) { |
59 |
|
|
i++; |
60 |
|
|
if (i == argc) { |
61 |
|
|
fatal("--no-instrument: option requires an argument"); |
62 |
|
|
} |
63 |
|
|
no_instrument[num_no_instrument] = argv[i]; |
64 |
|
|
num_no_instrument++; |
65 |
|
|
} |
66 |
|
|
else if (strncmp(argv[i], "--no-instrument=", 16) == 0) { |
67 |
|
|
no_instrument[num_no_instrument] = argv[i] + 16; |
68 |
|
|
num_no_instrument++; |
69 |
|
|
} |
70 |
|
|
else if (strcmp(argv[i], "--exclude") == 0) { |
71 |
|
|
i++; |
72 |
|
|
if (i == argc) { |
73 |
|
|
fatal("--exclude: option requires an argument"); |
74 |
|
|
} |
75 |
|
|
exclude[num_exclude] = argv[i]; |
76 |
|
|
num_exclude++; |
77 |
|
|
} |
78 |
|
|
else if (strncmp(argv[i], "--exclude=", 10) == 0) { |
79 |
|
|
exclude[num_exclude] = argv[i] + 10; |
80 |
|
|
num_exclude++; |
81 |
|
|
} |
82 |
|
|
else if (strncmp(argv[i], "-", 1) == 0) { |
83 |
|
|
fatal("unrecognized option `%s'", argv[i]); |
84 |
|
|
} |
85 |
|
|
else if (source == NULL) { |
86 |
|
|
source = argv[i]; |
87 |
|
|
} |
88 |
|
|
else if (destination == NULL) { |
89 |
|
|
destination = argv[i]; |
90 |
|
|
} |
91 |
|
|
else { |
92 |
|
|
fatal("too many arguments"); |
93 |
|
|
} |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
if (source == NULL || destination == NULL) { |
97 |
|
|
fatal("missing argument"); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
source = make_canonical_path(source); |
101 |
|
|
destination = make_canonical_path(destination); |
102 |
|
|
|
103 |
|
|
jscoverage_init(); |
104 |
|
|
jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument); |
105 |
|
|
jscoverage_cleanup(); |
106 |
|
|
|
107 |
|
|
free(source); |
108 |
|
|
free(destination); |
109 |
|
|
free(exclude); |
110 |
|
|
free(no_instrument); |
111 |
|
|
|
112 |
|
|
exit(EXIT_SUCCESS); |
113 |
|
|
} |