PageRenderTime 38ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /*
  2. jscoverage.c - main routine for `jscoverage' program
  3. Copyright (C) 2007, 2008 siliconforks.com
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include <config.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include "global.h"
  21. #include "instrument.h"
  22. #include "instrument-js.h"
  23. #include "resource-manager.h"
  24. #include "util.h"
  25. const char * jscoverage_encoding = "ISO-8859-1";
  26. bool jscoverage_highlight = true;
  27. int main(int argc, char ** argv) {
  28. int verbose = 0;
  29. // program = argv[0];
  30. program = "jscoverage";
  31. char * source = NULL;
  32. char * destination = NULL;
  33. char ** no_instrument = xnew(char *, argc - 1);
  34. int num_no_instrument = 0;
  35. char ** exclude = xnew(char *, argc - 1);
  36. int num_exclude = 0;
  37. jscoverage_highlight = false;
  38. for (int i = 1; i < argc; i++) {
  39. if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
  40. copy_resource_to_stream("jscoverage-help.txt", stdout);
  41. exit(EXIT_SUCCESS);
  42. }
  43. else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
  44. version();
  45. }
  46. else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
  47. verbose = 1;
  48. }
  49. else if (strcmp(argv[i], "--mozilla") == 0) {
  50. jscoverage_mozilla = true;
  51. jscoverage_set_js_version("180");
  52. }
  53. else if (strcmp(argv[i], "--no-instrument") == 0) {
  54. i++;
  55. if (i == argc) {
  56. fatal_command_line("--no-instrument: option requires an argument");
  57. }
  58. no_instrument[num_no_instrument] = argv[i];
  59. num_no_instrument++;
  60. }
  61. else if (strncmp(argv[i], "--no-instrument=", 16) == 0) {
  62. no_instrument[num_no_instrument] = argv[i] + 16;
  63. num_no_instrument++;
  64. }
  65. else if (strcmp(argv[i], "--exclude") == 0) {
  66. i++;
  67. if (i == argc) {
  68. fatal_command_line("--exclude: option requires an argument");
  69. }
  70. exclude[num_exclude] = argv[i];
  71. num_exclude++;
  72. }
  73. else if (strncmp(argv[i], "--exclude=", 10) == 0) {
  74. exclude[num_exclude] = argv[i] + 10;
  75. num_exclude++;
  76. }
  77. else if (strcmp(argv[i], "--encoding") == 0) {
  78. i++;
  79. if (i == argc) {
  80. fatal_command_line("--encoding: option requires an argument");
  81. }
  82. jscoverage_encoding = argv[i];
  83. }
  84. else if (strncmp(argv[i], "--encoding=", 11) == 0) {
  85. jscoverage_encoding = argv[i] + 11;
  86. }
  87. else if (strcmp(argv[i], "--js-version") == 0) {
  88. i++;
  89. if (i == argc) {
  90. fatal_command_line("--js-version: option requires an argument");
  91. }
  92. jscoverage_set_js_version(argv[i]);
  93. }
  94. else if (strncmp(argv[i], "--js-version=", 13) == 0) {
  95. jscoverage_set_js_version(argv[i] + 13);
  96. }
  97. else if (strncmp(argv[i], "-", 1) == 0) {
  98. fatal_command_line("unrecognized option `%s'", argv[i]);
  99. }
  100. else if (source == NULL) {
  101. source = argv[i];
  102. }
  103. else if (destination == NULL) {
  104. destination = argv[i];
  105. }
  106. else {
  107. fatal_command_line("too many arguments");
  108. }
  109. }
  110. if (source == NULL || destination == NULL) {
  111. fatal_command_line("missing argument");
  112. }
  113. source = make_canonical_path(source);
  114. destination = make_canonical_path(destination);
  115. jscoverage_init();
  116. jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument);
  117. jscoverage_cleanup();
  118. free(source);
  119. free(destination);
  120. free(exclude);
  121. free(no_instrument);
  122. exit(EXIT_SUCCESS);
  123. }