Esempio n. 1
0
/*
 * Formerly
NC_new_dim(const char *uname, long size)
 */
static NC_dim *
new_NC_dim(const char *uname, size_t size)
{
	NC_string *strp;
	NC_dim *dimp;

	char *name = (char *)utf8proc_NFC((const unsigned char *)uname);
	if(name == NULL)
	    return NULL;
	strp = new_NC_string(strlen(name), name);
	free(name);
	if(strp == NULL)
		return NULL;

	dimp = new_x_NC_dim(strp);
	if(dimp == NULL)
	{
		free_NC_string(strp);
		return NULL;
	}

	dimp->size = size;

	return(dimp);
}
Esempio n. 2
0
/*
 * Step thru NC_DIMENSION array, seeking match on uname.
 * Return dimid or -1 on not found.
 * *dimpp is set to the appropriate NC_dim.
 * The loop structure is odd. In order to parallelize,
 * we moved a clearer 'break' inside the loop body to the loop test.
 */
static int
NC_finddim(const NC_dimarray *ncap, const char *uname, NC_dim **dimpp)
{

   int dimid;
   NC_dim ** loc;
   char *name;

   assert(ncap != NULL);

   if(ncap->nelems == 0)
      return -1;

   {
      dimid = 0;
      loc = (NC_dim **) ncap->value;

      /* normalized version of uname */
      name = (char *)utf8proc_NFC((const unsigned char *)uname);
      if(name == NULL)
	 return NC_ENOMEM;
      dimid = (int)NC_hashmapGetDim(ncap, name);
      free(name);
      if (dimid >= 0) {
	if (dimpp != NULL)
	  *dimpp = ncap->value[dimid];
      }
      return(dimid); /* Normal return */
   }
   return -1;
}
Esempio n. 3
0
/*
 * Step thru NC_VARIABLE array, seeking match on name.
 * Return varid or -1 on not found.
 * *varpp is set to the appropriate NC_var.
 * Formerly (sort of)
NC_hvarid
 */
int
NC_findvar(const NC_vararray *ncap, const char *uname, NC_var **varpp)
{
	NC_var **loc;
 	uint32_t shash;
	int varid;
	char *name;

	assert(ncap != NULL);

	if(ncap->nelems == 0)
		return -1;

	loc = (NC_var **) ncap->value;

	/* normalized version of uname */
	name = (char *)utf8proc_NFC((const unsigned char *)uname);
	if(name == NULL)
	    return NC_ENOMEM;
 	shash = hash_fast(name, strlen(name));

	for(varid = 0; (size_t) varid < ncap->nelems; varid++, loc++)
	{
		if((*loc)->hash == shash &&
		   strncmp((*loc)->name->cp, name, strlen(name)) == 0)
		{
			if(varpp != NULL)
				*varpp = *loc;
			free(name);
			return(varid); /* Normal return */
		}
	}
	free(name);
	return(-1); /* not found */
}
Esempio n. 4
0
File: attr.c Progetto: UMhaus/VTK
int
NC3_del_att(int ncid, int varid, const char *uname)
{
        int status;
        NC *ncp;
        NC_attrarray *ncap;
        NC_attr **attrpp;
        NC_attr *old = NULL;
        int attrid;
        size_t slen;

        status = NC_check_id(ncid, &ncp);
        if(status != NC_NOERR)
                return status;

        if(!NC_indef(ncp))
                return NC_ENOTINDEFINE;

        ncap = NC_attrarray0(ncp, varid);
        if(ncap == NULL)
                return NC_ENOTVAR;

        {
        char *name = (char *)utf8proc_NFC((const unsigned char *)uname);
        if(name == NULL)
            return NC_ENOMEM;

                        /* sortof inline NC_findattr() */
        slen = strlen(name);

        attrpp = (NC_attr **) ncap->value;
        for(attrid = 0; (size_t) attrid < ncap->nelems; attrid++, attrpp++)
            {
                if( slen == (*attrpp)->name->nchars &&
                        strncmp(name, (*attrpp)->name->cp, slen) == 0)
                {
                        old = *attrpp;
                        break;
                }
            }
        free(name);
        }
        if( (size_t) attrid == ncap->nelems )
                return NC_ENOTATT;
                        /* end inline NC_findattr() */

        /* shuffle down */
        for(attrid++; (size_t) attrid < ncap->nelems; attrid++)
        {
                *attrpp = *(attrpp + 1);
                attrpp++;
        }
        *attrpp = NULL;
        /* decrement count */
        ncap->nelems--;

        free_NC_attr(old);

        return NC_NOERR;
}
Esempio n. 5
0
/*
 * Formerly
NC_new_var()
 */
