static void gen_data_config_set_template( gen_data_config_type * config , const char * template_ecl_file , const char * template_data_key ) { util_safe_free( config->template_buffer ); config->template_buffer = NULL; if (template_ecl_file != NULL) { char *data_ptr; config->template_buffer = util_fread_alloc_file_content( template_ecl_file , &config->template_buffer_size); if (template_data_key != NULL) { data_ptr = strstr(config->template_buffer , template_data_key); if (data_ptr == NULL) util_abort("%s: template:%s can not be used - could not find data key:%s \n",__func__ , template_ecl_file , template_data_key); else { config->template_data_offset = data_ptr - config->template_buffer; config->template_data_skip = strlen( template_data_key ); } } else { /* We are using a template without a template_data_key - the data is assumed to come at the end of the template. */ config->template_data_offset = strlen( config->template_buffer ); config->template_data_skip = 0; } } else config->template_buffer = NULL; config->template_file = util_realloc_string_copy( config->template_file , template_ecl_file ); config->template_key = util_realloc_string_copy( config->template_key , template_data_key ); }
int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); const char * config_file = argv[1]; ert_test_context_type * test_context = ert_test_context_alloc("VerifyJobsFileTest" , config_file); enkf_main_type * enkf_main = ert_test_context_get_main(test_context); { const int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc(0, false); bool_vector_iset( iactive , ens_size - 1 , true ); enkf_main_create_run_path(enkf_main , iactive , 0); bool_vector_free(iactive); } const char * filename = util_alloc_filename(ert_test_context_get_cwd(test_context), "simulations/run0/jobs.py", NULL); const char * jobs_file_content = util_fread_alloc_file_content(filename, NULL); test_assert_true (strstr(jobs_file_content, "umask = 0022") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 0023") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 0032") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 0122") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 1022") != NULL); ert_test_context_free(test_context); exit(0); }
stringlist_type * basic_parser_tokenize_file(const basic_parser_type * parser, const char * filename, bool strip_quote_marks) { stringlist_type * tokens; char * buffer = util_fread_alloc_file_content( filename, NULL ); tokens = basic_parser_tokenize_buffer( parser, buffer, strip_quote_marks ); free(buffer); return tokens; }
char * parser_fread_alloc_file_content(const char * filename , const char * quote_set , const char * delete_set , const char * comment_start , const char * comment_end) { parser_type * parser = parser_alloc( NULL , quote_set , NULL , delete_set , comment_start , comment_end); char * buffer = util_fread_alloc_file_content( filename , NULL); parser_strip_buffer( parser , &buffer ); parser_free( parser ); return buffer; }
void test_assert_file_content__( const char * input_file , const char * expected, const char * src_file , int line) { if (util_file_exists( input_file )) { char * content = util_fread_alloc_file_content(input_file, NULL); if (!util_string_equal( content , expected)) test_error_exit("%s:%d content difference \n",src_file , line); free( content ); } else test_error_exit("%s:%d => No such file:%s \n", src_file , line , input_file); }
void job_queue_node_fscanf_EXIT( job_queue_node_type * node ) { job_queue_node_free_error_info( node ); if (node->exit_file) { if (util_file_exists( node->exit_file )) { char * xml_buffer = util_fread_alloc_file_content( node->exit_file, NULL); node->failed_job = __alloc_tag_content( xml_buffer , "job" ); node->error_reason = __alloc_tag_content( xml_buffer , "reason" ); node->stderr_capture = __alloc_tag_content( xml_buffer , "stderr"); node->stderr_file = __alloc_tag_content( xml_buffer , "stderr_file"); free( xml_buffer ); } else node->failed_job = util_alloc_sprintf("EXIT file:%s not found - load failure?" , node->exit_file); } }
bool gen_data_config_set_template( gen_data_config_type * config , const char * template_ecl_file , const char * template_data_key ) { char * template_buffer = NULL; bool template_valid = true; int template_buffer_size; if (template_ecl_file) { if (util_file_readable( template_ecl_file )) { template_buffer = util_fread_alloc_file_content( template_ecl_file , &template_buffer_size); if (template_data_key) { if (strstr(template_buffer , template_data_key) == NULL) template_valid = false; } } else template_valid = false; } if (template_valid) { gen_data_config_reset_template(config); if (template_ecl_file != NULL) { char *data_ptr; config->template_buffer = template_buffer; config->template_buffer_size = template_buffer_size; if (template_data_key != NULL) { data_ptr = strstr(config->template_buffer , template_data_key); if (data_ptr == NULL) util_abort("%s: template:%s can not be used - could not find data key:%s \n",__func__ , template_ecl_file , template_data_key); else { config->template_data_offset = data_ptr - config->template_buffer; config->template_data_skip = strlen( template_data_key ); } } else { /* We are using a template without a template_data_key - the data is assumed to come at the end of the template. */ config->template_data_offset = strlen( config->template_buffer ); config->template_data_skip = 0; } config->template_file = util_realloc_string_copy( config->template_file , template_ecl_file ); config->template_key = util_realloc_string_copy( config->template_key , template_data_key ); if (config->output_format != ASCII_TEMPLATE) fprintf(stderr,"**WARNING: The template settings will ignored for key:%s - use OUTPUT_FORMAT:ASCII_TEMPLATE to get template behaviour\n", config->key); } } return template_valid; }
void test_filter_file2() { subst_list_type * subst_list = subst_list_alloc( NULL ); test_work_area_type * work_area = test_work_area_alloc("subst_list/filter2"); { FILE * stream = util_fopen("template" , "w"); fprintf(stream , "MAGIC_PRINT magic-list.txt <ERTCASE> __MAGIC__"); fclose(stream); } subst_list_append_copy( subst_list , "<QC_PATH>" , "QC" , NULL); subst_list_append_copy( subst_list , "__MAGIC__" , "MagicAllTheWayToWorkFlow" , NULL); subst_list_append_copy( subst_list , "<CASE>" , "SUPERcase" , NULL); subst_list_append_copy( subst_list , "<ERTCASE>" , "default" , NULL); subst_list_filter_file( subst_list , "template" , "target"); { char * target_string = util_fread_alloc_file_content( "target" , NULL ); test_assert_string_equal( target_string , "MAGIC_PRINT magic-list.txt default MagicAllTheWayToWorkFlow"); free( target_string ); } test_work_area_free( work_area ); subst_list_free( subst_list ); }