herr_t H5IMmake_image_24bit( hid_t loc_id, const char *dset_name, hsize_t width, hsize_t height, const char *interlace, const unsigned char *buf ) { hsize_t dims[IMAGE24_RANK]; /* check the arguments */ if (interlace == NULL) return -1; if (dset_name == NULL) return -1; /* Initialize the image dimensions */ if ( HDstrncmp( interlace, "INTERLACE_PIXEL",15 ) == 0 ) { /* Number of color planes is defined as the third dimension */ dims[0] = height; dims[1] = width; dims[2] = IMAGE24_RANK; } else if ( HDstrncmp( interlace, "INTERLACE_PLANE",15 ) == 0 ) { /* Number of color planes is defined as the first dimension */ dims[0] = IMAGE24_RANK; dims[1] = height; dims[2] = width; } else return -1; /* Make the dataset */ if ( H5LTmake_dataset( loc_id, dset_name, IMAGE24_RANK, dims, H5T_NATIVE_UCHAR, buf ) < 0) return -1; /* Attach the CLASS attribute */ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0) return -1; /* Attach the VERSION attribute */ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0) return -1; /* Attach the IMAGE_SUBCLASS attribute */ if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_TRUECOLOR" ) < 0) return -1; /* Attach the INTERLACE_MODE attribute. This attributes is only for true color images */ if ( H5LTset_attribute_string( loc_id, dset_name, "INTERLACE_MODE", interlace ) < 0) return -1; return 0; }
/*-------------------------------------------------------------------------- NAME DFPIopen -- open/reopen file for palette interface USAGE int32 DFPIopen(filename,acc_mode) char *filename; IN: name of HDF file intn acc_mode; IN: type of access to open file with RETURNS HDF file handle on success, FAIL on failure. DESCRIPTION Open/reopen a file for the DFP interface to work with. GLOBAL VARIABLES Refset, Readref, Lastfile COMMENTS, BUGS, ASSUMPTIONS This is a hook for someday providing more efficient ways to reopen a file, to avoid re-reading all the headers EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ PRIVATE int32 DFPIopen(const char *filename, intn acc_mode) { CONSTR(FUNC, "DFPIopen"); int32 file_id; int32 ret_value = SUCCEED; /* use reopen if same file as last time - more efficient */ if (HDstrncmp(Lastfile, filename, DF_MAXFNLEN) || (acc_mode == DFACC_CREATE)) { /* treat create as different file */ if ((file_id = Hopen(filename, acc_mode, 0)) == FAIL) HGOTO_ERROR(DFE_BADOPEN, FAIL); Refset = 0; /* no ref to get set for this file */ Readref = 0; } /* end if */ else if ((file_id = Hopen(filename, acc_mode, 0)) == FAIL) HGOTO_ERROR(DFE_BADOPEN, FAIL); /* remember filename, so reopen may be used next time if same file */ HDstrncpy(Lastfile, filename, DF_MAXFNLEN); ret_value = (file_id); done: if(ret_value == FAIL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end DFPIopen() */
pack_info_t* options_get_object(const char *path, pack_opttbl_t *table) { unsigned int i; char tbl_path[MAX_NC_NAME + 1]; /* +1 for start with "/" case */ for (i = 0; i < table->nelems; i++) { /* make full path (start with "/") to compare correctly */ if (HDstrncmp(table->objs[i].path, "/", 1)) { HDstrcpy(tbl_path, "/"); HDstrcat(tbl_path, table->objs[i].path); } else HDstrcpy(tbl_path, table->objs[i].path); /* found it */ if (HDstrcmp(tbl_path, path) == 0) { return (&table->objs[i]); } } return NULL; }
/*------------------------------------------------------------------------- * Function: find_palette * * Purpose: operator function used by H5LT_find_palette * * Return: * * Programmer: Pedro Vicente Nunes, [email protected] * * Date: May 28, 2001 * * Comments: * * Modifications: * *------------------------------------------------------------------------- */ static herr_t find_palette(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *op_data) { int ret = H5_ITER_CONT; /* check the arguments */ if (name == NULL) return -1; /* Shut compiler up */ loc_id = loc_id; ainfo = ainfo; op_data = op_data; /* Define a positive value for return value if the attribute was found. This will * cause the iterator to immediately return that positive value, * indicating short-circuit success */ if(HDstrncmp(name, "PALETTE",7) == 0) ret = H5_ITER_STOP; return ret; }
static int parse_command_line(int argc, const char **argv, pack_opt_t* options) { int opt; int ret_value = 0; /* parse command line options */ while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { switch ((char) opt) { /* -i for backward compability */ case 'i': infile = opt_arg; has_i_o = 1; break; /* -o for backward compability */ case 'o': outfile = opt_arg; has_i_o = 1; break; case 'h': usage(h5tools_getprogname()); h5tools_setstatus(EXIT_SUCCESS); ret_value = -1; goto done; case 'V': print_version(h5tools_getprogname()); h5tools_setstatus(EXIT_SUCCESS); ret_value = -1; goto done; case 'v': options->verbose = 1; break; case 'f': /* parse the -f filter option */ if (h5repack_addfilter(opt_arg, options) < 0) { error_msg("in parsing filter\n"); h5tools_setstatus(EXIT_FAILURE); ret_value = -1; goto done; } break; case 'l': /* parse the -l layout option */ if (h5repack_addlayout(opt_arg, options) < 0) { error_msg("in parsing layout\n"); h5tools_setstatus(EXIT_FAILURE); ret_value = -1; goto done; } break; case 'm': options->min_comp = HDatoi( opt_arg ); if ((int) options->min_comp <= 0) { error_msg("invalid minimum compress size <%s>\n", opt_arg); h5tools_setstatus(EXIT_FAILURE); ret_value = -1; goto done; } break; case 'e': ret_value = read_info(opt_arg, options); if (ret_value < 0) goto done; break; case 'n': options->use_native = 1; break; case 'L': options->latest = 1; break; case 'c': options->grp_compact = HDatoi( opt_arg ); if (options->grp_compact > 0) options->latest = 1; /* must use latest format */ break; case 'd': options->grp_indexed = HDatoi( opt_arg ); if (options->grp_indexed > 0) options->latest = 1; /* must use latest format */ break; case 's': { int idx = 0; int ssize = 0; char *msgPtr = HDstrchr( opt_arg, ':'); options->latest = 1; /* must use latest format */ if (msgPtr == NULL) { ssize = HDatoi( opt_arg ); for (idx = 0; idx < 5; idx++) options->msg_size[idx] = ssize; } else { char msgType[10]; HDstrcpy(msgType, msgPtr + 1); msgPtr[0] = '\0'; ssize = HDatoi( opt_arg ); if (HDstrncmp(msgType, "dspace",6) == 0) { options->msg_size[0] = ssize; } else if (HDstrncmp(msgType, "dtype", 5) == 0) { options->msg_size[1] = ssize; } else if (HDstrncmp(msgType, "fill", 4) == 0) { options->msg_size[2] = ssize; } else if (HDstrncmp(msgType, "pline", 5) == 0) { options->msg_size[3] = ssize; } else if (HDstrncmp(msgType, "attr", 4) == 0) { options->msg_size[4] = ssize; } } } break; case 'u': options->ublock_filename = opt_arg; break; case 'b': options->ublock_size = (hsize_t) HDatol( opt_arg ); break; case 'M': options->meta_block_size = (hsize_t) HDatol( opt_arg ); break; case 't': options->threshold = (hsize_t) HDatol( opt_arg ); break; case 'a': options->alignment = HDatol( opt_arg ); if (options->alignment < 1) { error_msg("invalid alignment size\n", opt_arg); h5tools_setstatus(EXIT_FAILURE); ret_value = -1; goto done; } break; default: break; } /* switch */ } /* while */ if (has_i_o == 0) { /* check for file names to be processed */ if (argc <= opt_ind || argv[opt_ind + 1] == NULL) { error_msg("missing file names\n"); usage(h5tools_getprogname()); h5tools_setstatus(EXIT_FAILURE); ret_value = -1; } } done: return ret_value; }
/**************************************************************** ** ** test_grp_memb_funcs(): Test group member information ** functionality ** ****************************************************************/ static void test_grp_memb_funcs(hid_t fapl) { hid_t file; /* File ID */ hid_t dataset; /* Dataset ID */ hid_t datatype; /* Common datatype ID */ hid_t filespace; /* Common dataspace ID */ hid_t root_group,grp; /* Root group ID */ int i; /* counting variable */ char name[NAMELEN]; /* temporary name buffer */ char *dnames[NDATASETS+2];/* Names of the datasets created */ char *obj_names[NDATASETS+2];/* Names of the objects in group */ char dataset_name[NAMELEN]; /* dataset name */ ssize_t name_len; /* Length of object's name */ H5G_info_t ginfo; /* Buffer for querying object's info */ herr_t ret = SUCCEED; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Group Member Information Functionality\n")); /* Create the test file with the datasets */ file = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); CHECK(file, FAIL, "H5Fcreate"); datatype = H5Tcopy(H5T_NATIVE_INT); CHECK(datatype, FAIL, "H5Tcopy"); filespace = H5Screate(H5S_SCALAR); CHECK(filespace, FAIL, "H5Screate"); for(i = 0; i < NDATASETS; i++) { sprintf(name, "Dataset %d", i); dataset = H5Dcreate2(file, name, datatype, filespace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate2"); /* Keep a copy of the dataset names around for later */ dnames[i] = HDstrdup(name); CHECK(dnames[i], NULL, "strdup"); ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); } /* end for */ /* Create a group and named datatype under root group for testing */ grp = H5Gcreate2(file, "grp", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(ret, FAIL, "H5Gcreate2"); dnames[NDATASETS] = HDstrdup("grp"); CHECK(dnames[NDATASETS], NULL, "strdup"); ret = H5Tcommit2(file, "dtype", datatype, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(ret, FAIL, "H5Tcommit2"); dnames[NDATASETS + 1] = HDstrdup("dtype"); CHECK(dnames[NDATASETS], NULL, "strdup"); /* Close everything up */ ret = H5Tclose(datatype); CHECK(ret, FAIL, "H5Tclose"); ret = H5Gclose(grp); CHECK(ret, FAIL, "H5Gclose"); ret = H5Sclose(filespace); CHECK(ret, FAIL, "H5Sclose"); ret = H5Fclose(file); CHECK(ret, FAIL, "H5Fclose"); /* Sort the dataset names */ HDqsort(dnames, (size_t)(NDATASETS + 2), sizeof(char *), iter_strcmp); /* Iterate through the datasets in the root group in various ways */ file = H5Fopen(DATAFILE, H5F_ACC_RDONLY, fapl); CHECK(file, FAIL, "H5Fopen"); /* These two functions, H5Oget_info_by_idx and H5Lget_name_by_idx, actually * iterate through B-tree for group members in internal library design. */ root_group = H5Gopen2(file, "/", H5P_DEFAULT); CHECK(root_group, FAIL, "H5Gopen2"); ret = H5Gget_info(root_group, &ginfo); CHECK(ret, FAIL, "H5Gget_info"); VERIFY(ginfo.nlinks, (NDATASETS + 2), "H5Gget_info"); for(i = 0; i < (int)ginfo.nlinks; i++) { H5O_info_t oinfo; /* Object info */ /* Test with NULL for name, to query length */ name_len = H5Lget_name_by_idx(root_group, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)i, NULL, (size_t)NAMELEN, H5P_DEFAULT); CHECK(name_len, FAIL, "H5Lget_name_by_idx"); ret = (herr_t)H5Lget_name_by_idx(root_group, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)i, dataset_name, (size_t)(name_len + 1), H5P_DEFAULT); CHECK(ret, FAIL, "H5Lget_name_by_idx"); /* Double-check that the length is the same */ VERIFY(ret, name_len, "H5Lget_name_by_idx"); /* Keep a copy of the dataset names around for later */ obj_names[i] = HDstrdup(dataset_name); CHECK(obj_names[i], NULL, "strdup"); ret = H5Oget_info_by_idx(root_group, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)i, &oinfo, H5P_DEFAULT); CHECK(ret, FAIL, "H5Oget_info_by_idx"); if(!HDstrcmp(dataset_name, "grp")) VERIFY(oinfo.type, H5O_TYPE_GROUP, "H5Lget_name_by_idx"); if(!HDstrcmp(dataset_name, "dtype")) VERIFY(oinfo.type, H5O_TYPE_NAMED_DATATYPE, "H5Lget_name_by_idx"); if(!HDstrncmp(dataset_name, "Dataset", (size_t)7)) VERIFY(oinfo.type, H5O_TYPE_DATASET, "H5Lget_name_by_idx"); } /* end for */ H5E_BEGIN_TRY { ret = (herr_t)H5Lget_name_by_idx(root_group, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)(NDATASETS+3), dataset_name, (size_t)NAMELEN, H5P_DEFAULT); } H5E_END_TRY; VERIFY(ret, FAIL, "H5Lget_name_by_idx"); /* Sort the dataset names */ HDqsort(obj_names, (size_t)(NDATASETS + 2), sizeof(char *), iter_strcmp); /* Compare object names */ for(i = 0; i< (int)ginfo.nlinks; i++) { ret = HDstrcmp(dnames[i], obj_names[i]); VERIFY(ret, 0, "HDstrcmp"); } /* end for */ ret = H5Gclose(root_group); CHECK(ret, FAIL, "H5Gclose"); ret = H5Fclose(file); CHECK(ret, FAIL, "H5Fclose"); /* Free the dataset names */ for(i = 0; i< (NDATASETS + 2); i++) { HDfree(dnames[i]); HDfree(obj_names[i]); } /* end for */ } /* test_grp_memb_funcs() */
/*------------------------------------------------------------------------- * Function: H5F_sblock_load * * Purpose: Loads the superblock from the file, and deserializes * its information into the H5F_super_t structure. * * Return: Success: SUCCEED * Failure: NULL * * Programmer: Mike McGreevy * [email protected] * April 8, 2009 * *------------------------------------------------------------------------- */ static H5F_super_t * H5F_sblock_load(H5F_t *f, hid_t dxpl_id, haddr_t UNUSED addr, void *_udata) { H5F_super_t *sblock = NULL; /* File's superblock */ haddr_t base_addr = HADDR_UNDEF; /* Base address of file */ uint8_t sbuf[H5F_MAX_SUPERBLOCK_SIZE]; /* Buffer for superblock */ H5P_genplist_t *dxpl; /* DXPL object */ H5P_genplist_t *c_plist; /* File creation property list */ H5F_file_t *shared; /* shared part of `file' */ H5FD_t *lf; /* file driver part of `shared' */ haddr_t stored_eoa; /*relative end-of-addr in file */ haddr_t eof; /*end of file address */ uint8_t sizeof_addr; /* Size of offsets in the file (in bytes) */ uint8_t sizeof_size; /* Size of lengths in the file (in bytes) */ const size_t fixed_size = H5F_SUPERBLOCK_FIXED_SIZE; /*fixed sizeof superblock */ size_t variable_size; /*variable sizeof superblock */ uint8_t *p; /* Temporary pointer into encoding buffer */ unsigned super_vers; /* Superblock version */ hbool_t *dirtied = (hbool_t *)_udata; /* Set up dirtied out value */ H5F_super_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* check arguments */ HDassert(f); HDassert(H5F_addr_eq(addr, 0)); HDassert(dirtied); /* Short cuts */ shared = f->shared; lf = shared->lf; /* Get the shared file creation property list */ if(NULL == (c_plist = (H5P_genplist_t *)H5I_object(shared->fcpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "can't get property list") /* Get the base address for the file in the VFD */ if(HADDR_UNDEF == (base_addr = H5FD_get_base_addr(lf))) HGOTO_ERROR(H5E_FILE, H5E_CANTGET, NULL, "failed to get base address for file driver") /* Allocate space for the superblock */ if(NULL == (sblock = H5FL_CALLOC(H5F_super_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Get the DXPL plist object for DXPL ID */ if(NULL == (dxpl = (H5P_genplist_t *)H5I_object(dxpl_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "can't get property list") /* Read fixed-size portion of the superblock */ p = sbuf; H5_CHECK_OVERFLOW(fixed_size, size_t, haddr_t); if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, (haddr_t)fixed_size) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, (haddr_t)0, fixed_size, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_READERROR, NULL, "unable to read superblock") /* Skip over signature (already checked when locating the superblock) */ p += H5F_SIGNATURE_LEN; /* Superblock version */ super_vers = *p++; if(super_vers > HDF5_SUPERBLOCK_VERSION_LATEST) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad superblock version number") if(H5P_set(c_plist, H5F_CRT_SUPER_VERS_NAME, &super_vers) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set superblock version") /* Record the superblock version */ sblock->super_vers = super_vers; /* Sanity check */ HDassert(((size_t)(p - sbuf)) == fixed_size); /* Determine the size of the variable-length part of the superblock */ variable_size = (size_t)H5F_SUPERBLOCK_VARLEN_SIZE(super_vers, f); HDassert(variable_size > 0); HDassert(fixed_size + variable_size <= sizeof(sbuf)); /* Read in variable-sized portion of superblock */ if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, (haddr_t)(fixed_size + variable_size)) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, (haddr_t)fixed_size, variable_size, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read superblock") /* Check for older version of superblock format */ if(super_vers < HDF5_SUPERBLOCK_VERSION_2) { uint32_t status_flags; /* File status flags */ unsigned btree_k[H5B_NUM_BTREE_ID]; /* B-tree internal node 'K' values */ unsigned sym_leaf_k; /* Symbol table leaf node's 'K' value */ /* Freespace version (hard-wired) */ if(HDF5_FREESPACE_VERSION != *p++) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad free space version number") /* Root group version number (hard-wired) */ if(HDF5_OBJECTDIR_VERSION != *p++) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad object directory version number") /* Skip over reserved byte */ p++; /* Shared header version number (hard-wired) */ if(HDF5_SHAREDHEADER_VERSION != *p++) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad shared-header format version number") /* Size of file addresses */ sizeof_addr = *p++; if(sizeof_addr != 2 && sizeof_addr != 4 && sizeof_addr != 8 && sizeof_addr != 16 && sizeof_addr != 32) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad byte number in an address") if(H5P_set(c_plist, H5F_CRT_ADDR_BYTE_NUM_NAME, &sizeof_addr) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set byte number in an address") shared->sizeof_addr = sizeof_addr; /* Keep a local copy also */ /* Size of file sizes */ sizeof_size = *p++; if(sizeof_size != 2 && sizeof_size != 4 && sizeof_size != 8 && sizeof_size != 16 && sizeof_size != 32) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad byte number for object size") if(H5P_set(c_plist, H5F_CRT_OBJ_BYTE_NUM_NAME, &sizeof_size) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set byte number for object size") shared->sizeof_size = sizeof_size; /* Keep a local copy also */ /* Skip over reserved byte */ p++; /* Various B-tree sizes */ UINT16DECODE(p, sym_leaf_k); if(sym_leaf_k == 0) HGOTO_ERROR(H5E_FILE, H5E_BADRANGE, NULL, "bad symbol table leaf node 1/2 rank") if(H5P_set(c_plist, H5F_CRT_SYM_LEAF_NAME, &sym_leaf_k) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set rank for symbol table leaf nodes") sblock->sym_leaf_k = sym_leaf_k; /* Keep a local copy also */ /* Need 'get' call to set other array values */ if(H5P_get(c_plist, H5F_CRT_BTREE_RANK_NAME, btree_k) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "unable to get rank for btree internal nodes") UINT16DECODE(p, btree_k[H5B_SNODE_ID]); if(btree_k[H5B_SNODE_ID] == 0) HGOTO_ERROR(H5E_FILE, H5E_BADRANGE, NULL, "bad 1/2 rank for btree internal nodes") /* * Delay setting the value in the property list until we've checked * for the indexed storage B-tree internal 'K' value later. */ /* File status flags (not really used yet) */ UINT32DECODE(p, status_flags); HDassert(status_flags <= 255); sblock->status_flags = (uint8_t)status_flags; if(sblock->status_flags & ~H5F_SUPER_ALL_FLAGS) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad flag value for superblock") /* * If the superblock version # is greater than 0, read in the indexed * storage B-tree internal 'K' value */ if(super_vers > HDF5_SUPERBLOCK_VERSION_DEF) { UINT16DECODE(p, btree_k[H5B_CHUNK_ID]); /* Reserved bytes are present only in version 1 */ if(super_vers == HDF5_SUPERBLOCK_VERSION_1) p += 2; /* reserved */ } /* end if */ else btree_k[H5B_CHUNK_ID] = HDF5_BTREE_CHUNK_IK_DEF; /* Set the B-tree internal node values, etc */ if(H5P_set(c_plist, H5F_CRT_BTREE_RANK_NAME, btree_k) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, NULL, "unable to set rank for btree internal nodes") HDmemcpy(sblock->btree_k, btree_k, sizeof(unsigned) * (size_t)H5B_NUM_BTREE_ID); /* Keep a local copy also */ /* Remainder of "variable-sized" portion of superblock */ H5F_addr_decode(f, (const uint8_t **)&p, &sblock->base_addr/*out*/); H5F_addr_decode(f, (const uint8_t **)&p, &sblock->ext_addr/*out*/); H5F_addr_decode(f, (const uint8_t **)&p, &stored_eoa/*out*/); H5F_addr_decode(f, (const uint8_t **)&p, &sblock->driver_addr/*out*/); /* Allocate space for the root group symbol table entry */ HDassert(!sblock->root_ent); if(NULL == (sblock->root_ent = (H5G_entry_t *)H5MM_calloc(sizeof(H5G_entry_t)))) HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "can't allocate space for root group symbol table entry") /* decode the root group symbol table entry */ if(H5G_ent_decode(f, (const uint8_t **)&p, sblock->root_ent) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTDECODE, NULL, "can't decode root group symbol table entry") /* Set the root group address to the correct value */ sblock->root_addr = sblock->root_ent->header; /* * Check if superblock address is different from base address and * adjust base address and "end of address" address if so. */ if(!H5F_addr_eq(base_addr, sblock->base_addr)) { /* Check if the superblock moved earlier in the file */ if(H5F_addr_lt(base_addr, sblock->base_addr)) stored_eoa -= (sblock->base_addr - base_addr); else /* The superblock moved later in the file */ stored_eoa += (base_addr - sblock->base_addr); /* Adjust base address for offsets of the HDF5 data in the file */ sblock->base_addr = base_addr; /* Set the base address for the file in the VFD now */ if(H5FD_set_base_addr(lf, sblock->base_addr) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "failed to set base address for file driver") /* Indicate that the superblock should be marked dirty */ *dirtied = TRUE; } /* end if */ /* This step is for h5repart tool only. If user wants to change file driver * from family to sec2 while using h5repart, set the driver address to * undefined to let the library ignore the family driver information saved * in the superblock. */ if(H5F_HAS_FEATURE(f, H5FD_FEAT_IGNORE_DRVRINFO)) { /* Eliminate the driver info */ sblock->driver_addr = HADDR_UNDEF; /* Indicate that the superblock should be marked dirty */ *dirtied = TRUE; } /* end if */ /* Decode the optional driver information block */ if(H5F_addr_defined(sblock->driver_addr)) { uint8_t dbuf[H5F_MAX_DRVINFOBLOCK_SIZE]; /* Buffer for driver info block */ char drv_name[9]; /* Name of driver */ unsigned drv_vers; /* Version of driver info block */ size_t drv_variable_size; /* Size of variable-length portion of driver info block, in bytes */ /* Read in fixed-sized portion of driver info block */ p = dbuf; if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, sblock->driver_addr + H5F_DRVINFOBLOCK_HDR_SIZE) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, sblock->driver_addr, (size_t)H5F_DRVINFOBLOCK_HDR_SIZE, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read driver information block") /* Version number */ drv_vers = *p++; if(drv_vers != HDF5_DRIVERINFO_VERSION_0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "bad driver information block version number") p += 3; /* reserved bytes */ /* Driver info size */ UINT32DECODE(p, drv_variable_size); /* Sanity check */ HDassert(H5F_DRVINFOBLOCK_HDR_SIZE + drv_variable_size <= sizeof(dbuf)); /* Driver name and/or version */ HDstrncpy(drv_name, (const char *)p, (size_t)8); drv_name[8] = '\0'; p += 8; /* advance past name/version */ /* Check if driver matches driver information saved. Unfortunately, we can't push this * function to each specific driver because we're checking if the driver is correct. */ if(!HDstrncmp(drv_name, "NCSAfami", (size_t)8) && HDstrcmp(lf->cls->name, "family")) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "family driver should be used") if(!HDstrncmp(drv_name, "NCSAmult", (size_t)8) && HDstrcmp(lf->cls->name, "multi")) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "multi driver should be used") /* Read in variable-sized portion of driver info block */ if(H5FD_set_eoa(lf, H5FD_MEM_SUPER, sblock->driver_addr + H5F_DRVINFOBLOCK_HDR_SIZE + drv_variable_size) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, NULL, "set end of space allocation request failed") if(H5FD_read(lf, dxpl, H5FD_MEM_SUPER, sblock->driver_addr + H5F_DRVINFOBLOCK_HDR_SIZE, drv_variable_size, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to read file driver information") /* Decode driver information */ if(H5FD_sb_decode(lf, drv_name, p) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to decode driver information") } /* end if */
static int read_palette(const char* fname, rgb_t *palette, size_t palette_size) { FILE *file; char buffer[80]; unsigned u; unsigned int red; unsigned int green; unsigned int blue; unsigned nentries; char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]; /* buffer to hold name of existing data file */ /*------------------------------------------------------------------------- * compose the name of the file to open, using "srcdir", if appropriate *------------------------------------------------------------------------- */ HDstrcpy(data_file, ""); if (srcdir) { HDstrcpy(data_file, srcdir); HDstrcat(data_file, "/"); } HDstrcat(data_file,fname); /* ensure the given palette is valid */ if (!palette) return -1; /* open the input file */ if (!(file = HDfopen(data_file, "r"))) { printf( "Could not open file %s. Try set $srcdir \n", data_file ); return -1; } /* read the file ident string */ if (HDfgets(buffer, sizeof(buffer), file) == NULL) { HDfclose(file); return -1; } /* ensure it matches the palette file ident string */ if ( HDstrncmp(buffer, STRING_JASC, sizeof(STRING_JASC) - 1) != 0 && HDstrncmp(buffer, STRING_CWPAL, sizeof(STRING_CWPAL) - 1) != 0 ) { HDfclose(file); return -1; } /* read the version string */ if (HDfgets(buffer, sizeof(buffer), file) == NULL) { HDfclose(file); return -1; } /* ensure it matches the palette file version string */ if ( HDstrncmp(buffer, VERSION_JASC, sizeof(VERSION_JASC) - 1) != 0 && HDstrncmp(buffer, VERSION_CWPAL, sizeof(VERSION_CWPAL) - 1) != 0 ) { HDfclose(file); return -1; } /* read the number of colors */ if (HDfgets(buffer, sizeof(buffer), file) == NULL) { HDfclose(file); return -1; } /* extract the number of colors. check for missing version or number of colors in this case it reads the first entry */ if ( HDstrlen( buffer ) > 4 ) { HDfclose(file); return -1; } if (sscanf(buffer, "%u", &nentries) != 1) { HDfclose(file); return -1; } /* ensure there are a sensible number of colors in the palette */ if ((nentries > 256) || (nentries > palette_size)) { HDfclose(file); return(-1); } /* read the palette entries */ for (u = 0; u < nentries; u++) { /* extract the red, green and blue color components. */ if (fscanf(file, "%u %u %u", &red, &green, &blue) != 3) { HDfclose(file); return -1; } /* store this palette entry */ palette[u].r = (unsigned char)red; palette[u].g = (unsigned char)green; palette[u].b = (unsigned char)blue; } /* close file */ HDfclose(file); return (int)nentries; }
static intn test_dim1_SDS1(void) { char sds_name[20]; float32 sds1_data[] = {0.1, 2.3, 4.5, 6.7, 8.9}; float32 out_data[5]; int32 dimsize[1]; int32 sds_id, file_id, dim_id, index; int32 start=0, stride=1; int32 scale1 [5] = {101,102,103,104,105}, scale1_out[5]; int32 num_type, array_rank, count; int32 n_datasets, n_file_attrs, n_local_attrs, n_vars = 0; intn datanum, ranknum, status =0, i, idx, idx1, idx2; hdf_varlist_t* var_list; intn is_coord = FALSE; char attr_name[H4_MAX_NC_NAME], attr_values[80]; intn num_errs = 0; /* number of errors so far */ file_id = SDstart(FILE1, DFACC_CREATE); CHECK(file_id, FAIL, "SDstart"); /* Create a one-dim dataset named VAR1_NAME, of type DFNT_FLOAT32. */ dimsize[0] = 5; sds_id = SDcreate(file_id, VAR1_NAME, DFNT_FLOAT32, 1, dimsize); CHECK(sds_id, FAIL, "SDcreate"); /* Set the dimension name to be the same as its dataset. */ dim_id = SDgetdimid(sds_id, 0); CHECK(dim_id, FAIL, "SDgetdimid"); status = SDsetdimname(dim_id, VAR1_NAME); /* status = SDsetdimname(dim_id, VAR1_NAME); */ CHECK(status, FAIL, "SDsetdimname"); /* Get file info and verify that there is 1 dataset in the file. */ status = SDfileinfo(file_id, &n_datasets, &n_file_attrs); CHECK(status, FAIL, "SDfileinfo"); VERIFY(n_datasets, 1, "SDfileinfo"); /* Set an attribute to dimension VAR1_NAME. */ status = SDsetattr(dim_id, ATTR1_NAME, DFNT_CHAR8, ATTR1_LEN, ATTR1_VAL); CHECK(status, FAIL, "SDsetattr"); /* Set an attribute to dataset VAR1_NAME. */ status = SDsetattr(sds_id, ATTR2_NAME, DFNT_CHAR8, ATTR2_LEN, ATTR2_VAL); CHECK(status, FAIL, "SDsetattr"); /* Get file info and verify that there are 2 datasets in the file: 1 SDS and 1 coordinate variable (because of SDsetattr dim) */ status = SDfileinfo(file_id, &n_datasets, &n_file_attrs); CHECK(status, FAIL, "SDfileinfo"); VERIFY(n_datasets, 2, "SDfileinfo"); /* Write data to the SDS */ status = SDwritedata(sds_id, &start, &stride, dimsize, (VOIDP)sds1_data); CHECK(status, FAIL, "SDwritedata"); /* Close dataset and file. */ status = SDendaccess(sds_id); CHECK(status, FAIL, "SDendaccess"); status = SDend(file_id); CHECK(status, FAIL, "SDend"); /* Open the file again to check its data */ file_id = SDstart(FILE1, DFACC_RDWR); CHECK(file_id, FAIL, "SDstart"); /* Check variable type and attributes of each element in the file */ /* Get the number of variables of name VAR1_NAME */ status = SDgetnumvars_byname(file_id, VAR1_NAME, &n_vars); if (n_vars == 1) { /* Get index of dataset VAR1_NAME */ index = SDnametoindex(file_id, VAR1_NAME); CHECK(index, FAIL, "SDnametoindex"); } else { /* Get the list of all variables of named VAR1_NAME */ var_list = (hdf_varlist_t *)HDmalloc(n_vars * sizeof(hdf_varlist_t)); status = SDnametoindices(file_id, VAR1_NAME, var_list); /* In this case, the first variable is a dataset */ for (idx = 0; idx < n_vars; idx++) { if (var_list[idx].var_type == IS_SDSVAR) { index = var_list[idx].var_index; VERIFY(index, 0, "SDnametoindices"); } } } sds_id = SDselect(file_id, index); CHECK(sds_id, FAIL, "SDselect"); /* Verify that this variable is a dataset. */ is_coord = SDiscoordvar(sds_id); VERIFY(is_coord, FALSE, "SDiscoordvar"); /* Read and verify the information of the SDS' first attribute. */ status = SDattrinfo(sds_id, 0, attr_name, &num_type, &count); CHECK(status, FAIL, "SDattrinfo"); VERIFY(count, ATTR2_LEN, "SDattrinfo"); VERIFY(HDstrncmp(attr_name, ATTR2_NAME, 14), 0, "SDattrinfo"); /* Read and verify the values of the SDS' first attribute. */ status = SDreadattr(sds_id, 0, attr_values); CHECK(status, FAIL, "SDreadattr"); if (HDstrncmp(attr_values, ATTR2_VAL, ATTR2_LEN) != 0) { fprintf(stderr, "Unmatched attribute values for SDS %s: is <%s>, should be <%s>\n", VAR1_NAME, attr_values, ATTR2_VAL); num_errs++; } /* Get access to the SDS' first dimension. */ dim_id = SDgetdimid(sds_id, 0); CHECK(dim_id, FAIL, "SDgetdimid"); /* Read and verify the information of the dimension's first attribute. */ status = SDattrinfo(dim_id, 0, attr_name, &num_type, &count); CHECK(status, FAIL, "SDattrinfo"); VERIFY(count, 19, "SDattrinfo"); VERIFY(HDstrncmp(attr_name, ATTR1_NAME, 21), 0, "SDattrinfo"); /* Read and verify the values of the dimension's first attribute. */ status = SDreadattr(dim_id, 0, attr_values); CHECK(status, FAIL, "SDreadattr"); if (HDstrncmp(attr_values, ATTR1_VAL, ATTR1_LEN) != 0) { fprintf(stderr, "Unmatched attribute values for dimension %s: is <%s>, should be <%s>\n", VAR1_NAME, attr_values, ATTR1_VAL); num_errs++; } /* Verify again that the number of datasets in the file is 2, 1 SDS and 1 coordinate variable */ status = SDfileinfo(file_id, &n_datasets, &n_file_attrs); CHECK(status, FAIL, "SDfileinfo"); VERIFY(n_datasets, 2, "SDfileinfo"); VERIFY(n_file_attrs, 0, "SDfileinfo"); /* Read and verify the dataset's data */ status = SDreaddata (sds_id, &start, NULL, dimsize, &out_data); CHECK(status, FAIL, "SDreaddata"); for (idx1 = 0; idx1 < dimsize[0]; idx1++) if (out_data[idx1] != sds1_data[idx1]) { fprintf(stderr, "Read value (%f) differs from written (%f) at [%d]\n", out_data[idx1], sds1_data[idx1], idx1); num_errs++; } /* Close dataset and file. */ status = SDendaccess(sds_id); CHECK(status, FAIL, "SDendaccess"); status = SDend(file_id); CHECK(status, FAIL, "SDend"); /* Return the number of errors that's been kept track of so far */ return num_errs; } /* test_dim1_SDS1 */
herr_t H5IMget_image_info( hid_t loc_id, const char *dset_name, hsize_t *width, hsize_t *height, hsize_t *planes, char *interlace, hssize_t *npals ) { hid_t did; hid_t sid; hsize_t dims[IMAGE24_RANK]; hid_t aid; hid_t asid; hid_t atid; H5T_class_t aclass; int has_pal; int has_attr; /* check the arguments */ if (dset_name == NULL) return -1; if (interlace == NULL) return -1; /*assume initially we have no palettes attached*/ *npals = 0; /* Open the dataset. */ if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; /* Try to find the attribute "INTERLACE_MODE" on the >>image<< dataset */ has_attr = H5LT_find_attribute(did, "INTERLACE_MODE"); /* It exists, get it */ if(has_attr == 1) { if((aid = H5Aopen(did, "INTERLACE_MODE", H5P_DEFAULT)) < 0) goto out; if((atid = H5Aget_type(aid)) < 0) goto out; if(H5Aread(aid, atid, interlace) < 0) goto out; if(H5Tclose(atid) < 0) goto out; if(H5Aclose(aid) < 0) goto out; } /* Get the dataspace handle */ if ( (sid = H5Dget_space( did )) < 0) goto out; /* Get dimensions */ if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0) goto out; /* Initialize the image dimensions */ if ( has_attr == 1 ) /* This is a 24 bit image */ { if ( HDstrncmp( interlace, "INTERLACE_PIXEL", 15 ) == 0 ) { /* Number of color planes is defined as the third dimension */ *height = dims[0]; *width = dims[1]; *planes = dims[2]; } else if ( HDstrncmp( interlace, "INTERLACE_PLANE", 15 ) == 0 ) { /* Number of color planes is defined as the first dimension */ *planes = dims[0]; *height = dims[1]; *width = dims[2]; } else return -1; } else /* This is a 8 bit image */ { *height = dims[0]; *width = dims[1]; *planes = 1; } /* Close */ if ( H5Sclose( sid ) < 0) goto out; /* Get number of palettes */ /* Try to find the attribute "PALETTE" on the >>image<< dataset */ has_pal = H5IM_find_palette(did); if(has_pal == 1) { if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0) goto out; if((atid = H5Aget_type(aid)) < 0) goto out; if((aclass = H5Tget_class(atid)) < 0) goto out; /* Check if it is really a reference */ if(aclass == H5T_REFERENCE) { /* Get the reference(s) */ if ( (asid = H5Aget_space( aid )) < 0) goto out; *npals = H5Sget_simple_extent_npoints( asid ); if ( H5Sclose( asid ) < 0) goto out; } /* H5T_REFERENCE */ if ( H5Tclose( atid ) < 0) goto out; /* Close the attribute. */ if ( H5Aclose( aid ) < 0) goto out; } /* End access to the dataset and release resources used by it. */ if ( H5Dclose( did ) < 0) goto out; return 0; out: H5Dclose( did ); H5Aclose( aid ); H5Sclose( asid ); H5Tclose( atid ); return -1; }
herr_t H5IMis_palette( hid_t loc_id, const char *dset_name ) { hid_t did; int has_class; hid_t atid; hid_t aid = -1; char* attr_data; /* Name of attribute */ hsize_t storage_size; /* Size of storage for attribute */ herr_t ret; /* check the arguments */ if (dset_name == NULL) return -1; /* Assume initially fail condition */ ret = -1; /* Open the dataset. */ if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; /* Try to find the attribute "CLASS" on the dataset */ has_class = H5LT_find_attribute(did, "CLASS"); if(has_class == 0) { H5Dclose( did ); return 0; } else if(has_class == 1) { if((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0) goto out; if((atid = H5Aget_type(aid)) < 0) goto out; /* check to make sure attribute is a string */ if(H5T_STRING != H5Tget_class(atid)) goto out; /* check to make sure string is null-terminated */ if(H5T_STR_NULLTERM != H5Tget_strpad(atid)) goto out; /* allocate buffer large enough to hold string */ if((storage_size = H5Aget_storage_size(aid)) == 0) goto out; attr_data = (char*)HDmalloc( (size_t)storage_size * sizeof(char) + 1); if(attr_data == NULL) goto out; if(H5Aread(aid, atid, attr_data) < 0) goto out; if(HDstrncmp(attr_data, PALETTE_CLASS, MIN(HDstrlen(PALETTE_CLASS),HDstrlen(attr_data))) == 0) ret = 1; else ret = 0; HDfree(attr_data); if ( H5Tclose( atid ) < 0) goto out; if ( H5Aclose( aid ) < 0) goto out; } /* Close the dataset. */ if ( H5Dclose( did ) < 0) return -1; return ret; out: H5Dclose( did ); return -1; }
int_f h5ltget_attribute_c(hid_t_f *loc_id, size_t_f *namelen, _fcd dsetname, size_t_f *attrnamelen, _fcd attrname, void *buf, char *dtype, size_t_f *sizeof_val) { int ret_value = -1; herr_t ret; hid_t c_loc_id; char *c_name = NULL; char *c_attrname = NULL; /* * convert FORTRAN name to C name */ c_name = (char *)HD5f2cstring(dsetname, (size_t)*namelen); if (c_name == NULL) goto done; c_attrname = (char *)HD5f2cstring(attrname, (size_t)*attrnamelen); if (c_attrname == NULL) goto done; /* * call H5LTget_attribute_int function. */ c_loc_id = (hid_t)*loc_id; if( HDstrncmp(dtype,"I",1) == 0) { if((size_t)*sizeof_val == sizeof(int)) ret = H5LTget_attribute(c_loc_id,c_name,c_attrname,H5T_NATIVE_INT,buf); else if ((size_t)*sizeof_val == sizeof(long)) ret = H5LTget_attribute(c_loc_id,c_name,c_attrname,H5T_NATIVE_LONG,buf); else if ((size_t)*sizeof_val == sizeof(long long)) ret = H5LTget_attribute(c_loc_id,c_name,c_attrname,H5T_NATIVE_LLONG,buf); else goto done; } else if ( HDstrncmp(dtype,"R",1) == 0 ) { if((size_t)*sizeof_val == sizeof(float)) ret = H5LTget_attribute(c_loc_id,c_name,c_attrname,H5T_NATIVE_FLOAT,buf); else if((size_t)*sizeof_val == sizeof(double)) ret = H5LTget_attribute(c_loc_id,c_name,c_attrname,H5T_NATIVE_DOUBLE,buf); #if H5_SIZEOF_LONG_DOUBLE !=0 else if((size_t)*sizeof_val == sizeof(long double)) ret = H5LTget_attribute(c_loc_id,c_name,c_attrname,H5T_NATIVE_LDOUBLE,buf); #endif else goto done; } if (ret < 0) goto done; ret_value = 0; done: if(c_name!=NULL) HDfree(c_name); if(c_attrname!=NULL) HDfree(c_attrname); return ret_value; }
/*------------------------------------------------------------------------- * Function: get_option * * Purpose: Determine the command-line options a user specified. We can * accept both short and long type command-lines. * * Return: Success: The short valued "name" of the command line * parameter or EOF if there are no more * parameters to process. * * Failure: A question mark. * * Programmer: Bill Wendling * Friday, 5. January 2001 * * Modifications: Pedro Vicente * October, 27 2008 * Wilcard "*" argument type * *------------------------------------------------------------------------- */ int get_option(int argc, const char **argv, const char *opts, const struct long_options *l_opts) { static int sp = 1; /* character index in current token */ int opt_opt = '?'; /* option character passed back to user */ if (sp == 1) { /* check for more flag-like tokens */ if (opt_ind >= argc || argv[opt_ind][0] != '-' || argv[opt_ind][1] == '\0') { return EOF; } else if (HDstrcmp(argv[opt_ind], "--") == 0) { opt_ind++; return EOF; } } if (sp == 1 && argv[opt_ind][0] == '-' && argv[opt_ind][1] == '-') { /* long command line option */ const char *arg = &argv[opt_ind][2]; int i; for (i = 0; l_opts && l_opts[i].name; i++) { size_t len = HDstrlen(l_opts[i].name); if (HDstrncmp(arg, l_opts[i].name, len) == 0) { /* we've found a matching long command line flag */ opt_opt = l_opts[i].shortval; if (l_opts[i].has_arg != no_arg) { if (arg[len] == '=') { opt_arg = &arg[len + 1]; } else if (l_opts[i].has_arg != optional_arg) { if (opt_ind < (argc - 1)) if (argv[opt_ind + 1][0] != '-') opt_arg = argv[++opt_ind]; } else if (l_opts[i].has_arg == require_arg) { if (opt_err) HDfprintf(rawerrorstream, "%s: option required for \"--%s\" flag\n", argv[0], arg); opt_opt = '?'; } } else { if (arg[len] == '=') { if (opt_err) HDfprintf(rawerrorstream, "%s: no option required for \"%s\" flag\n", argv[0], arg); opt_opt = '?'; } opt_arg = NULL; } break; } } if (l_opts[i].name == NULL) { /* exhausted all of the l_opts we have and still didn't match */ if (opt_err) HDfprintf(rawerrorstream, "%s: unknown option \"%s\"\n", argv[0], arg); opt_opt = '?'; } opt_ind++; sp = 1; } else { register char *cp; /* pointer into current token */ /* short command line option */ opt_opt = argv[opt_ind][sp]; if (opt_opt == ':' || (cp = HDstrchr(opts, opt_opt)) == 0) { if (opt_err) HDfprintf(rawerrorstream, "%s: unknown option \"%c\"\n", argv[0], opt_opt); /* if no chars left in this token, move to next token */ if (argv[opt_ind][++sp] == '\0') { opt_ind++; sp = 1; } return '?'; } if (*++cp == ':') { /* if a value is expected, get it */ if (argv[opt_ind][sp + 1] != '\0') { /* flag value is rest of current token */ opt_arg = &argv[opt_ind++][sp + 1]; } else if (++opt_ind >= argc) { if (opt_err) HDfprintf(rawerrorstream, "%s: value expected for option \"%c\"\n", argv[0], opt_opt); opt_opt = '?'; } else { /* flag value is next token */ opt_arg = argv[opt_ind++]; } sp = 1; } /* wildcard argument */ else if (*cp == '*') { /* check the next argument */ opt_ind++; /* we do have an extra argument, check if not last */ if ( argv[opt_ind][0] != '-' && (opt_ind+1) < argc ) { opt_arg = argv[opt_ind++]; } else { opt_arg = NULL; } } else { /* set up to look at next char in token, next time */ if (argv[opt_ind][++sp] == '\0') { /* no more in current token, so setup next token */ opt_ind++; sp = 1; } opt_arg = NULL; } } /* return the current flag character found */ return opt_opt; }