Example #1
0
/* write a legend
 * MputLegend writes a (version 2) legend to a map replacing
 * the old one if existent.
 * See  csfattr.h for the legend structure.
 *
 * returns 
 * 0 in case of an error,
 * nonzero otherwise
 *
 * Merrno
 * NOACCESS
 * WRITE_ERROR
 */
int MputLegend(
	MAP *m,        /* Map handle */
	CSF_LEGEND *l, /* read-write, array with name and entries, the entries
	                * are sorted before writing to the file.
	                * Strings are padded with zeros.
	                */
	size_t nrEntries) /* number of array elements. That is name plus real legend entries */
{
	int i = NrLegendEntries(m);
	CSF_ATTR_ID id = i < 0 ? ATTR_ID_LEGEND_V1 : ATTR_ID_LEGEND_V2;
	if (i)
		if (! MdelAttribute(m, id))
			return 0;
	SortEntries(l, nrEntries);
	if (CsfSeekAttrSpace(m, ATTR_ID_LEGEND_V2, (size_t)(nrEntries*CSF_LEGEND_ENTRY_SIZE)) == 0)
			return 0;
	for(i = 0; i < (int)nrEntries; i++)
	{
	     if(
		m->write(&(l[i].nr), sizeof(INT4), (size_t)1, m->fp) != 1 ||
		m->write(
		 CsfStringPad(l[i].descr,(size_t)CSF_LEGEND_DESCR_SIZE), 
		 sizeof(char), (size_t)CSF_LEGEND_DESCR_SIZE, m->fp) 
		 != CSF_LEGEND_DESCR_SIZE )
		 {
		 	M_ERROR(WRITE_ERROR);
		 	return 0;
		 }
	}
	return 1;
}
Example #2
0
/* replace an attribute (LIBRARY_INTERNAL)
 *
 */
CSF_ATTR_ID CsfUpdateAttribute(
	MAP *m,       		/* map handle */
	CSF_ATTR_ID id,               /* attribute identification */
	size_t itemSize,        /* size of each attribute element.
	                         * 1 or sizeof(char) in case of a
	                         * string
	                         */
	size_t nitems,          /* number of attribute elements or
	                         * strlen+1 in case of a variable character
	                         * string field. Don't forget to pad a
	                         * non-variable field with '\0'!
	                         */
	void *attr)       /* buffer containing attribute */
{
	PRECOND(CsfValidSize(itemSize));
	if (CsfAttributeSize(m,id))
		if (! MdelAttribute(m,id))
			return 0;
	return CsfPutAttribute(m,id,itemSize,nitems, attr);
}