Ejemplo n.º 1
0
void(*GetBehaviorFromString(char * String))(BEHAVIOR * Owner, char * Trigger)
{
  if (myStrCmp(String, "PlayerBehavior") <= 0) return PlayerBehavior;
  if (myStrCmp(String, "GoRightBehavior") <= 0) return GoRightBehavior;
  if (myStrCmp(String, "DefaultBehavior") <= 0) return DefaultBehavior;
  if (myStrCmp(String, "BulletBehavior") <= 0) return BulletBehavior;
  if (myStrCmp(String, "EnemyBehavior") <= 0) return EnemyBehavior;
}
Ejemplo n.º 2
0
VTYPE GetVTypeFromString(char * theString)
{
    if (myStrCmp(theString, "Float") <= 0)
    {
        return Float;
    }
    if (myStrCmp(theString, "Int") <= 0)
    {
        return Int;
    }
    if (myStrCmp(theString, "Vector") <= 0)
    {
        return Vector;
    }
    if (myStrCmp(theString, "String") <= 0)
    {
        return String;
    }
    if (myStrCmp(theString, "Bool") <= 0)
    {
        return Bool;
    }
    if (myStrCmp(theString, "Color") <= 0)
    {
        return Color;
    }
    if (myStrCmp(theString, "Char") <= 0)
    {
        return Char;
    }
    if (myStrCmp(theString, "Matrix") <= 0)
    {
        return Matrix;
    }
}
setStatus  setIsNotEqual(set setA, set setB) {
	// normalise both and then single string compare
	// SIDE-EFFECTS !! - The supplied sets get normalised.  No harm there though iff TRUE sets.
	// TODO: Be defensive - check ret codes of setNormalise...
	setStatus nA, nB;
	nA=setNormalise(setA);
	nB=setNormalise(setB);
	if (nA) return nA;
	if (nB) return nB;
	return (myStrCmp(setA, setB) ? setNotEqual : setOK);
}
Ejemplo n.º 4
0
TAG GetTagFromString(char * String)
{
    if (myStrCmp(String, "DEFUALT") <= 0)
    {
        return DEFAULT;
    }
    else if (myStrCmp(String, "PLAYER") <= 0)
    {
        return PLAYER;
    }
    else if (myStrCmp(String, "BAD") <= 0)
    {
        return BAD;
    }
    else if (myStrCmp(String, "ENEMY") <= 0)
    {
        return ENEMY;
    }
    else if (myStrCmp(String, "WALL") <= 0)
    {
        return WALL;
    }
    else if (myStrCmp(String, "WEAPON") <= 0)
    {
        return WEAPON;
    }
}
Ejemplo n.º 5
0
LEVEL * FindLevelByName(GAME *pGame, char * Name)
{
	LEVEL * temp = pGame->nextLevel;
	while (temp)
	{
		if (myStrCmp(temp->Name, Name) <= 0)
		{
			return temp;
		}
		temp = temp->nextLevel;
	}
	return NULL;
}
Ejemplo n.º 6
0
UNIT * FindUnitByName(LEVEL *pLevel, char * Name)
{
  UNIT * temp = pLevel->nextUnit;
  while (temp)
  {
    if (myStrCmp(temp->Name, Name) <= 0)
    {
      return temp;
    }
    temp = temp->nextUnit;
  }
  return NULL;
}
Ejemplo n.º 7
0
ARCHETYPE * FindArchetypeByName(GAME *pGame, char *Name)
{
	ARCHETYPE * temp = pGame->nextArchetype;
	while (temp)
	{
		if (myStrCmp(temp->Name, Name) <= 0)
		{
			return temp;
		}
		temp = temp->nextArchetype;
	}
	return NULL;
}
Ejemplo n.º 8
0
VAR * GetActualVar(char * Name, BEHAVIOR * Owner)
{
  VAR * temp = Owner->nextVar;
  while (temp)
  {
    if (myStrCmp(temp->Name, Name) <= 0)
    {
      return temp;
    }
    temp = temp->nextVar;
  }
  return NULL;
}
bool HttpHandler::parseRequest()
{
    int count, sizeOfRequest, start;
    char *clientRequest, *method, *httpString;

    clientRequest = this->request;
    sizeOfRequest = strlen(clientRequest);
    count = 0;

    // Parsing the method type
    start = count;
    while(clientRequest[count] != ' ' && clientRequest[count] != '\t' && count < sizeOfRequest)
        count++;
    method = new char[count-start+1];
    for(int i = start; i < count; i++)  // Constructing the method name from the request
        method[i-start] = clientRequest[i];
    method[count-start] = '\0';

    if(myStrCmp(method, count-start, "GET", strlen("GET")))
        this->methodType = GET;
    else if(myStrCmp(method, count-start, "HEAD", strlen("HEAD")))
        this->methodType = HEAD;
    else if(myStrCmp(method, count-start, "PUT", strlen("PUT")))
        this->methodType = PUT;
    else if(myStrCmp(method, count-start, "DELETE", strlen("DELETE")))
        this->methodType = DELETE;
    else if(myStrCmp(method, count-start, "TRACE", strlen("TRACE")))
        this->methodType = TRACE;
    else if(myStrCmp(method, count-start, "OPTIONS", strlen("OPTIONS")))
        this->methodType = OPTIONS;
    else
    {
        cout<<"\nMethod invalid";
        this->methodType = INVALID;
        this->statusCode= 400;
        return false;
    }
    count++;

    // Parsing the URL
    while((clientRequest[count] == ' ' || clientRequest[count] == '\t') && count < sizeOfRequest) // Skipping all blank spaces
        count++;
    start = count;
    while(clientRequest[count] != ' ' && clientRequest[count] != '\t' && count < sizeOfRequest) // Counting the length of the URL
        count++;
    // for zero length check error
    if(count - start == 1 && clientRequest[start] == '/')
        this->URL = new char[count-start+strlen(DEFAULT_PAGE)+1];
    else
        this->URL = new char[count-start+1];
    for(int i = start; i < count; i++)  // Constructing the URL
        this->URL[i-start] = clientRequest[i];
    if(count - start == 1 && clientRequest[start] == '/')
    {
        char defaultPage[] = DEFAULT_PAGE;
        for(int i = 0; i < strlen(DEFAULT_PAGE); i++)
            this->URL[count-start+i] = defaultPage[i];
        this->URL[count-start+strlen(DEFAULT_PAGE)] = '\0';
    }
    else
        this->URL[count-start] = '\0';

    // Parsing the client HTTP version
    while((clientRequest[count] == ' ' || clientRequest[count] == '\t') && count < sizeOfRequest) // Skipping all blank spaces
        count++;
    start = count;
    while(clientRequest[count] != ' ' && clientRequest[count] != '\t' && clientRequest[count] != '\r' && clientRequest[count] != '\n' && count < sizeOfRequest) // Counting the length of the http version signature
        count++;
    if(count-start == 8)
    {
        httpString = new char[count-start+1];
        for(int i = start; i < count; i++)  // Constructing the HTTP string from the request
            httpString[i-start] = clientRequest[i];
        httpString[count-start] = '\0';
        if(myStrCmp(httpString, count-start, "HTTP/1.0", strlen("HTTP/1.0")))
            this->clientHttp10 = true;
        else if(myStrCmp(httpString, count-start, "HTTP/1.1", strlen("HTTP/1.1")))
            this->clientHttp10 = false;
        else
        {
            cout<<"\nHTTP version invalid";
            this->statusCode = 400;
            delete[] httpString;
            httpString = NULL;
            return false;
        }
        delete[] httpString;
        httpString = NULL;
    }
    else
    {
        cout<<"\nHTTP string size invalid";
        this->statusCode = 400;
        return false;
    }

    if((clientRequest[count] == '\r' && clientRequest[count+1] == '\n') && count+1 < sizeOfRequest)
        count += 2;
    else if(clientRequest[count] == '\n' && count < sizeOfRequest)
        clientRequest++;
    else if(count == sizeOfRequest)
    {
        cout<<"\nNo crlf after first line";
        this->statusCode = 400;
        return false;
    }

    // Parsing the headers
    int crlf = 1;
    while(count < sizeOfRequest)
    {
        int headStart, headStop, valueStart, valueStop;

        if(clientRequest[count] == '\r')
        {
            count++;
            if(clientRequest[count] == '\n' && count < sizeOfRequest)
            {
                count++;
                crlf++;
                if(crlf == 2)
                    break;
                else
                    continue;
            }
            else if(count == sizeOfRequest)
            {
                cout<<"\nNo lf after cr";
                this->statusCode = 400;
                return false;
            }
        }
        else if(clientRequest[count] == '\n' && count < sizeOfRequest)
        {
            crlf++;
            if(crlf == 2)
                break;
            else
                continue;
        }

        headStart = count;
        while(clientRequest[count] != '\r' && clientRequest[count] != '\n' && count < sizeOfRequest)
        {
            if(clientRequest[count] == ':' && (clientRequest[count+1] == ' ' || clientRequest[count+1] == '\t'))
            {
                headStop = count - 1;
                valueStart = count + 1;
            }
            count++;
        }
        valueStop = count - 1;

        if(count == sizeOfRequest)
        {
            cout<<"\nno crlf after headers";
            this->statusCode = 400;
            return false;
        }
        if(clientRequest[count] == '\r')
            crlf = 0;
        else if(clientRequest[count] == '\n')
            crlf = 1;
    }

    // Extracting the message body
    if(count != sizeOfRequest)
    {
        start = count;
        while(count < sizeOfRequest)
            count++;
        this->clientMsg = new char[count-start];
        for(int i = start; i < count; i++)
            this->clientMsg[i-start] = clientRequest[i];
        this->sizeOfResponse = count - start;
    }

    this->statusCode = 200;
    return true;
}
Ejemplo n.º 10
0
void InterpretArchetype(FILE * fpArch)
{
    char buffer[MAX_LENGTH];
    ARCHETYPE * pNewArchetype = malloc(sizeof(ARCHETYPE));
    COMPONENT * pCurrComp = NULL;
    pNewArchetype->Name = "Untitled";
    pNewArchetype->nextArchetype = NULL;
    pNewArchetype->nextComponent = NULL;
    pNewArchetype->pGame = pTheGame;
    pNewArchetype->pUnit = NULL;
    pNewArchetype->nextArchetype = pTheGame->nextArchetype;
    pTheGame->nextArchetype = pNewArchetype;
    while (!feof(fpArch))
    {
        if (fgets(buffer, MAX_LENGTH, fpArch))
        {
            char question[MAX_LENGTH];
            int inputInt = 0;
            float inputFloat = 0.0f;
            VECTOR inputVector = NewVector(0, 0);
            AddNull(buffer);
            if (buffer[0] != '#' && strlen(buffer) > 2)
            {
                sscanf(buffer, "%s", &question);
                if (myStrCmp(question, "Name") <= 0)
                {
                    char nameInput[MAX_LENGTH];
                    sscanf(buffer, "Name = %s", nameInput);
                    pNewArchetype->Name = myStrCpy(nameInput);
                    continue;
                }

                if (myStrCmp(question, "Tag") <= 0)
                {
                    char tagInput[MAX_LENGTH];
                    sscanf(buffer, "Tag = %s", tagInput);
                    pNewArchetype->Tag = GetTagFromString(tagInput);
                    continue;
                }

                if (myStrCmp(question, "COMPONENT") <= 0)
                {
                    COMPONENTTYPE theType;
                    char typeInput[MAX_LENGTH];
                    sscanf(buffer, "COMPONENT |%s|", &typeInput);
                    if (myStrCmp(typeInput, "Sprite") <= 0) theType = Sprite;
                    if (myStrCmp(typeInput, "Mesh") <= 0) theType = Mesh;
                    if (myStrCmp(typeInput, "Behavior") <= 0) theType = Behavior;
                    if (myStrCmp(typeInput, "Physics") <= 0) theType = Physics;
                    if (myStrCmp(typeInput, "Collider") <= 0) theType = Collider;
                    if (myStrCmp(typeInput, "KSound") <= 0) theType = KSound;


                    pCurrComp = AddComponent(pNewArchetype, theType);
                    continue;
                }

                if (pCurrComp)
                {
                    if (pCurrComp->Type == Mesh)
                    {
                        MESH * pMesh = (MESH*)pCurrComp->pStruct;
                        if (myStrCmp(question, "Size") <= 0)
                        {
                            sscanf(buffer, "\tSize = (%f, %f)", &inputVector.x, &inputVector.y);
                            pMesh->Size = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Color") <= 0)
                        {
                            COLOR inputColor;
                            sscanf(buffer, "\tColor = (%f, %f, %f, %f)", &inputColor.r, &inputColor.g, &inputColor.b, &inputColor.a);
                            pMesh->Color = inputColor;
                            continue;
                        }

                        if (myStrCmp(question, "Opacity") <= 0)
                        {
                            sscanf(buffer, "\tOpacity = %f", &inputFloat);
                            pMesh->Opacity = inputFloat;
                            continue;
                        }
                    }

                    if (pCurrComp->Type == Behavior)
                    {
                        BEHAVIOR * pBehavior = (BEHAVIOR*)pCurrComp->pStruct;
                        if (myStrCmp(question, "BehaviorScript") <= 0)
                        {
                            char scriptInput[MAX_LENGTH];
                            sscanf(buffer, "\tBehaviorScript = %s", &scriptInput);
                            pBehavior->BehaviorScript = GetBehaviorFromString(scriptInput);
                            continue;
                        }
                    }

                    if (pCurrComp->Type == Physics)
                    {
                        PHYSICS * pPhysics = (PHYSICS*)pCurrComp->pStruct;
                        if (myStrCmp(question, "Gravity") <= 0)
                        {
                            sscanf(buffer, "\tGravity = %f", &inputFloat);
                            pPhysics->Gravity = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "MaxSpeed") <= 0)
                        {
                            sscanf(buffer, "\tMaxSpeed = %f", &inputFloat);
                            pPhysics->MaxSpeed = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Friction") <= 0)
                        {
                            sscanf(buffer, "\tFriction = %f", &inputFloat);
                            pPhysics->Friction = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Velocity") <= 0)
                        {
                            sscanf(buffer, "\tVelocity = (%f, %f)", &inputVector.x, &inputVector.y);
                            pPhysics->Velocity = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Acceleration") <= 0)
                        {
                            sscanf(buffer, "\tAcceleration = (%f, %f)", &inputVector.x, &inputVector.y);
                            pPhysics->Acceleration = inputVector;
                            continue;
                        }
                    }

                    if (pCurrComp->Type == Collider)
                    {
                        COLLIDER * pCollider = (COLLIDER*)pCurrComp->pStruct;

                        if (myStrCmp(question, "Offset") <= 0)
                        {
                            sscanf(buffer, "\tOffset = (%f, %f)", &inputVector.x, &inputVector.y);
                            pCollider->Offset = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Height") <= 0)
                        {
                            sscanf(buffer, "\tHeight = %f", &inputFloat);
                            pCollider->Height = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Width") <= 0)
                        {
                            sscanf(buffer, "\tWidth = %f", &inputFloat);
                            pCollider->Width = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "IsGhosted") <= 0)
                        {
                            sscanf(buffer, "\tIsGhosted = %i", &inputInt);
                            pCollider->IsGhosted = inputInt;
                            continue;
                        }
                    }

                    if (pCurrComp->Type == KSound)
                    {
                        KSOUND * pSound = (KSOUND*)pCurrComp->pStruct;

                        if (myStrCmp(question, "Volume") <= 0)
                        {
                            sscanf(buffer, "\tVolume = %f", &inputFloat);
                            pSound->Volume = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Positional") <= 0)
                        {
                            sscanf(buffer, "\tPositional = %i", &inputInt);
                            pSound->Positional = inputInt;
                            continue;
                        }

                        if (myStrCmp(question, "MaxReach") <= 0)
                        {
                            sscanf(buffer, "\tMaxReach = %f", &inputFloat);
                            pSound->MaxReach = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "SoundFile") <= 0)
                        {
                            char scriptInput[MAX_LENGTH];
                            sscanf(buffer, "\tSoundFile = %s", &scriptInput);
                            pSound->SoundFile = scriptInput;
                            continue;
                        }

                        if (myStrCmp(question, "PlayOnStart") <= 0)
                        {
                            sscanf(buffer, "\tPlayOnStart = %i", &inputInt);
                            pSound->PlayOnStart = inputInt;
                            continue;
                        }

                        // TODO : Add the rest of the params.
                    }

                    if (pCurrComp->Type == Sprite)
                    {
                        SPRITE * pSprite = (SPRITE*)pCurrComp->pStruct;
                        if (myStrCmp(question, "TextureFile") <= 0)
                        {
                            int temp;
                            char textureInput[MAX_LENGTH];
                            sscanf(buffer, "\tTextureFile = %i , ", &temp);
                            MultipleAnimations(buffer, temp, pSprite);
                            continue;
                        }

                        if (myStrCmp(question, "Animated") <= 0)
                        {
                            sscanf(buffer, "\tAnimated = %i", &inputInt);
                            pSprite->Animated = inputInt;
                            continue;
                        }

                        if (myStrCmp(question, "RowCol") <= 0)
                        {
                            sscanf(buffer, "\tRowCol = (%f, %f)", &inputVector.x, &inputVector.y);
                            pSprite->RowCol = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Offset") <= 0)
                        {
                            sscanf(buffer, "\tOffset = (%f, %f)", &inputVector.x, &inputVector.y);
                            pSprite->Offset = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "AnimationSpeed") <= 0)
                        {
                            sscanf(buffer, "\tAnimationSpeed = %f", &inputFloat);
                            pSprite->AnimationSpeed = inputFloat;
                            continue;
                        }
                    }

                    if (myStrCmp(question, "EndComponent") <= 0)
                    {
                        pCurrComp = NULL;
                        continue;
                    }
                }
            }
        }
    }
}
Ejemplo n.º 11
0
void InterpretLevel(FILE * fpLevel)
{
    char buffer[MAX_LENGTH];
    LEVEL * pNewLevel = malloc(sizeof(LEVEL));
    CAMERA * pCam = malloc(sizeof(CAMERA));
    UNIT * pCurrUnit = NULL;
    pCam->Position = NewVector(0, 0);
    pCam->Zoom = 48;
    pNewLevel->Name = "Untitled";
    pNewLevel->Order = 0;
    pNewLevel->pCamera = pCam;
    pNewLevel->nextUnit = NULL;
    pNewLevel->pGame = pTheGame;
    pNewLevel->nextLevel = pTheGame->nextLevel;
    pTheGame->nextLevel = pNewLevel;
    while (!feof(fpLevel))
    {
        if (fgets(buffer, MAX_LENGTH, fpLevel))
        {
            char question[MAX_LENGTH];
            int inputInt = 0;
            float inputFloat = 0.0f;
            VECTOR inputVector = NewVector(0, 0);

            AddNull(buffer);
            if (buffer[0] != '#' && strlen(buffer) > 2)
            {
                sscanf(buffer, "%s", &question);
                if ((myStrCmp(question, "Name") <= 0) && pCurrUnit == NULL)
                {
                    char nameInput[MAX_LENGTH];
                    sscanf(buffer, "Name = %s", nameInput);
                    pNewLevel->Name = myStrCpy(nameInput);
                    continue;
                }

                if (myStrCmp(question, "Order") <= 0)
                {
                    char nameInput[MAX_LENGTH];
                    sscanf(buffer, "Order = %i", &inputInt);
                    pNewLevel->Order = inputInt;
                    continue;
                }

                if (myStrCmp(question, "UNIT") <= 0)
                {
                    char archInput[MAX_LENGTH];
                    char nameInput[MAX_LENGTH];
                    ARCHETYPE * pArchetype = NULL;
                    sscanf(buffer, "UNIT < %s > %s", &archInput, &nameInput);
                    pArchetype = FindArchetypeByName(pTheGame, archInput);
                    pCurrUnit = AddUnit(pNewLevel, pArchetype, myStrCpy(nameInput));
                    continue;
                }

                if (pCurrUnit)
                {
                    if (myStrCmp(question, "Tag") <= 0)
                    {
                        char tagInput[MAX_LENGTH];
                        sscanf(buffer, "\tTag = %s", tagInput);
                        pCurrUnit->Tag = GetTagFromString(tagInput);
                        continue;
                    }

                    if (myStrCmp(question, "InitialPosition") <= 0)
                    {
                        sscanf(buffer, "\tInitialPosition = (%f, %f)", &inputVector.x, &inputVector.y);
                        pCurrUnit->pInitTransform->Position = inputVector;
                        continue;
                    }

                    if (myStrCmp(question, "InitialRotation") <= 0)
                    {
                        sscanf(buffer, "\tInitialRotation = %f", &inputFloat);
                        pCurrUnit->pInitTransform->Rotation = inputFloat;
                        continue;
                    }

                    if (myStrCmp(question, "InitialScale") <= 0)
                    {
                        sscanf(buffer, "\tInitialScale = (%f, %f)", &inputVector.x, &inputVector.y);
                        pCurrUnit->pInitTransform->Scale = inputVector;
                        continue;
                    }

                    if (myStrCmp(question, "VAR") <= 0)
                    {
                        VTYPE theType;
                        VAR * newVar;
                        char varInput[MAX_LENGTH];
                        char typeInput[MAX_LENGTH];
                        char dataInput[MAX_LENGTH];
                        void * data;
                        sscanf(buffer, "\tVAR %s : %s = %s", &varInput, &typeInput, &dataInput);
                        theType = GetVTypeFromString(typeInput);

                        newVar = AddUnitVar(theType, varInput, pCurrUnit);

                        if (theType == Float)
                        {
                            float x;
                            sscanf(dataInput, "%f", &x);
                            data = malloc(sizeof(x));
                            *((float*)newVar->Data) = x;
                        }
                        else if (theType == Int)
                        {
                            int x;
                            sscanf(dataInput, "%i", &x);
                            data = malloc(sizeof(x));
                            *(int*)newVar->Data = x;
                        }
                        else if (theType == Vector)
                        {
                            VECTOR x;
                            sscanf(dataInput, "(%f, %f)", &x.x, &x.y);
                            data = malloc(sizeof(x));
                            *(VECTOR*)newVar->Data = x;
                        }
                        else if (theType == String)
                        {
                            char * x;
                            x = myStrCpy(dataInput);
                            data = malloc(sizeof(x));
                            *(char**)newVar->Data = x;
                        }
                        else if (theType == Bool)
                        {
                            BOOL x;
                            sscanf(dataInput, "%i", &x);
                            data = malloc(sizeof(x));
                            *(BOOL*)newVar->Data = x;
                        }
                        else if (theType == Color)
                        {
                            COLOR x;
                            sscanf(dataInput, "(%f, %f, %f, %f)", &x.r, &x.g, &x.b, &x.a);
                            data = malloc(sizeof(x));
                            *(COLOR*)newVar->Data = x;
                        }
                        else if (theType == Char)
                        {
                            char x;
                            sscanf(dataInput, "%c", &x);
                            data = malloc(sizeof(x));
                            *(char*)newVar->Data = x;
                        }
                        else if (theType == Matrix)
                        {
                            MATRIX x;
                            sscanf(dataInput, "{ {%f, %f, %f} {%f, %f, %f} {%f, %f, %f} }",
                                   &x.m[0][0], &x.m[0][1], &x.m[0][2],
                                   &x.m[1][0], &x.m[1][1], &x.m[1][2],
                                   &x.m[2][0], &x.m[2][1], &x.m[2][2]);
                            data = malloc(sizeof(x));
                            *(MATRIX*)newVar->Data = x;
                        }


                    }
                }


                if (myStrCmp(question, "EndUnit") <= 0)
                {

                    pCurrUnit = NULL;
                    continue;
                }

            }
        }
    }
}
static setStatus        listNormaliseOrDuplicates(set setA, myBool Normalise) {
// spec
//  o IN-PLACE normalisation (or listDuplicates) of a set - ie I will write to *setA !
//  o Either 'normalise' functionality -or- reports duplicates, dependent on myBool Normalise
// spec - Normalise
//   (1) Order, (2) Reduce WS to single char, (3) remove duplicates, 
// spec - Duplicates
//   (1) Order, (2) Reduce WS to single char, (3) report only duplicates ((single) entry *only* for those duplicated)
// Design
//   o Take a temporary copy of the supplied string, into local array.
//   o Create local array of ptrs of posn of each token (member) within the copy of the string.
//   o Sort the array of ptrs; 
//   o Generate new string(normalised or duplicates) at location pointed to by original string (formal param),

	SL64 MAX_MEMBERS_X_2=2 * setImp.setMaxMembers;  
// #define	MAX_MEMBERS_X_2  (2 * setImp.setMaxMembers)

	UC8 *tT[MAX_MEMBERS_X_2]; // token Table of ptrs to start of each token
	int tTindex=-1;                  // Index into tT
	int numTokens;                   // Number of tokens discovered

	UC8 sCopy[setImp.setMaxChars]; // Copy of supplied set. Use of strtok damages the supplied string.
	UC8 *aMember;                   // a token       

	int pass;                        // Multiple passes within the sort function...

	// Deal with some exceptional conditions
	if (!setA)             return setBadSet;  // No set supplied
	if (!*setA)            return setOK;      // Empty set supplied
	if (isBadLength(setA)) return setBadSet;  // Set TOO large
	if (setCardinal(setA) > MAX_MEMBERS_X_2) return setBadSet;  // Set TOO many members

	// Generate tT - Create this table of ptrs 
	(void) strncpy(sCopy, setA, setImp.setMaxChars);        
	do {
		aMember=strtok((tTindex == -1) ? sCopy : NULL, setImp.setWhiteSpaceChars);
		if (aMember) {
			if (tTindex == MAX_MEMBERS_X_2) 
				return setBadSet;
			else 
				tT[++tTindex]=aMember;   // Got one 
			}
	} while (aMember);

	// Really poor sort algorithm - but heh it's not production.
	// Could use stdlib's qsort.....
	numTokens=tTindex;
	for (pass=numTokens; pass >=0; pass--) {
		for (tTindex=numTokens; tTindex; tTindex--) {
			if (myStrCmp(tT[tTindex], tT[tTindex -1]) < 0) {
				swapCharPtr(&(tT[tTindex]), &(tT[tTindex -1]));
			}
		}
	}

	*setA=(UC8)0; // Bang !! - Sometimes you cannot write to here - unless its a TRUE set that I made....
	for (tTindex=0; tTindex <=numTokens; tTindex++) {
			// WHY? Get MISRA slap for side-effect ON RHS of &&
		if (Normalise != (tTindex && !myStrCmp(tT[tTindex], tT[tTindex -1])))  { 
			if (*setA) setA=strcat(setA, " ");  // Only pre-pend space on non-initial members
			setA=strcat(setA, tT[tTindex]); //zzz
		}
	}
	if (setCardinal(setA) > setImp.setMaxMembers) return setBadSet;  // Set TOO many members
	return setOK;
}
Ejemplo n.º 13
0
// interpret sequence data
char decode (char* input) {							
        
	if (myStrCmp(input,"10000100"))
	{
		return '1';
	}
	else if (myStrCmp(input,"01000100"))
	{
	   return '2';
	}
	else if (myStrCmp(input,"11000100"))
	{
	   return '3';
	}
	else if (myStrCmp(input,"00100100"))
	{
	   return '4';
	}
	else if (myStrCmp(input,"10100100"))
	{
	   return '5';
	}
	else if (myStrCmp(input,"01100100"))
	{
	   return '6';
	}
	else if (myStrCmp(input,"11100100"))
	{
	   return '7';
	}
	else if (myStrCmp(input,"00010100"))
	{
	   return '8';
	}
	else if (myStrCmp(input,"10010100"))
	{
	   return '9';
	}
	else if (myStrCmp(input,"00000100"))
	{
	   return '0';
	}
	else if (myStrCmp(input,"10011000"))
	{
	   return 'U';
	}
	else if (myStrCmp(input,"11111000"))
	{
	   return 'L';
	}
	else if (myStrCmp(input,"01111000"))
	{
	   return 'R';
	}
	else if (myStrCmp(input,"00011000"))
	{
	   return 'D';
	}
	else if (myStrCmp(input,"01100111")) // Delete
	{
	   return 'T';
	}
	else if (myStrCmp(input,"11001001")) // Last
	{			
			return 'S';
	}
	else
	{
		return 'P';
	}
 }
Ejemplo n.º 14
0
bool String::operator!=(const String& rhs)
{
  return myStrCmp(data, rhs.data) != 0;
}