- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
273
costa.c
273
costa.c
@ -45,154 +45,145 @@
|
||||
#include "costa.h"
|
||||
#include "costa.i"
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
pCosta CreateCommandStack(void)
|
||||
{
|
||||
pCosta pNew = NULL;
|
||||
|
||||
pNew = (pCosta)malloc(sizeof(Costa));
|
||||
if(!pNew)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
memset(pNew,0,sizeof(Costa));
|
||||
pNew->iList = LLDcreate(sizeof(char *));
|
||||
if(pNew->iList < 0)
|
||||
{
|
||||
free(pNew);
|
||||
return NULL;
|
||||
}
|
||||
pNew->iCount = 0;
|
||||
pNew->iMaxSize = INT_MAX;
|
||||
return pNew;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
void DeleteCommandStack(pCosta self)
|
||||
{
|
||||
int iRet;
|
||||
char *pPtr;
|
||||
|
||||
assert(self);
|
||||
|
||||
iRet = LLDnodePtr2First(self->iList);
|
||||
while(iRet != 0)
|
||||
{
|
||||
pPtr = NULL;
|
||||
LLDnodeDataTo(self->iList,&pPtr);
|
||||
if(pPtr)
|
||||
{
|
||||
free(pPtr);
|
||||
}
|
||||
iRet = LLDnodePtr2Next(self->iList);
|
||||
}
|
||||
LLDdelete(self->iList);
|
||||
free(self);
|
||||
pCosta CreateCommandStack(void)
|
||||
{
|
||||
pCosta pNew = NULL;
|
||||
|
||||
pNew = (pCosta) malloc(sizeof(Costa));
|
||||
if (!pNew) {
|
||||
return NULL;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int SetCommandStackMaxSize(pCosta self, int iNew)
|
||||
{
|
||||
assert(self);
|
||||
|
||||
if(iNew > 0)
|
||||
{
|
||||
self->iMaxSize = iNew;
|
||||
return 1;
|
||||
memset(pNew, 0, sizeof(Costa));
|
||||
pNew->iList = LLDcreate(sizeof(char *));
|
||||
if (pNew->iList < 0) {
|
||||
free(pNew);
|
||||
return NULL;
|
||||
}
|
||||
pNew->iCount = 0;
|
||||
pNew->iMaxSize = INT_MAX;
|
||||
return pNew;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
void DeleteCommandStack(pCosta self)
|
||||
{
|
||||
int iRet;
|
||||
char *pPtr;
|
||||
|
||||
assert(self);
|
||||
|
||||
iRet = LLDnodePtr2First(self->iList);
|
||||
while (iRet != 0) {
|
||||
pPtr = NULL;
|
||||
LLDnodeDataTo(self->iList, &pPtr);
|
||||
if (pPtr) {
|
||||
free(pPtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
iRet = LLDnodePtr2Next(self->iList);
|
||||
}
|
||||
LLDdelete(self->iList);
|
||||
free(self);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int CostaTop(pCosta self, char *pCommand)
|
||||
{
|
||||
char *pPtr = NULL;
|
||||
int iRet, iRes = 1;
|
||||
|
||||
assert(self);
|
||||
|
||||
/* check for lock */
|
||||
if(self->iLock)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/* check Size */
|
||||
if(self->iCount >= self->iMaxSize)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* do not want 0 commands */
|
||||
if(strlen(pCommand) < 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
pPtr = strdup(pCommand);
|
||||
iRet = LLDnodeAppendFrom(self->iList,&pPtr);
|
||||
if(iRet < 0)
|
||||
{
|
||||
iRes = 0;
|
||||
}
|
||||
self->iCount++;
|
||||
return iRes;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int CostaBottom(pCosta self, char *pCommand)
|
||||
{
|
||||
char *pPtr = NULL;
|
||||
int iRet, iRes = 1;
|
||||
assert(self);
|
||||
int SetCommandStackMaxSize(pCosta self, int iNew)
|
||||
{
|
||||
assert(self);
|
||||
|
||||
/* check for lock */
|
||||
if(self->iLock)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* do not want 0 commands */
|
||||
if(strlen(pCommand) < 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
pPtr = strdup(pCommand);
|
||||
iRet = LLDnodePrependFrom(self->iList,&pPtr);
|
||||
if(iRet < 0)
|
||||
{
|
||||
iRes = 0;
|
||||
}
|
||||
self->iCount++;
|
||||
return iRes;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int CostaPop(pCosta self, char **pBuf)
|
||||
{
|
||||
char *pPtr = NULL;
|
||||
int iRet;
|
||||
|
||||
assert(self);
|
||||
iRet = LLDnodePtr2First(self->iList);
|
||||
if(iRet != 0)
|
||||
{
|
||||
LLDnodeDataTo(self->iList,&pPtr);
|
||||
*pBuf = pPtr;
|
||||
LLDnodeDelete(self->iList);
|
||||
self->iCount--;
|
||||
return 1;
|
||||
}
|
||||
*pBuf = NULL;
|
||||
if (iNew > 0) {
|
||||
self->iMaxSize = iNew;
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void CostaLock(pCosta self)
|
||||
{
|
||||
self->iLock = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void CostaUnlock(pCosta self)
|
||||
{
|
||||
self->iLock = 0;
|
||||
int CostaTop(pCosta self, char *pCommand)
|
||||
{
|
||||
char *pPtr = NULL;
|
||||
int iRet, iRes = 1;
|
||||
|
||||
assert(self);
|
||||
|
||||
/* check for lock */
|
||||
if (self->iLock) {
|
||||
return 0;
|
||||
}
|
||||
/* check Size */
|
||||
if (self->iCount >= self->iMaxSize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* do not want 0 commands */
|
||||
if (strlen(pCommand) < 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
pPtr = strdup(pCommand);
|
||||
iRet = LLDnodeAppendFrom(self->iList, &pPtr);
|
||||
if (iRet < 0) {
|
||||
iRes = 0;
|
||||
}
|
||||
self->iCount++;
|
||||
return iRes;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int CostaBottom(pCosta self, char *pCommand)
|
||||
{
|
||||
char *pPtr = NULL;
|
||||
int iRet, iRes = 1;
|
||||
assert(self);
|
||||
|
||||
/* check for lock */
|
||||
if (self->iLock) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* do not want 0 commands */
|
||||
if (strlen(pCommand) < 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
pPtr = strdup(pCommand);
|
||||
iRet = LLDnodePrependFrom(self->iList, &pPtr);
|
||||
if (iRet < 0) {
|
||||
iRes = 0;
|
||||
}
|
||||
self->iCount++;
|
||||
return iRes;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int CostaPop(pCosta self, char **pBuf)
|
||||
{
|
||||
char *pPtr = NULL;
|
||||
int iRet;
|
||||
|
||||
assert(self);
|
||||
iRet = LLDnodePtr2First(self->iList);
|
||||
if (iRet != 0) {
|
||||
LLDnodeDataTo(self->iList, &pPtr);
|
||||
*pBuf = pPtr;
|
||||
LLDnodeDelete(self->iList);
|
||||
self->iCount--;
|
||||
return 1;
|
||||
}
|
||||
*pBuf = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void CostaLock(pCosta self)
|
||||
{
|
||||
self->iLock = 1;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void CostaUnlock(pCosta self)
|
||||
{
|
||||
self->iLock = 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user