Ejemplo n.º 1
0
    /** Skips a 3D vector */
    void skipVector(bitstream &stream, sendprop* pr) {
        skipFloat(stream, pr);
        skipFloat(stream, pr);

        if (pr->getFlags() & SPROP_NORMAL) {
            stream.seekForward(1);
        } else {
            skipFloat(stream, pr);
        }
    }
Ejemplo n.º 2
0
    void property::skip(bitstream& stream, sendprop* prop) {
        switch (prop->getType()) {
            // Skip over Integer
            case sendprop::T_Int:
                skipInt(stream, prop);
                break;

            // Skip over Float
            case sendprop::T_Float:
                skipFloat(stream, prop);
                break;

            // Skip over 3D Vector
            case sendprop::T_Vector:
                skipVector(stream, prop);
                break;

            // Skip 2D Vector
            case sendprop::T_VectorXY:
                skipVectorXY(stream, prop);
                break;

            // Skip String
            case sendprop::T_String:
                skipString(stream);
                break;

            // Skip Array
            case sendprop::T_Array:
                skipArray(stream, prop);
                break;

            // Skip 64 bit Integer
            case sendprop::T_Int64:
                skipInt64(stream, prop);
                break;

            default:
                BOOST_THROW_EXCEPTION( propertyInvalidType()
                    << (EArgT<1, uint32_t>::info(prop->getType()))
                );
                break;
        }
    }
Ejemplo n.º 3
0
/**
 * Parse the Aphelion element and return the stored value
 * @param str Pointer to a string structure
 * @return Returns the double value or -1.0 on failure. Aphelion should never be negative.
 **/
double extractAphelion( pstring str )
{
	char *temp = NULL;
	double aphelion = -1.0;
	int start = 0;
	int end = 0;

	/// These will be used specifically for the data
	int ps = 0;
	int pe = 0;

	if (str == NULL ) {
		return -1.0;
	}

	start = skipWhiteSpace(str);

	if ( !atChar( str, '{' ) ) {
		printf("!!Failed to locate opening brace\n");
		return aphelion;
	}

	/// Skip past the curly brace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip opening brace\n");
		return aphelion;
	}

	/// Skip any additional whitespace
	start = skipWhiteSpace(str);

	/// This should skip any to either whitespace or a closing '}'
	end = skipToNonAlphaNum( str );

	if ( end == -1 ) {
		printf("!!Failed to locate the end of the element id\n");
		return aphelion;
	}

	/// Copy the element id from the string
	temp = copyData( str, start, end );

	if ( temp == NULL ) {
		printf("!!Copy from @d to @d failed\n", start, end);
		return -1.0;
	}

	/// If the element id is not "Aphelion" then this is the wrong function
	if ( strcmp( temp, "Aphelion") != 0 ) {
		printf("!!Element id is not \"Aphelion\"\n");
		deallocate( temp, strlen(temp) + 1 );
		temp = NULL;
		return aphelion;
	}

	/// The buffer is no longer needed so free it
	deallocate(temp, strlen(temp) + 1);

	/// Skip to the end of the element id
	skipWhiteSpace( str );

	/// If it is not a closing brace then this is improperly formatted.
	if ( !atChar( str, '}' ) ) {
		printf("!!Failed to locate initial closing brace\n");
		return -1.0;
	}

	/// Skip the closing brace as well as any whitespace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip initial closing brace\n");
		return aphelion;
	}

	skipWhiteSpace( str );

	/// Copy the start index to store the data
	getIndex( str, &ps );

	/// The period data must be a float
	pe = skipFloat( str );

	if ( pe == -1 ) {
		printf("!!Failed to locate the end of the period data\n");
		return aphelion;
	}

	/// The rest of this code is a check to ensure proper formatting except for the copy data
	skipWhiteSpace( str );

	/// If this is not an opening curly brace then fail
	if ( !atChar( str, '{' ) ) {
		printf("!!Failed to locate the final opening brace\n");
		return -1.0;
	}

	/// Skip past the brace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip the final opening brace\n");
		return aphelion;
	}
	
	skipWhiteSpace(str);

	/// If this is not a # indicating the closing brace then fail
	if ( !atChar( str, '#' ) ) {
		printf("!!Failed to locate the closing mark\n");		
		return -1.0;
	}

	/// Skip past the # but save the start
	start = skipLength( str, 1 );

	if ( start == -1 ) {
		printf("!!Failed to skip closing mark\n");
		return aphelion;
	}

	end = skipToNonAlphaNum( str );

	if ( end == -1 ) {
		printf("!!Failed to locate the end of the closing element id\n");
		return -1.0;
	}
	
	temp = copyData( str, start, end );

