///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetVector2( Vector2& vec2 )
{
    std::string string = "";
    if (PeekString( string ))
    {
        if (IsFloat( string ))
        {
            vec2.x = strtof( string.c_str(), nullptr );
            m_currentIndex++;
        }
        else
            return false;
    }

    if (PeekString( string ))
    {
        if (IsFloat( string ))
        {
            vec2.y = strtof( string.c_str(), nullptr );
            m_currentIndex++;
            return true;
        }
        else
            return false;
    }
    return false;
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetColorFromInts( Rgba& color )
{
    std::string string = "";


    if (PeekString( string ))
    {
        if (IsInt( string ))
        {
            color.r = (char)strtol( string.c_str(), nullptr, 10 );
            m_currentIndex++;
        }
        else
            return false;
    }
    if (PeekString( string ))
    {
        if (IsInt( string ))
        {
            color.g = (char)strtol( string.c_str(), nullptr, 10 );
            m_currentIndex++;
        }
        else
            return false;
    }

    if (PeekString( string ))
    {
        if (IsInt( string ))
        {
            color.b = (char)strtol( string.c_str(), nullptr, 10 );
            m_currentIndex++;
        }
        else
            return false;
    }

    if (PeekString( string ))
    {
        if (IsInt( string ))
        {
            color.a = (char)strtol( string.c_str(), nullptr, 10 );
            m_currentIndex++;
            return true;
        }
        else
            return false;
    }
    return false;
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetString( std::string& string )
{
    // TODO: Change this function to find opening and closing quotations to denote a string

    if (PeekString( string ))
    {
        m_currentIndex++;
        return true;
    }

    return false;
}
Beispiel #4
0
/* MakeSpecifiedProcedureName: make a unique name for a specified parameterised procedure.
   The name will be of the form baseName-<unique-integer> */
tIdent MakeSpecifiedProcedureName (tIdent baseName)
{
    static unsigned procedureCount = 0;
    char *baseNameStr = PeekString (baseName);
    unsigned length = strlen (baseNameStr) + 20;
    tIdent ret;

    Ptrchar name = NEW_ARRAY (char, length);

    sprintf (name, "%s-%d", baseNameStr, procedureCount);
    procedureCount++;
    ret = MakeIdent1 (name);
    FREE_ARRAY (char, length, name);

    return ret;
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetDouble( double& doub )
{
    std::string string = "";
    if (PeekString( string ))
    {
        if (IsDouble( string ))
        {
            doub = strtod( string.c_str(), nullptr );
            m_currentIndex++;
            return true;
        }

        return false;
    }
    return false;
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetInt( int& integer )
{
    std::string string = "";
    if (PeekString( string ))
    {
        if (IsInt( string ))
        {
            integer = strtol( string.c_str(), nullptr, 10 );
            m_currentIndex++;
            return true;
        }

        return false;
    }
    return false;
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetFloat( float& flt )
{
    std::string string = "";
    if (PeekString( string ))
    {
        if (IsFloat( string ))
        {
            flt = strtof( string.c_str(), nullptr );
            m_currentIndex++;
            return true;
        }

        return false;
    }
    return false;
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetBool( bool& boolean )
{
    std::string string = "";
    if (PeekString( string ))
    {
        string = ConvertToLowerCase( string );
        if (string == "true")
            boolean = true;
        else if (string == "false")
            boolean = false;

        m_currentIndex++;
        return true;
    }

    return false;
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetColorFromString( Rgba& color )
{
    std::string string = "";
    if (PeekString( string ))
    {
        string = ConvertToLowerCase( string );
        if (string == "red")
            color = Rgba::RED;

        else if (string == "blue")
            color = Rgba::BLUE;

        else if (string == "green")
            color = Rgba::GREEN;

        else if (string == "black")
            color = Rgba::BLACK;

        else if (string == "white")
            color = Rgba::WHITE;

        else if (string == "aqua")
            color = Rgba::AQUA;

        else if (string == "orange")
            color = Rgba::ORANGE;

        else if (string == "yellow")
            color = Rgba::YELLOW;

        else if (string == "grey")
            color = Rgba::GREY;

        else if (string == "magenta")
            color = Rgba::MAGENTA;

        else
            return false;

        m_currentIndex++;
        return true;
    }

    return false;
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool DeveloperConsoleArguments::GetColorFromHex( Rgba& color )
{
    std::string string = "";
    if (PeekString( string ))
    {
        if (IsHexInt( string ))
        {
            unsigned int colorVal = strtoul( string.c_str(), nullptr, 0 );
            color = Rgba( colorVal );
            m_currentIndex++;
            return true;
        }

        else
            return false;
    }

    return false;
}
Beispiel #11
0
 std::string PopString(Machine& machine)
 {
     std::string s = PeekString(machine, 0);
     machine.stack.Pop();
     return s;
 }
Beispiel #12
0
bool ParseMeal(std::ifstream & infile, Meal & meal)
{
	if (true == infile.eof())
	{
		return false;
	}

	const int MAX_TOKEN = 256;
	std::string line;
	std::string tokenBuf(MAX_TOKEN, '\0');

	const char * delim = ",\n";
	
	do
	{
		// read line
		std::getline(infile, line);

		// grab first token
		char * token = nullptr;
		char * nextToken = nullptr;
		token = strtok_s(&line[0], delim, &nextToken);

		bool mealTypeParsed = false;
		bool caloriesParsed = false;

		// locals for meal header row
		MealType mealType = MealType::MEAL_BREAKFAST;
		float calories;

		// walk the line
		while (token != nullptr && nextToken != nullptr)
		{
			// valid meal type?
			std::string tokTrimmed = token;
			trim_str(tokTrimmed);

			String tokStr(ConvertStringToWString(tokTrimmed));

			if (true == StringToMealType(tokStr, mealType))
			{
				mealTypeParsed = true;
			}
			else if (true == mealTypeParsed)
			{
				calories = (float)atof(token);

				// if calories column is empty or whitespace, or an invalid number, skip this meal
				if (calories > 0)
				{
					caloriesParsed = true;
					break;
				}
			}

			// next token plz
			token = strtok_s(nullptr, delim, &nextToken);
		}

		// if we didn't parse a meal line, fail
		if (false == mealTypeParsed || false == caloriesParsed)
		{
			// try the next line
			continue;
		}

		assert(true == IsValidMealType(mealType) && calories > 0);

		// parse as many food items are below the meal line
		Meal workingMeal(mealType, calories);

		FoodItem foodItem;
		while (false == infile.eof() && true == ParseFoodItem(infile, foodItem))
		{
			workingMeal.AddFoodItem(foodItem);

			// make sure this line isn't starting a new meal
			std::string peekFirstToken;
			if (false == PeekString(infile, delim, peekFirstToken))
			{
				// couldn't read a token, done with this meal
				return true;
			}

			trim_str(peekFirstToken);
			String strFirstToken(ConvertStringToWString(peekFirstToken));
			MealType nextTokMealType;
			if (true == StringToMealType(strFirstToken, nextTokMealType))
			{
				// next token is a meal type, so we're done with this meal
				break;
			}
		}

		// meal is valid
		meal = workingMeal;
		
		break;
	} 
	while (false == infile.eof());

	return true;
}
Beispiel #13
0
/* LogError : `log' an error at the given position and of the given type, file and lineNo
   should contain the __FILE__ and __LINE__ values at point of invocation of LOG_ERROR.
   Function can also (optionally, NULL == don't bother) print out the function name of
   the error */
void LogError (ErrorType error, tIdent str, tPosition position, char *file, const char *function, int lineNo)
{
    static int lastContextNumber = -1;
    bool printErrorContext = true;

    if (SourceDecorateErrorMessages) /* Decorate error messages with balsa-c source position */
    {
        if (function)
            fprintf (stderr, "[%s:%s:%d] ", file, function, lineNo);
        else
            fprintf (stderr, "[%s:%d] ", file, lineNo);
    }

    WriteErrorPosition (stderr, position);
    switch (BalsacErrors[error].errorClass)
    {
    case ReportErrorClass:
        fprintf (stderr, " report: ");
        printErrorContext = false;
        break;
    case NoteErrorClass:
        fprintf (stderr, " note: ");
        break;
    case WarningErrorClass:
        fprintf (stderr, " warning: ");
        WarningCount++;
        break;
    case DeprecatedFeatureErrorClass:
        fprintf (stderr, " deprecation: ");
        WarningCount++;
        break;
    case FatalErrorClass:
        fprintf (stderr, " fatal: ");
        ErrorCount++;
        break;
    default:
        putc (' ', stderr);
        ErrorCount++;
        break;
    }
    if (str == NoIdent)
        fprintf (stderr, "%s\n", BalsacErrors[error].prefixString);
    else
    {
        if (*(BalsacErrors[error].prefixString) != '\0')
            fprintf (stderr, "%s ", BalsacErrors[error].prefixString);
        fprintf (stderr, "`%s' %s\n", PeekString (str), BalsacErrors[error].postfixString);
    }

    if (printErrorContext)
    {
        if (!GlobalErrorContext || lastContextNumber != CAR (GlobalErrorContext)->contextNumber)
        {
            PtrErrorContextList context = GlobalErrorContext;

            while (context)
            {
                fprintf (stderr, "  ");
                WriteErrorPosition (stderr, context->body->position);
                fprintf (stderr, " ");
                fprintf (stderr, "%s", context->body->str);
                context = CDR (context);
                fprintf (stderr, "\n");
            }
        } else
        {
            fprintf (stderr, "  (same context as previous message)\n");
        }

        if (GlobalErrorContext)
            lastContextNumber = CAR (GlobalErrorContext)->contextNumber;
    }

    if (BalsacErrors[error].errorClass == FatalErrorClass)
        ReportErrors ();
}