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

Contents of /trunk/jscoverage.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 191 - (show annotations)
Tue Sep 23 03:49:29 2008 UTC (10 years, 11 months ago) by siliconforks
Original Path: trunk/main.c
File MIME type: text/plain
File size: 3789 byte(s)
Print 'Try --help' only for command-line errors.
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 printf("jscoverage %s\n", VERSION);
57 exit(EXIT_SUCCESS);
58 }
59 else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
60 verbose = 1;
61 }
62 else if (strcmp(argv[i], "--no-highlight") == 0) {
63 jscoverage_highlight = false;
64 }
65 else if (strcmp(argv[i], "--no-instrument") == 0) {
66 i++;
67 if (i == argc) {
68 fatal_command_line("--no-instrument: option requires an argument");
69 }
70 no_instrument[num_no_instrument] = argv[i];
71 num_no_instrument++;
72 }
73 else if (strncmp(argv[i], "--no-instrument=", 16) == 0) {
74 no_instrument[num_no_instrument] = argv[i] + 16;
75 num_no_instrument++;
76 }
77 else if (strcmp(argv[i], "--exclude") == 0) {
78 i++;
79 if (i == argc) {
80 fatal_command_line("--exclude: option requires an argument");
81 }
82 exclude[num_exclude] = argv[i];
83 num_exclude++;
84 }
85 else if (strncmp(argv[i], "--exclude=", 10) == 0) {
86 exclude[num_exclude] = argv[i] + 10;
87 num_exclude++;
88 }
89 else if (strcmp(argv[i], "--encoding") == 0) {
90 i++;
91 if (i == argc) {
92 fatal_command_line("--encoding: option requires an argument");
93 }
94 jscoverage_encoding = argv[i];
95 }
96 else if (strncmp(argv[i], "--encoding=", 11) == 0) {
97 jscoverage_encoding = argv[i] + 11;
98 }
99 else if (strncmp(argv[i], "-", 1) == 0) {
100 fatal_command_line("unrecognized option `%s'", argv[i]);
101 }
102 else if (source == NULL) {
103 source = argv[i];
104 }
105 else if (destination == NULL) {
106 destination = argv[i];
107 }
108 else {
109 fatal_command_line("too many arguments");
110 }
111 }
112
113 if (source == NULL || destination == NULL) {
114 fatal_command_line("missing argument");
115 }
116
117 source = make_canonical_path(source);
118 destination = make_canonical_path(destination);
119
120 jscoverage_init();
121 jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument);
122 jscoverage_cleanup();
123
124 free(source);
125 free(destination);
126 free(exclude);
127 free(no_instrument);
128
129 exit(EXIT_SUCCESS);
130 }

  ViewVC Help
Powered by ViewVC 1.1.24