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

Annotation of /trunk/jscoverage.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 339 - (hide annotations)
Fri Oct 24 16:13:57 2008 UTC (10 years, 10 months ago) by siliconforks
Original Path: trunk/main.c
File MIME type: text/plain
File size: 4066 byte(s)
Add support for the JS 1.6 `for each' statement.
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 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     copy_resource_to_stream("help.txt", stdout);
53     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 2 else if (strcmp(argv[i], "--no-instrument") == 0) {
65     i++;
66     if (i == argc) {
67 siliconforks 191 fatal_command_line("--no-instrument: option requires an argument");
68 siliconforks 2 }
69     no_instrument[num_no_instrument] = argv[i];
70     num_no_instrument++;
71     }
72     else if (strncmp(argv[i], "--no-instrument=", 16) == 0) {
73     no_instrument[num_no_instrument] = argv[i] + 16;
74     num_no_instrument++;
75     }
76     else if (strcmp(argv[i], "--exclude") == 0) {
77     i++;
78     if (i == argc) {
79 siliconforks 191 fatal_command_line("--exclude: option requires an argument");
80 siliconforks 2 }
81     exclude[num_exclude] = argv[i];
82     num_exclude++;
83     }
84     else if (strncmp(argv[i], "--exclude=", 10) == 0) {
85     exclude[num_exclude] = argv[i] + 10;
86     num_exclude++;
87     }
88 siliconforks 174 else if (strcmp(argv[i], "--encoding") == 0) {
89     i++;
90     if (i == argc) {
91 siliconforks 191 fatal_command_line("--encoding: option requires an argument");
92 siliconforks 174 }
93     jscoverage_encoding = argv[i];
94     }
95     else if (strncmp(argv[i], "--encoding=", 11) == 0) {
96     jscoverage_encoding = argv[i] + 11;
97     }
98 siliconforks 339 else if (strcmp(argv[i], "--js-version") == 0) {
99     i++;
100     if (i == argc) {
101     fatal_command_line("--js-version: option requires an argument");
102     }
103     jscoverage_set_js_version(argv[i]);
104     }
105     else if (strncmp(argv[i], "--js-version=", 13) == 0) {
106     jscoverage_set_js_version(argv[i] + 13);
107     }
108 siliconforks 2 else if (strncmp(argv[i], "-", 1) == 0) {
109 siliconforks 191 fatal_command_line("unrecognized option `%s'", argv[i]);
110 siliconforks 2 }
111     else if (source == NULL) {
112     source = argv[i];
113     }
114     else if (destination == NULL) {
115     destination = argv[i];
116     }
117     else {
118 siliconforks 191 fatal_command_line("too many arguments");
119 siliconforks 2 }
120     }
121    
122     if (source == NULL || destination == NULL) {
123 siliconforks 191 fatal_command_line("missing argument");
124 siliconforks 2 }
125    
126     source = make_canonical_path(source);
127     destination = make_canonical_path(destination);
128    
129     jscoverage_init();
130     jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument);
131     jscoverage_cleanup();
132    
133     free(source);
134     free(destination);
135     free(exclude);
136     free(no_instrument);
137    
138     exit(EXIT_SUCCESS);
139     }

  ViewVC Help
Powered by ViewVC 1.1.24