#ifdef PATCHED
	if ( temp == NULL ) {
		return -1.0;
	}
#endif

	if ( strcmp( temp, "Aphelion") != 0 ) {
		printf("!!Invalid closing element id: @s\n", temp);
		deallocate(temp, strlen(temp)+1);
		return aphelion;
	}

	deallocate(temp, strlen(temp)+1);

	skipWhiteSpace( str );

	/// Check the final curly brace
	if ( !atChar( str, '}' ) ) {
		printf("!!Failed to locate final closing brace\n");
		return -1.0;
	}

	/// Skip past the closing brace
	skipLength( str, 1 );
		
	/// Copy the name element data
	temp = copyData( str, ps, pe );

	if ( temp == NULL ) {
		printf("!!Failed to copy period data\n");
		return -1;
	}

	aphelion = atof( temp );

	deallocate( temp, strlen(temp) + 1 );

	return aphelion;
}
Ejemplo n.º 4
0
/**
 * Parse the OrbitSpeed element and return the stored value
 * @param str Pointer to a string structure
 * @return Returns the double value or -1.0 on failure. Orbit speed should never be negative.
 **/
double extractOrbitSpeed( pstring str )
{
	char *temp = NULL;
	double speed = -1.0;
	register int start = 0;
	register int end = 0;
	int ss = 0;
	int se = 0;

	if (str == NULL ) {
		goto reterrvalue;	
	}

	start = skipWhiteSpace(str);

	if ( !(atChar( str, '{' ) & 1) ) {
		printf("!!Failed to locate opening brace\n");
		goto reterrspeed;
	}

	/// Skip past the curly brace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip opening brace\n");
		return speed;
	}

	/// Skip any additional whitespace
	start = skipWhiteSpace(str);

	/// This should skip any to either whitespace or a closing '}'
	end = skipToNonAlphaNum( str );

	if ( end == -1 ) {
		printf("!!Failed to locate the end of the element id\n");
		goto reterrvalue;
	}

	/// Copy the element id from the string
	temp = copyData( str, start, end );

	if ( temp == NULL ) {
		printf("!!Copy from @d to @d failed\n", start, end);
		return -1.0;
	}

	/// If the element id is not "OrbitSpeed" then this is the wrong function
	if ( strcmp( temp, "OrbitSpeed") != 0 ) {
		printf("!!Element id is not \"OrbitSpeed\"\n");
		bzero( temp, strlen(temp) );
		deallocate( temp, strlen(temp) + 1 );
		temp = NULL;
		goto reterrvalue;
	}

	/// The buffer is no longer needed so free it
	bzero( temp, strlen(temp) + 1 );
	deallocate(temp, strlen(temp) + 1);

	/// Skip to the end of the element id
	skipWhiteSpace( str );

	/// If it is not a closing brace then this is improperly formatted.
	if ( !atChar( str, '}' ) ) {
		printf("!!Failed to locate initial closing brace\n");
		goto reterrspeed;
	}

	/// Skip the closing brace as well as any whitespace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip initial closing brace\n");
		goto retspeed;
	}

	skipWhiteSpace( str );

	/// Copy the start index to store the data
	ss = str->index;

	/// The period data must be a float
	se = skipFloat( str );

	if (se == -1 ) {
		printf("!!Failed to locate the end of the period data\n");
		return -1.0;
	}

	/// The rest of this code is a check to ensure proper formatting except for the copy data
	skipWhiteSpace( str );

	/// If this is not an opening curly brace then fail
	if ( !atChar( str, '{' ) ) {
		printf("!!Failed to locate the final opening brace\n");
		goto reterrvalue;
	}

	/// Skip past the brace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip the final opening brace\n");
		goto reterrspeed;
	}
	
	skipWhiteSpace(str);

	/// If this is not a # indicating the closing brace then fail
	if ( !atChar( str, '#' ) ) {
		printf("!!Failed to locate the closing mark\n");		
		return -1.0;
	}

	/// Skip past the # but save the start
	start = skipLength( str, 1 );

	if ( start == -1 ) {
		printf("!!Failed to skip closing mark\n");
		goto reterrvalue;
	}

	end = skipToNonAlphaNum( str );

	if ( end == -1 ) {
		printf("!!Failed to locate the end of the closing element id\n");
		return -1.0;
	}
	
	temp = copyData( str, start, end );

