Example #1
0
/*
   *  this routine checks that the given OPENED file is compatible with
   *    version 2.0 or later of the HDF Vset library .
   *  RETURNS 1  if file already compatible with r2.
   *          0  if not compatible.
   *          -1 if error.
 */
int32
vicheckcompat(HFILEID f)
{
    int16       foundold, foundnew;
    int32       aid;

    foundold = 0;
    foundnew = 0;
    /* locate any OLD vgs */
    aid = Hstartread(f, (uint16) OLD_VGDESCTAG, DFREF_WILDCARD);
    if (aid != FAIL)
      {
        foundold++;
        Hendaccess(aid);
      }

    /* locate any OLD vdatas */
    aid = Hstartread(f, (uint16) OLD_VSDESCTAG, DFREF_WILDCARD);
    if (aid != FAIL)
      {
        foundold++;
        Hendaccess(aid);
      }

    /* locate any NEW vgs */
    aid = Hstartread(f, NEW_VGDESCTAG, DFREF_WILDCARD);
    if (aid != FAIL)
      {
        foundnew++;
        Hendaccess(aid);
      }

    /* locate any NEW vdatas */
    aid = Hstartread(f, NEW_VSDESCTAG, DFREF_WILDCARD);
    if (aid != FAIL)
      {
        foundnew++;
        Hendaccess(aid);
      }

    HEclear();	/* clear the stack to remove faux failures - bug #655 */
    if (foundold == 0)  /* has no old vset elements */
        return (1);     /* just assume compatible */

    if (foundnew > 0)
        return (1);     /* file is already compatible */
    else
        return (0);     /* file is not compatible */
}   /* vicheckcompat */
Example #2
0
/*
   ** NAME
   **   DFdescriptors -- return a list of the data descriptors in the file
   ** USAGE
   **   int DFdescriptors(dfile, ptr, begin, num)
   **   DF *dfile;              IN: pointer to an open DF file
   **   DFdesc ptr[];           IN: pointer to space for the list of DDs
   **   int begin;              IN: starting DD number
   **   int num;                IN: number of entries
   ** RETURNS
   **   number of DDs returned in the list
   ** DESCRIPTION
   **   Fills in a list of all DDs in the file beginning with DD begin and
   **   including a maximum of num entries.  The number of DDs actually entered
   **   into the list is returned.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   ** EXAMPLES
   ** REVISION LOG
 */
int
DFdescriptors(DF * dfile, DFdesc ptr[], int begin, int num)
{
    int         i, ret;
    int32       aid;

    if (DFIcheck(dfile) != 0)
      {
          DFerror = DFE_NOTOPEN;
          return (-1);
      }
    else
        DFerror = DFE_NONE;

    aid = Hstartread(DFid, DFTAG_WILDCARD, DFREF_WILDCARD);

    if (aid == FAIL)
      {
          DFerror = (int)HEvalue(1);
          return (-1);
      }

    for (i = 2; i <= begin; i++)
      {
          ret = Hnextread(aid, DFTAG_WILDCARD, DFREF_WILDCARD, DF_CURRENT);
          if (ret == FAIL)
            {
                Hendaccess(aid);
                DFerror = (int)HEvalue(1);
                return (-1);
            }
      }

    Hinquire(aid, NULL, &ptr[0].tag, &ptr[0].ref, &ptr[0].length,
             &ptr[0].offset, NULL, NULL, NULL);

    for (i = 1; i < num; i++)
      {
          ret = Hnextread(aid, DFTAG_WILDCARD, DFREF_WILDCARD, DF_CURRENT);
          if (ret == FAIL)
            {
              Hendaccess(aid);
              return (i);
            }
          Hinquire(aid, NULL, &ptr[i].tag, &ptr[i].ref, &ptr[i].length,
                   &ptr[i].offset, NULL, NULL, NULL);
      }
    Hendaccess(aid);

    return (i);
}
Example #3
0
File: dfp.c Project: schwehr/hdf4
/*--------------------------------------------------------------------------
 NAME
    DFPreadref -- set ref # of palette to read next
 USAGE
    intn DFPreadref(filename,ref)
        char *filename;         IN: name of HDF file
        uint16 ref;             IN: ref # of palette to read next
 RETURNS
    SUCCEED on success, FAIL on failure.
 DESCRIPTION
    Sets the ref # of the next palette to read from a file
 GLOBAL VARIABLES
    Refset
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
intn
DFPreadref(const char *filename, uint16 ref)
{
  CONSTR(FUNC, "DFPreadref");
  int32       file_id;
  int32       aid;
  intn        ret_value = SUCCEED;

  HEclear();

  if ((file_id = DFPIopen(filename, DFACC_READ)) == FAIL)
    HGOTO_ERROR(DFE_BADOPEN, FAIL);

  aid = Hstartread(file_id, DFTAG_IP8, ref);
  if (aid == FAIL)
    {
      aid = Hstartread(file_id, DFTAG_LUT, ref);
      if (aid == FAIL)
        {
          ret_value = (HDerr(file_id));
          goto done;
        }
    }     /* end if */

  Hendaccess(aid);
  Refset = ref;

  ret_value = (Hclose(file_id));

