1 |
/* |
/* |
2 |
main.c - JSCoverage main routine |
jscoverage.c - main routine for `jscoverage' program |
3 |
Copyright (C) 2007, 2008 siliconforks.com |
Copyright (C) 2007, 2008, 2009 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 |
49 |
|
|
50 |
for (int i = 1; i < argc; i++) { |
for (int i = 1; i < argc; i++) { |
51 |
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { |
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { |
52 |
copy_resource_to_stream("help.txt", stdout); |
copy_resource_to_stream("jscoverage-help.txt", stdout); |
53 |
exit(EXIT_SUCCESS); |
exit(EXIT_SUCCESS); |
54 |
} |
} |
55 |
else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) { |
else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) { |
56 |
printf("jscoverage %s\n", VERSION); |
version(); |
|
exit(EXIT_SUCCESS); |
|
57 |
} |
} |
58 |
else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) { |
else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) { |
59 |
verbose = 1; |
verbose = 1; |
61 |
else if (strcmp(argv[i], "--no-highlight") == 0) { |
else if (strcmp(argv[i], "--no-highlight") == 0) { |
62 |
jscoverage_highlight = false; |
jscoverage_highlight = false; |
63 |
} |
} |
64 |
|
else if (strcmp(argv[i], "--mozilla") == 0) { |
65 |
|
jscoverage_mozilla = true; |
66 |
|
jscoverage_set_js_version("180"); |
67 |
|
} |
68 |
else if (strcmp(argv[i], "--no-instrument") == 0) { |
else if (strcmp(argv[i], "--no-instrument") == 0) { |
69 |
i++; |
i++; |
70 |
if (i == argc) { |
if (i == argc) { |
71 |
fatal("--no-instrument: option requires an argument"); |
fatal_command_line("--no-instrument: option requires an argument"); |
72 |
} |
} |
73 |
no_instrument[num_no_instrument] = argv[i]; |
no_instrument[num_no_instrument] = argv[i]; |
74 |
num_no_instrument++; |
num_no_instrument++; |
80 |
else if (strcmp(argv[i], "--exclude") == 0) { |
else if (strcmp(argv[i], "--exclude") == 0) { |
81 |
i++; |
i++; |
82 |
if (i == argc) { |
if (i == argc) { |
83 |
fatal("--exclude: option requires an argument"); |
fatal_command_line("--exclude: option requires an argument"); |
84 |
} |
} |
85 |
exclude[num_exclude] = argv[i]; |
exclude[num_exclude] = argv[i]; |
86 |
num_exclude++; |
num_exclude++; |
92 |
else if (strcmp(argv[i], "--encoding") == 0) { |
else if (strcmp(argv[i], "--encoding") == 0) { |
93 |
i++; |
i++; |
94 |
if (i == argc) { |
if (i == argc) { |
95 |
fatal("--encoding: option requires an argument"); |
fatal_command_line("--encoding: option requires an argument"); |
96 |
} |
} |
97 |
jscoverage_encoding = argv[i]; |
jscoverage_encoding = argv[i]; |
98 |
} |
} |
99 |
else if (strncmp(argv[i], "--encoding=", 11) == 0) { |
else if (strncmp(argv[i], "--encoding=", 11) == 0) { |
100 |
jscoverage_encoding = argv[i] + 11; |
jscoverage_encoding = argv[i] + 11; |
101 |
} |
} |
102 |
|
else if (strcmp(argv[i], "--js-version") == 0) { |
103 |
|
i++; |
104 |
|
if (i == argc) { |
105 |
|
fatal_command_line("--js-version: option requires an argument"); |
106 |
|
} |
107 |
|
jscoverage_set_js_version(argv[i]); |
108 |
|
} |
109 |
|
else if (strncmp(argv[i], "--js-version=", 13) == 0) { |
110 |
|
jscoverage_set_js_version(argv[i] + 13); |
111 |
|
} |
112 |
else if (strncmp(argv[i], "-", 1) == 0) { |
else if (strncmp(argv[i], "-", 1) == 0) { |
113 |
fatal("unrecognized option `%s'", argv[i]); |
fatal_command_line("unrecognized option `%s'", argv[i]); |
114 |
} |
} |
115 |
else if (source == NULL) { |
else if (source == NULL) { |
116 |
source = argv[i]; |
source = argv[i]; |
119 |
destination = argv[i]; |
destination = argv[i]; |
120 |
} |
} |
121 |
else { |
else { |
122 |
fatal("too many arguments"); |
fatal_command_line("too many arguments"); |
123 |
} |
} |
124 |
} |
} |
125 |
|
|
126 |
if (source == NULL || destination == NULL) { |
if (source == NULL || destination == NULL) { |
127 |
fatal("missing argument"); |
fatal_command_line("missing argument"); |
128 |
} |
} |
129 |
|
|
130 |
source = make_canonical_path(source); |
source = make_canonical_path(source); |