Skip to content
Snippets Groups Projects
Commit e1f34dcc authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

three functions that will be used in the iterator [patch 10/14 from Nathanael]

parent b2115367
No related branches found
No related tags found
No related merge requests found
......@@ -326,13 +326,15 @@ void cdiInitialize(void);
void uuid2str(const unsigned char *uuid, char *uuidstr);
int str2uuid(const char *uuidstr, unsigned char *uuid);
static inline int
cdiUUIDIsNull(const unsigned char uuid[CDI_UUID_SIZE])
static inline int cdiUUIDIsNull(const unsigned char uuid[CDI_UUID_SIZE])
{
static const unsigned char uuid_nil[CDI_UUID_SIZE];
return !memcmp(uuid, uuid_nil, CDI_UUID_SIZE);
}
char* cdiEscapeSpaces(const char* string);
char* cdiUnescapeSpaces(const char* string, const char** outStringEnd);
#define CDI_UNIT_PA 1
#define CDI_UNIT_HPA 2
......
......@@ -91,12 +91,57 @@ int str2uuid(const char *uuidstr, unsigned char *uuid)
return iret;
}
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
//Returns a malloc'ed string that escapes all spaces and backslashes with backslashes.
char* cdiEscapeSpaces(const char* string)
{
//How much memory do we need?
size_t escapeCount = 0, length = 0;
for(const char* current = string; *current; current++)
{
if(strchr(" \\", *current)) escapeCount++;
length++;
}
char* result = malloc(length + escapeCount + 1);
if(!result) return NULL;
//Do the escaping.
for(size_t in = 0, out = 0; in < length;)
{
if(strchr(" \\", string[in])) result[out++] = '\\';
result[out++] = string[in++];
}
result[length + escapeCount] = 0; //termination!
return result;
}
//input: a space terminated string that may contain escaped characters
//output: a new zero terminated string with the escape characters removed
//*outStringEnd points to the terminating character upon return.
char* cdiUnescapeSpaces(const char* string, const char** outStringEnd)
{
//How much memory do we need?
size_t escapeCount = 0, length = 0;
for(const char* current = string; *current && *current != ' '; current++)
{
if(*current == '\\')
{
current++, escapeCount++;
if(!current) return NULL;
}
length++;
}
char* result = malloc(length + 1);
if(!result) return NULL;
//Do the unescaping.
for(size_t in = 0, out = 0; out < length;)
{
if(string[in] == '\\') in++;
result[out++] = string[in++];
}
result[length] = 0; //termination!
if(outStringEnd) *outStringEnd = &string[length + escapeCount];
return result;
}
......@@ -105,6 +105,26 @@ static const resOps zaxisOps = {
static int ZAXIS_Debug = 0; /* If set to 1, debugging */
void zaxisGetTypeDescription(int zaxisType, int* outPositive, const char** outName, const char** outLongName, const char** outStdName, const char** outUnit)
{
if(zaxisType < 0 || zaxisType >= CDI_NumZaxistype)
{
if(outPositive) *outPositive = 0;
if(outName) *outName = NULL;
if(outLongName) *outLongName = NULL;
if(outStdName) *outStdName = NULL;
if(outUnit) *outUnit = NULL;
}
else
{
if(outPositive) *outPositive = ZaxistypeEntry[zaxisType].positive;
if(outName) *outName = ZaxistypeEntry[zaxisType].name;
if(outLongName) *outLongName = ZaxistypeEntry[zaxisType].longname;
if(outStdName) *outStdName = ZaxistypeEntry[zaxisType].stdname;
if(outUnit) *outUnit = ZaxistypeEntry[zaxisType].units;
}
}
static
void zaxisDefaultValue(zaxis_t *zaxisptr)
{
......@@ -708,6 +728,7 @@ void zaxisDefUUID(int zaxisID, const unsigned char uuid[CDI_UUID_SIZE])
@Prototype void zaxisInqUUID(int zaxisID, char *uuid)
@Parameter
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate} or @fref{vlistInqVarZaxis}.
@Item uuid A user supplied buffer of at least 16 bytes.
@Description
The function @func{zaxisInqUUID} returns the UUID to a generalized Z-axis.
......
#ifndef _ZAXIS_H
#define _ZAXIS_H
void zaxisGetTypeDescription(int zaxisType, int* outPositive, const char** outName, const char** outLongName, const char** outStdName, const char** outUnit); //The returned const char* point to static storage. Don't free or modify them.
int zaxisSize(void);
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment