コード例 #1
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
    boost::any visit( FunctionDeclaration functionDeclaration ) {

        extractToken( TokenType::KeywordFunction );

        functionDeclaration->identifier = parseIdentifier();

        extractToken( TokenType::PunctuatorOpeningParenthesis );

        while( !currentTokenIs(TokenType::PunctuatorClosingParenthesis) ) {

            if( !functionDeclaration->arguments.empty() )
                extractToken( TokenType::PunctuatorComma );

            functionDeclaration->arguments.emplace_back(
                parse<_FunctionArgument>() );
        }

        extractToken( TokenType::PunctuatorClosingParenthesis );

        if( !currentTokenIs(TokenType::PunctuatorOpeningBrace) )
            functionDeclaration->returnType = parse<_Type>();

        functionDeclaration->block = parse<_Block>();

        return boost::any();
    }
コード例 #2
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
 boost::any visit( PointerType type ) {
     extractToken( TokenType::KeywordPointer );
     extractToken( TokenType::PunctuatorOpeningBracket );
     type->targetType = parse<_Type>();
     extractToken( TokenType::PunctuatorClosingBracket );
     return boost::any();
 }
コード例 #3
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
    boost::any visit( ReturnStatement statement ) {

        extractToken( TokenType::KeywordReturn );

        if( !currentTokenIs(TokenType::PunctuatorSemicolon) )
            statement->expression = parse<_Expression>();

        extractToken( TokenType::PunctuatorSemicolon );

        return boost::any();
    }
コード例 #4
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
    boost::any visit( Block block ) {

        extractToken( TokenType::PunctuatorOpeningBrace );

        while( !currentTokenIs(TokenType::PunctuatorClosingBrace) )
            block->statements.emplace_back( parse<_Statement>() );

        extractToken( TokenType::PunctuatorClosingBrace );

        return boost::any();
    }
コード例 #5
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
    boost::any visit( WhileStatement statement ) {

        extractToken( TokenType::KeywordWhile );

        extractToken( TokenType::PunctuatorOpeningParenthesis );
        statement->condition = parse<_Expression>();
        extractToken( TokenType::PunctuatorClosingParenthesis );

        statement->block = parse<_Block>();

        return boost::any();
    }
コード例 #6
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
    boost::any visit( VariableDeclaration variableDeclaraion ) {

        extractToken( TokenType::KeywordVariable );

        variableDeclaraion->identifier = parseIdentifier();

        if( currentTokenIs(TokenType::OperatorAssign) ) {
            extractToken( TokenType::OperatorAssign );
            variableDeclaraion->initializer = parse<_Expression>();
        } else
            variableDeclaraion->type = parse<_Type>();

        extractToken( TokenType::PunctuatorSemicolon );

        return boost::any();
    }
コード例 #7
0
bool WuResubmit(const char *wuid)
{
    Owned<IWorkUnitFactory> factory = getWorkUnitFactory();
    Owned<IWorkUnit> wu = factory->updateWorkUnit(wuid);
    if (!wu)
    {
        ERRLOG("WuResubmit(%s): could not find workunit",wuid);
        return false;
    }
    if (wu->getState()!=WUStateFailed)
    {
        ERRLOG("WuResubmit(%s): could not resubmit as workunit state is '%s'", wuid, wu->queryStateDesc());
        return false;
    }
    SCMStringBuffer token;
    wu->getSecurityToken(token);
    SCMStringBuffer user;
    SCMStringBuffer password;
    extractToken(token.str(), wuid, user, password);
    wu->resetWorkflow();
    wu->setState(WUStateSubmitted);
    wu->commit();
    wu.clear();
    submitWorkUnit(wuid,user.str(),password.str());

    PROGLOG("WuResubmit(%s): resubmitted",wuid);
    return true;
}
コード例 #8
0
ファイル: CommandLine.c プロジェクト: imclab/CocoaMSX
void emuCheckFullscreenArgument(Properties* properties, char* cmdLine){
    int i;
    char* argument;

    if (NULL == extractToken(cmdLine, 0)) {
        return;
    }

//    properties->video.windowSize = P_VIDEO_SIZEX2;

    for (i = 0; (argument = extractToken(cmdLine, i)) != NULL; i++) {
        if (checkArg(argument, "fullscreen")) {
            properties->video.windowSize = P_VIDEO_SIZEFULLSCREEN;
        }
    }
}
コード例 #9
0
ファイル: lexer.c プロジェクト: t3rm1n4l/alloy
/** pushes a token with no content */
void pushToken(Lexer *self, int type) {
	Token *tok = createToken(self->lineNumber, self->charNumber, self->fileName);
	tok->type = type;
	tok->content = extractToken(self, self->startPos, self->pos - self->startPos);
	verboseModeMessage("Lexed token: %-15s, type %s", tok->content, getTokenTypeName(tok->type));
	pushBackItem(self->tokenStream, tok);
}
コード例 #10
0
daeBool
daeTokenType::stringToMemory(daeChar* src, daeChar* dst)
{
	src = skipWhitespace(src);
	daeChar* srcTmp = extractToken(src);
	*((daeStringRef*)dst) = srcTmp;
	if (srcTmp != src)
		delete[] srcTmp;
	return true;
}
コード例 #11
0
ファイル: CommandLine.c プロジェクト: imclab/CocoaMSX
char* emuCheckThemeArgument(char* cmdLine){
    static char themeName[PROP_MAXPATH];
    int i;
    char* argument;

    themeName[0] = 0;

    for (i = 0; (argument = extractToken(cmdLine, i)) != NULL; i++) {
        if (checkArg(argument, "theme")) {
            argument = extractToken(cmdLine, i + 1);
            if (argument != NULL) {
                strcat(themeName, argument);
            }
            return themeName;
        }
    }

    return NULL;
}
コード例 #12
0
daeBool
daeIDResolverType::stringToMemory(daeChar* src, daeChar* dstMemory)
{
	src = skipWhitespace(src);
	daeChar* id = extractToken(src);
	((daeIDRef*)dstMemory)->setID(id);
	if (id != src)
		delete[] id;
	return true;
}
コード例 #13
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
    boost::any visit( IfStatement statement ) {

        extractToken( TokenType::KeywordIf );

        extractToken( TokenType::PunctuatorOpeningParenthesis );
        statement->condition = parse<_Expression>();
        extractToken( TokenType::PunctuatorClosingParenthesis );

        statement->trueBlock = parse<_Block>();

        if( currentTokenIs(TokenType::KeywordElse) ) {
            extractToken();
            statement->falseBlock = parse<_Block>();
        } else
            // Creates a dummy empty block. This allows to handle "if"
            // statements with "false" blocks and without them uniformly
            statement->falseBlock = std::make_shared<_Block>();

        return boost::any();
    }
