gridspec_api/global/nccf_add_global_att.c

00001 
00007 #include <string.h>
00008 
00009 #include "nccf_global.h"
00010 
00011 int nccf_add_global_att(int globalid, const char *attname, const char *attvalue,
00012                         int actionflag ){
00013 
00014   struct nccf_global_type *self;
00015   self = nccf_li_find(&CFLIST_GLOBAL, globalid);
00016 
00017   int status = NC_NOERR;
00018   char *oldval = NULL;
00019   char *newval = NULL;
00020   int len;
00021 
00022 
00023   /* Append attvalue to attname using space seperation */
00024   switch( actionflag ){
00025 
00026     case 1:  /* APPEND - attvalue to end of current value after delimeter */
00027 
00028       status = nccf_varGetAttribPtr( &self->global, attname, (const char**)&oldval );
00029 
00030       /* If the attribute is empty, set it. */
00031       if( oldval == NULL ){
00032         nccf_varSetAttrib( &self->global, attname, attvalue );
00033         break;
00034       }
00035 
00036       /* Append otherwise */
00037       len = strlen( oldval );
00038       len += strlen( attvalue );
00039       newval = (char*)calloc(len+2, sizeof(char));
00040       strcat( newval, oldval );
00041       strcat( newval, " " );
00042       strcat( newval, attvalue );
00043       nccf_varSetAttrib( &self->global, attname, newval );
00044       oldval = NULL;
00045       break;
00046 
00047     case 2: /* Replace - Overwrite */
00048       status = nccf_varSetAttrib(&self->global, attname, attvalue);
00049       break;
00050 
00051     default:  /* SET - No replacement */
00052       len = strlen( attvalue );
00053 
00054       status = nccf_varGetAttribPtr( &self->global, attname, (const char**)&oldval );
00055 
00056       if( oldval == NULL ){
00057         nccf_varSetAttrib( &self->global, attname, attvalue );
00058 
00059       } else {
00060         status = NC_EATTEXISTS;
00061 
00062       }
00063 
00064       break;
00065 
00066   }
00067 
00068   if( newval != NULL ) free( newval );
00069   return status;
00070 
00071 }
00072 
 All Classes Files Functions Defines

Generated on Tue Mar 1 2011 06:36:59 for libCF. LibCF is a Unidata library.