int hashify_process_files(string_t* files, bool check_only) { int result = HASHIFY_RESULT_OK; hashify_string_t* history = 0; size_t ifile, files_size; for (ifile = 0, files_size = array_size(files); (result == HASHIFY_RESULT_OK) && (ifile < files_size); ++ifile) { string_t input_filename; string_t output_filename; string_const_t base_filename; stream_t* input_file; stream_t* output_file; input_filename = string_allocate(0, BUILD_MAX_PATHLEN); input_filename = string_copy(input_filename.str, BUILD_MAX_PATHLEN, STRING_ARGS(files[ifile])); input_filename = path_clean(STRING_ARGS(input_filename), BUILD_MAX_PATHLEN); error_context_push(STRING_CONST("parsing file"), STRING_ARGS(input_filename)); base_filename = path_base_file_name_with_directory(STRING_ARGS(input_filename)); output_filename = string_allocate_format(STRING_CONST("%.*s.h"), STRING_FORMAT(base_filename)); log_infof(0, STRING_CONST("Hashifying %.*s -> %.*s"), STRING_FORMAT(input_filename), STRING_FORMAT(output_filename)); input_file = stream_open(STRING_ARGS(input_filename), STREAM_IN); //If only validating, open the final output file. If generating, make a memory buffer as intermediate storage if (check_only) output_file = stream_open(STRING_ARGS(output_filename), STREAM_IN); else output_file = buffer_stream_allocate(memory_allocate(0, 65536, 0, MEMORY_PERSISTENT), STREAM_IN | STREAM_OUT, 0, 65536, true, true); if (!input_file) { log_warnf(0, WARNING_INVALID_VALUE, STRING_CONST("Unable to open input file: %.*s"), STRING_FORMAT(input_filename)); result = HASHIFY_RESULT_MISSING_INPUT_FILE; } else if (!output_file) { log_warnf(0, WARNING_INVALID_VALUE, STRING_CONST("Unable to open output file: %.*s"), STRING_FORMAT(output_filename)); result = HASHIFY_RESULT_MISSING_OUTPUT_FILE; } if (input_file && output_file) { result = hashify_process_file(input_file, output_file, output_filename, check_only, &history); if ((result == HASHIFY_RESULT_OK) && !check_only) result = hashify_write_file(output_file, output_filename); } stream_deallocate(input_file); stream_deallocate(output_file); error_context_pop(); string_deallocate(input_filename.str); string_deallocate(output_filename.str); } if ((result == HASHIFY_RESULT_OK) && (files_size > 0)) { if (check_only) log_info(0, STRING_CONST("All hashes validated")); else log_info(0, STRING_CONST("All hashes generated")); } array_deallocate(history); return result; }
int hashify_process_files( const char* const* files, bool check_only ) { int result = HASHIFY_RESULT_OK; hashify_string_t* history = 0; unsigned int ifile, files_size; for( ifile = 0, files_size = array_size( files ); ( result == HASHIFY_RESULT_OK ) && ( ifile < files_size ); ++ifile ) { char* input_filename; char* output_filename; stream_t* input_file; stream_t* output_file; input_filename = path_clean( string_clone( files[ifile] ), path_is_absolute( files[ifile] ) ); error_context_push( "parsing file", input_filename ); output_filename = string_append( path_base_file_name_with_path( input_filename ), ".h" ); log_infof( "Hashifying %s -> %s", input_filename, output_filename ); input_file = stream_open( input_filename, STREAM_IN ); //If only validating, open the final output file. If generating, make a memory buffer as intermediate storage if( check_only ) output_file = stream_open( output_filename, STREAM_IN ); else output_file = buffer_stream_allocate( memory_allocate( 65536, 0, MEMORY_PERSISTENT ), STREAM_IN | STREAM_OUT, 0, 65536, true, true ); if( !input_file ) { log_warnf( WARNING_BAD_DATA, "Unable to open input file: %s", input_filename ); result = HASHIFY_RESULT_MISSING_INPUT_FILE; } else if( !output_file ) { log_warnf( WARNING_BAD_DATA, "Unable to open output file: %s", output_filename ); result = HASHIFY_RESULT_MISSING_OUTPUT_FILE; } if( input_file && output_file ) { result = hashify_process_file( input_file, output_file, check_only, &history ); if( ( result == HASHIFY_RESULT_OK ) && !check_only ) result = hashify_write_file( output_file, output_filename ); } stream_deallocate( input_file ); stream_deallocate( output_file ); error_context_pop(); string_deallocate( input_filename ); string_deallocate( output_filename ); } if( ( result == HASHIFY_RESULT_OK ) && ( files_size > 0 ) ) { if( check_only ) log_infof( "All hashes validated" ); else log_infof( "All hashes generated" ); } array_deallocate( history ); return result; }