コード例 #14
0
ファイル: PXMFileUtils.cpp プロジェクト: geraldpark/optflow
void PNMFileUtils::checkMagicNumber(ifstream &inputStream, const string &id)
{
  char token[TOKEN_SIZE];
  
  extractToken(inputStream, token, TOKEN_SIZE);
  if(strcmp(token, id.c_str()) != 0)
  {
    cerr<<"Magic number "<<token<<" != "<<id<<endl;
    throw runtime_error("Bad magic number");
  }
}
コード例 #15
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
    boost::any visit( BooleanConstant booleanConstant ) {

        if( currentTokenIs(TokenType::KeywordTrue) )
            booleanConstant->value = true;
        else if( currentTokenIs(TokenType::KeywordFalse) )
            booleanConstant->value = false;
        else
            throw createSyntaxError( "Expected 'true' or 'false'" );

        extractToken();

        return boost::any();
    }
コード例 #16
0
ファイル: CommandLine.c プロジェクト: imclab/CocoaMSX
int emuCheckResetArgument(char* cmdLine) {
    int i;
    char*   argument;

    for (i = 0; (argument = extractToken(cmdLine, i)) != NULL; i++) {
        if (checkArg(argument, "reset")) {
            return 1;
        }
        if (checkArg(argument, "resetregs")) {
            return 2;
        }
    }

    return 0;
}
コード例 #17
0
daeBool
daeEnumType::stringToMemory(daeChar* src, daeChar* dst )
{
	src = skipWhitespace(src);
	daeChar* srcTmp = extractToken(src);

	size_t index(0);
	bool result = _strings->find(srcTmp, index) != DAE_ERR_QUERY_NO_MATCH;
	if (result) {
		daeEnum val = _values->get( index );
		*((daeEnum*)dst) = val;
	}

	if (srcTmp != src)
		delete[] srcTmp;

	return result;
}
コード例 #18
0
ファイル: Tokenizer.cpp プロジェクト: guoqi/MutC
Token::Ptr MutCTokenizer::extractToken ()
{
    Token::Ptr token;
    // terminate
    if (currentChar () == EOF)
    {
        token = make_shared <TerminatorToken> (__source);
    }
    // skip space character
    else if (isspace (currentChar ()))
    {
        nextChar ();
        return extractToken ();
    }
    // number
    else if (currentChar () >= '0' && currentChar () <= '9')
    {
        token = make_shared<NumberToken> (__source);
    }
    // identifier
    else if (isalpha (currentChar ()) || currentChar () == '_')
    {
        token = make_shared <IdentifierToken> (__source);
    }
    // symbol
    else if (! isalnum (currentChar ()) && currentChar () != '_')
    {
        token = make_shared <SymbolToken> (__source);
    }
    // string
    else if (currentChar () == '"')
    {
        token = make_shared <StringToken> (__source);
    }
    else
    {
        // TODO error handling: unexpected beginning character
        return nullptr;
    }
    token->build (__source);
    return token;
}
コード例 #19
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
    template<> Statement parse<_Statement>() {

        const TokenType tokenType = _lexicalAnalyser.getCurrentToken().type;

        switch( tokenType ) {
        case TokenType::PunctuatorOpeningBrace:
            return parse<_Block>();
        case TokenType::KeywordIf:
            return parse<_IfStatement>();
        case TokenType::KeywordReturn:
            return parse<_ReturnStatement>();
        case TokenType::KeywordVariable:
            return parse<_VariableDeclaration>();
        case TokenType::KeywordWhile:
            return parse<_WhileStatement>();
        }

        Statement statement = parse<_Expression>();
        extractToken( TokenType::PunctuatorSemicolon );
        return statement;
    }
