1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF. The full HDF copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hrepack_lsttable.h"
/*-------------------------------------------------------------------------
* Function: list_table_search
*
* Purpose: linear search the table for tag and ref
*
* Return: index on success, -1 on failure
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: July 3, 2003
*
*-------------------------------------------------------------------------
*/
int
list_table_search(list_table_t *list_tbl, int tag, int ref)
{
int i;
for (i = 0; i < list_tbl->nobjs; i++) {
if (list_tbl->objs[i].tag == tag && list_tbl->objs[i].ref == ref)
return i;
}
return -1;
}
/*-------------------------------------------------------------------------
* Function: list_table_add
*
* Purpose: add pair tag/ref and object path to table
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: July 3, 2003
*
*-------------------------------------------------------------------------
*/
void
list_table_add(list_table_t *list_tbl, int tag, int ref, char *path)
{
int path_len;
int i;
if (list_tbl->nobjs == list_tbl->size) {
list_tbl->size *= 2;
list_tbl->objs = (obj_info_t *)realloc(list_tbl->objs, list_tbl->size * sizeof(obj_info_t));
for (i = list_tbl->nobjs; i < list_tbl->size; i++) {
list_tbl->objs[i].tag = -1;
list_tbl->objs[i].ref = -1;
list_tbl->objs[i].path = NULL;
}
}
i = list_tbl->nobjs++;
list_tbl->objs[i].tag = tag;
list_tbl->objs[i].ref = ref;
/* copy the path over */
path_len = strlen(path);
list_tbl->objs[i].path = (char *)malloc(path_len + 1);
HIstrncpy(list_tbl->objs[i].path, path, path_len + 1);
}
/*-------------------------------------------------------------------------
* Function: list_table_init
*
* Purpose: initialize table
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: July 3, 2003
*
*-------------------------------------------------------------------------
*/
void
list_table_init(list_table_t **tbl)
{
int i;
list_table_t *list_tbl = (list_table_t *)malloc(sizeof(list_table_t));
list_tbl->size = 20;
list_tbl->nobjs = 0;
list_tbl->objs = (obj_info_t *)malloc(list_tbl->size * sizeof(obj_info_t));
for (i = 0; i < list_tbl->size; i++) {
list_tbl->objs[i].tag = -1;
list_tbl->objs[i].ref = -1;
}
*tbl = list_tbl;
}
/*-------------------------------------------------------------------------
* Function: list_table_free
*
* Purpose: free table memory
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: July 3, 2003
*
*-------------------------------------------------------------------------
*/
void
list_table_free(list_table_t *list_tbl)
{
int i;
for (i = 0; i < list_tbl->nobjs; i++) {
assert(list_tbl->objs[i].path);
free(list_tbl->objs[i].path);
}
free(list_tbl->objs);
free(list_tbl);
}
/*-------------------------------------------------------------------------
* Function: list_table_check
*
* Purpose: search the table for valid objects
*
* Return: error string or NULL for success
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: July 3, 2003
*
*-------------------------------------------------------------------------
*/
const char *
list_table_check(list_table_t *list_tbl, char *obj_name)
{
int i;
int32 tag;
for (i = 0; i < list_tbl->nobjs; i++) {
if (strcmp(list_tbl->objs[i].path, obj_name) == 0) {
/* found the name; check if it is an SDS or Image */
tag = list_tbl->objs[i].tag;
if (tag == DFTAG_SD || tag == DFTAG_SDG || tag == DFTAG_NDG || tag == DFTAG_RI ||
tag == DFTAG_CI || tag == DFTAG_RIG || tag == DFTAG_RI8 || tag == DFTAG_CI8 ||
tag == DFTAG_II8)
return NULL;
else
return "not compressible/chunk object";
}
}
return "not found";
}
/*-------------------------------------------------------------------------
* Function: list_table_print
*
* Purpose: print object list
*
* Return: void
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: August 25, 2003
*
*-------------------------------------------------------------------------
*/
void
list_table_print(list_table_t *list_tbl)
{
int i;
printf("---------------------------------------\n");
printf("%5s %6s %-15s\n", "Tag", "Ref", "Name");
printf("---------------------------------------\n");
for (i = 0; i < list_tbl->nobjs; i++) {
printf("%5d %6d %-15s\n", list_tbl->objs[i].tag, list_tbl->objs[i].ref, list_tbl->objs[i].path);
}
}
|