Exemple #1
0
int main(int argc , char ** argv) {
  char * cwd = util_alloc_cwd();

  {
    config_root_path_type * root_path = config_root_path_alloc( NULL );
    
    if (!test_check_string_equal( config_root_path_get_abs_path( root_path ) , cwd ))
      test_error_exit("abs:path:%s   expeceted:%s \n",config_root_path_get_abs_path( root_path ) , cwd );

    if (!test_check_string_equal( config_root_path_get_input_path( root_path ) , NULL ))
      test_error_exit("input:path:%s   expeceted:%s \n",config_root_path_get_input_path( root_path ) , NULL );
    
    if (!test_check_string_equal( config_root_path_get_rel_path( root_path ) , NULL ))
      test_error_exit("rel:path:%s   expeceted:%s \n",config_root_path_get_rel_path( root_path ) , NULL );

    
    config_root_path_free( root_path );
  }


  {
    config_root_path_type * root_path = config_root_path_alloc( "/does/not/exist" );
    if (root_path != NULL)
      test_error_exit("Created root_path instance for not-existing input \n");
  }
  

  
  {
    const char * input_path = argv[1];
    char * cwd      = util_alloc_cwd();
    char * rel_path = util_alloc_rel_path( cwd , input_path );

    config_root_path_type * root_path1 = config_root_path_alloc( input_path );
    config_root_path_type * root_path2 = config_root_path_alloc( rel_path );

    if (!test_check_string_equal( config_root_path_get_rel_path( root_path1 ) , config_root_path_get_rel_path( root_path2 )))
      test_error_exit("Rel: %s != %s \n",config_root_path_get_rel_path( root_path1 ) , config_root_path_get_rel_path( root_path2));
    
    if (!test_check_string_equal( config_root_path_get_abs_path( root_path1 ) , config_root_path_get_abs_path( root_path2 )))
      test_error_exit("Abs: %s != %s \n",config_root_path_get_abs_path( root_path1 ) , config_root_path_get_abs_path( root_path2 ));
    
    config_root_path_free( root_path1 );
    config_root_path_free( root_path2 );
  }


  exit(0);
}
Exemple #2
0
config_path_elm_type * config_content_add_path_elm( config_content_type * content , const char * path ) {
  const config_path_elm_type * current_path_elm;

  if (vector_get_size( content->path_elm_stack ) == 0)
    current_path_elm = NULL;
  else
    current_path_elm = vector_get_last_const(content->path_elm_stack);

  {
    config_path_elm_type * new_path_elm;

    {
      char * rel_path = NULL;
      config_root_path_type * invoke_path = config_content_get_invoke_path( content );
      if (path != NULL) {
        if (current_path_elm == NULL)
          rel_path = util_alloc_rel_path( config_root_path_get_abs_path(invoke_path) , path);
        else
          rel_path = config_path_elm_alloc_relpath( current_path_elm , path );
      }
      new_path_elm = config_path_elm_alloc( invoke_path , rel_path );
      util_safe_free( rel_path );
    }
    vector_append_owned_ref( content->path_elm_storage , new_path_elm , config_path_elm_free__);
    vector_append_ref( content->path_elm_stack , new_path_elm );
    return new_path_elm;
  }
}