예제 #1
0
파일: sdli.cpp 프로젝트: dtzWill/supernes
static void processEvent(const SDL_Event& event)
{
	if (videoEventFilter(event)) return;
	if (keyboardBindingFilter(event)) return;

  int key = 0;
  int x, y, xnew, ynew;
	switch (event.type) 
	{
		case SDL_KEYDOWN:
      key = event.key.keysym.sym;

			if (Config.action[key]) 
				S9xDoAction(Config.action[key]);

      joypads[0] |= getJoyMask(Config.joypad1Mapping, key);
      joypads[1] |= getJoyMask(Config.joypad2Mapping, key);

      checkOther(Config.joypad1Mapping, key );
      checkOther(Config.joypad2Mapping, key );
			break;
		case SDL_KEYUP:
      key = event.key.keysym.sym;
      joypads[0] &= ~getJoyMask(Config.joypad1Mapping, key);
      joypads[1] &= ~getJoyMask(Config.joypad2Mapping, key);
			break;
		case SDL_MOUSEBUTTONUP:
		case SDL_MOUSEBUTTONDOWN:
      x = event.button.x; y = event.button.y;
      // We interpret mouse input differently depending on orientation
      if ( orientation != ORIENTATION_PORTRAIT )
      {
        // XXX: Make this not magical
        y = 320 - event.button.x;
        x = event.button.y;
      }
			processMouse(x, y,
					(event.button.state == SDL_PRESSED));
			break;
		case SDL_MOUSEMOTION:
      xnew = event.motion.x; ynew = event.motion.y;
      x = xnew - event.motion.xrel; y = ynew - event.motion.yrel;

      // We interpret mouse input differently depending on orientation
      if ( orientation != ORIENTATION_PORTRAIT )
      {
        // XXX: Make this not magical
        ynew = 320 - event.motion.x;
        xnew = event.motion.y;
        x = xnew - event.motion.yrel;
        y = ynew + event.motion.xrel;
      }
			processMouseMotion(x, y, xnew, ynew);
			break;
//		case SDL_QUIT:
//			Config.running = false;
//			break;
	}
}
예제 #2
0
    void check(const char code[]) {
        // Clear the error buffer..
        errout.str("");

        // Tokenize..
        Tokenizer tokenizer(&settings, this);
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");

        // Check char variable usage..
        CheckOther checkOther(&tokenizer, &settings, this);
        checkOther.checkCharVariable();
    }
예제 #3
0
void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const int dealloc)
{
    // Ignore function call?
    const bool ignore = bool(_settings->library.leakignore.find(tok->str()) != _settings->library.leakignore.end());
    if (ignore)
        return;

    std::map<unsigned int, int> &alloctype = varInfo->alloctype;
    std::map<unsigned int, std::string> &possibleUsage = varInfo->possibleUsage;

    for (const Token *arg = tok->tokAt(2); arg; arg = arg->nextArgument()) {
        if (arg->str() == "new")
            arg = arg->next();

        if ((Token::Match(arg, "%var% [-,)]") && arg->varId() > 0) ||
            (Token::Match(arg, "& %var%") && arg->next()->varId() > 0)) {

            // goto variable
            if (arg->str() == "&")
                arg = arg->next();

            // Is variable allocated?
            const auto var = alloctype.find(arg->varId());
            if (var != alloctype.end()) {
                if (dealloc == NOALLOC) {
                    // possible usage
                    possibleUsage[arg->varId()] = tok->str();
                    if (var->second == DEALLOC && arg->previous()->str() == "&")
                        varInfo->erase(arg->varId());
                } else if (var->second == DEALLOC) {
                    CheckOther checkOther(_tokenizer, _settings, _errorLogger);
                    checkOther.doubleFreeError(tok, arg->str());
                } else if (var->second != dealloc) {
                    // mismatching allocation and deallocation
                    mismatchError(tok, arg->str());
                    varInfo->erase(arg->varId());
                } else {
                    // deallocation
                    var->second = DEALLOC;
                }
            } else if (dealloc != NOALLOC) {
                alloctype[arg->varId()] = DEALLOC;
            }
        } else if (Token::Match(arg, "%var% (")) {
            functionCall(arg, varInfo, dealloc);
        }
    }
}
예제 #4
0
    void strPlusChar(const char code[])
    {
        // Tokenize..
        Tokenizer tokenizer;
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");
        tokenizer.setVarId();

        // Clear the error buffer..
        errout.str("");

        // Check for redundant code..
        Settings settings;
        CheckOther checkOther(&tokenizer, &settings, this);
        checkOther.strPlusChar();
    }
