Doxygen Source Code Documentation
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"Go to the source code of this file.
| Functions | |
| void | free_NC_string (NC_string *ncstrp) | 
| int | NC_check_name (const char *name) | 
| NC_string * | new_NC_string (size_t slen, const char *str) | 
| int | set_NC_string (NC_string *ncstrp, const char *str) | 
Function Documentation
| 
 | 
| 
 Definition at line 21 of file string.c. References free. 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(). 
 00022 {
00023         if(ncstrp==NULL)
00024                 return;
00025         free(ncstrp);
00026 }
 | 
| 
 | 
| 
 Definition at line 35 of file string.c. References name. Referenced by nc_def_dim(), nc_def_var(), nc_put_att_double(), nc_put_att_float(), nc_put_att_int(), nc_put_att_long(), nc_put_att_schar(), nc_put_att_short(), nc_put_att_text(), nc_put_att_uchar(), nc_rename_att(), nc_rename_dim(), and nc_rename_var(). 
 00036 {
00037         const char *cp = name;
00038         assert(name != NULL);
00039 
00040         if(*name == 0)
00041                 return NC_EBADNAME; /* empty names disallowed */
00042 
00043         for(; *cp != 0; cp++)
00044         {
00045                 int ch = *cp;
00046                 if(!isalnum(ch))
00047                 {
00048                         if(ch != '_' && ch != '-' && ch != '.')
00049                                 return NC_EBADNAME;
00050                 }
00051         }
00052         if(cp - name > NC_MAX_NAME)
00053                 return NC_EMAXNAME;
00054 
00055         return NC_NOERR;
00056 }
 | 
| 
 | ||||||||||||
| 
 Definition at line 66 of file string.c. References _RNDUP, NC_string::cp, M_RNDUP, malloc, 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(). 
 00067 {
00068         NC_string *ncstrp;
00069         size_t sz = M_RNDUP(sizeof(NC_string)) + slen + 1;
00070 
00071 #if 0
00072         sz = _RNDUP(sz, X_ALIGN);
00073 #endif
00074                 
00075         ncstrp = (NC_string *)malloc(sz);
00076         if( ncstrp == NULL )
00077                 return NULL;
00078         (void) memset(ncstrp, 0, sz);
00079 
00080         ncstrp->nchars = sz - M_RNDUP(sizeof(NC_string)) - 1;
00081         assert(ncstrp->nchars + 1 > slen);
00082         ncstrp->cp = (char *)ncstrp + M_RNDUP(sizeof(NC_string));
00083 
00084         if(str != NULL && *str != 0)
00085         {
00086                 (void) strncpy(ncstrp->cp, str, ncstrp->nchars +1);
00087                 ncstrp->cp[ncstrp->nchars] = 0;
00088         }
00089         
00090         return(ncstrp);
00091 }
 | 
| 
 | ||||||||||||
| 
 Definition at line 101 of file string.c. References NC_string::cp, and NC_string::nchars. Referenced by nc_rename_att(), nc_rename_dim(), and nc_rename_var(). 
 00102 {
00103         size_t slen;
00104         size_t diff;
00105 
00106         assert(str != NULL && *str != 0);
00107 
00108         slen = strlen(str);
00109 
00110         if(ncstrp->nchars < slen)
00111                 return NC_ENOTINDEFINE;
00112 
00113         (void) memcpy(ncstrp->cp, str, slen);
00114         diff = ncstrp->nchars - slen;
00115         if(diff != 0)
00116                 (void) memset(ncstrp->cp + slen, 0, diff);
00117 
00118         return NC_NOERR;
00119 }
 | 
 
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
 
 
 
 
       
	   
	   
	   
	  