/[jscoverage]/trunk/jscoverage.c
ViewVC logotype

Contents of /trunk/jscoverage.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 431 - (show annotations)
Wed Feb 18 18:24:51 2009 UTC (10 years, 6 months ago) by siliconforks
File MIME type: text/plain
File size: 4349 byte(s)
Add --no-browser option.
1 /*
2 jscoverage.c - main routine for `jscoverage' program
3 Copyright (C) 2007, 2008, 2009 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 <config.h>
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "global.h"
27 #include "instrument.h"
28 #include "instrument-js.h"
29 #include "resource-manager.h"
30 #include "util.h"
31
32 const char * jscoverage_encoding = "ISO-8859-1";
33 bool jscoverage_highlight = true;
34
35 int main(int argc, char ** argv) {
36 int verbose = 0;
37
38 // program = argv[0];
39 program = "jscoverage";
40
41 char * source = NULL;
42 char * destination = NULL;
43
44 char ** no_instrument = xnew(char *, argc - 1);
45 int num_no_instrument = 0;
46
47 char ** exclude = xnew(char *, argc - 1);
48 int num_exclude = 0;
49
50 for (int i = 1; i < argc; i++) {
51 if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
52 copy_resource_to_stream("jscoverage-help.txt", stdout);
53 exit(EXIT_SUCCESS);
54 }
55 else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
56 version();
57 }
58 else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
59 verbose = 1;
60 }
61 else if (strcmp(argv[i], "--no-highlight") == 0) {
62 jscoverage_highlight = false;
63 }
64 else if (strcmp(argv[i], "--mozilla") == 0) {
65 jscoverage_mode = JSCOVERAGE_MOZILLA;
66 jscoverage_set_js_version("180");
67 }
68 else if (strcmp(argv[i], "--no-browser") == 0) {
69 jscoverage_mode = JSCOVERAGE_NO_BROWSER;
70 }
71 else if (strcmp(argv[i], "--no-instrument") == 0) {
72 i++;
73 if (i == argc) {
74 fatal_command_line("--no-instrument: option requires an argument");
75 }
76 no_instrument[num_no_instrument] = argv[i];
77 num_no_instrument++;
78 }
79 else if (strncmp(argv[i], "--no-instrument=", 16) == 0) {
80 no_instrument[num_no_instrument] = argv[i] + 16;
81 num_no_instrument++;
82 }
83 else if (strcmp(argv[i], "--exclude") == 0) {
84 i++;
85 if (i == argc) {
86 fatal_command_line("--exclude: option requires an argument");
87 }
88 exclude[num_exclude] = argv[i];
89 num_exclude++;
90 }
91 else if (strncmp(argv[i], "--exclude=", 10) == 0) {
92 exclude[num_exclude] = argv[i] + 10;
93 num_exclude++;
94 }
95 else if (strcmp(argv[i], "--encoding") == 0) {
96 i++;
97 if (i == argc) {
98 fatal_command_line("--encoding: option requires an argument");
99 }
100 jscoverage_encoding = argv[i];
101 }
102 else if (strncmp(argv[i], "--encoding=", 11) == 0) {
103 jscoverage_encoding = argv[i] + 11;
104 }
105 else if (strcmp(argv[i], "--js-version") == 0) {
106 i++;
107 if (i == argc) {
108 fatal_command_line("--js-version: option requires an argument");
109 }
110 jscoverage_set_js_version(argv[i]);
111 }
112 else if (strncmp(argv[i], "--js-version=", 13) == 0) {
113 jscoverage_set_js_version(argv[i] + 13);
114 }
115 else if (strncmp(argv[i], "-", 1) == 0) {
116 fatal_command_line("unrecognized option `%s'", argv[i]);
117 }
118 else if (source == NULL) {
119 source = argv[i];
120 }
121 else if (destination == NULL) {
122 destination = argv[i];
123 }
124 else {
125 fatal_command_line("too many arguments");
126 }
127 }
128
129 if (source == NULL || destination == NULL) {
130 fatal_command_line("missing argument");
131 }
132
133 source = make_canonical_path(source);
134 destination = make_canonical_path(destination);
135
136 jscoverage_init();
137 jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument);
138 jscoverage_cleanup();
139
140 free(source);
141 free(destination);
142 free(exclude);
143 free(no_instrument);
144
145 exit(EXIT_SUCCESS);
146 }

  ViewVC Help
Powered by ViewVC 1.1.24