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

Diff of /trunk/instrument.c

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

revision 174 by siliconforks, Sat Sep 20 23:27:14 2008 UTC revision 241 by siliconforks, Fri Oct 3 23:52:10 2008 UTC
# Line 29  Line 29 
29  #include <sys/stat.h>  #include <sys/stat.h>
30  #include <sys/types.h>  #include <sys/types.h>
31    
32    #include "encoding.h"
33  #include "global.h"  #include "global.h"
34  #include "instrument-js.h"  #include "instrument-js.h"
35  #include "resource-manager.h"  #include "resource-manager.h"
# Line 90  Line 91 
91        break;        break;
92      case FILE_TYPE_JS:      case FILE_TYPE_JS:
93        {        {
94          FILE * input = xfopen(source_file, "r");          FILE * input = xfopen(source_file, "rb");
95          FILE * output = xfopen(destination_file, "w");          FILE * output = xfopen(destination_file, "wb");
96    
97          Stream * input_stream = Stream_new(0);          Stream * input_stream = Stream_new(0);
98          Stream * output_stream = Stream_new(0);          Stream * output_stream = Stream_new(0);
99    
100          Stream_write_file_contents(input_stream, input);          Stream_write_file_contents(input_stream, input);
101    
102          jscoverage_instrument_js(id, jscoverage_encoding, input_stream, output_stream);          size_t num_characters = input_stream->length;
103            uint16_t * characters = NULL;
104            int result = jscoverage_bytes_to_characters(jscoverage_encoding, input_stream->data, input_stream->length, &characters, &num_characters);
105            if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) {
106              fatal("encoding %s not supported", jscoverage_encoding);
107            }
108            else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
109              fatal("error decoding %s in file %s", jscoverage_encoding, id);
110            }
111            jscoverage_instrument_js(id, characters, num_characters, output_stream);
112            free(characters);
113    
114          if (fwrite(output_stream->data, 1, output_stream->length, output) != output_stream->length) {          if (fwrite(output_stream->data, 1, output_stream->length, output) != output_stream->length) {
115            fatal("cannot write to file: %s", destination_file);            fatal("cannot write to file: %s", destination_file);

Legend:
Removed from v.174  
changed lines
  Added in v.241

  ViewVC Help
Powered by ViewVC 1.1.24