#ifdef PATCHED
	if ( temp == NULL ) {
		return -1.0;
	}
#endif

	if ( strcmp( temp, "OrbitSpeed") != 0 ) {
		printf("!!Invalid closing element id: @s\n", temp);
		bzero(temp, strlen(temp) + 1 );
		deallocate(temp, strlen(temp)+1);
		return -1.0;
	}

	bzero( temp, strlen(temp) + 1 );
	deallocate(temp, strlen(temp)+1);

	skipWhiteSpace( str );

	/// Check the final curly brace
	if ( !atChar( str, '}' ) ) {
		printf("!!Failed to locate final closing brace\n");
		goto reterrspeed;
	}

	/// Skip past the closing brace
	skipLength( str, 1 );
		
	/// Copy the name element data
	temp = copyData( str, ss, se );

	if ( temp == NULL ) {
		printf("!!Failed to copy period data\n");
		goto retspeed;
	}

	speed = atof( temp );

	deallocate( temp, strlen(temp) + 1 );

	goto retspeed;

reterrvalue:
	return -1.0; 

reterrspeed:
	speed = -1.0;
	return speed;

retspeed:
	return speed;
}
Ejemplo n.º 5
0
/**
 * Parse the Border element and return a structure containing the data
 * @param str Pointer to a string structure
 * @return Returns a pointer to a border structure or NULL on failure
 **/