static NC_var *
new_NC_var(const char *uname, nc_type type,
	size_t ndims, const int *dimids)
{
	NC_string *strp;
	NC_var *varp;

	char *name = (char *)utf8proc_NFC((const unsigned char *)uname);
	if(name == NULL)
	    return NULL;
	strp = new_NC_string(strlen(name), name);
	free(name);
	if(strp == NULL)
		return NULL;

	varp = new_x_NC_var(strp, ndims);
	if(varp == NULL )
	{
		free_NC_string(strp);
		return NULL;
	}
	
	varp->type = type;

	if( ndims != 0 && dimids != NULL)
		(void) memcpy(varp->dimids, dimids, ndims * sizeof(int));

	return(varp);
}
Esempio n. 6
0
File: attr.c Progetto: UMhaus/VTK
/*
 * Formerly
NC_new_attr(name,type,count,value)
 */
static NC_attr *
new_NC_attr(
        const char *uname,
        nc_type type,
        size_t nelems)
{
        NC_string *strp;
        NC_attr *attrp;

        char *name = (char *)utf8proc_NFC((const unsigned char *)uname);
        if(name == NULL)
            return NULL;
        assert(name != NULL && *name != 0);

        strp = new_NC_string(strlen(name), name);
        free(name);
        if(strp == NULL)
                return NULL;

        attrp = new_x_NC_attr(strp, type, nelems);
        if(attrp == NULL)
        {
                free_NC_string(strp);
                return NULL;
        }

        return(attrp);
}
Esempio n. 7
0
/*
 * Step thru NC_VARIABLE array, seeking match on name.
 * Return varid or -1 on not found.
 * *varpp is set to the appropriate NC_var.
 * Formerly (sort of)
NC_hvarid
 */
int
NC_findvar(const NC_vararray *ncap, const char *uname, NC_var **varpp)
{
	int hash_var_id;
	char *name;

	assert(ncap != NULL);

	if(ncap->nelems == 0)
		return -1;


	/* normalized version of uname */
	name = (char *)utf8proc_NFC((const unsigned char *)uname);
	if(name == NULL)
	    return NC_ENOMEM;

	hash_var_id = (int)NC_hashmapGetVar(ncap, name);
	free(name);
	if (hash_var_id >= 0) {
	  if (varpp != NULL)
	    *varpp = ncap->value[hash_var_id];
	  return(hash_var_id); /* Normal return */
	}
	return(-1); /* not found */
}
Esempio n. 8
0
static void issue128(void) /* #128 */
{
    utf8proc_uint8_t input[] = {0x72, 0xcc, 0x87, 0xcc, 0xa3, 0x00}; /* "r\u0307\u0323" */
    utf8proc_uint8_t nfc[] = {0xe1, 0xb9, 0x9b, 0xcc, 0x87, 0x00}; /* "\u1E5B\u0307" */
    utf8proc_uint8_t nfd[] = {0x72, 0xcc, 0xa3, 0xcc, 0x87, 0x00}; /* "r\u0323\u0307" */
    utf8proc_uint8_t *nfc_out, *nfd_out;
    nfc_out = utf8proc_NFC(input);
    printf("NFC \"%s\" -> \"%s\" vs. \"%s\"\n", (char*)input, (char*)nfc_out, (char*)nfc);
    check(strlen((char*) nfc_out) == 5, "incorrect nfc length");
    check(!memcmp(nfc, nfc_out, 6), "incorrect nfc data");
    nfd_out = utf8proc_NFD(input);
    printf("NFD \"%s\" -> \"%s\" vs. \"%s\"\n", (char*)input, (char*)nfd_out, (char*)nfd);
    check(strlen((char*) nfd_out) == 5, "incorrect nfd length");
    check(!memcmp(nfd, nfd_out, 6), "incorrect nfd data");
    free(nfd_out); free(nfc_out);
}
Esempio n. 9
0
File: dim.c Progetto: 151706061/VTK
/*
 * Step thru NC_DIMENSION array, seeking match on uname.
 * Return dimid or -1 on not found.
 * *dimpp is set to the appropriate NC_dim.
 * The loop structure is odd. In order to parallelize,
 * we moved a clearer 'break' inside the loop body to the loop test.
 */
