ncdf4a13/libsrc/string.c File Reference

#include "nc.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "ncx.h"
#include "rnd.h"

Include dependency graph for string.c:

Go to the source code of this file.

Functions

void free_NC_string (NC_string *ncstrp)
int NC_check_name (const char *name)
NC_stringnew_NC_string (size_t slen, const char *str)
int set_NC_string (NC_string *ncstrp, const char *str)


Function Documentation

void free_NC_string NC_string ncstrp  ) 
 

Definition at line 22 of file string.c.

Referenced by free_NC_attr(), free_NC_dim(), free_NC_var(), nc_rename_att(), nc_rename_dim(), nc_rename_var(), new_NC_attr(), new_NC_dim(), new_NC_var(), v1h_get_NC_attr(), v1h_get_NC_dim(), v1h_get_NC_string(), and v1h_get_NC_var().

00023 {
00024         if(ncstrp==NULL)
00025                 return;
00026         free(ncstrp);
00027 }

int NC_check_name const char *  name  ) 
 

Definition at line 39 of file string.c.

References NC_EBADNAME, NC_EMAXNAME, NC_MAX_NAME, and NC_NOERR.

00040 {
00041         const char *cp = name;
00042         assert(name != NULL);
00043 
00044         if(*name == 0)
00045                 return NC_EBADNAME; /* empty names disallowed */
00046 
00047         for(; *cp != 0; cp++)
00048         {
00049                 int ch = *cp;
00050                 if(!isalnum(ch))
00051                 {
00052                     if(ch != '_' && ch != '-' && ch != '+' && ch != '.' && 
00053                        ch != ':' && ch != '@' && ch != '(' && ch != ')')
00054                                 return NC_EBADNAME;
00055                 }
00056         }
00057         if(cp - name > NC_MAX_NAME)
00058                 return NC_EMAXNAME;
00059 
00060         return NC_NOERR;
00061 }

NC_string* new_NC_string size_t  slen,
const char *  str
 

Definition at line 71 of file string.c.

References _RNDUP, NC_string::cp, M_RNDUP, NC_string::nchars, and X_ALIGN.

Referenced by nc_rename_att(), nc_rename_dim(), nc_rename_var(), new_NC_attr(), new_NC_dim(), new_NC_var(), and v1h_get_NC_string().

00072 {
00073         NC_string *ncstrp;
00074         size_t sz = M_RNDUP(sizeof(NC_string)) + slen + 1;
00075 
00076 #if 0
00077         sz = _RNDUP(sz, X_ALIGN);
00078 #endif
00079                 
00080         ncstrp = (NC_string *)malloc(sz);
00081         if( ncstrp == NULL )
00082                 return NULL;
00083         (void) memset(ncstrp, 0, sz);
00084 
00085         ncstrp->nchars = sz - M_RNDUP(sizeof(NC_string)) - 1;
00086         assert(ncstrp->nchars + 1 > slen);
00087         ncstrp->cp = (char *)ncstrp + M_RNDUP(sizeof(NC_string));
00088 
00089         if(str != NULL && *str != 0)
00090         {
00091                 (void) strncpy(ncstrp->cp, str, ncstrp->nchars +1);
00092                 ncstrp->cp[ncstrp->nchars] = 0;
00093         }
00094         
00095         return(ncstrp);
00096 }

int set_NC_string NC_string ncstrp,
const char *  str
 

Definition at line 106 of file string.c.

References NC_string::cp, NC_ENOTINDEFINE, NC_NOERR, and NC_string::nchars.

Referenced by nc_rename_att(), nc_rename_dim(), and nc_rename_var().

00107 {
00108         size_t slen;
00109         size_t diff;
00110 
00111         assert(str != NULL && *str != 0);
00112 
00113         slen = strlen(str);
00114 
00115         if(ncstrp->nchars < slen)
00116                 return NC_ENOTINDEFINE;
00117 
00118         (void) memcpy(ncstrp->cp, str, slen);
00119         diff = ncstrp->nchars - slen;
00120         if(diff != 0)
00121                 (void) memset(ncstrp->cp + slen, 0, diff);
00122 
00123         return NC_NOERR;
00124 }


Generated on Thu Mar 16 18:11:16 2006 for nco by  doxygen 1.4.4