Border *extractBorder( pstring str )
{
	char *temp = NULL;
	pBorder bor = NULL;
	int start = 0;
	int end = 0;

	if (str == NULL ) {
		return bor;
	}

	/// Allocate a new border structure
	if ( allocate( sizeof(Border), 0, (void**)&bor) != 0 ) {
		bor = NULL;
		return bor;
	}

	skipWhiteSpace(str);

	/// If it does not open with a '{' then it is invalid.
	if ( !atChar( str, '{' ) ) {
		printf("!!Failed to locate opening brace\n");
		goto error;
	}

	/// Skip past the curly brace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip opening brace\n");
		goto error;
	}

	/// Skip any additional whitespace
	skipWhiteSpace(str);

	/// Save the index
	start = str->index;

	/// This should skip any to either whitespace or a closing '}'
	end = skipAlpha( str );

	if ( end == -1 ) {
		printf("!!Failed to locate the end of the element id\n");
		goto error;
	}

	/// If start and end are then same then it is an invalid character
	if ( start == end ) {
		goto error;
	}

	/// Copy the element id from the string
	temp = copyData( str, start, end );

	if ( temp == NULL ) {
		printf("!!Copy from @d to @d failed\n", start, end);
		goto error;
	}

	/// If the element id is not "Border" then this is the wrong function
	if ( strcmp( temp, "Border") != 0 ) {
		printf("!!Element id is not \"Border\"\n");
		deallocate( temp, strlen(temp) + 1 );
		temp = NULL;
		goto error;
	}

	/// The buffer is no longer needed so free it
	deallocate(temp, strlen(temp) + 1);

	/// Skip to the end of the element id
	skipWhiteSpace( str );

	/// If it is not a closing brace then this is improperly formatted.
	if ( !atChar( str, '}' ) ) {
		printf("!!Failed to locate initial closing brace\n");
		goto error;
	}

	/// Skip the closing brace as well as any whitespace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip initial closing brace\n");
		goto error;
	}

	start = skipWhiteSpace( str );

	/// The border data must be a float
	end = skipFloat( str );

	if ( start == end ) {
		printf("!!Failed to locate first lat\n");
		goto error;
	}

	if ( end == -1 ) {
		printf("!!Failed to locate the end of the first latitude float\n");
		goto error;
	}

	temp = copyData( str, start, end );

	if (temp == NULL ) {
		printf("!!Failed to copy first latitude float\n");
		goto error;
	}

	/// Convert the first value
	bor->latStart = atof( temp );

	deallocate( temp, (end-start) + 1 );

	/// Skip to the next value
	start = skipWhiteSpace( str );

	end = skipFloat(str);

	if ( start == end ) {
		printf("!!Failed to locate first long\n");
		goto error;
	}

	if ( start == -1 || end == -1 ) {
		printf("!!Failed to locate first longitude float\n");
		goto error;
	}

	temp = copyData( str, start, end );

	if ( temp == NULL ) {
		printf("!!Failed to copy first longitude float\n");
		goto error;
	}

	/// Convert the first long
	bor->lngStart = atof( temp );

	deallocate( temp, (end-start) + 1 );

	/// Skip to the next value
	start = skipWhiteSpace( str );

	end = skipFloat(str);

	if ( start == end ) {
		printf("!!Failed to locate second lat\n");
		goto error;
	}

	if ( start == -1 || end == -1 ) {
		printf("!!Failed to locate second latitude float\n");
		goto error;
	}

	temp = copyData( str, start, end );

	if ( temp == NULL ) {
		printf("!!Failed to copy second latitude float\n");
		goto error;
	}

	/// Convert the second lat
	bor->latEnd = atof( temp );

	deallocate( temp, (end-start) + 1 );

	/// Skip to the next value
	start = skipWhiteSpace( str );

	end = skipFloat(str);

	if ( start == end ) {
		printf("!!Failed to locate second long\n");
		goto error;
	}

	if ( start == -1 || end == -1 ) {
		printf("!!Failed to locate second longitude float\n");
		goto error;
	}

	temp = copyData( str, start, end );

	if ( temp == NULL ) {
		printf("!!Failed to copy second longitude float\n");
		goto error;
	}

	/// Convert the second long
	bor->lngEnd = atof( temp );

	deallocate( temp, (end-start) + 1 );

	skipWhiteSpace( str );

	/// If this is not an opening curly brace then fail
	if ( !atChar( str, '{' ) ) {
		printf("!!Failed to locate the final opening brace\n");
		goto error;
	}

	/// Skip past the brace
	if ( skipLength( str, 1 ) == -1 ) {
		printf("!!Failed to skip the final opening brace\n");
		goto error;
	}
	
	skipWhiteSpace(str);

	/// If this is not a # indicating the closing brace then fail
	if ( !atChar( str, '#' ) ) {
		printf("!!Failed to locate the closing mark\n");		
		goto error;
	}

	/// Skip past the # but save the start
	start = skipLength( str, 1 );

	if ( start == -1 ) {
		printf("!!Failed to skip closing mark\n");
		goto error;
	}

	end = skipAlpha( str );

	if ( end == -1 ) {
		printf("!!Failed to locate the end of the closing element id\n");
		goto error;
	}
	
	temp = copyData( str, start, end );

#ifdef PATCHED
	if ( temp == NULL ) {
		goto error;
	}
#endif

	if ( strcmp( temp, "Border") != 0 ) {
		printf("!!Invalid closing element id: @s\n", temp);
		deallocate(temp, strlen(temp)+1);
		goto error;
	}

	deallocate(temp, strlen(temp)+1);

	skipWhiteSpace( str );

	/// Check the final curly brace
	if ( !atChar( str, '}' ) ) {
		printf("!!Failed to locate final closing brace\n");
		goto error;
	}

	/// Skip past the closing brace
	skipLength( str, 1 );

	/// Everything succeeded, skip error
	goto fin;
		
error:
	deallocate( bor, sizeof(Border) );
	bor = NULL;

fin:
	return bor;
}
Ejemplo n.º 6
0
 /** Skips a 2D vector */
 void skipVectorXY(bitstream &stream, sendprop* pr) {
     skipFloat(stream, pr);
     skipFloat(stream, pr);
 }