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

Annotation of /trunk/jscoverage.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 385 - (hide annotations)
Thu Oct 30 03:13:23 2008 UTC (9 years, 11 months ago) by siliconforks
File MIME type: text/plain
File size: 4226 byte(s)
Rename help.txt to jscoverage-help.txt.
1 siliconforks 2 /*
2 siliconforks 382 jscoverage.c - main routine for `jscoverage' program
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 siliconforks 174 #include "global.h"
27 siliconforks 2 #include "instrument.h"
28     #include "instrument-js.h"
29     #include "resource-manager.h"
30     #include "util.h"
31    
32 siliconforks 174 const char * jscoverage_encoding = "ISO-8859-1";
33 siliconforks 179 bool jscoverage_highlight = true;
34 siliconforks 174
35 siliconforks 2 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 siliconforks 107 char ** no_instrument = xnew(char *, argc - 1);
45 siliconforks 2 int num_no_instrument = 0;
46    
47 siliconforks 107 char ** exclude = xnew(char *, argc - 1);
48 siliconforks 2 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 siliconforks 385 copy_resource_to_stream("jscoverage-help.txt", stdout);
53 siliconforks 2 exit(EXIT_SUCCESS);
54     }
55     else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
56 siliconforks 311 version();
57 siliconforks 2 }
58     else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
59     verbose = 1;
60     }
61 siliconforks 179 else if (strcmp(argv[i], "--no-highlight") == 0) {
62     jscoverage_highlight = false;
63     }
64 siliconforks 361 else if (strcmp(argv[i], "--mozilla") == 0) {
65     jscoverage_mozilla = true;
66     jscoverage_set_js_version("180");
67     }
68 siliconforks 2 else if (strcmp(argv[i], "--no-instrument") == 0) {
69     i++;
70     if (i == argc) {
71 siliconforks 191 fatal_command_line("--no-instrument: option requires an argument");
72 siliconforks 2 }
73     no_instrument[num_no_instrument] = argv[i];
74     num_no_instrument++;
75     }
76     else if (strncmp(argv[i], "--no-instrument=", 16) == 0) {
77     no_instrument[num_no_instrument] = argv[i] + 16;
78     num_no_instrument++;
79     }
80     else if (strcmp(argv[i], "--exclude") == 0) {
81     i++;
82     if (i == argc) {
83 siliconforks 191 fatal_command_line("--exclude: option requires an argument");
84 siliconforks 2 }
85     exclude[num_exclude] = argv[i];
86     num_exclude++;
87     }
88     else if (strncmp(argv[i], "--exclude=", 10) == 0) {
89     exclude[num_exclude] = argv[i] + 10;
90     num_exclude++;
91     }
92 siliconforks 174 else if (strcmp(argv[i], "--encoding") == 0) {
93     i++;
94     if (i == argc) {
95 siliconforks 191 fatal_command_line("--encoding: option requires an argument");
96 siliconforks 174 }
97     jscoverage_encoding = argv[i];
98     }
99     else if (strncmp(argv[i], "--encoding=", 11) == 0) {
100     jscoverage_encoding = argv[i] + 11;
101     }
102 siliconforks 339 else if (strcmp(argv[i], "--js-version") == 0) {
103     i++;
104     if (i == argc) {
105     fatal_command_line("--js-version: option requires an argument");
106     }
107     jscoverage_set_js_version(argv[i]);
108     }
109     else if (strncmp(argv[i], "--js-version=", 13) == 0) {
110     jscoverage_set_js_version(argv[i] + 13);
111     }
112 siliconforks 2 else if (strncmp(argv[i], "-", 1) == 0) {
113 siliconforks 191 fatal_command_line("unrecognized option `%s'", argv[i]);
114 siliconforks 2 }
115     else if (source == NULL) {
116     source = argv[i];
117     }
118     else if (destination == NULL) {
119     destination = argv[i];
120     }
121     else {
122 siliconforks 191 fatal_command_line("too many arguments");
123 siliconforks 2 }
124     }
125    
126     if (source == NULL || destination == NULL) {
127 siliconforks 191 fatal_command_line("missing argument");
128 siliconforks 2 }
129    
130     source = make_canonical_path(source);
131     destination = make_canonical_path(destination);
132    
133     jscoverage_init();
134     jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument);
135     jscoverage_cleanup();
136    
137     free(source);
138     free(destination);
139     free(exclude);
140     free(no_instrument);
141    
142     exit(EXIT_SUCCESS);
143     }

  ViewVC Help
Powered by ViewVC 1.1.24