コード例 #20
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
    Expression leftDenotation( Expression expression ) {

        // TODO: use 'parse<_BinaryOperatorExpression>()' etc. instead of
        // explicit parsing in this function

        struct UnaryOperatorParsingRule {
            TokenType tokenType;
            UnaryOperation operation;
        };

        struct BinaryOperatorParsingRule {
            TokenType tokenType;
            BinaryOperation operation;
        };

        static const UnaryOperatorParsingRule unaryOperatorParsingRules[] = {
            {TokenType::OperatorIncrement, UnaryOperation::Increment},
            {TokenType::OperatorDecrement, UnaryOperation::Decrement}
        };

        static const BinaryOperatorParsingRule binaryOperatorParsingRules[] = {
            {TokenType::OperatorAssign,   BinaryOperation::Assignment},
            {TokenType::OperatorPlus,     BinaryOperation::Addition},
            {TokenType::OperatorMinus,    BinaryOperation::Subtraction},
            {TokenType::OperatorMultiply, BinaryOperation::Multiplication},
            {TokenType::OperatorDivide,   BinaryOperation::Division},
            {TokenType::KeywordAnd,       BinaryOperation::LogicAnd},
            {TokenType::KeywordOr,        BinaryOperation::LogicOr},
            {TokenType::OperatorLess,     BinaryOperation::LessComparison},
            {TokenType::OperatorGreater,  BinaryOperation::GreaterComparison},
            {TokenType::OperatorEqual,    BinaryOperation::EqualComparison},
            {TokenType::OperatorNotEqual, BinaryOperation::NotEqualComparison},
            {TokenType::OperatorLessOrEqual,
                BinaryOperation::LessOrEqualComparison},
            {TokenType::OperatorGreaterOrEqual,
                BinaryOperation::GreaterOrEqualComparison}
        };

        const TokenType tokenType = _lexicalAnalyser.getCurrentToken().type;

        const int bindingPower = getLeftBindingPower();

        for( auto &rule : binaryOperatorParsingRules ) {
            if( tokenType == rule.tokenType ) {
                auto sourceLocation = extractToken().sourceLocation;
                auto result = std::make_shared<_BinaryOperationExpression>();
                result->sourceLocation = sourceLocation;
                result->operation = rule.operation;
                result->leftOperand = expression;
                result->rightOperand = parseExpression( bindingPower );
                return result;
            }
        }

        for( auto &rule : unaryOperatorParsingRules ) {
            if( tokenType == rule.tokenType ) {
                auto sourceLocation = extractToken().sourceLocation;
                auto result = std::make_shared<_UnaryOperationExpression>();
                result->sourceLocation = sourceLocation;
                result->operation = rule.operation;
                result->operand = expression;
                return result;
            }
        }

        if( tokenType == TokenType::PunctuatorOpeningParenthesis ) {
            auto sourceLocation = extractToken().sourceLocation;
            auto result = std::make_shared<_CallExpression>();
            result->sourceLocation = sourceLocation;
            result->callee = expression;
            while( !currentTokenIs(TokenType::PunctuatorClosingParenthesis) ) {
                if( !result->arguments.empty() )
                    extractToken( TokenType::PunctuatorComma );
                result->arguments.emplace_back( parse<_Expression>() );
            }
            extractToken( TokenType::PunctuatorClosingParenthesis );
            return result;
        }

        if( tokenType == TokenType::PunctuatorDot ) {
            auto sourceLocation = extractToken().sourceLocation;
            auto result = std::make_shared<_MemberAccessExpression>();
            result->sourceLocation = sourceLocation;
            result->object = expression;
            result->memberIdentifier = parseIdentifier();
            return result;
        }

        return expression;
    }
