2003-04-03 02:44:12 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
|
|
* the files COPYING and Copyright.html. COPYING can be found at the root *
|
|
|
|
* of the source code distribution tree; Copyright.html can be found at the *
|
|
|
|
* root level of an installed copy of the electronic HDF5 document set and *
|
|
|
|
* is linked from the top-level documents page. It can also be found at *
|
|
|
|
* http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
|
|
|
|
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
#include "h5trav.h"
|
2005-08-14 04:53:35 +08:00
|
|
|
#include "H5private.h"
|
2003-04-09 04:27:27 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
/* functions for traversal */
|
2006-01-24 04:46:34 +08:00
|
|
|
static int traverse( hid_t loc_id,
|
2005-08-14 04:53:35 +08:00
|
|
|
const char *group_name,
|
|
|
|
trav_table_t *table,
|
|
|
|
trav_info_t *info,
|
2004-06-28 22:29:20 +08:00
|
|
|
int *idx,
|
|
|
|
int print);
|
2003-10-29 01:40:05 +08:00
|
|
|
|
2006-01-24 04:46:34 +08:00
|
|
|
static hssize_t get_nnames( hid_t loc_id,
|
2004-10-07 00:11:18 +08:00
|
|
|
const char *group_name );
|
2003-10-29 01:40:05 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
herr_t get_name_type( hid_t loc_id,
|
|
|
|
const char *group_name,
|
|
|
|
int idx,
|
|
|
|
char **name,
|
2003-12-04 23:31:05 +08:00
|
|
|
H5G_obj_t *type );
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-10-29 01:40:05 +08:00
|
|
|
* Function: h5trav_getinfo
|
2003-01-24 06:08:51 +08:00
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Purpose: get an array of "trav_info_t" , containing the name and type of
|
2003-10-29 01:40:05 +08:00
|
|
|
* objects in the file
|
2003-01-24 06:08:51 +08:00
|
|
|
*
|
2003-12-19 00:18:09 +08:00
|
|
|
* Return: number of object names in file
|
2003-01-24 06:08:51 +08:00
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: November 6, 2002
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
int h5trav_getinfo(hid_t file_id,
|
|
|
|
trav_info_t *info,
|
2004-06-28 22:29:20 +08:00
|
|
|
int print )
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
|
|
|
|
2003-10-29 01:40:05 +08:00
|
|
|
trav_table_t *table=NULL;
|
2003-12-19 00:18:09 +08:00
|
|
|
int nnames=0;
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
/* init table */
|
2003-10-29 01:40:05 +08:00
|
|
|
trav_table_init( &table );
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
/* iterate starting on the root group */
|
2004-06-28 22:29:20 +08:00
|
|
|
if (( nnames = traverse( file_id, "/", table, info, &nnames, print )) < 0 )
|
2003-01-24 06:08:51 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* free table */
|
2003-10-29 01:40:05 +08:00
|
|
|
trav_table_free( table );
|
2003-01-24 06:08:51 +08:00
|
|
|
|
2003-12-19 00:18:09 +08:00
|
|
|
return nnames;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: h5trav_gettable
|
|
|
|
*
|
|
|
|
* Purpose: get the trav_table_t struct
|
|
|
|
*
|
|
|
|
* Return: 0, -1 on error
|
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: December 17, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
int h5trav_gettable(hid_t fid, trav_table_t *travt)
|
|
|
|
{
|
|
|
|
int nnames=0;
|
|
|
|
|
|
|
|
/* iterate starting on the root group */
|
2004-06-28 22:29:20 +08:00
|
|
|
if (( nnames = traverse(fid,"/",travt,NULL,&nnames,0))<0)
|
2003-12-19 00:18:09 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-10-23 05:30:19 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-10-29 01:40:05 +08:00
|
|
|
* Function: h5trav_getindex
|
2003-10-23 05:30:19 +08:00
|
|
|
*
|
|
|
|
* Purpose: get index of OBJ in list
|
|
|
|
*
|
|
|
|
* Return: index, -1 if not found
|
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: May 9, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2003-10-29 01:40:05 +08:00
|
|
|
int h5trav_getindex( const char *obj, int nobjs, trav_info_t *info )
|
2003-10-23 05:30:19 +08:00
|
|
|
{
|
|
|
|
char *pdest;
|
|
|
|
int result;
|
|
|
|
int i;
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
for ( i = 0; i < nobjs; i++)
|
2003-10-23 05:30:19 +08:00
|
|
|
{
|
|
|
|
if ( strcmp(obj,info[i].name)==0 )
|
|
|
|
return i;
|
|
|
|
|
|
|
|
pdest = strstr( info[i].name, obj );
|
|
|
|
result = (int)(pdest - info[i].name);
|
|
|
|
|
|
|
|
/* found at position 1, meaning without '/' */
|
|
|
|
if( pdest != NULL && result==1 )
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-10-29 01:40:05 +08:00
|
|
|
* Function: h5trav_freeinfo
|
2003-10-23 05:30:19 +08:00
|
|
|
*
|
|
|
|
* Purpose: free info memory
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2003-10-29 01:40:05 +08:00
|
|
|
void h5trav_freeinfo( trav_info_t *info, int nobjs )
|
2003-10-23 05:30:19 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if ( info )
|
|
|
|
{
|
|
|
|
for ( i = 0; i < nobjs; i++)
|
|
|
|
{
|
|
|
|
if (info[i].name)
|
|
|
|
HDfree( info[i].name );
|
|
|
|
}
|
|
|
|
HDfree(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-19 00:18:09 +08:00
|
|
|
* Function: get_nnames
|
2003-01-24 06:08:51 +08:00
|
|
|
*
|
2003-12-19 00:18:09 +08:00
|
|
|
* Purpose: Counts the number of names in the group GROUP_NAME
|
2003-01-24 06:08:51 +08:00
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: October 10, 2002
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Return:
|
2003-01-24 06:08:51 +08:00
|
|
|
* Success: The return value of the first operator that
|
|
|
|
* returns non-zero, or zero if all members were
|
|
|
|
* processed with no operator returning non-zero.
|
|
|
|
*
|
|
|
|
* Failure: Negative if something goes wrong within the
|
|
|
|
* library, or the negative value returned by one
|
|
|
|
* of the operators.
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2006-01-24 04:46:34 +08:00
|
|
|
static hssize_t get_nnames( hid_t loc_id, const char *group_name )
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
2006-01-24 04:46:34 +08:00
|
|
|
hid_t gid;
|
|
|
|
hsize_t nobjs = 0;
|
2003-01-24 06:08:51 +08:00
|
|
|
|
2006-01-24 04:46:34 +08:00
|
|
|
/* Open the group */
|
|
|
|
if((gid = H5Gopen(loc_id, group_name)) < 0)
|
|
|
|
return(-1);
|
2003-01-24 06:08:51 +08:00
|
|
|
|
2006-01-24 04:46:34 +08:00
|
|
|
/* Retrieve the number of objects in it */
|
|
|
|
if(H5Gget_num_objs(gid, &nobjs) < 0)
|
|
|
|
return(-1);
|
2003-01-24 06:08:51 +08:00
|
|
|
|
2006-01-24 04:46:34 +08:00
|
|
|
/* Close the group */
|
|
|
|
if(H5Gclose(gid) < 0)
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
return((hssize_t)nobjs);
|
2003-01-24 06:08:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: opget_info
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Purpose: operator function
|
2003-01-24 06:08:51 +08:00
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: October 10, 2002
|
|
|
|
*
|
|
|
|
* Comments:
|
|
|
|
*
|
|
|
|
* Modifications:
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
static herr_t opget_info( hid_t loc_id, const char *name, void *op_data)
|
|
|
|
{
|
|
|
|
|
|
|
|
H5G_stat_t statbuf;
|
|
|
|
|
2006-01-24 04:46:34 +08:00
|
|
|
if (H5Gget_objinfo( loc_id, name, FALSE, &statbuf) < 0 )
|
2003-08-22 21:45:40 +08:00
|
|
|
return -1;
|
2003-01-24 06:08:51 +08:00
|
|
|
|
2003-10-29 01:40:05 +08:00
|
|
|
((trav_info_t *)op_data)->type = statbuf.type;
|
|
|
|
((trav_info_t *)op_data)->name = (char *)HDstrdup(name);
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
/* Define 1 for return. This will cause the iterator to stop */
|
|
|
|
return 1;
|
2005-08-14 04:53:35 +08:00
|
|
|
}
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: get_name_type
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Purpose:
|
2003-01-24 06:08:51 +08:00
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: October 10, 2002
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Return:
|
2003-01-24 06:08:51 +08:00
|
|
|
* Success: The return value of the first operator that
|
|
|
|
* returns non-zero, or zero if all members were
|
|
|
|
* processed with no operator returning non-zero.
|
|
|
|
*
|
|
|
|
* Failure: Negative if something goes wrong within the
|
|
|
|
* library, or the negative value returned by one
|
|
|
|
* of the operators.
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
herr_t get_name_type( hid_t loc_id,
|
|
|
|
const char *group_name,
|
|
|
|
int idx,
|
|
|
|
char **name,
|
|
|
|
H5G_obj_t *type )
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
|
|
|
|
2003-10-29 01:40:05 +08:00
|
|
|
trav_info_t info;
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
if (H5Giterate( loc_id, group_name, &idx, opget_info, (void *)&info) < 0 )
|
|
|
|
return -1;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
*name = info.name;
|
|
|
|
*type = info.type;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: traverse
|
|
|
|
*
|
2003-10-29 01:40:05 +08:00
|
|
|
* Purpose: recursive function that searches HDF5 objects in LOC_ID
|
2003-01-24 06:08:51 +08:00
|
|
|
*
|
2003-10-29 01:40:05 +08:00
|
|
|
* Return: number of objects found in LOC_ID
|
2003-01-24 06:08:51 +08:00
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: November 4, 2002
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2006-01-24 04:46:34 +08:00
|
|
|
static int traverse( hid_t loc_id,
|
2005-08-14 04:53:35 +08:00
|
|
|
const char *group_name,
|
|
|
|
trav_table_t *table,
|
|
|
|
trav_info_t *info,
|
2004-06-28 22:29:20 +08:00
|
|
|
int *idx,
|
2005-08-14 04:53:35 +08:00
|
|
|
int print)
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
2006-04-15 06:21:54 +08:00
|
|
|
haddr_t objno; /* Compact form of object's location */
|
2003-01-24 06:08:51 +08:00
|
|
|
char *name=NULL;
|
2003-12-03 23:35:32 +08:00
|
|
|
H5G_obj_t type;
|
2003-12-19 00:18:09 +08:00
|
|
|
int n_names;
|
2003-01-24 06:08:51 +08:00
|
|
|
char *path=NULL;
|
|
|
|
H5G_stat_t statbuf;
|
|
|
|
int inserted_objs=0;
|
2003-12-19 00:18:09 +08:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
/* get the number of names */
|
2006-01-24 04:46:34 +08:00
|
|
|
if (( n_names = (int)get_nnames( loc_id, group_name )) < 0 )
|
2003-01-24 06:08:51 +08:00
|
|
|
return -1;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
for ( i = 0; i < n_names; i++)
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
|
|
|
if (get_name_type( loc_id, group_name, i, &name, &type ) < 0 )
|
|
|
|
return -1;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
/* allocate path buffer */
|
2006-01-24 04:46:34 +08:00
|
|
|
path = (char*) HDmalloc(HDstrlen(group_name) + HDstrlen(name) + 2);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
/* initialize path */
|
2006-01-24 04:46:34 +08:00
|
|
|
HDstrcpy( path, group_name );
|
|
|
|
if ( HDstrcmp(group_name, "/") != 0 )
|
|
|
|
HDstrcat( path, "/" );
|
|
|
|
HDstrcat( path, name );
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
/* disable error reporting */
|
2003-08-09 03:30:19 +08:00
|
|
|
H5E_BEGIN_TRY {
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
/* get info */
|
2004-06-28 22:29:20 +08:00
|
|
|
H5Gget_objinfo( loc_id, path, FALSE, &statbuf);
|
2003-08-09 03:30:19 +08:00
|
|
|
} H5E_END_TRY;
|
2006-04-15 06:21:54 +08:00
|
|
|
objno = (haddr_t)statbuf.objno[0] | ((haddr_t)statbuf.objno[1] << (8 * sizeof(long)));
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
/* add to array */
|
|
|
|
if ( info )
|
|
|
|
{
|
2003-04-09 04:27:27 +08:00
|
|
|
info[*idx].name = (char *)HDstrdup(path);
|
2003-01-24 06:08:51 +08:00
|
|
|
info[*idx].type = type;
|
|
|
|
(*idx)++;
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
switch ( type )
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5G_GROUP
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
case H5G_GROUP:
|
|
|
|
|
|
|
|
/* increment */
|
|
|
|
inserted_objs++;
|
|
|
|
|
|
|
|
/* nlink is number of hard links to object */
|
2006-04-15 06:21:54 +08:00
|
|
|
if (statbuf.nlink > 0 && trav_table_search(objno, table ) == -1)
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
|
|
|
/* add object to table */
|
2006-04-15 06:21:54 +08:00
|
|
|
trav_table_add(objno, path, H5G_GROUP, table );
|
2004-06-28 22:29:20 +08:00
|
|
|
|
|
|
|
/* print it */
|
|
|
|
if (print)
|
|
|
|
printf(" %-10s %s\n", "group", path );
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
/* recurse with the absolute name */
|
2004-06-28 22:29:20 +08:00
|
|
|
inserted_objs += traverse( loc_id, path, table, info, idx, print );
|
2003-01-24 06:08:51 +08:00
|
|
|
}
|
|
|
|
|
2004-06-28 22:29:20 +08:00
|
|
|
/* search table
|
2003-01-24 06:08:51 +08:00
|
|
|
group with more than one link to it */
|
2006-04-15 06:21:54 +08:00
|
|
|
if (statbuf.nlink > 1)
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
2006-04-15 06:21:54 +08:00
|
|
|
if ((j = trav_table_search(objno, table )) < 0 )
|
2003-01-24 06:08:51 +08:00
|
|
|
return -1;
|
|
|
|
|
2004-06-28 22:29:20 +08:00
|
|
|
trav_table_addlink(table,j,path);
|
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
if ( table->objs[j].displayed == 0 )
|
|
|
|
{
|
|
|
|
table->objs[j].displayed = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-28 22:29:20 +08:00
|
|
|
/* print it */
|
|
|
|
if (print)
|
2004-07-03 04:28:49 +08:00
|
|
|
printf(" %-10s %s %s %s\n", "group", path, "->", table->objs[j].name );
|
2003-01-24 06:08:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5G_DATASET
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
case H5G_DATASET:
|
|
|
|
|
|
|
|
/* increment */
|
|
|
|
inserted_objs++;
|
|
|
|
|
|
|
|
/* nlink is number of hard links to object */
|
2006-04-15 06:21:54 +08:00
|
|
|
if (statbuf.nlink > 0 && trav_table_search(objno, table ) == -1)
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
|
|
|
/* add object to table */
|
2006-04-15 06:21:54 +08:00
|
|
|
trav_table_add(objno, path, H5G_DATASET, table );
|
2004-06-28 22:29:20 +08:00
|
|
|
|
|
|
|
/* print it */
|
|
|
|
if (print)
|
|
|
|
printf(" %-10s %s\n", "dataset", path );
|
2003-01-24 06:08:51 +08:00
|
|
|
}
|
|
|
|
|
2004-06-28 22:29:20 +08:00
|
|
|
/* search table
|
2003-01-24 06:08:51 +08:00
|
|
|
dataset with more than one link to it */
|
2006-04-15 06:21:54 +08:00
|
|
|
if (statbuf.nlink > 1)
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
2006-04-15 06:21:54 +08:00
|
|
|
if ((j = trav_table_search(objno, table )) < 0 )
|
2003-01-24 06:08:51 +08:00
|
|
|
return -1;
|
|
|
|
|
2004-06-28 22:29:20 +08:00
|
|
|
trav_table_addlink(table,j,path);
|
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
if ( table->objs[j].displayed == 0 )
|
|
|
|
{
|
|
|
|
table->objs[j].displayed = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-28 22:29:20 +08:00
|
|
|
/* print it */
|
|
|
|
if (print)
|
2004-07-03 04:28:49 +08:00
|
|
|
printf(" %-10s %s %s %s\n", "dataset", path, "->", table->objs[j].name );
|
2003-12-19 00:18:09 +08:00
|
|
|
} /* displayed==1 */
|
|
|
|
} /* nlink>1 */
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5G_TYPE
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
case H5G_TYPE:
|
|
|
|
|
|
|
|
/* increment */
|
|
|
|
inserted_objs++;
|
|
|
|
|
|
|
|
/* nlink is number of hard links to object */
|
2006-04-15 06:21:54 +08:00
|
|
|
if (statbuf.nlink > 0 && trav_table_search(objno, table ) == -1)
|
2003-01-24 06:08:51 +08:00
|
|
|
{
|
|
|
|
/* add object to table */
|
2006-04-15 06:21:54 +08:00
|
|
|
trav_table_add(objno, path, H5G_TYPE, table );
|
2004-06-28 22:29:20 +08:00
|
|
|
|
|
|
|
/* print it */
|
|
|
|
if (print)
|
|
|
|
printf(" %-10s %s\n", "datatype", path );
|
2003-01-24 06:08:51 +08:00
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5G_LINK
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
case H5G_LINK:
|
2006-08-03 07:41:53 +08:00
|
|
|
{
|
2004-06-28 22:29:20 +08:00
|
|
|
/* increment */
|
|
|
|
inserted_objs++;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2004-06-28 22:29:20 +08:00
|
|
|
/* add object to table */
|
2006-01-24 04:46:34 +08:00
|
|
|
trav_table_add(HADDR_UNDEF, path, H5G_LINK, table );
|
2003-01-24 06:08:51 +08:00
|
|
|
|
2006-04-15 06:21:54 +08:00
|
|
|
if (statbuf.linklen>0)
|
2004-06-28 22:29:20 +08:00
|
|
|
{
|
2006-01-24 04:46:34 +08:00
|
|
|
char *targbuf;
|
|
|
|
|
2006-04-15 06:21:54 +08:00
|
|
|
targbuf = HDmalloc(statbuf.linklen);
|
2006-01-24 04:46:34 +08:00
|
|
|
assert(targbuf);
|
2006-04-15 06:21:54 +08:00
|
|
|
H5Gget_linkval(loc_id,path,statbuf.linklen,targbuf);
|
2005-08-14 04:53:35 +08:00
|
|
|
if (print)
|
2004-06-28 22:29:20 +08:00
|
|
|
printf(" %-10s %s -> %s\n", "link", path, targbuf);
|
2006-01-24 04:46:34 +08:00
|
|
|
free(targbuf);
|
2004-06-28 22:29:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (print)
|
|
|
|
printf(" %-10s %s ->\n", "link", path);
|
|
|
|
}
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
break;
|
|
|
|
|
2006-08-03 07:41:53 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5G_UDLINK
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
case H5G_UDLINK:
|
|
|
|
{
|
2006-10-31 08:45:31 +08:00
|
|
|
H5L_info_t linkbuf;
|
2006-08-03 07:41:53 +08:00
|
|
|
|
|
|
|
/* increment */
|
|
|
|
inserted_objs++;
|
|
|
|
|
|
|
|
/* add object to table */
|
|
|
|
trav_table_add(HADDR_UNDEF, path, H5G_UDLINK, table );
|
|
|
|
|
|
|
|
/* Get type of link */
|
|
|
|
H5E_BEGIN_TRY {
|
2006-10-31 08:45:31 +08:00
|
|
|
/* get link class info */
|
|
|
|
H5Lget_info( loc_id, path, &linkbuf, H5P_DEFAULT);
|
2006-08-03 07:41:53 +08:00
|
|
|
} H5E_END_TRY;
|
|
|
|
|
2006-10-02 18:24:03 +08:00
|
|
|
if(linkbuf.type == H5L_TYPE_EXTERNAL)
|
2006-08-03 07:41:53 +08:00
|
|
|
{
|
|
|
|
if (statbuf.linklen>0)
|
|
|
|
{
|
|
|
|
char *targbuf;
|
|
|
|
char *objname;
|
|
|
|
|
|
|
|
targbuf = HDmalloc(statbuf.linklen);
|
|
|
|
assert(targbuf);
|
|
|
|
H5Gget_linkval(loc_id,path,statbuf.linklen,targbuf);
|
2006-10-31 04:24:19 +08:00
|
|
|
H5Lunpack_elink_val(targbuf, statbuf.linklen, NULL, &objname);
|
2006-08-03 07:41:53 +08:00
|
|
|
if (print)
|
|
|
|
printf(" %-10s %s -> %s %s\n", "ext link", path, targbuf, objname);
|
|
|
|
free(targbuf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (print)
|
|
|
|
printf(" %-10s %s ->\n", "udlink", path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* Unknown user-defined type */
|
|
|
|
{
|
|
|
|
if (print)
|
|
|
|
printf(" %-10s %s ->\n", "UD link type", path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
default:
|
2006-08-17 22:18:03 +08:00
|
|
|
HDfprintf(stderr, "traverse: Unknown object %d!\n", type);
|
2006-01-24 04:46:34 +08:00
|
|
|
return (-1);
|
2003-01-24 06:08:51 +08:00
|
|
|
break;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
}
|
2003-01-24 06:08:51 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* end switch
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
if ( name )
|
2003-10-23 05:30:19 +08:00
|
|
|
HDfree( name );
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
if ( path )
|
2003-10-23 05:30:19 +08:00
|
|
|
HDfree( path );
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
} /* i */
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-01-24 06:08:51 +08:00
|
|
|
return inserted_objs;
|
|
|
|
}
|
|
|
|
|
2003-12-17 22:07:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-19 00:18:09 +08:00
|
|
|
* Function: h5trav_printinfo
|
2003-12-17 22:07:41 +08:00
|
|
|
*
|
2003-12-19 00:18:09 +08:00
|
|
|
* Purpose: print list of names in file
|
2003-12-17 22:07:41 +08:00
|
|
|
*
|
|
|
|
* Return: void
|
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: May 9, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void h5trav_printinfo(int nobjs, trav_info_t *travi)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for ( i = 0; i < nobjs; i++)
|
|
|
|
{
|
|
|
|
switch ( travi[i].type )
|
|
|
|
{
|
|
|
|
case H5G_GROUP:
|
|
|
|
printf(" %-10s %s\n", "group", travi[i].name );
|
|
|
|
break;
|
|
|
|
case H5G_DATASET:
|
|
|
|
printf(" %-10s %s\n", "dataset", travi[i].name );
|
|
|
|
break;
|
|
|
|
case H5G_TYPE:
|
|
|
|
printf(" %-10s %s\n", "datatype", travi[i].name );
|
|
|
|
break;
|
|
|
|
case H5G_LINK:
|
|
|
|
printf(" %-10s %s\n", "link", travi[i].name );
|
|
|
|
break;
|
2006-08-03 07:41:53 +08:00
|
|
|
case H5G_UDLINK:
|
|
|
|
printf(" %-10s %s\n", "User defined link", travi[i].name );
|
|
|
|
break;
|
2003-12-17 22:07:41 +08:00
|
|
|
default:
|
|
|
|
printf(" %-10s %s\n", "User defined object", travi[i].name );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-19 00:18:09 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: h5trav_printtable
|
|
|
|
*
|
|
|
|
* Purpose: print list of objects in file
|
|
|
|
*
|
|
|
|
* Return: void
|
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: May 9, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void h5trav_printtable(trav_table_t *table)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for ( i = 0; i < table->nobjs; i++)
|
|
|
|
{
|
|
|
|
switch ( table->objs[i].type )
|
|
|
|
{
|
|
|
|
case H5G_GROUP:
|
|
|
|
printf(" %-10s %s\n", "group", table->objs[i].name );
|
|
|
|
break;
|
|
|
|
case H5G_DATASET:
|
|
|
|
printf(" %-10s %s\n", "dataset", table->objs[i].name );
|
|
|
|
break;
|
|
|
|
case H5G_TYPE:
|
|
|
|
printf(" %-10s %s\n", "datatype", table->objs[i].name );
|
|
|
|
break;
|
|
|
|
case H5G_LINK:
|
|
|
|
printf(" %-10s %s\n", "link", table->objs[i].name );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf(" %-10s %s\n", "User defined object", table->objs[i].name );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (table->objs[i].nlinks)
|
|
|
|
{
|
|
|
|
for ( j=0; j<table->objs[i].nlinks; j++)
|
|
|
|
{
|
2003-12-19 04:25:11 +08:00
|
|
|
printf(" %-10s %s\n", " hardlink", table->objs[i].links[j].new_name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: h5trav_getindext
|
|
|
|
*
|
|
|
|
* Purpose: get index of NAME in list
|
|
|
|
*
|
|
|
|
* Return: index, -1 if not found
|
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: December 18, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
int h5trav_getindext(const char *name, trav_table_t *table)
|
|
|
|
{
|
|
|
|
char *pdest;
|
|
|
|
int result;
|
|
|
|
int i, j;
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
for ( i = 0; i < table->nobjs; i++)
|
2003-12-19 04:25:11 +08:00
|
|
|
{
|
|
|
|
if ( strcmp(name,table->objs[i].name)==0 )
|
|
|
|
return i;
|
|
|
|
|
|
|
|
pdest = strstr( table->objs[i].name, name );
|
|
|
|
result = (int)(pdest - table->objs[i].name);
|
|
|
|
|
|
|
|
/* found at position 1, meaning without '/' */
|
2004-01-27 07:20:20 +08:00
|
|
|
if( pdest != NULL && result==1 && strlen(table->objs[i].name)-1==strlen(name))
|
2003-12-19 04:25:11 +08:00
|
|
|
return i;
|
|
|
|
|
|
|
|
/* search also in the list of links */
|
|
|
|
if (table->objs[i].nlinks)
|
|
|
|
{
|
|
|
|
for ( j=0; j<table->objs[i].nlinks; j++)
|
|
|
|
{
|
|
|
|
if ( strcmp(name,table->objs[i].links[j].new_name)==0 )
|
|
|
|
return i;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-12-19 04:25:11 +08:00
|
|
|
pdest = strstr( table->objs[i].links[j].new_name, name );
|
|
|
|
result = (int)(pdest - table->objs[i].links[j].new_name);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-12-19 04:25:11 +08:00
|
|
|
/* found at position 1, meaning without '/' */
|
|
|
|
if( pdest != NULL && result==1 )
|
|
|
|
return i;
|
|
|
|
|
2003-12-19 00:18:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2003-12-19 04:25:11 +08:00
|
|
|
return -1;
|
2003-12-19 00:18:09 +08:00
|
|
|
}
|
|
|
|
|