stringlist_type * config_content_item_alloc_stringlist(const config_content_item_type * item, bool copy) {
  const config_content_node_type * node = config_content_item_get_last_node( item );
  stringlist_type * stringlist = stringlist_alloc_new();
  const stringlist_type * src_list = config_content_node_get_stringlist( node );
  
  if (copy)
    stringlist_append_stringlist_copy( stringlist , src_list );
  else
    stringlist_append_stringlist_ref( stringlist , src_list );  
  
  return stringlist;
}
stringlist_type * config_content_item_alloc_complete_stringlist(const config_content_item_type * item, bool copy) {
  int inode;
  stringlist_type * stringlist = stringlist_alloc_new();
  for (inode = 0; inode < vector_get_size( item->nodes ); inode++) {
    const config_content_node_type * node = config_content_item_iget_node(item , inode);
    const stringlist_type * src_list = config_content_node_get_stringlist( node );
    
    if (copy)
      stringlist_append_stringlist_copy( stringlist , src_list );
    else
      stringlist_append_stringlist_ref( stringlist , src_list );  
    
  }

  return stringlist;
}
hash_type * config_content_item_alloc_hash(const config_content_item_type * item , bool copy) {
  hash_type * hash = hash_alloc();
  if (item != NULL) {
    int inode;
    for (inode = 0; inode < vector_get_size( item->nodes ); inode++) {
      const config_content_node_type * node = config_content_item_iget_node(item , inode);
      const stringlist_type * src_list = config_content_node_get_stringlist( node );
      const char * key = stringlist_iget(src_list , 0);
      const char * value = stringlist_iget(src_list , 1);
      
      if (copy) {
        hash_insert_hash_owned_ref(hash , 
                                   key ,
                                   util_alloc_string_copy(value) , 
                                   free);
      } else
        hash_insert_ref(hash , key , value );
      
    }
  }
  return hash;
}
const char * config_content_item_iget(const config_content_item_type * item , int occurence , int index) {
  const config_content_node_type * node = config_content_item_iget_node(item , occurence);  
  const stringlist_type * src_list = config_content_node_get_stringlist( node );
  return stringlist_iget( src_list , index );
}
const stringlist_type * config_content_item_get_stringlist_ref(const config_content_item_type * item) {
  const config_content_node_type * node = config_content_item_get_last_node( item );  
  return config_content_node_get_stringlist( node );
}
const stringlist_type * config_content_item_iget_stringlist_ref(const config_content_item_type * item, int occurence) {
  const config_content_node_type * node = config_content_item_iget_node(item , occurence);  
  return config_content_node_get_stringlist( node );
}
Exemple #7
0
bool workflow_try_compile( workflow_type * script , const subst_list_type * context) {
  if (util_file_exists( script->src_file )) {
    const char * src_file = script->src_file;
    char * tmp_file = NULL;
    bool   update = false;
    if (context != NULL) {
      tmp_file = util_alloc_tmp_file("/tmp" , "ert-workflow" , false );
      update = subst_list_filter_file( context , script->src_file , tmp_file );
      if (update) {
        script->compiled = false;
        src_file = tmp_file;
      } else {
        remove( tmp_file );
        free( tmp_file );
        tmp_file = NULL;
      }
    }

    {
      time_t src_mtime = util_file_mtime( script->src_file );
      if (script->compiled) {
        if (util_difftime_seconds( src_mtime , script->compile_time ) > 0 )
          return true;
        else {
          // Script has been compiled succesfully, but then changed afterwards.
          // We try to recompile; if that fails we are left with 'nothing'.
        }
      }
    }

    {
      // Try to compile
      config_parser_type * config_compiler = workflow_joblist_get_compiler( script->joblist );
      script->compiled = false;
      workflow_clear( script );
      {
        config_content_type * content = config_parse( config_compiler , src_file , WORKFLOW_COMMENT_STRING , WORKFLOW_INCLUDE , NULL , CONFIG_UNRECOGNIZED_ERROR , true );

        if (config_content_is_valid( content )) {
          int cmd_line;
          for (cmd_line = 0; cmd_line < config_content_get_size(content); cmd_line++) {
            const config_content_node_type * node = config_content_iget_node( content , cmd_line );
            const char * jobname = config_content_node_get_kw( node );
            const workflow_job_type * job = workflow_joblist_get_job( script->joblist , jobname );
            cmd_type * cmd = cmd_alloc( job , config_content_node_get_stringlist( node ));

            workflow_add_cmd( script , cmd );
          }
          script->compiled = true;
        } else
          workflow_store_error( script , config_content_get_errors( content ));

        config_content_free( content );
      }
    }

    if (tmp_file != NULL) {
      if (script->compiled)
        remove( tmp_file );
      free( tmp_file );
    }
  }

  // It is legal to remove the script after successfull compilation but
  // then the context will not be applied at subsequent invocations.
  return script->compiled;
}