Skip to content
This repository was archived by the owner on Oct 9, 2018. It is now read-only.

Handling multiple files of the same name #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Changing FileNames to include paths from the source argument.
  • Loading branch information
nivthefox committed Aug 25, 2012
commit 189a2ed72389f3adcec1b624f4eea0b627ece29e
13 changes: 9 additions & 4 deletions instrument.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void check_contains_file(const char * file1, const char * file2) {
}
}

static void instrument_file(const char * source_file, const char * destination_file, const char * id, int instrumenting) {
static void instrument_file(const char * source_file, const char * destination_file, const char * id, int instrumenting, char * filepath) {
if (g_verbose) {
printf("Instrumenting file %s\n", id);
}
Expand Down Expand Up @@ -108,7 +108,7 @@ static void instrument_file(const char * source_file, const char * destination_f
else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
fatal("error decoding %s in file %s", jscoverage_encoding, id);
}
jscoverage_instrument_js(id, characters, num_characters, output_stream);
jscoverage_instrument_js(filepath, characters, num_characters, output_stream);
free(characters);

if (fwrite(output_stream->data, 1, output_stream->length, output) != output_stream->length) {
Expand All @@ -135,7 +135,8 @@ void jscoverage_instrument(const char * source,
char ** exclude,
int num_exclude,
char ** no_instrument,
int num_no_instrument)
int num_no_instrument,
char * path)
{
assert(source != NULL);
assert(destination != NULL);
Expand Down Expand Up @@ -215,9 +216,13 @@ void jscoverage_instrument(const char * source,
free(ni);
}

instrument_file(s, d, p->name, instrument_this);
int length = strlen(path) + strlen(p->name) + 1;
char * filepath = malloc(length);
sprintf(filepath, "%s/%s", path, p->name);
instrument_file(s, d, p->name, instrument_this, filepath);

cleanup:
free(filepath);
free(s);
free(d);
}
Expand Down
3 changes: 2 additions & 1 deletion instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void jscoverage_instrument(const char * source,
char ** exclude,
int num_exclude,
char ** no_instrument,
int num_no_instrument);
int num_no_instrument,
const char * path);

#endif /* INSTRUMENT_H_ */
4 changes: 3 additions & 1 deletion jscoverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,19 @@ int main(int argc, char ** argv) {
fatal_command_line("missing argument");
}

char * path = strdup(source);
source = make_canonical_path(source);
destination = make_canonical_path(destination);

jscoverage_init();
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, path);
jscoverage_cleanup();

free(source);
free(destination);
free(exclude);
free(no_instrument);
free(path);

exit(EXIT_SUCCESS);
}