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

Annotation of /trunk/jscoverage.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 174 - (hide annotations)
Sat Sep 20 23:27:14 2008 UTC (10 years, 11 months ago) by siliconforks
Original Path: trunk/main.c
File MIME type: text/plain
File size: 3580 byte(s)
Provide better character encoding support.
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    
34 siliconforks 2 int main(int argc, char ** argv) {
35     int verbose = 0;
36    
37     // program = argv[0];
38     program = "jscoverage";
39    
40     char * source = NULL;
41     char * destination = NULL;
42    
43 siliconforks 107 char ** no_instrument = xnew(char *, argc - 1);
44 siliconforks 2 int num_no_instrument = 0;
45    
46 siliconforks 107 char ** exclude = xnew(char *, argc - 1);
47 siliconforks 2 int num_exclude = 0;
48    
49     for (int i = 1; i < argc; i++) {
50     if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
51     copy_resource_to_stream("help.txt", stdout);
52     exit(EXIT_SUCCESS);
53     }
54     else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
55     printf("jscoverage %s\n", VERSION);
56     exit(EXIT_SUCCESS);
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-instrument") == 0) {
62     i++;
63     if (i == argc) {
64     fatal("--no-instrument: option requires an argument");
65     }
66     no_instrument[num_no_instrument] = argv[i];
67     num_no_instrument++;
68     }
69     else if (strncmp(argv[i], "--no-instrument=", 16) == 0) {
70     no_instrument[num_no_instrument] = argv[i] + 16;
71     num_no_instrument++;
72     }
73     else if (strcmp(argv[i], "--exclude") == 0) {
74     i++;
75     if (i == argc) {
76     fatal("--exclude: option requires an argument");
77     }
78     exclude[num_exclude] = argv[i];
79     num_exclude++;
80     }
81     else if (strncmp(argv[i], "--exclude=", 10) == 0) {
82     exclude[num_exclude] = argv[i] + 10;
83     num_exclude++;
84     }
85 siliconforks 174 else if (strcmp(argv[i], "--encoding") == 0) {
86     i++;
87     if (i == argc) {
88     fatal("--encoding: option requires an argument");
89     }
90     jscoverage_encoding = argv[i];
91     }
92     else if (strncmp(argv[i], "--encoding=", 11) == 0) {
93     jscoverage_encoding = argv[i] + 11;
94     }
95 siliconforks 2 else if (strncmp(argv[i], "-", 1) == 0) {
96     fatal("unrecognized option `%s'", argv[i]);
97     }
98     else if (source == NULL) {
99     source = argv[i];
100     }
101     else if (destination == NULL) {
102     destination = argv[i];
103     }
104     else {
105     fatal("too many arguments");
106     }
107     }
108    
109     if (source == NULL || destination == NULL) {
110     fatal("missing argument");
111     }
112    
113     source = make_canonical_path(source);
114     destination = make_canonical_path(destination);
115    
116     jscoverage_init();
117     jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument);
118     jscoverage_cleanup();
119    
120     free(source);
121     free(destination);
122     free(exclude);
123     free(no_instrument);
124    
125     exit(EXIT_SUCCESS);
126     }

  ViewVC Help
Powered by ViewVC 1.1.24