PageRenderTime 61ms CodeModel.GetById 20ms app.highlight 11ms RepoModel.GetById 19ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/jscoverage.c

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C | 142 lines | 107 code | 16 blank | 19 comment | 64 complexity | 56c6e3e1e7335f8ebbd5a9c524223bef MD5 | raw file
  1/*
  2    jscoverage.c - main routine for `jscoverage' program
  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
 32const char * jscoverage_encoding = "ISO-8859-1";
 33bool jscoverage_highlight = true;
 34
 35int 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  jscoverage_highlight = false;
 51
 52  for (int i = 1; i < argc; i++) {
 53    if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
 54      copy_resource_to_stream("jscoverage-help.txt", stdout);
 55      exit(EXIT_SUCCESS);
 56    }
 57    else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
 58      version();
 59    }
 60    else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
 61      verbose = 1;
 62    }
 63    else if (strcmp(argv[i], "--mozilla") == 0) {
 64      jscoverage_mozilla = true;
 65      jscoverage_set_js_version("180");
 66    }
 67    else if (strcmp(argv[i], "--no-instrument") == 0) {
 68      i++;
 69      if (i == argc) {
 70        fatal_command_line("--no-instrument: option requires an argument");
 71      }
 72      no_instrument[num_no_instrument] = argv[i];
 73      num_no_instrument++;
 74    }
 75    else if (strncmp(argv[i], "--no-instrument=", 16) == 0) {
 76      no_instrument[num_no_instrument] = argv[i] + 16;
 77      num_no_instrument++;
 78    }
 79    else if (strcmp(argv[i], "--exclude") == 0) {
 80      i++;
 81      if (i == argc) {
 82        fatal_command_line("--exclude: option requires an argument");
 83      }
 84      exclude[num_exclude] = argv[i];
 85      num_exclude++;
 86    }
 87    else if (strncmp(argv[i], "--exclude=", 10) == 0) {
 88      exclude[num_exclude] = argv[i] + 10;
 89      num_exclude++;
 90    }
 91    else if (strcmp(argv[i], "--encoding") == 0) {
 92      i++;
 93      if (i == argc) {
 94        fatal_command_line("--encoding: option requires an argument");
 95      }
 96      jscoverage_encoding = argv[i];
 97    }
 98    else if (strncmp(argv[i], "--encoding=", 11) == 0) {
 99      jscoverage_encoding = argv[i] + 11;
100    }
101    else if (strcmp(argv[i], "--js-version") == 0) {
102      i++;
103      if (i == argc) {
104        fatal_command_line("--js-version: option requires an argument");
105      }
106      jscoverage_set_js_version(argv[i]);
107    }
108    else if (strncmp(argv[i], "--js-version=", 13) == 0) {
109      jscoverage_set_js_version(argv[i] + 13);
110    }
111    else if (strncmp(argv[i], "-", 1) == 0) {
112      fatal_command_line("unrecognized option `%s'", argv[i]);
113    }
114    else if (source == NULL) {
115      source = argv[i];
116    }
117    else if (destination == NULL) {
118      destination = argv[i];
119    }
120    else {
121      fatal_command_line("too many arguments");
122    }
123  }
124
125  if (source == NULL || destination == NULL) {
126    fatal_command_line("missing argument");
127  }
128
129  source = make_canonical_path(source);
130  destination = make_canonical_path(destination);
131
132  jscoverage_init();
133  jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument);
134  jscoverage_cleanup();
135
136  free(source);
137  free(destination);
138  free(exclude);
139  free(no_instrument);
140
141  exit(EXIT_SUCCESS);
142}