コード例 #21
0
ファイル: mptest.c プロジェクト: xluoly/raw-os_sqlite
/*
** Run a script.
*/
static void runScript(
  int iClient,       /* The client number, or 0 for the master */
  int taskId,        /* The task ID for clients.  0 for master */
  char *zScript,     /* Text of the script */
  char *zFilename    /* File from which script was read. */
){
  int lineno = 1;
  int prevLine = 1;
  int ii = 0;
  int iBegin = 0;
  int n, c, j;
  int len;
  int nArg;
  String sResult;
  char zCmd[30];
  char zError[1000];
  char azArg[MX_ARG][100];

  memset(&sResult, 0, sizeof(sResult));
  stringReset(&sResult);
  while( (c = zScript[ii])!=0 ){
    prevLine = lineno;
    len = tokenLength(zScript+ii, &lineno);
    if( isspace(c) || (c=='/' && zScript[ii+1]=='*') ){
      ii += len;
      continue;
    }
    if( c!='-' || zScript[ii+1]!='-' || !isalpha(zScript[ii+2]) ){
      ii += len;
      continue;
    }

    /* Run any prior SQL before processing the new --command */
    if( ii>iBegin ){
      char *zSql = sqlite3_mprintf("%.*s", ii-iBegin, zScript+iBegin);
      evalSql(&sResult, zSql);
      sqlite3_free(zSql);
      iBegin = ii + len;
    }

    /* Parse the --command */
    if( g.iTrace>=2 ) logMessage("%.*s", len, zScript+ii);
    n = extractToken(zScript+ii+2, len-2, zCmd, sizeof(zCmd));
    for(nArg=0; n<len-2 && nArg<MX_ARG; nArg++){
      while( n<len-2 && isspace(zScript[ii+2+n]) ){ n++; }
      if( n>=len-2 ) break;
      n += extractToken(zScript+ii+2+n, len-2-n,
                        azArg[nArg], sizeof(azArg[nArg]));
    }
    for(j=nArg; j<MX_ARG; j++) azArg[j++][0] = 0;

    /*
    **  --sleep N
    **
    ** Pause for N milliseconds
    */
    if( strcmp(zCmd, "sleep")==0 ){
      sqlite3_sleep(atoi(azArg[0]));
    }else 

    /*
    **   --exit N
    **
    ** Exit this process.  If N>0 then exit without shutting down
    ** SQLite.  (In other words, simulate a crash.)
    */
    if( strcmp(zCmd, "exit")==0 ){
      int rc = atoi(azArg[0]);
      finishScript(iClient, taskId, 1);
      if( rc==0 ) sqlite3_close(g.db);
      exit(rc);
    }else

    /*
    **   --testcase NAME
    **
    ** Begin a new test case.  Announce in the log that the test case
    ** has begun.
    */
    if( strcmp(zCmd, "testcase")==0 ){
      if( g.iTrace==1 ) logMessage("%.*s", len - 1, zScript+ii);
      stringReset(&sResult);
    }else

    /*
    **   --finish
    **
    ** Mark the current task as having finished, even if it is not.
    ** This can be used in conjunction with --exit to simulate a crash.
    */
    if( strcmp(zCmd, "finish")==0 && iClient>0 ){
      finishScript(iClient, taskId, 1);
    }else

    /*
    **  --reset
    **
    ** Reset accumulated results back to an empty string
    */
    if( strcmp(zCmd, "reset")==0 ){
      stringReset(&sResult);
    }else

    /*
    **  --match ANSWER...
    **
    ** Check to see if output matches ANSWER.  Report an error if not.
    */
    if( strcmp(zCmd, "match")==0 ){
      int jj;
      char *zAns = zScript+ii;
      for(jj=7; jj<len-1 && isspace(zAns[jj]); jj++){}
      zAns += jj;
      if( len-jj-1!=sResult.n || strncmp(sResult.z, zAns, len-jj-1) ){
        errorMessage("line %d of %s:\nExpected [%.*s]\n     Got [%s]",
          prevLine, zFilename, len-jj-1, zAns, sResult.z);
      }
      g.nTest++;
      stringReset(&sResult);
    }else

    /*
    **  --glob ANSWER...
    **  --notglob ANSWER....
    **
    ** Check to see if output does or does not match the glob pattern
    ** ANSWER.
    */
    if( strcmp(zCmd, "glob")==0 || strcmp(zCmd, "notglob")==0 ){
      int jj;
      char *zAns = zScript+ii;
      char *zCopy;
      int isGlob = (zCmd[0]=='g');
      for(jj=9-3*isGlob; jj<len-1 && isspace(zAns[jj]); jj++){}
      zAns += jj;
      zCopy = sqlite3_mprintf("%.*s", len-jj-1, zAns);
      if( (sqlite3_strglob(zCopy, sResult.z)==0)^isGlob ){
        errorMessage("line %d of %s:\nExpected [%s]\n     Got [%s]",
          prevLine, zFilename, zCopy, sResult.z);
      }
      sqlite3_free(zCopy);
      g.nTest++;
      stringReset(&sResult);
    }else

    /*
    **  --output
    **
    ** Output the result of the previous SQL.
    */
    if( strcmp(zCmd, "output")==0 ){
      logMessage("%s", sResult.z);
    }else

    /*
    **  --source FILENAME
    **
    ** Run a subscript from a separate file.
    */
    if( strcmp(zCmd, "source")==0 ){
      char *zNewFile, *zNewScript;
      char *zToDel = 0;
      zNewFile = azArg[0];
      if( zNewFile[0]!='/' ){
        int k;
        for(k=(int)strlen(zFilename)-1; k>=0 && zFilename[k]!='/'; k--){}
        if( k>0 ){
          zNewFile = zToDel = sqlite3_mprintf("%.*s/%s", k,zFilename,zNewFile);
        }
      }
      zNewScript = readFile(zNewFile);
      if( g.iTrace ) logMessage("begin script [%s]\n", zNewFile);
      runScript(0, 0, zNewScript, zNewFile);
      sqlite3_free(zNewScript);
      if( g.iTrace ) logMessage("end script [%s]\n", zNewFile);
      sqlite3_free(zToDel);
    }else

    /*
    **  --print MESSAGE....
    **
    ** Output the remainder of the line to the log file
    */
    if( strcmp(zCmd, "print")==0 ){
      int jj;
      for(jj=7; jj<len && isspace(zScript[ii+jj]); jj++){}
      logMessage("%.*s", len-jj, zScript+ii+jj);
    }else

    /*
    **  --if EXPR
    **
    ** Skip forward to the next matching --endif or --else if EXPR is false.
    */
    if( strcmp(zCmd, "if")==0 ){
      int jj, rc;
      sqlite3_stmt *pStmt;
      for(jj=4; jj<len && isspace(zScript[ii+jj]); jj++){}
      pStmt = prepareSql("SELECT %.*s", len-jj, zScript+ii+jj);
      rc = sqlite3_step(pStmt);
      if( rc!=SQLITE_ROW || sqlite3_column_int(pStmt, 0)==0 ){
        ii += findEndif(zScript+ii+len, 1, &lineno);
      }
      sqlite3_finalize(pStmt);
    }else

    /*
    **  --else
    **
    ** This command can only be encountered if currently inside an --if that
    ** is true.  Skip forward to the next matching --endif.
    */
    if( strcmp(zCmd, "else")==0 ){
      ii += findEndif(zScript+ii+len, 0, &lineno);
    }else

    /*
    **  --endif
    **
    ** This command can only be encountered if currently inside an --if that
    ** is true or an --else of a false if.  This is a no-op.
    */
    if( strcmp(zCmd, "endif")==0 ){
      /* no-op */
    }else

    /*
    **  --start CLIENT
    **
    ** Start up the given client.
    */
    if( strcmp(zCmd, "start")==0 && iClient==0 ){
      int iNewClient = atoi(azArg[0]);
      if( iNewClient>0 ){
        startClient(iNewClient);
      }
    }else

    /*
    **  --wait CLIENT TIMEOUT
    **
    ** Wait until all tasks complete for the given client.  If CLIENT is
    ** "all" then wait for all clients to complete.  Wait no longer than
    ** TIMEOUT milliseconds (default 10,000)
    */
    if( strcmp(zCmd, "wait")==0 && iClient==0 ){
      int iTimeout = nArg>=2 ? atoi(azArg[1]) : 10000;
      sqlite3_snprintf(sizeof(zError),zError,"line %d of %s\n",
                       prevLine, zFilename);
      waitForClient(atoi(azArg[0]), iTimeout, zError);
    }else

    /*
    **  --task CLIENT
    **     <task-content-here>
    **  --end
    **
    ** Assign work to a client.  Start the client if it is not running
    ** already.
    */
    if( strcmp(zCmd, "task")==0 && iClient==0 ){
      int iTarget = atoi(azArg[0]);
      int iEnd;
      char *zTask;
      char *zTName;
      iEnd = findEnd(zScript+ii+len, &lineno);
      if( iTarget<0 ){
        errorMessage("line %d of %s: bad client number: %d",
                     prevLine, zFilename, iTarget);
      }else{
        zTask = sqlite3_mprintf("%.*s", iEnd, zScript+ii+len);
        if( nArg>1 ){
          zTName = sqlite3_mprintf("%s", azArg[1]);
        }else{
          zTName = sqlite3_mprintf("%s:%d", filenameTail(zFilename), prevLine);
        }
        startClient(iTarget);
        runSql("INSERT INTO task(client,script,name)"
               " VALUES(%d,'%q',%Q)", iTarget, zTask, zTName);
        sqlite3_free(zTask);
        sqlite3_free(zTName);
      }
      iEnd += tokenLength(zScript+ii+len+iEnd, &lineno);
      len += iEnd;
      iBegin = ii+len;
    }else

    /*
    **  --breakpoint
    **
    ** This command calls "test_breakpoint()" which is a routine provided
    ** as a convenient place to set a debugger breakpoint.
    */
    if( strcmp(zCmd, "breakpoint")==0 ){
      test_breakpoint();
    }else

    /*
    **  --show-sql-errors BOOLEAN
    **
    ** Turn display of SQL errors on and off.
    */
    if( strcmp(zCmd, "show-sql-errors")==0 ){
      g.bIgnoreSqlErrors = nArg>=1 ? !booleanValue(azArg[0]) : 1;
    }else


    /* error */{
      errorMessage("line %d of %s: unknown command --%s",
                   prevLine, zFilename, zCmd);
    }
    ii += len;
  }
  if( iBegin<ii ){
    char *zSql = sqlite3_mprintf("%.*s", ii-iBegin, zScript+iBegin);
    runSql(zSql);
    sqlite3_free(zSql);
  }
  stringFree(&sResult);
}
コード例 #22
0
ファイル: CommandLine.c プロジェクト: imclab/CocoaMSX
static int emuStartWithArguments(Properties* properties, char* commandLine, char *gamedir) {
    int i;
    char    cmdLine[512] = "";
    char*   argument;
    char    rom1[512] = "";
    char    rom2[512] = "";
    char    rom1zip[256] = "";
    char    rom2zip[256] = "";
    RomType romType1  = ROM_UNKNOWN;
    RomType romType2  = ROM_UNKNOWN;
    char    machineName[64] = "";
    char    diskA[512] = "";
    char    diskB[512] = "";
    char    diskAzip[256] = "";
    char    diskBzip[256] = "";
    char    ide1p[256] = "";
    char    ide1s[256] = "";
    char    cas[512] = "";
    char    caszip[256] = "";
    int     fullscreen = 0;
#ifdef WII
    int     startEmu = 1; // always start
#else
    int     startEmu = 0;
#endif

    if (commandLine[0] != '/' && commandLine[1] == ':') {
        char* ptr;
        strcat(cmdLine, "\"");
        strcat(cmdLine, commandLine);
        ptr = cmdLine + strlen(commandLine);
        while (ptr > cmdLine && *ptr == ' ') {
            *ptr-- = '\0';
        }
        strcat(cmdLine, "\"");
    }
    else {
        strcat(cmdLine, commandLine);
    }

    // If one argument, assume it is a rom or disk to run
    if (!extractToken(cmdLine, 1)) {
        argument = extractToken(cmdLine, 0);

        // AK: if (argument && *argument != '/') {
        if (argument) {
            if (*argument == '\"') argument++;

            if (*argument) {
                int i;

                for (i = 0; i < PROP_MAX_CARTS; i++) {
                    properties->media.carts[i].fileName[0] = 0;
                    properties->media.carts[i].fileNameInZip[0] = 0;
                    properties->media.carts[i].type = ROM_UNKNOWN;
                    updateExtendedRomName(i, properties->media.carts[i].fileName, properties->media.carts[i].fileNameInZip);
                }

                for (i = 0; i < PROP_MAX_DISKS; i++) {
                    properties->media.disks[i].fileName[0] = 0;
                    properties->media.disks[i].fileNameInZip[0] = 0;
                    updateExtendedDiskName(i, properties->media.disks[i].fileName, properties->media.disks[i].fileNameInZip);
                }

                return tryLaunchUnknownFile(properties, argument, 1);
            }
            return 0;
        }
    }

    // If more than one argument, check arguments,
    // set configuration and then run

    for (i = 0; (argument = extractToken(cmdLine, i)) != NULL; i++) {
        if (checkArg(argument, "rom1")) {
            argument = extractTokenEx(cmdLine, ++i, gamedir);
            if (argument == NULL || !isRomFileType(argument, rom1zip)) return 0; // Invaid argument
            strcpy(rom1, argument);
            startEmu = 1;
        }
        if (checkArg(argument, "rom1zip")) {
            argument = extractToken(cmdLine, ++i);
            if (argument == NULL) return 0;
            strcpy(rom1zip, argument);
        }
        if (checkArg(argument, "romtype1")) {
            argument = extractToken(cmdLine, ++i);
            if (argument == NULL) return 0; // Invaid argument
            romType1 = romNameToType(argument);
            startEmu = 1;
        }
        if (checkArg(argument, "rom2")) {
            argument = extractTokenEx(cmdLine, ++i, gamedir);
            if (argument == NULL || !isRomFileType(argument, rom2zip)) return 0; // Invaid argument
            strcpy(rom2, argument);
            startEmu = 1;
        }
        if (checkArg(argument, "rom2zip")) {
            argument = extractToken(cmdLine, ++i);
            if (argument == NULL) return 0;
            strcpy(rom2zip, argument);
        }
        if (checkArg(argument, "romtype2")) {
            argument = extractToken(cmdLine, ++i);
            if (argument == NULL) return 0; // Invaid argument
            romType2 = romNameToType(argument);
            startEmu = 1;
        }
        if (checkArg(argument, "diskA")) {
            argument = extractTokenEx(cmdLine, ++i, gamedir);
            if (argument == NULL || !isDskFileType(argument, diskAzip)) return 0; // Invaid argument
            strcpy(diskA, argument);
            startEmu = 1;
        }
        if (checkArg(argument, "diskAzip")) {
            argument = extractToken(cmdLine, ++i);
            if (argument == NULL) return 0;
            strcpy(diskAzip, argument);
        }
        if (checkArg(argument, "diskB")) {
            argument = extractTokenEx(cmdLine, ++i, gamedir);
            if (argument == NULL || !isDskFileType(argument, diskBzip)) return 0; // Invaid argument
            strcpy(diskB, argument);
            startEmu = 1;
        }
        if (checkArg(argument, "diskBzip")) {
            argument = extractToken(cmdLine, ++i);
            if (argument == NULL) return 0;
            strcpy(diskBzip, argument);
        }
        if (checkArg(argument, "cas")) {
            argument = extractTokenEx(cmdLine, ++i, gamedir);
            if (argument == NULL || !isCasFileType(argument, caszip)) return 0; // Invaid argument
            strcpy(cas, argument);
            startEmu = 1;
        }
        if (checkArg(argument, "ide1primary")) {
            argument = extractToken(cmdLine, ++i);
            if (argument == NULL) return 0; // Invaid argument
            strcpy(ide1p, argument);
            startEmu = 1;
        }
        if (checkArg(argument, "ide1secondary")) {
            argument = extractToken(cmdLine, ++i);
            if (argument == NULL) return 0; // Invaid argument
            strcpy(ide1s, argument);
            startEmu = 1;
        }
        if (checkArg(argument, "caszip")) {
            argument = extractToken(cmdLine, ++i);
            if (argument == NULL) return 0;
            strcpy(caszip, argument);
        }
        if (checkArg(argument, "machine")) {
            argument = extractToken(cmdLine, ++i);
            if (argument == NULL) return 0; // Invaid argument
            strcpy(machineName, argument);
            if (!machineIsValid(machineName, 1)) return 0;
            startEmu = 1;
        }
        if (checkArg(argument, "fullscreen")) {
            fullscreen = 1;
        }
    }

    if (!startEmu) {
        return 1;
    }

    for (i = 0; i < PROP_MAX_CARTS; i++) {
        properties->media.carts[i].fileName[0] = 0;
        properties->media.carts[i].fileNameInZip[0] = 0;
        properties->media.carts[i].type = ROM_UNKNOWN;
        updateExtendedRomName(i, properties->media.carts[i].fileName, properties->media.carts[i].fileNameInZip);
    }

    for (i = 0; i < PROP_MAX_DISKS; i++) {
        properties->media.disks[i].fileName[0] = 0;
        properties->media.disks[i].fileNameInZip[0] = 0;
        updateExtendedDiskName(i, properties->media.disks[i].fileName, properties->media.disks[i].fileNameInZip);
    }

    for (i = 0; i < PROP_MAX_TAPES; i++) {
        properties->media.tapes[i].fileName[0] = 0;
        properties->media.tapes[i].fileNameInZip[0] = 0;
        updateExtendedCasName(i, properties->media.tapes[i].fileName, properties->media.tapes[i].fileNameInZip);
    }

    if (!strlen(rom1)) {
        switch (romType1) {
        case ROM_SCC:         strcat(rom1, CARTNAME_SCC); romType1 = ROM_SCC; break;
        case ROM_SCCPLUS:     strcat(rom1, CARTNAME_SCCPLUS); romType1 = ROM_SCCPLUS; break;
        case ROM_SNATCHER:    strcat(rom1, CARTNAME_SNATCHER); break;
        case ROM_SDSNATCHER:  strcat(rom1, CARTNAME_SDSNATCHER); break;
        case ROM_SCCMIRRORED: strcat(rom1, CARTNAME_SCCMIRRORED); break;
        case ROM_SCCEXTENDED: strcat(rom1, CARTNAME_SCCEXPANDED); break;
        case ROM_FMPAC:       strcat(rom1, CARTNAME_FMPAC); break;
        case ROM_PAC:         strcat(rom1, CARTNAME_PAC); break;
        case ROM_GAMEREADER:  strcat(rom1, CARTNAME_GAMEREADER); break;
        case ROM_SUNRISEIDE:  strcat(rom1, CARTNAME_SUNRISEIDE); break;
        case ROM_NOWIND:      strcat(rom1, CARTNAME_NOWINDDOS1); break;
        case ROM_BEERIDE:     strcat(rom1, CARTNAME_BEERIDE); break;
        case ROM_GIDE:        strcat(rom1, CARTNAME_GIDE); break;
        case ROM_GOUDASCSI:   strcat(rom1, CARTNAME_GOUDASCSI); break;
        case ROM_NMS1210:     strcat(rom1, CARTNAME_NMS1210); break;
        case ROM_SONYHBI55:   strcat(rom1, CARTNAME_SONYHBI55); break;
        }
    }

    if (!strlen(rom2)) {
        switch (romType2) {
        case ROM_SCC:         strcat(rom2, CARTNAME_SCC); romType2 = ROM_SCC; break;
        case ROM_SCCPLUS:     strcat(rom2, CARTNAME_SCCPLUS); romType2 = ROM_SCCPLUS; break;
        case ROM_SNATCHER:    strcat(rom2, CARTNAME_SNATCHER); break;
        case ROM_SDSNATCHER:  strcat(rom2, CARTNAME_SDSNATCHER); break;
        case ROM_SCCMIRRORED: strcat(rom2, CARTNAME_SCCMIRRORED); break;
        case ROM_SCCEXTENDED: strcat(rom2, CARTNAME_SCCEXPANDED); break;
        case ROM_FMPAC:       strcat(rom2, CARTNAME_FMPAC); break;
        case ROM_PAC:         strcat(rom2, CARTNAME_PAC); break;
        case ROM_GAMEREADER:  strcat(rom2, CARTNAME_GAMEREADER); break;
        case ROM_SUNRISEIDE:  strcat(rom2, CARTNAME_SUNRISEIDE); break;
        case ROM_NOWIND:      strcat(rom2, CARTNAME_NOWINDDOS1); break;
        case ROM_BEERIDE:     strcat(rom2, CARTNAME_BEERIDE); break;
        case ROM_GIDE:        strcat(rom2, CARTNAME_GIDE); break;
        case ROM_GOUDASCSI:   strcat(rom2, CARTNAME_GOUDASCSI); break;
        case ROM_NMS1210:     strcat(rom2, CARTNAME_NMS1210); break;
        case ROM_SONYHBI55:   strcat(rom2, CARTNAME_SONYHBI55); break;
        }
    }

    if (properties->cassette.rewindAfterInsert) tapeRewindNextInsert();

    if (strlen(rom1)  && !insertCartridge(properties, 0, rom1, *rom1zip ? rom1zip : NULL, romType1, -1)) return 0;
    if (strlen(rom2)  && !insertCartridge(properties, 1, rom2, *rom2zip ? rom2zip : NULL, romType2, -1)) return 0;
    if (strlen(diskA) && !insertDiskette(properties, 0, diskA, *diskAzip ? diskAzip : NULL, -1)) return 0;
    if (strlen(diskB) && !insertDiskette(properties, 1, diskB, *diskBzip ? diskBzip : NULL, -1)) return 0;
    if (strlen(ide1p) && !insertDiskette(properties, diskGetHdDriveId(0, 0), ide1p, NULL, -1)) return 0;
    if (strlen(ide1s) && !insertDiskette(properties, diskGetHdDriveId(0, 1), ide1s, NULL, -1)) return 0;
    if (strlen(cas)   && !insertCassette(properties, 0, cas, *caszip ? caszip : NULL, -1)) return 0;

    if (strlen(machineName)) strcpy(properties->emulation.machineName, machineName);
#ifdef WII
    else strcpy(properties->emulation.machineName, "MSX2 - No Moonsound"); /* If not specified, use MSX2 without moonsound as default */
#endif

    emulatorStop();
    emulatorStart(NULL);

    return 1;
}
コード例 #23
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
    Expression nullDenotation() {

        const TokenType tokenType = _lexicalAnalyser.getCurrentToken().type;

        switch( tokenType ) {
        case TokenType::KeywordInstance:
            return parse<_InstanceExpression>();
        case TokenType::Identifier:
            return parse<_IdentifierExpression>();
        case TokenType::ConstantInteger:
            return parse<_IntegerConstant>();
        case TokenType::ConstantString:
            return parse<_StringConstant>();
        case TokenType::KeywordTrue:
        case TokenType::KeywordFalse:
            return parse<_BooleanConstant>();

        case TokenType::PunctuatorOpeningParenthesis: {

            extractToken();

            Expression expression = parse<_Expression>();

            extractToken( TokenType::PunctuatorClosingParenthesis );

            return expression;
        }

        case TokenType::KeywordBoolean:
        case TokenType::KeywordInteger:
        case TokenType::KeywordReal:
        case TokenType::KeywordPointerTo:
        {
            UnaryOperation operation;

            if( tokenType == TokenType::KeywordBoolean )
                operation =  UnaryOperation::BooleanConversion;
            else if( tokenType == TokenType::KeywordInteger )
                operation =  UnaryOperation::IntegerConversion;
            else if( tokenType == TokenType::KeywordReal )
                operation =  UnaryOperation::RealConversion;
            else if( tokenType == TokenType::KeywordPointerTo )
                operation =  UnaryOperation::PointerConversion;

            auto sourceLocation = extractToken().sourceLocation;
            extractToken( TokenType::PunctuatorOpeningParenthesis );

            auto expression = std::make_shared<_UnaryOperationExpression>();
            expression->sourceLocation = sourceLocation;
            expression->operation = operation;
            expression->operand = parse<_Expression>();

            extractToken( TokenType::PunctuatorClosingParenthesis );

            return expression;

        }

        case TokenType::KeywordNot:
        {
            const int bindingPower = getLeftBindingPower();

            auto expression = std::make_shared<_UnaryOperationExpression>();
            expression->sourceLocation = extractToken().sourceLocation;
            expression->operation = UnaryOperation::LogicInversion;
            expression->operand = parseExpression( bindingPower );

            return expression;
        }

        }

        throw createSyntaxError( "Unexpected token" );
    }
