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

Contents of /trunk/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 339 - (show annotations)
Fri Oct 24 16:13:57 2008 UTC (9 years, 11 months ago) by siliconforks
File MIME type: text/plain
File size: 4066 byte(s)
Add support for the JS 1.6 `for each' statement.
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 <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("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], "--no-instrument") == 0) {
65 i++;
66 if (i == argc) {
67 fatal_command_line("--no-instrument: option requires an argument");
68 }
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 fatal_command_line("--exclude: option requires an argument");
80 }
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 else if (strcmp(argv[i], "--encoding") == 0) {
89 i++;
90 if (i == argc) {
91 fatal_command_line("--encoding: option requires an argument");
92 }
93 jscoverage_encoding = argv[i];
94 }
95 else if (strncmp(argv[i], "--encoding=", 11) == 0) {
96 jscoverage_encoding = argv[i] + 11;
97 }
98 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 else if (strncmp(argv[i], "-", 1) == 0) {
109 fatal_command_line("unrecognized option `%s'", argv[i]);
110 }
111 else if (source == NULL) {
112 source = argv[i];
113 }
114 else if (destination == NULL) {
115 destination = argv[i];
116 }
117 else {
118 fatal_command_line("too many arguments");
119 }
120 }
121
122 if (source == NULL || destination == NULL) {
123 fatal_command_line("missing argument");
124 }
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