Example #1
0
int main(int argc , char ** argv) {
  const char * config_file = argv[1];
  config_parser_type * config = config_alloc();
  {
    config_schema_item_type * item  = config_add_schema_item(config , "APPEND" , false );
    config_schema_item_set_argc_minmax( item , 1 , 1);
  }
  config_add_schema_item(config , "NEXT"   , false );

  config_content_type * content = config_parse(config , config_file , "--" , NULL , NULL , NULL , false , true );

  if (config_content_is_valid( content )) {
    if (config_content_get_size( content ) == 4) {
      const config_content_node_type * node0 = config_content_iget_node( content , 0 );
      if (strcmp( config_content_node_get_kw( node0 ) , "APPEND") == 0) {
        if (config_content_node_get_size(node0) == 1) {
          const config_content_node_type * node3 = config_content_iget_node( content , 3 );
          if (strcmp( config_content_node_get_kw( node3 ) , "NEXT") == 0) {
            if (config_content_node_get_size(node3) == 2) {
              config_content_free( content );
              exit(0);
            } else printf("Size error node3\n");
          } else printf("kw error node3 \n");
        } else printf("Size error node0\n");
      } else printf("kw error node0 kw:%s \n", config_content_node_get_kw( node0 ));
    } else printf("Size error \n");
  } else printf("Parse error");

  config_content_free( content );
  exit(1);
}
Example #2
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;
}