Example #1
0
int main(int argc, char* argv[])
{
    if (argc > 0)
    {
        std::string path(argv[0]);
        size_t filePos(path.find_last_of("/\\"));

        jlug::Constants::getInstance().set("exec", path);

        if (filePos != std::string::npos)
            jlug::Constants::getInstance().set("path", 
                    path.substr(0, filePos)+'/');
        else
            jlug::Constants::getInstance().set("path", "./");
        
        for (int i(0); i < argc ; ++i)
        {
            std::ostringstream oss;
            oss << "argv[" << i << "]";
            jlug::Constants::getInstance().set(oss.str(), argv[i]);
        }
    }
    else
    {
        jlug::Constants::getInstance().set("argv[0]", "");
        jlug::Constants::getInstance().set("exec", "");
        jlug::Constants::getInstance().set("path", "./");
    }

    jlug::Constants::getInstance().set("charsets", "../res/charsets/");

    game();
    return 0;
}
Example #2
0
bool ejson::internal::Document::parse(const std::string& _data) {
	EJSON_VERBOSE("Start parsing document (type: string) size=" << _data.size());
	clear();
	ejson::FilePos filePos(1,0);
	size_t parsePos = 0;
	return iParse(_data, parsePos, filePos, *this);
}
Example #3
0
void Foam::functionEntries::ifeqEntry::skipUntil
(
    DynamicList<filePos>& stack,
    const dictionary& parentDict,
    const word& endWord,
    Istream& is
)
{
    while (!is.eof())
    {
        token t;
        readToken(t, is);
        if (t.isWord())
        {
            if (t.wordToken() == "#if" || t.wordToken() == "#ifeq")
            {
                stack.append(filePos(is.name(), is.lineNumber()));
                skipUntil(stack, parentDict, "#endif", is);
                stack.remove();
            }
            else if (t.wordToken() == endWord)
            {
                return;
            }
        }
    }

    FatalIOErrorInFunction(parentDict)
        << "Did not find matching " << endWord << exit(FatalIOError);
}
CORBA::ULong File_impl::_local_sizeOf ()throw (CORBA::SystemException,
                                        CF::FileException)
{
    TRACE_ENTER(File_impl)

    CORBA::ULong fileSize(0), filePos(0);

    int fsOpSuccessAttempts = 0;
    bool fsOpSuccess = false;
    while (!fsOpSuccess) {
        try {
            filePos = f.tellg();
            f.seekg(0, std::ios::end);
            fileSize = f.tellg();
            f.seekg(filePos);

            fsOpSuccess = true;

            LOG_TRACE(File_impl, "In sizeOf with size = " << fileSize);

        } catch ( const fs::filesystem_error& ex ) {
            LOG_WARN(File_impl, "Error in filesystem: "<<ex.what()<<". Attempting again")
            fsOpSuccessAttempts++;
            if (fsOpSuccessAttempts == 10)
                { break; }
            usleep(10000);
        } catch ( ... ) {
            LOG_WARN(File_impl, "Caught an unhandled file system exception. Attempting again")
            fsOpSuccessAttempts++;
            if (fsOpSuccessAttempts == 10)
                { break; }
            usleep(10000);
        }
    }
    if (!fsOpSuccess) {
        LOG_ERROR(File_impl, "Error checking the size of file, " << fName);
        throw (CF::File::IOException (CF::CF_EIO, "[File_impl::sizeOf] Error checking the size of file"));
    }

    TRACE_EXIT(File_impl)
    return fileSize;
}
Example #5
0
bool Foam::functionEntries::ifeqEntry::execute
(
    DynamicList<filePos>& stack,
    dictionary& parentDict,
    Istream& is
)
{
    const label nNested = stack.size();

    stack.append(filePos(is.name(), is.lineNumber()));

    // Read first token and expand any string
    token cond1(is);
    cond1 = expand(parentDict, cond1);

    // Read second token and expand any string
    token cond2(is);
    cond2 = expand(parentDict, cond2);

    const bool equal = equalToken(cond1, cond2);

    // Info<< "Using #" << typeName << " " << cond1
    //     << " == " << cond2
    //     << " at line " << stack.last().second()
    //     << " in file " <<  stack.last().first() << endl;

    bool ok = ifeqEntry::execute(equal, stack, parentDict, is);

    if (stack.size() != nNested)
    {
        FatalIOErrorInFunction(parentDict)
            << "Did not find matching #endif for condition starting"
            << " at line " << stack.last().second()
            << " in file " <<  stack.last().first() << exit(FatalIOError);
    }

    return ok;
}
Example #6
0
bool Foam::functionEntries::ifeqEntry::execute
(
    const bool doIf,
    DynamicList<filePos>& stack,
    dictionary& parentDict,
    Istream& is
)
{
    if (doIf)
    {
        evaluate(true, stack, parentDict, is);
    }
    else
    {
        // Fast-forward to #else
        token t;
        while (!is.eof())
        {
            readToken(t, is);
            if
            (
                t.isWord()
             && (t.wordToken() == "#if" || t.wordToken() == "#ifeq")
            )
            {
                stack.append(filePos(is.name(), is.lineNumber()));
                skipUntil(stack, parentDict, "#endif", is);
                stack.remove();
            }
            else if (t.isWord() && t.wordToken() == "#else")
            {
                break;
            }
            else if (t.isWord() && t.wordToken() == "#elif")
            {
                // const label lineNo = is.lineNumber();

                // Read line
                string line;
                dynamic_cast<ISstream&>(is).getLine(line);
                line += ';';
                IStringStream lineStream(line);
                const primitiveEntry e("ifEntry", parentDict, lineStream);
                const Switch doIf(e.stream());

                if (doIf)
                {
                    // Info<< "Using #elif " << doIf << " at line " << lineNo
                    //     << " in file " << is.name() << endl;
                    break;
                }
            }
            else if (t.isWord() && t.wordToken() == "#endif")
            {
                stack.remove();
                break;
            }
        }

        if (t.wordToken() == "#else")
        {
            // Evaluate until we hit #endif
            evaluate(false, stack, parentDict, is);
        }
        else if (t.wordToken() == "#elif")
        {
            // Evaluate until we hit #else or #endif
            evaluate(true, stack, parentDict, is);
        }
    }
    return true;
}