static int
NC_finddim(const NC_dimarray *ncap, const char *uname, NC_dim **dimpp)
{

   int dimid;
   uint32_t shash;
   NC_dim ** loc;
   char *name;

   assert(ncap != NULL);

   if(ncap->nelems == 0)
      return -1;

   {
      dimid = 0;
      loc = (NC_dim **) ncap->value;
      /* normalized version of uname */
      name = (char *)utf8proc_NFC((const unsigned char *)uname);
      if(name == NULL)
	 return NC_ENOMEM;
      shash = hash_fast(name, strlen(name));

      for(; (size_t) dimid < ncap->nelems
	     && ((*loc)->hash != shash
		 || strncmp((*loc)->name->cp, name, strlen(name)) != 0);
	  dimid++, loc++)
      {
	 /*EMPTY*/
      }
      free(name);
      if(dimid >= ncap->nelems)
	 return(-1); /* not found */
      /* else, normal return */
      if(dimpp != NULL)
	 *dimpp = *loc;
      return(dimid);
   }
}
Esempio n. 10
0
/* Check and normalize and name. */
int
nc4_check_name(const char *name, char *norm_name)
{
   char *temp;
   int retval;

   /* Check the length. */
   if (strlen(name) > NC_MAX_NAME)
      return NC_EMAXNAME;

   /* Make sure this is a valid netcdf name. This should be done
    * before the name is normalized, because it gives better error
    * codes for bad utf8 strings. */
   if ((retval = NC_check_name(name)))
      return retval;

   /* Normalize the name. */
   if (!(temp = (char *)utf8proc_NFC((const unsigned char *)name)))
      return NC_EINVAL;
   strcpy(norm_name, temp);
   free(temp);

   return NC_NOERR;
}
Esempio n. 11
0
int
NC3_rename_dim( int ncid, int dimid, const char *unewname)
{
	int status;
	NC *nc;
	NC3_INFO* ncp;
	int existid;
	NC_dim *dimp;
	char *newname;		/* normalized */

	status = NC_check_id(ncid, &nc); 
	if(status != NC_NOERR)
		return status;
	ncp = NC3_DATA(nc);

	if(NC_readonly(ncp))
		return NC_EPERM;

	status = NC_check_name(unewname);
	if(status != NC_NOERR)
		return status;

	existid = NC_finddim(&ncp->dims, unewname, &dimp);
	if(existid != -1)
		return NC_ENAMEINUSE;

	dimp = elem_NC_dimarray(&ncp->dims, (size_t)dimid);
	if(dimp == NULL)
		return NC_EBADDIM;

	NC_string *old = dimp->name;
	newname = (char *)utf8proc_NFC((const unsigned char *)unewname);
	if(newname == NULL)
	    return NC_ENOMEM;
	if(NC_indef(ncp))
	{
		NC_string *newStr = new_NC_string(strlen(newname), newname);
		free(newname);
		if(newStr == NULL)
			return NC_ENOMEM;
		dimp->name = newStr;

		/* Remove old name from hashmap; add new... */
		NC_hashmapRemoveDim(&ncp->dims, old->cp);
		NC_hashmapAddDim(&ncp->dims, dimid, newStr->cp);
		free_NC_string(old);

		return NC_NOERR;
	}

	/* else, not in define mode */

	status = set_NC_string(dimp->name, newname);
	free(newname);
	if(status != NC_NOERR)
		return status;

	/* Remove old name from hashmap; add new... */
	NC_hashmapRemoveDim(&ncp->dims, old->cp);
	NC_hashmapAddDim(&ncp->dims, dimid, dimp->name->cp);

	set_NC_hdirty(ncp);

	if(NC_doHsync(ncp))
	{
		status = NC_sync(ncp);
		if(status != NC_NOERR)
			return status;
	}

	return NC_NOERR;
}
Esempio n. 12
0
int
NC3_rename_var(int ncid, int varid, const char *unewname)
{
	int status;
	NC *nc;
	NC3_INFO* ncp;
	NC_var *varp;
	NC_string *old, *newStr;
	int other;
	char *newname;		/* normalized */

	status = NC_check_id(ncid, &nc); 
	if(status != NC_NOERR)
		return status;
	ncp = NC3_DATA(nc);

	if(NC_readonly(ncp))
	{
		return NC_EPERM;
	}

	status = NC_check_name(unewname);
	if(status != NC_NOERR)
		return status;

	/* check for name in use */
	other = NC_findvar(&ncp->vars, unewname, &varp);
	if(other != -1)
	{
		return NC_ENAMEINUSE;
	}
	
	varp = NC_lookupvar(ncp, varid);
	if(varp == NULL)
	{
		/* invalid varid */
		return NC_ENOTVAR; /* TODO: is this the right error code? */
	}

	old = varp->name;
	newname = (char *)utf8proc_NFC((const unsigned char *)unewname);
	if(newname == NULL)
	    return NC_ENOMEM;
	if(NC_indef(ncp))
	{
		newStr = new_NC_string(strlen(newname),newname);
		free(newname);
		if(newStr == NULL)
			return(-1);
		varp->name = newStr;
		varp->hash = hash_fast(newStr->cp, strlen(newStr->cp));
		free_NC_string(old);
		return NC_NOERR;
	}

	/* else, not in define mode */
	status = set_NC_string(varp->name, newname);
	varp->hash = hash_fast(newname, strlen(newname));
	free(newname);
	if(status != NC_NOERR)
		return status;

	set_NC_hdirty(ncp);

	if(NC_doHsync(ncp))
	{
		status = NC_sync(ncp);
		if(status != NC_NOERR)
			return status;
	}

	return NC_NOERR;
}
Esempio n. 13
0
File: attr.c Progetto: UMhaus/VTK
int
NC3_rename_att( int ncid, int varid, const char *name, const char *unewname)
{
        int status;
        NC *ncp;
        NC_attrarray *ncap;
        NC_attr **tmp;
        NC_attr *attrp;
        NC_string *newStr, *old;
        char *newname;  /* normalized version */

                        /* sortof inline clone of NC_lookupattr() */
        status = NC_check_id(ncid, &ncp);
        if(status != NC_NOERR)
                return status;

        if(NC_readonly(ncp))
                return NC_EPERM;

        ncap = NC_attrarray0(ncp, varid);
        if(ncap == NULL)
                return NC_ENOTVAR;

        status = NC_check_name(unewname);
        if(status != NC_NOERR)
                return status;

        tmp = NC_findattr(ncap, name);
        if(tmp == NULL)
                return NC_ENOTATT;
        attrp = *tmp;
                        /* end inline clone NC_lookupattr() */

        if(NC_findattr(ncap, unewname) != NULL)
        {
                /* name in use */
                return NC_ENAMEINUSE;
        }

        old = attrp->name;
        newname = (char *)utf8proc_NFC((const unsigned char *)unewname);
        if(newname == NULL)
            return NC_EBADNAME;
        if(NC_indef(ncp))
        {
                newStr = new_NC_string(strlen(newname), newname);
                free(newname);
                if( newStr == NULL)
                        return NC_ENOMEM;
                attrp->name = newStr;
                free_NC_string(old);
                return NC_NOERR;
        }
        /* else */
        status = set_NC_string(old, newname);
        free(newname);
        if( status != NC_NOERR)
                return status;

        set_NC_hdirty(ncp);

        if(NC_doHsync(ncp))
        {
                status = NC_sync(ncp);
                if(status != NC_NOERR)
                        return status;
        }

        return NC_NOERR;
}
Esempio n. 14
0
int
NC3_rename_var(int ncid, int varid, const char *unewname)
{
	int status;
	NC *nc;
	NC3_INFO* ncp;
	NC_var *varp;
	NC_string *old, *newStr;
	int other;
	char *newname;		/* normalized */

	status = NC_check_id(ncid, &nc);
	if(status != NC_NOERR)
		return status;
	ncp = NC3_DATA(nc);

	if(NC_readonly(ncp))
	{
		return NC_EPERM;
	}

	status = NC_check_name(unewname);
	if(status != NC_NOERR)
		return status;

	/* check for name in use */
	other = NC_findvar(&ncp->vars, unewname, &varp);
	if(other != -1)
	{
		return NC_ENAMEINUSE;
	}

	status = NC_lookupvar(ncp, varid, &varp);
	if(status != NC_NOERR)
	{
		/* invalid varid */
		return status;
	}


	old = varp->name;
	newname = (char *)utf8proc_NFC((const unsigned char *)unewname);
	if(newname == NULL)
	    return NC_ENOMEM;
	if(NC_indef(ncp))
	{
		newStr = new_NC_string(strlen(newname),newname);
		free(newname);
		if(newStr == NULL)
			return(-1);
		varp->name = newStr;

		/* Remove old name from hashmap; add new... */
		NC_hashmapRemoveVar(&ncp->vars, old->cp);
		NC_hashmapAddVar(&ncp->vars, varid, newStr->cp);
		free_NC_string(old);

		return NC_NOERR;
	}

	/* else, not in define mode */
	status = set_NC_string(varp->name, newname);
	free(newname);
	if(status != NC_NOERR)
		return status;

	/* Remove old name from hashmap; add new... */
	NC_hashmapRemoveVar(&ncp->vars, old->cp);
	NC_hashmapAddVar(&ncp->vars, varid, varp->name->cp);

	set_NC_hdirty(ncp);

	if(NC_doHsync(ncp))
	{
		status = NC_sync(ncp);
		if(status != NC_NOERR)
			return status;
	}

	return NC_NOERR;
}