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

Diff of /trunk/jscoverage.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/main.c revision 2 by siliconforks, Wed Aug 1 13:51:53 2007 UTC trunk/jscoverage.c revision 505 by siliconforks, Sat Jan 2 04:55:54 2010 UTC
# Line 1  Line 1 
1  /*  /*
2      main.c - JSCoverage main routine      jscoverage.c - main routine for `jscoverage' program
3      Copyright (C) 2007 siliconforks.com      Copyright (C) 2007, 2008, 2009, 2010 siliconforks.com
4    
5      This program is free software; you can redistribute it and/or modify      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      it under the terms of the GNU General Public License as published by
# Line 17  Line 17 
17      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */  */
19    
20    #include <config.h>
21    
22  #include <stdio.h>  #include <stdio.h>
23  #include <stdlib.h>  #include <stdlib.h>
24  #include <string.h>  #include <string.h>
25    
26    #include "global.h"
27  #include "instrument.h"  #include "instrument.h"
28  #include "instrument-js.h"  #include "instrument-js.h"
29  #include "resource-manager.h"  #include "resource-manager.h"
30  #include "util.h"  #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) {  int main(int argc, char ** argv) {
36    int verbose = 0;    int verbose = 0;
37    
   // program = argv[0];  
38    program = "jscoverage";    program = "jscoverage";
39    
40    char * source = NULL;    char * source = NULL;
41    char * destination = NULL;    char * destination = NULL;
42    
43    char ** no_instrument = xmalloc((argc - 1) * sizeof(char *));    char ** no_instrument = xnew(char *, argc - 1);
44    int num_no_instrument = 0;    int num_no_instrument = 0;
45    
46    char ** exclude = xmalloc((argc - 1) * sizeof(char *));    char ** exclude = xnew(char *, argc - 1);
47    int num_exclude = 0;    int num_exclude = 0;
48    
49    for (int i = 1; i < argc; i++) {    for (int i = 1; i < argc; i++) {
50      if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {      if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
51        copy_resource_to_stream("help.txt", stdout);        copy_resource_to_stream("jscoverage-help.txt", stdout);
52        exit(EXIT_SUCCESS);        exit(EXIT_SUCCESS);
53      }      }
54      else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {      else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
55        printf("jscoverage %s\n", VERSION);        version();
       exit(EXIT_SUCCESS);  
56      }      }
57      else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {      else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
58        verbose = 1;        verbose = 1;
59      }      }
60        else if (strcmp(argv[i], "--no-highlight") == 0) {
61          jscoverage_highlight = false;
62        }
63        else if (strcmp(argv[i], "--mozilla") == 0) {
64          jscoverage_mode = JSCOVERAGE_MOZILLA;
65          jscoverage_set_js_version("180");
66        }
67        else if (strcmp(argv[i], "--no-browser") == 0) {
68          jscoverage_mode = JSCOVERAGE_NO_BROWSER;
69        }
70      else if (strcmp(argv[i], "--no-instrument") == 0) {      else if (strcmp(argv[i], "--no-instrument") == 0) {
71        i++;        i++;
72        if (i == argc) {        if (i == argc) {
73          fatal("--no-instrument: option requires an argument");          fatal_command_line("--no-instrument: option requires an argument");
74        }        }
75        no_instrument[num_no_instrument] = argv[i];        no_instrument[num_no_instrument] = argv[i];
76        num_no_instrument++;        num_no_instrument++;
# Line 68  Line 82 
82      else if (strcmp(argv[i], "--exclude") == 0) {      else if (strcmp(argv[i], "--exclude") == 0) {
83        i++;        i++;
84        if (i == argc) {        if (i == argc) {
85          fatal("--exclude: option requires an argument");          fatal_command_line("--exclude: option requires an argument");
86        }        }
87        exclude[num_exclude] = argv[i];        exclude[num_exclude] = argv[i];
88        num_exclude++;        num_exclude++;
# Line 77  Line 91 
91        exclude[num_exclude] = argv[i] + 10;        exclude[num_exclude] = argv[i] + 10;
92        num_exclude++;        num_exclude++;
93      }      }
94        else if (strcmp(argv[i], "--encoding") == 0) {
95          i++;
96          if (i == argc) {
97            fatal_command_line("--encoding: option requires an argument");
98          }
99          jscoverage_encoding = argv[i];
100        }
101        else if (strncmp(argv[i], "--encoding=", 11) == 0) {
102          jscoverage_encoding = argv[i] + 11;
103        }
104        else if (strcmp(argv[i], "--js-version") == 0) {
105          i++;
106          if (i == argc) {
107            fatal_command_line("--js-version: option requires an argument");
108          }
109          jscoverage_set_js_version(argv[i]);
110        }
111        else if (strncmp(argv[i], "--js-version=", 13) == 0) {
112          jscoverage_set_js_version(argv[i] + 13);
113        }
114      else if (strncmp(argv[i], "-", 1) == 0) {      else if (strncmp(argv[i], "-", 1) == 0) {
115        fatal("unrecognized option `%s'", argv[i]);        fatal_command_line("unrecognized option `%s'", argv[i]);
116      }      }
117      else if (source == NULL) {      else if (source == NULL) {
118        source = argv[i];        source = argv[i];
# Line 87  Line 121 
121        destination = argv[i];        destination = argv[i];
122      }      }
123      else {      else {
124        fatal("too many arguments");        fatal_command_line("too many arguments");
125      }      }
126    }    }
127    
128    if (source == NULL || destination == NULL) {    if (source == NULL || destination == NULL) {
129      fatal("missing argument");      fatal_command_line("missing argument");
130    }    }
131    
132    source = make_canonical_path(source);    source = make_canonical_path(source);
# Line 100  Line 134 
134    
135    jscoverage_init();    jscoverage_init();
136    jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument);    jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument);
   jscoverage_copy_resources(destination);  
137    jscoverage_cleanup();    jscoverage_cleanup();
138    
139    free(source);    free(source);

Legend:
Removed from v.2  
changed lines
  Added in v.505

  ViewVC Help
Powered by ViewVC 1.1.24