done:
  if(ret_value == FAIL)   
    { /* Error condition cleanup */

    } /* end if */

  /* Normal function cleanup */
  return ret_value;
}   /* end DFPreadref() */
Example #4
0
int
DFgetcomp(int32 file_id, uint16 tag, uint16 ref, uint8 *image, int32 xdim,
          int32 ydim, uint16 scheme)
{
    CONSTR(FUNC, "DFgetcomp");
    uint8      *buffer;
    uint8      *in;
    uint8      *out;
    int32       cisize, crowsize, buflen, bufleft;  /* bufleft: bytes left in buffer */

    int32       i;
    int32       totalread;
    int32       n;
    int32       aid;

    if (!HDvalidfid(file_id) || !tag || !ref || xdim <= 0 || ydim <= 0 || !image)
        HRETURN_ERROR(DFE_ARGS, FAIL);

    /* put this call up here instead of in switch statement, to make the */
    /* code easier to follow */
    if (scheme == DFTAG_JPEG5 || scheme == DFTAG_GREYJPEG5
            || scheme==DFTAG_JPEG || scheme==DFTAG_GREYJPEG)
        return (DFCIunjpeg(file_id, tag, ref, (VOIDP) image, xdim, ydim, (int16)scheme));

    /* Only do this stuff for non-JPEG compressed images */
    aid = Hstartread(file_id, tag, ref);
    if (aid == FAIL)
        HRETURN_ERROR(DFE_NOMATCH, FAIL);
    if (Hinquire(aid, (int32 *) NULL, (uint16 *) NULL, (uint16 *) NULL, &cisize,
    (int32 *) NULL, (int32 *) NULL, (int16 *) NULL, (int16 *) NULL) == FAIL)
        return FAIL;

    switch (scheme)
      {
          case DFTAG_RLE:
              crowsize = xdim * 121 / 120 + 128;    /* max size of a row */

              buffer = (uint8 *) HDmalloc((uint32) cisize);
              if (!buffer)
                {
                    buffer = (uint8 *) HDmalloc((uint32) crowsize);
                    if (!buffer)
                      {
                          Hendaccess(aid);
                          HRETURN_ERROR(DFE_NOSPACE, FAIL)
                      }     /* end if */
                    buflen = crowsize;
                }   /* end if */
Example #5
0
/*
   ** NAME
   **   DFfind -- perform wildcard searches
   ** USAGE
   **   int DFfind(dfile, ptr)
   **   DF *dfile;              IN: pointer to an open DF file
   **   DFdesc *ptr;            IN: pointer to put in DD when found
   ** RETURNS
   **   0 on success, -1 on failure
   ** DESCRIPTION
   **   If desired tag/ref is found, its DD is copied to *ptr.
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   ** EXAMPLES
   ** REVISION LOG
 */
int
DFfind(DF * dfile, DFdesc * ptr)
{
    int         ret;

    if (DFIcheck(dfile) != 0)
      {
          DFerror = DFE_NOTOPEN;
          return (-1);
      }
    else
        DFerror = DFE_NONE;

    if (search_stat == DFSRCH_NEW)
      {
          search_aid = Hstartread(DFid, search_tag, search_ref);
          search_stat = DFSRCH_OLD;
          ret = 0;
      }
    else
      {
          ret = Hnextread(search_aid, search_tag, search_ref, DF_CURRENT);
      }

    if ((search_aid == FAIL) || (ret == FAIL))
      {
          DFerror = DFE_NOMATCH;
          ptr->tag = 0;
          ptr->ref = 0;
          return (-1);
      }

    Hinquire(search_aid, NULL, &ptr->tag, &ptr->ref, &ptr->length, &ptr->offset,
             NULL, NULL, NULL);

    return (0);
}
Example #6
0
/*
   ** NAME
   **   DFread -- read a portion of a data element
   ** USAGE
   **   int32 DFread(dfile, ptr, len)
   **   DF *dfile;              IN: pointer to open DF file
   **   char *ptr;              IN: pointer to space to read data into
   **   int32 len;              IN: number of bytes to read
   ** RETURNS
   **   number of bytes read on success, -1 on failure
   ** DESCRIPTION
   **   Read bytes from a DF file (part of element specified by DFaccess)
   ** GLOBAL VARIABLES
   ** COMMENTS, BUGS, ASSUMPTIONS
   **   Space for data is assumed to be pre-allocated.
   ** EXAMPLES
   ** REVISION LOG
 */
int32
DFread(DF * dfile, char *ptr, int32 len)
{
    int32       ret;

    if (DFIcheck(dfile) != 0)
      {
          DFerror = DFE_NOTOPEN;
          return (-1);
      }
    else
        DFerror = DFE_NONE;

    DFaid = Hstartread(DFid, acc_tag, acc_ref);
    ret = Hseek(DFaid, DFelseekpos, 0);
    if (ret == FAIL)
      {
          Hendaccess(DFaid);
          DFerror = (int)HEvalue(1);
          return (-1);
      }

    ret = Hread(DFaid, len, (unsigned char *) ptr);
    Hendaccess(DFaid);

    if (ret == FAIL)
      {
          DFerror = (int)HEvalue(1);
          return (-1);
      }
    else
      {
          DFelseekpos += ret;
          return (ret);
      }
}
Example #7
0
int
main(int argc, char *argv[])
{
    int32       infile, aid, ret;
    char       *filename;
    char        datafilename[DF_MAXFNLEN];

    uint16      tag;
    uint16      ref;
    int32       offset, fileoffset;
    int32       length;
    int16       special;

    /* Get invocation name of program */
    progname = *argv++;
    argc--;

    /* parse arguments */
    while (argc > 0 && **argv == '-')
      {
          switch ((*argv)[1])
            {
                case 'd':
                    argc--;
                    argv++;
                    if (argc > 0)
                      {
                          strcpy(datafilename, *argv++);
                          argc--;
                      }
                    else
                      {
                          usage();
                          exit(1);
                      }
                    break;
                default:
                    usage();
                    exit(1);
            }
      }

    if (argc == 1)
      {
          filename = *argv++;
          argc--;
      }
    else
      {
          usage();
          exit(1);
      }

    if (datafilename[0] == '\0')
        strcpy(datafilename, DefaultDatafile);

    /* Check to make sure input file is HDF */
    ret = (int) Hishdf(filename);
    if (ret == FALSE)
      {
          error("given file is not an HDF file\n");
      }

    /* check if datafile already exists.  If so, set offset to its length. */
    {
        struct stat buf;
        if (stat(datafilename, &buf) == 0)
          {
              printf("External file %s already exists.  Using append mode.\n", datafilename);
              fileoffset = (int32)buf.st_size;
          }
        else
            fileoffset = 0;
    }

    /* Open HDF file */
    infile = Hopen(filename, DFACC_RDWR, 0);
    if (infile == FAIL)
      {
          error("Can't open the HDF file\n");
      }

    /* Process the file */
    ret = aid = Hstartread(infile, DFTAG_SD, DFREF_WILDCARD);
    while (ret != FAIL)
      {
          /*
           * Get data about the current one
           */
          ret = Hinquire(aid, NULL, &tag, &ref, &length, &offset, NULL, NULL, &special);

          /* check the tag value since external element object are returned the same. */
          if (tag == DFTAG_SD)
            {
                printf("moving Scientific Data (%d,%d) to %s\n", tag, ref, datafilename);
                ret = HXcreate(infile, tag, ref, datafilename, fileoffset, length);
                fileoffset += length;
            }

          /*
           * Move to the next one
           */
          ret = Hnextread(aid, DFTAG_SD, DFREF_WILDCARD, DF_CURRENT);
      }

    /*
     * Close the access element
     */
    ret = Hendaccess(aid);
    if (ret == FAIL)
        hdferror();

    /* done; close files */
    Hclose(infile);
    return (0);
}
Example #8
0
/*--------------------------------------------------------------------------
 NAME
    HCIcszip_decode -- Decode SZIP compressed data into a buffer.

 USAGE
    int32 HCIcszip_decode(info,length,buf)
    compinfo_t *info;   IN: the info about the compressed element
    int32 length;       IN: number of bytes to read into the buffer
    uint8 *buf;         OUT: buffer to store the bytes read

 RETURNS
    Returns SUCCEED or FAIL

 DESCRIPTION
    Common code called to decode SZIP data from the file.

 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
PRIVATE int32
HCIcszip_decode(compinfo_t * info, int32 length, uint8 *buf)
{
    CONSTR(FUNC, "HCIcszip_decode");
#ifdef H4_HAVE_LIBSZ
    accrec_t *access_rec;
    comp_coder_szip_info_t *szip_info;    /* ptr to SZIP info */
    uint8 *in_buffer;
    uint8 *out_buffer;
    int32 in_length;
    int32 out_length;
    int bytes_per_pixel;
    int32 rbytes;
    uint16 tag,ref;
    int32 len1;
    int32 aid;
    int32 status;
    size_t size_out;
    uint8 *cp;
    int32 good_bytes;
    int32 old_way;
    SZ_com_t sz_param;
#endif

#ifdef H4_HAVE_LIBSZ

    szip_info = &(info->cinfo.coder_info.szip_info);
    if (szip_info->szip_state == SZIP_INIT) {
	/*  Load from disk, decode the data */

	if ((access_rec = HAatom_object(info->aid)) == NULL)    /* get the access_rec pointer */
	    HRETURN_ERROR(DFE_ARGS, FAIL);

	/* Discover how much data must be read */
	if(HTPinquire(access_rec->ddid,&tag,&ref,NULL,&in_length)==FAIL)
		HRETURN_ERROR(DFE_INTERNAL, FAIL);

        if (in_length == -1)
		HRETURN_ERROR(DFE_INTERNAL, FAIL);

        if (tag & 0x4000) {
	    /* this is linked list -- get the length of the data */
            aid = Hstartread(access_rec->file_id, tag, ref);
            if (HDinqblockinfo(aid, &len1, NULL, NULL, NULL) == FAIL) {
	       Hendaccess(aid);
	       HRETURN_ERROR(DFE_INTERNAL, FAIL);
            }
            in_length = len1; 
	    Hendaccess(aid);
        }

	old_way = (int)(szip_info->options_mask & SZ_H4_REV_2);
	if (old_way == 0) {
		/* special case: read data encoded in V4.2r0 */
		old_way = 1;
		good_bytes = in_length;
                in_length = in_length+5;
	        if ((in_buffer = (uint8 *) HDmalloc(in_length)) == NULL)
    	           HRETURN_ERROR(DFE_NOSPACE, FAIL);
		cp = in_buffer;
		*cp = 0;
		cp++;
		INT32ENCODE(cp, good_bytes);
	} else {
		/*  V4.2r1: in_length is correct */
		old_way = 0;
	        if ((in_buffer = (uint8 *) HDmalloc(in_length)) == NULL)
    	           HRETURN_ERROR(DFE_NOSPACE, FAIL);
	}

        /* Allocate memory for the uncompressed data */
	bytes_per_pixel = (szip_info->bits_per_pixel + 7) >> 3;
	if (bytes_per_pixel == 3)
		bytes_per_pixel++;

        out_length = szip_info->pixels * bytes_per_pixel;
	if ((out_buffer = (uint8 *) HDmalloc(out_length)) == NULL)
		HRETURN_ERROR(DFE_NOSPACE, FAIL);

	/* Read the unompressed data */
	if (old_way == 1) {
		/* this is encoded in V4.2r0 */
		/* the preamble isn't in the file, so read only the data */
		if ((rbytes = Hread(info->aid, in_length-5, in_buffer+5)) == FAIL)
		{
			HDfree(out_buffer);
			HDfree(in_buffer);
			HRETURN_ERROR(DFE_READERROR, FAIL);
		}
		if (rbytes == 0 || rbytes != (in_length - 5)) {
			/* is this possible? */
			HDfree(out_buffer);
			HDfree(in_buffer);
			HRETURN_ERROR(DFE_READERROR, FAIL);
		}
	} else {
		/* HDF4.2R1: read the data plus preamble */
		if ((rbytes = Hread(info->aid, in_length, in_buffer)) == FAIL)
		{
			HDfree(out_buffer);
			HDfree(in_buffer);
			HRETURN_ERROR(DFE_READERROR, FAIL);
		}
		if (rbytes == 0 || rbytes != in_length) {
			/* is this possible? */
			HDfree(out_buffer);
			HDfree(in_buffer);
			HRETURN_ERROR(DFE_READERROR, FAIL);
		}
	}
        cp = in_buffer;
        cp++;
        INT32DECODE(cp, good_bytes);
	if (in_buffer[0] == 1) {
           /* This byte means the data was not compressed -- just copy out */
	    szip_info->szip_state = SZIP_RUN;
	    HDmemcpy(out_buffer, in_buffer+5, good_bytes);
	    szip_info->buffer = out_buffer;
	    szip_info->buffer_pos = 0;
	    szip_info->buffer_size = good_bytes;
	    szip_info->offset = 0;
	    if (good_bytes > length) {
		/* partial read */
		HDmemcpy(buf, in_buffer+5, length);
	        szip_info->buffer_pos += length;
	        szip_info->buffer_size -= length;
	    } else {
		/* read the whole data block to the user buffer */
		HDmemcpy(buf, in_buffer+5, good_bytes);
	        szip_info->buffer_pos += good_bytes;
	        szip_info->buffer_size -= good_bytes;
	    }
	    szip_info->offset = szip_info->buffer_pos;
	    HDfree(in_buffer);
	    if (szip_info->buffer_size == 0) {
		if (szip_info->buffer != NULL) {
		   HDfree(szip_info->buffer);
		   szip_info->buffer = NULL;
		}
	    }
	    return (SUCCEED);
        }

	/* Decompress the data */
     
        /* set up the parameters */
	sz_param.options_mask = (szip_info->options_mask & ~SZ_H4_REV_2);
	sz_param.bits_per_pixel = szip_info->bits_per_pixel;
	sz_param.pixels_per_block = szip_info->pixels_per_block;
	sz_param.pixels_per_scanline = szip_info->pixels_per_scanline;
	size_out = out_length;
	if(SZ_OK!= (status = SZ_BufftoBuffDecompress(out_buffer, &size_out, (in_buffer+5), good_bytes, &sz_param)))
         {
		HDfree(out_buffer);
		HDfree(in_buffer);
		HRETURN_ERROR(DFE_CDECODE, FAIL);
        }

	if ((int32)size_out != out_length) {
	   /* This should never happen?? */
	   printf("status: %d ??bytes != out_length %d != %d\n",status,size_out,out_length);
	}

        /* The data is successfully decompressed. Put into the szip struct */
	 HDfree(in_buffer);
	 szip_info->szip_state = SZIP_RUN;
	 szip_info->buffer = out_buffer;
	 szip_info->buffer_pos = 0;
	 szip_info->buffer_size = out_length;
	 szip_info->offset = 0;
    }

   /* copy the data into the return buffer */
    if (length > szip_info->buffer_size)
    {	
        /*  can't happen?? panic?? */
	if (szip_info->buffer != NULL) {
            HDfree(szip_info->buffer);
	    szip_info->buffer = NULL;
        } 
        return (FAIL);
    }

    HDmemcpy(buf, szip_info->buffer + szip_info->buffer_pos, length);
    szip_info->buffer_pos += length;
    szip_info->buffer_size -= length;
    szip_info->offset = szip_info->buffer_pos;

    if (szip_info->buffer_size == 0) {
       if (szip_info->buffer != NULL) {
  	    HDfree(szip_info->buffer);
	    szip_info->buffer = NULL;
       }
    }

    return (SUCCEED);

#else /* ifdef H4_HAVE_LIBSZ */

    HRETURN_ERROR(DFE_CANTCOMP, FAIL);

#endif /* H4_HAVE_LIBSZ */

}   /* end HCIcszip_decode() */
Example #9
0
File: dfp.c Project: schwehr/hdf4
/*--------------------------------------------------------------------------
 NAME
    DFPgetpal -- get next palette from file
 USAGE
    intn DFPgetpal(filename,palette)
        char *filename;         IN: name of HDF file
        void * palette;          OUT: ptr to the buffer to store the palette in
 RETURNS
    SUCCEED on success, FAIL on failure.
 DESCRIPTION
    Gets the next palette from the file specified.
 GLOBAL VARIABLES
    Lastref, Refset
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
intn
DFPgetpal(const char *filename, void * palette)
{
  CONSTR(FUNC, "DFPgetpal");
  int32       file_id;
  int32       aid;
  int32       length;
  intn        ret_value = SUCCEED;

  HEclear();

  if (!palette)
    HGOTO_ERROR(DFE_ARGS, FAIL);

  if ((file_id = DFPIopen(filename, DFACC_READ)) == FAIL)
    HGOTO_ERROR(DFE_BADOPEN, FAIL);

  if (Refset)
    {
      aid = Hstartread(file_id, DFTAG_IP8, Refset);
      if (aid == FAIL)
        aid = Hstartread(file_id, DFTAG_LUT, Refset);
    }     /* end if */
  else if (Readref)
    {
      aid = Hstartread(file_id, DFTAG_IP8, Readref);
      if (aid == FAIL)
        aid = Hstartread(file_id, DFTAG_LUT, Readref);
      if (aid != FAIL &&
          (Hnextread(aid, DFTAG_IP8, DFREF_WILDCARD, DF_CURRENT) == FAIL))
        {
          if (Hnextread(aid, DFTAG_LUT, DFREF_WILDCARD, DF_CURRENT) == FAIL)
            {
              Hendaccess(aid);
              aid = FAIL;
            }     /* end if */
        }   /* end if */
    }     /* end if */
  else
    {
      aid = Hstartread(file_id, DFTAG_IP8, DFREF_WILDCARD);
      if (aid == FAIL)
        aid = Hstartread(file_id, DFTAG_LUT, DFREF_WILDCARD);
    }     /* end else */

  Refset = 0;
  /* on error, close file and return -1 */
  if (aid == FAIL)
    {
      ret_value = (HDerr(file_id));
      goto done;
    }

  if (Hinquire(aid, (int32 *) NULL, (uint16 *) NULL, &Readref, &length,
               (int32 *) NULL, (int32 *) NULL, (int16 *) NULL, (int16 *) NULL) == FAIL)
    {
      Hendaccess(aid);
      ret_value = HDerr(file_id);
      goto done;
    }     /* end if */

  /* read palette */
  if (Hread(aid, length, (uint8 *) palette) == FAIL)
    {
      Hendaccess(aid);
      ret_value = (HDerr(file_id));
      goto done;
    }     /* end if */

  Hendaccess(aid);

  Lastref = Readref;

  ret_value = Hclose(file_id);

done:
  if(ret_value == FAIL)   
    { /* Error condition cleanup */

    } /* end if */

  /* Normal function cleanup */
  return ret_value;
}   /* end DFPgetpal() */
Example #10
0
int
updateDesc(void)
{
    int32      fid;
    int32       groupID;
    int32       aid, status;
    int i, j;

    if ((fid = Hopen(he_file, DFACC_READ, 0)) == 0)
      {
          printf("failed opening\n");
          HEprint(stdout, 0);
          return FAIL;
      }

    aid = Hstartread(fid, DFTAG_WILDCARD, DFREF_WILDCARD);
    if (aid == FAIL)
      {
          HEprint(stderr, 0);
          return FAIL;
      }

    status = SUCCEED;
    for (i = 0; (i < HE_DESC_SZ) && (status != FAIL); i++)
      {
          Hinquire(aid, NULL, &he_desc[i].tag, &he_desc[i].ref, &he_desc[i].length,
                   &he_desc[i].offset, NULL, (int16 *) NULL, (int16 *) NULL);
          status = Hnextread(aid, DFTAG_WILDCARD, DFREF_WILDCARD, DF_CURRENT);
      }
    he_numDesc = i;

    /* get informations about the groups */
    he_numGrp = 0;
    for (i = 0; i < he_numDesc; i++)
      {
          if (isGrp(he_desc[i].tag))
            {
                he_grp[he_numGrp].desc = i;
/*                he_grp[he_numGrp].size = (int) (he_desc[i].length / sizeof(tag_ref));
                he_grp[he_numGrp].ddList = (tag_ref_ptr) HDmalloc(he_desc[i].length);
*/
                he_grp[he_numGrp].size = (int) (he_desc[i].length / 4);
                he_grp[he_numGrp].ddList = (tag_ref_ptr) HDmalloc(he_grp[he_numGrp].size*sizeof(tag_ref));

                if (!he_grp[he_numGrp].ddList)
                  {
                      fprintf(stderr, "Out of memory. Closing file.\n");
                      closeFile(1);     /* keep the backup */
                      return FAIL;
                  }
                groupID = DFdiread(fid, he_desc[i].tag, he_desc[i].ref);
                if (groupID < 0)
                  {
                      HEprint(stderr, 0);
                      return FAIL;
                  }
                for (j = 0; j < he_grp[he_numGrp].size; j++)
                    DFdiget(groupID, &he_grp[he_numGrp].ddList[j].tag,
                            &he_grp[he_numGrp].ddList[j].ref);

                he_numGrp++;
            }
      }
    Hendaccess(aid);
    Hclose(fid);
    return SUCCEED;
}
Example #11
0
int32
vimakecompat(HFILEID f)
{
    VGROUP     *vg;
    VDATA      *vs;
    uint8      *buf = NULL;     /* to store an old vdata or vgroup descriptor  */
    int32       old_bsize = 0, bsize=0;
    int32       aid;
    int32       ret;
    uintn       u;
    uint16      tag=DFTAG_NULL, ref=DFTAG_NULL;
    CONSTR(FUNC, "vimakecompat");

    /* =============================================  */
    /* --- read all vgs and convert each --- */

    /* allocate space for vg */
    if (NULL == (vg =VIget_vgroup_node()))
        HRETURN_ERROR(DFE_NOSPACE, 0);
    ret = aid = Hstartread(f, (uint16) OLD_VGDESCTAG, DFREF_WILDCARD);
    while (ret != FAIL)
      {
          HQuerytagref(aid, &tag, &ref);
          HQuerylength(aid, &bsize);
          if (buf == NULL || bsize > old_bsize)
            {
                if (buf != NULL)
                    HDfree((VOIDP) buf);
                if ((buf = (uint8 *) HDmalloc(bsize)) == NULL)
                    HRETURN_ERROR(DFE_NOSPACE, 0);
                old_bsize = bsize;
            }   /* end if */
          ret = Hgetelement(f, (uint16) OLD_VGDESCTAG, ref, (uint8 *) buf);
          if (ret == FAIL)
            {
                HDfree((VOIDP) buf);
                HRETURN_ERROR(DFE_READERROR, 0)
            }   /* end if */

          oldunpackvg(vg, buf, &bsize);
          /* add new items */
          vg->vgclass = NULL;
          /* vg->vgclass[0] = '\0'; */ 
          vg->extag = 0;
          vg->exref = 0;
          vg->version = 2;  /* version 2 */
          vg->more = 0;
          /* inside each vgroup, change the old tags to new */
          for (u = 0; u < (uintn)vg->nvelt; u++)
              if (vg->tag[u] == OLD_VGDESCTAG)
                  vg->tag[u] = NEW_VGDESCTAG;
              else if (vg->tag[u] == OLD_VSDESCTAG)
                  vg->tag[u] = NEW_VSDESCTAG;
              else  /* BAD */
                  HERROR(DFE_NOTINSET);
          vpackvg(vg, buf, &bsize);

          ret = Hputelement(f, VGDESCTAG, ref, (uint8 *) buf, bsize);
          HDfree((VOIDP) buf);
          if (ret == FAIL)
              HRETURN_ERROR(DFE_WRITEERROR, 0);

          ret = Hnextread(aid, (uint16) OLD_VGDESCTAG, DFREF_WILDCARD, DF_CURRENT);
      }     /* while */