- Adapted indenation to new agreed upon system

- Added support for second generation scriptcontext based counter
This commit is contained in:
koennecke
2009-02-13 09:00:03 +00:00
parent a3dcad2bfa
commit 91d4af0541
405 changed files with 88101 additions and 88173 deletions

View File

@ -46,261 +46,239 @@
#include "stringdict.h"
/*-------------------------------------------------------------------------*/
typedef struct __StringDict {
int iList;
int iTraverse;
} StringDict;
typedef struct __StringDict {
int iList;
int iTraverse;
} StringDict;
typedef struct {
char *name;
char *value;
} SDE, *pSDE;
/*-------------------------------------------------------------------------*/
pStringDict CreateStringDict(void)
{
pStringDict pNew = NULL;
pNew = (pStringDict)malloc(sizeof(StringDict));
if(!pNew)
{
return NULL;
}
pNew->iList = LLDcreate(sizeof(SDE));
if(pNew->iList < 0)
{
free(pNew);
return NULL;
}
pNew->iTraverse = 0;
return pNew;
}
/*------------------------------------------------------------------------*/
void DeleteStringDict(pStringDict self)
{
int iRet;
SDE sVal;
assert(self);
iRet = LLDnodePtr2First(self->iList);
while(iRet != 0)
{
LLDnodeDataTo(self->iList,&sVal);
if(sVal.name)
{
free(sVal.name);
}
if(sVal.value)
{
free(sVal.value);
}
iRet = LLDnodePtr2Next(self->iList);
}
LLDdelete(self->iList);
free(self);
}
typedef struct {
char *name;
char *value;
} SDE, *pSDE;
/*-------------------------------------------------------------------------*/
int StringDictAddPair(pStringDict self, char *name, char *value)
{
SDE sVal;
assert(self);
sVal.name = NULL;
sVal.value = NULL;
sVal.name = strdup(name);
sVal.value = strdup(value);
LLDnodeAppendFrom(self->iList,&sVal);
return 1;
pStringDict CreateStringDict(void)
{
pStringDict pNew = NULL;
pNew = (pStringDict) malloc(sizeof(StringDict));
if (!pNew) {
return NULL;
}
/*---------------------------------------------------------------------------*/
int StringDictExists(pStringDict self, char *name)
{
SDE sVal;
int iRet;
iRet = LLDnodePtr2First(self->iList);
while(iRet != 0)
{
LLDnodeDataTo(self->iList,&sVal);
if(strcmp(sVal.name,name) == 0)
{
return 1;
}
iRet = LLDnodePtr2Next(self->iList);
}
return 0;
}
/*--------------------------------------------------------------------------*/
int StringDictUpdate(pStringDict self, char *name, char *value)
{
SDE sVal;
int iRet;
iRet = LLDnodePtr2First(self->iList);
while(iRet != 0)
{
LLDnodeDataTo(self->iList,&sVal);
if(strcmp(sVal.name,name) == 0)
{
if(sVal.value)
{
free(sVal.value);
}
sVal.value = strdup(value);
LLDnodeDataFrom(self->iList,&sVal);
return 1;
}
iRet = LLDnodePtr2Next(self->iList);
}
return 0;
}
/*--------------------------------------------------------------------------*/
int StringDictGet(pStringDict self, char *name, char *pResult, int iLen)
{
SDE sVal;
int iRet;
if(pResult != NULL)
{
pResult[0] = '\0';
}
iRet = LLDnodePtr2First(self->iList);
while(iRet != 0)
{
LLDnodeDataTo(self->iList,&sVal);
if(strcmp(sVal.name,name) == 0)
{
if(pResult == NULL)
{
return strlen(sVal.value) + 1; /* for \0 */
}
else
{
strncpy(pResult,sVal.value,iLen);
/* strncpy is not guaranteed to be '\0' terminated */
if (iLen > 0 && pResult[iLen-1] != '\0') {
/* overflow */
pResult[iLen-1] = '\0';
}
return 1;
}
}
iRet = LLDnodePtr2Next(self->iList);
}
return 0;
}
/*--------------------------------------------------------------------------*/
char *StringDictGetShort(pStringDict self, char *name)
{
SDE sVal;
int iRet;
iRet = LLDnodePtr2First(self->iList);
while(iRet != 0)
{
LLDnodeDataTo(self->iList,&sVal);
if(strcmp(sVal.name,name) == 0)
{
return sVal.value;
}
iRet = LLDnodePtr2Next(self->iList);
}
return NULL;
}
/*------------------------------------------------------------------------*/
int StringDictDelete(pStringDict self, char *name)
{
SDE sVal;
int iRet;
iRet = LLDnodePtr2First(self->iList);
while(iRet != 0)
{
LLDnodeDataTo(self->iList,&sVal);
if(strcmp(sVal.name,name) == 0)
{
if(sVal.name)
{
free(sVal.name);
}
if(sVal.value)
{
free(sVal.value);
}
LLDnodeDelete(self->iList);
return 1;
}
iRet = LLDnodePtr2Next(self->iList);
}
return 0;
}
pNew->iList = LLDcreate(sizeof(SDE));
if (pNew->iList < 0) {
free(pNew);
return NULL;
}
pNew->iTraverse = 0;
return pNew;
}
/*------------------------------------------------------------------------*/
int StringDictGetAsNumber(pStringDict self, char *name, float *fVal)
{
char pBueffel[80];
int iRet;
SDE sVal;
assert(self);
iRet = StringDictGet(self,name,pBueffel,79);
if(!iRet)
{
return iRet;
}
iRet = sscanf(pBueffel,"%f",fVal);
if(iRet != 1)
{
return 0;
}
return 1;
}
/*-------------------------------------------------------------------------*/
const char *StringDictGetNext(pStringDict self, char *pValue, int iValLen)
{
int iRet;
SDE sVal;
assert(self);
if(self->iTraverse)
{
iRet = LLDnodePtr2Next(self->iList);
if(iRet == 0) /* exhausted */
{
self->iTraverse = 0;
return NULL;
}
else
{
LLDnodeDataTo(self->iList,&sVal);
strncpy(pValue,sVal.value,iValLen);
return sVal.name;
}
}
else /* start a new one */
{
iRet = LLDnodePtr2First(self->iList);
if(iRet == 0)
{
return NULL;
}
else
{
self->iTraverse = 1;
LLDnodeDataTo(self->iList,&sVal);
strncpy(pValue,sVal.value,iValLen);
return sVal.name;
}
}
return NULL;
void DeleteStringDict(pStringDict self)
{
int iRet;
SDE sVal;
assert(self);
iRet = LLDnodePtr2First(self->iList);
while (iRet != 0) {
LLDnodeDataTo(self->iList, &sVal);
if (sVal.name) {
free(sVal.name);
}
if (sVal.value) {
free(sVal.value);
}
iRet = LLDnodePtr2Next(self->iList);
}
LLDdelete(self->iList);
free(self);
}
/*-------------------------------------------------------------------------*/
void StringDictKillScan(pStringDict self)
{
assert(self);
self->iTraverse = 0;
int StringDictAddPair(pStringDict self, char *name, char *value)
{
SDE sVal;
assert(self);
sVal.name = NULL;
sVal.value = NULL;
sVal.name = strdup(name);
sVal.value = strdup(value);
LLDnodeAppendFrom(self->iList, &sVal);
return 1;
}
/*---------------------------------------------------------------------------*/
int StringDictExists(pStringDict self, char *name)
{
SDE sVal;
int iRet;
iRet = LLDnodePtr2First(self->iList);
while (iRet != 0) {
LLDnodeDataTo(self->iList, &sVal);
if (strcmp(sVal.name, name) == 0) {
return 1;
}
iRet = LLDnodePtr2Next(self->iList);
}
return 0;
}
/*--------------------------------------------------------------------------*/
int StringDictUpdate(pStringDict self, char *name, char *value)
{
SDE sVal;
int iRet;
iRet = LLDnodePtr2First(self->iList);
while (iRet != 0) {
LLDnodeDataTo(self->iList, &sVal);
if (strcmp(sVal.name, name) == 0) {
if (sVal.value) {
free(sVal.value);
}
sVal.value = strdup(value);
LLDnodeDataFrom(self->iList, &sVal);
return 1;
}
iRet = LLDnodePtr2Next(self->iList);
}
return 0;
}
/*--------------------------------------------------------------------------*/
int StringDictGet(pStringDict self, char *name, char *pResult, int iLen)
{
SDE sVal;
int iRet;
if (pResult != NULL) {
pResult[0] = '\0';
}
iRet = LLDnodePtr2First(self->iList);
while (iRet != 0) {
LLDnodeDataTo(self->iList, &sVal);
if (strcmp(sVal.name, name) == 0) {
if (pResult == NULL) {
return strlen(sVal.value) + 1; /* for \0 */
} else {
strncpy(pResult, sVal.value, iLen);
/* strncpy is not guaranteed to be '\0' terminated */
if (iLen > 0 && pResult[iLen - 1] != '\0') {
/* overflow */
pResult[iLen - 1] = '\0';
}
return 1;
}
}
iRet = LLDnodePtr2Next(self->iList);
}
return 0;
}
/*--------------------------------------------------------------------------*/
char *StringDictGetShort(pStringDict self, char *name)
{
SDE sVal;
int iRet;
iRet = LLDnodePtr2First(self->iList);
while (iRet != 0) {
LLDnodeDataTo(self->iList, &sVal);
if (strcmp(sVal.name, name) == 0) {
return sVal.value;
}
iRet = LLDnodePtr2Next(self->iList);
}
return NULL;
}
/*------------------------------------------------------------------------*/
int StringDictDelete(pStringDict self, char *name)
{
SDE sVal;
int iRet;
iRet = LLDnodePtr2First(self->iList);
while (iRet != 0) {
LLDnodeDataTo(self->iList, &sVal);
if (strcmp(sVal.name, name) == 0) {
if (sVal.name) {
free(sVal.name);
}
if (sVal.value) {
free(sVal.value);
}
LLDnodeDelete(self->iList);
return 1;
}
iRet = LLDnodePtr2Next(self->iList);
}
return 0;
}
/*------------------------------------------------------------------------*/
int StringDictGetAsNumber(pStringDict self, char *name, float *fVal)
{
char pBueffel[80];
int iRet;
SDE sVal;
assert(self);
iRet = StringDictGet(self, name, pBueffel, 79);
if (!iRet) {
return iRet;
}
iRet = sscanf(pBueffel, "%f", fVal);
if (iRet != 1) {
return 0;
}
return 1;
}
/*-------------------------------------------------------------------------*/
const char *StringDictGetNext(pStringDict self, char *pValue, int iValLen)
{
int iRet;
SDE sVal;
assert(self);
if (self->iTraverse) {
iRet = LLDnodePtr2Next(self->iList);
if (iRet == 0) { /* exhausted */
self->iTraverse = 0;
return NULL;
} else {
LLDnodeDataTo(self->iList, &sVal);
strncpy(pValue, sVal.value, iValLen);
return sVal.name;
}
} else { /* start a new one */
iRet = LLDnodePtr2First(self->iList);
if (iRet == 0) {
return NULL;
} else {
self->iTraverse = 1;
LLDnodeDataTo(self->iList, &sVal);
strncpy(pValue, sVal.value, iValLen);
return sVal.name;
}
}
return NULL;
}
/*-------------------------------------------------------------------------*/
void StringDictKillScan(pStringDict self)
{
assert(self);
self->iTraverse = 0;
}