예제 #5
0
    void check(const char code[], bool inconclusive = false) {
        // Clear the error buffer..
        errout.str("");

        Settings settings;
        settings.addEnabled("style");
        settings.inconclusive = inconclusive;

        // Tokenize..
        Tokenizer tokenizer(&settings, this);
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");

        // Check for unsigned divisions..
        CheckOther checkOther(&tokenizer, &settings, this);
        checkOther.checkUnsignedDivision();
    }
예제 #6
0
    void checkpostIncrementDecrement(const char code[])
    {
        // Tokenize..
        Tokenizer tokenizer;
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");
        tokenizer.setVarId();

        // Clear the error buffer..
        errout.str("");

        // Check for redundant code..
        Settings settings;
        settings._checkCodingStyle = true;
        CheckOther checkOther(&tokenizer, &settings, this);
        checkOther.postIncrement();
    }
예제 #7
0
    void varScope(const char code[])
    {
        // Tokenize..
        Tokenizer tokenizer;
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");
        tokenizer.simplifyTokenList();

        // Clear the error buffer..
        errout.str("");

        // Check for redundant code..
        Settings settings;
        settings._checkCodingStyle = true;
        CheckOther checkOther(&tokenizer, &settings, this);
        checkOther.checkVariableScope();
    }
    void check(const char code[]) {
        // Clear the error buffer..
        errout.str("");

        Settings settings;
        settings.addEnabled("warning");

        // Tokenize..
        Tokenizer tokenizer(&settings, this);
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");
        tokenizer.simplifyTokenList2();

        // Check for incomplete statements..
        CheckOther checkOther(&tokenizer, &settings, this);
        checkOther.checkIncompleteStatement();
    }
예제 #9
0
    void check(const char code[])
    {
        // Tokenize..
        Tokenizer tokenizer;
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");
        tokenizer.simplifyTokenList();

        // Clear the error buffer..
        errout.str("");

        // Check for incomplete statements..
        Settings settings;
        settings._checkCodingStyle = true;
        CheckOther checkOther(&tokenizer, &settings, this);
        checkOther.checkIncompleteStatement();
    }
예제 #10
0
void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const std::string &dealloc)
{
    std::map<unsigned int, std::string> &alloctype = varInfo->alloctype;
    std::map<unsigned int, std::string> &possibleUsage = varInfo->possibleUsage;

    // Ignore function call?
    const bool ignore = bool(cfgignore.find(tok->str()) != cfgignore.end());
    //const bool use = bool(cfguse.find(tok->str()) != cfguse.end());

    if (ignore)
        return;

    for (const Token *arg = tok->tokAt(2); arg; arg = arg->nextArgument()) {
        if ((Token::Match(arg, "%var% [-,)]") && arg->varId() > 0) ||
            (Token::Match(arg, "& %var%") && arg->next()->varId() > 0)) {

            // goto variable
            if (arg->str() == "&")
                arg = arg->next();

            // Is variable allocated?
            const std::map<unsigned int,std::string>::iterator var = alloctype.find(arg->varId());
            if (var != alloctype.end()) {
                if (dealloc.empty()) {
                    // possible usage
                    possibleUsage[arg->varId()] = tok->str();
                } else if (var->second == "dealloc") {
                    CheckOther checkOther(_tokenizer, _settings, _errorLogger);
                    checkOther.doubleFreeError(tok, arg->str());
                } else if (var->second != dealloc) {
                    // mismatching allocation and deallocation
                    mismatchError(tok, arg->str());
                    varInfo->erase(arg->varId());
                } else {
                    // deallocation
                    var->second = "dealloc";
                }
            } else if (!dealloc.empty()) {
                alloctype[arg->varId()] = "dealloc";
            }
        } else if (Token::Match(arg, "%var% (")) {
            functionCall(arg, varInfo, dealloc);
        }
    }
}
예제 #11
0
    void sprintfUsage(const char code[])
    {
        // Tokenize..
        Tokenizer tokenizer;
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");
        tokenizer.setVarId();

        //tokenizer.tokens()->printOut( "tokens" );

        // Clear the error buffer..
        errout.str("");

        // Check for redundant code..
        Settings settings;
        CheckOther checkOther(&tokenizer, &settings, this);
        checkOther.invalidFunctionUsage();
    }
예제 #12
0
    void check(const char code[])
    {
        // Tokenize..
        Tokenizer tokenizer;
        std::istringstream istr(code);
        tokenizer.tokenize(istr, "test.cpp");

        // Simplify token list..
        tokenizer.simplifyTokenList();

        // Clear the error buffer..
        errout.str("");

        // Check for redundant code..
        Settings settings;
        CheckOther checkOther(&tokenizer, &settings, this);
        checkOther.warningRedundantCode();
        checkOther.checkZeroDivision();
    }