コード例 #24
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
 boost::any visit( RealType type ) {
     extractToken( TokenType::KeywordReal );
     return boost::any();
 }
コード例 #25
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
 boost::any visit( StringType type ) {
     extractToken( TokenType::KeywordString );
     return boost::any();
 }
コード例 #26
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
 boost::any visit( InstanceExpression expression ) {
     extractToken( TokenType::KeywordInstance );
     return boost::any();
 }
コード例 #27
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
 boost::any visit( IntegerType type ) {
     extractToken( TokenType::KeywordInteger );
     return boost::any();
 }
コード例 #28
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
 boost::any visit( BooleanType type ) {
     extractToken( TokenType::KeywordBoolean );
     return boost::any();
 }
コード例 #29
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
 boost::any visit( StringConstant stringConstant ) {
     const auto &lexem = extractToken( TokenType::ConstantString ).lexem;
     // Remove surrounding '"' symbols
     stringConstant->value = lexem.substr( 1, lexem.size() - 2 );
     return boost::any();
 }
コード例 #30
0
ファイル: Parser.cpp プロジェクト: vanderlokken/8b
 boost::any visit( IntegerConstant integerConstant ) {
     std::stringstream stream;
     stream << extractToken( TokenType::ConstantInteger ).lexem;
     stream >> integerConstant->value;
     return boost::any();
 }