Exemplo n.º 1
0
  //
  // CmdParse::Error
  //
  // Handler for parsing errors
  //
  void FASTCALL CmdParse::Error(const char *, U32 x, U32, const char *errStr)
  {  
    // Display error message
    CON_ERR(("(col %d) %s", x, errStr))

    // Throw an exception
    throw (0);
  }
Exemplo n.º 2
0
  //
  // ParseAssignment
  //
  // Parse an item value assignment
  //
  Bool CmdParse::ParseAssignment(void *context, VarSys::VarItem *item)
  {
    ASSERT(item);

    // Peek at the next token
    switch (tBuf.PeekToken())
    { 
      case TR_OK:
        break;

      case TR_PUN:
      {
        switch (*tBuf.peekToken)
        {
          case '=':
            tBuf.AcceptPunct();
            break;

          case ';':
            return (FALSE);
            break;
        }
        break;
      }

      case TR_EOF:
        return (FALSE);
        break;

      default:
        ERR_FATAL(("Missing case"));
    }    

    // Allow editing in a development build
    #ifdef DEVELOPMENT

      // But give a warning
      if (item->flags & VarSys::NOEDIT)
      {
        CON_ERR(("Warning! Can not be modified in a release build"))
      } 

    #else

      // Check that this item can be edited from the console
      if (item->flags & VarSys::NOEDIT)
      {
        tBuf.TokenError("This item can not be modified");
      }

    #endif

    VNode *node;

    // See if we are assigning one var to another
    if (ParseVarAssignment(context, item))
    {
      return (TRUE);
    }

    // Parse the VNode data
    if ((node = StdParse::ParseAtomicVNode(&tBuf)) == NULL)
    {
      // Convert a single identifier to a string value
      if (tBuf.PeekToken() == TR_OK)
      {
        tBuf.AcceptIdent();
        node = new VNode;
        node->SetupString(tBuf.lastToken);   
      }
      else
      {  
        tBuf.TokenError("Invalid value");
      }
    }
  
    // Assign the new value
    switch (item->type)
    {
      // Changing an integer item
      case VarSys::VI_INTEGER:
        switch (node->aType)
        {
          case VNode::AT_INTEGER:
            item->SetInteger(node->GetInteger());
            break;
          case VNode::AT_FPOINT:
            item->SetInteger((S32)node->GetFPoint());
            break;
          default:
            delete node;
            tBuf.TokenError("Expected %s value", VarSys::GetTypeString(item->type));
        }
        break;

      // Changing a floating point item
      case VarSys::VI_FPOINT:
        switch (node->aType)
        {
          case VNode::AT_INTEGER:
            item->SetFloat((F32)node->GetInteger());
            break;
          case VNode::AT_FPOINT:
            item->SetFloat(node->GetFPoint());
            break;
          default:
            delete node;
            tBuf.TokenError("Expected %s value", VarSys::GetTypeString(item->type));
        }
        break;

      // Changing a string item
      case VarSys::VI_STRING:
        switch (node->aType)
        {
          case VNode::AT_STRING:
            item->SetStr(node->GetString());
            break;
          default:
            delete node;
            tBuf.TokenError("Expected %s value", VarSys::GetTypeString(item->type));
        }
        break;

      // Unable to change this type of item
      default :
        delete node;
        tBuf.TokenError("Unable to modify items of this type");  
    }

    // Delete the temporary VNode
    delete node;

    // Success
    return (TRUE);
  }
Exemplo n.º 3
0
  //
  // CmdHandler
  //
  // Handles all global level console commands
  //
  static void CmdHandler(U32 pathCrc)
  {
    switch (pathCrc)
    {
      //
      // Root level commands
      //
      case 0xB4729720: // "quit"
        runCodes.Set("QUIT");
        break;

    #ifdef DEVELOPMENT

      case 0xBC36982D: // "ls"
      {
        U32 flags = Console::SHOWSCOPES | Console::SHOWVARS | Console::SHOWCMDS;    

        // Recurse if there are any args ;)
        if (Console::ArgCount() == 1)
        {
          flags |= Console::NORECURSE;
        }

        Console::DisplayVarScope(VarSys::gScope, 0, flags);
        break;
      }

    #endif

      case 0xC39EE127: // "op"
      {
        const char *var, *op;
        VarSys::VarItem *param;

        if (Console::GetArgString(1, var) && Console::GetArgString(2, op) && Console::GetArg(3, param))
        {
          Operation::Console(var, op, param);
        }
        else
        {
          CON_ERR((Console::ARGS))
        }
        break;
      }

      case 0x5D8A9066: // "?"
      case 0xFF52E6E7: // "help"
        CON_DIAG(("Commands at the global scope :"))
        Console::DisplayVarScope(VarSys::gScope, 0, Console::SHOWCMDS);
        break;

      case 0x4CE2B3B3: // "bind"
      {
        const char *s1 = NULL, *s2;

        // If one argument is provided then print the binding for that item
        if (Console::GetArgString(1, s1))
        {
          if (Console::GetArgString(2, s2))
          {
            // Bind the key
            KeyBind::Create(s1, s2);
            break;
          }
        }

        // Print the binding
        KeyBind::Dump(KeyBind::DUMP_PRESS | KeyBind::DUMP_HOLD, s1);

        break;
      }

      case 0x3E3AF310: // "unbind"
      {
        const char *s;

        if (!Console::GetArgString(1, s))
        {
          CON_ERR((Console::ARGS))
        }
        else
        {
          // Unbind the key
          KeyBind::Remove(s);
        }
        break;
      }

      case 0xAAD665AB: // "exec"
      {
        const char *name;

        if (Console::GetArgString(1, name))
        {
          if (!Exec(name, ScopeHandler, FALSE))
          {
            CON_ERR(("Unable to exec file '%s' (not found)", name))
          }
        }
        else
        {
          CON_ERR((Console::ARGS))
        }
        break;
      }

      case 0x93890429: // "echo"
      {
        const char *str;

        if (Console::GetArgString(1, str))
        {
          CON_MSG((str))
        }
        break;
      }

      //
      // System commands
      //
      case 0x2AF1E6BC: // "sys.info"
        CON_DIAG(("CPU: %s", Hardware::CPU::GetDetailedDesc()))
        CON_DIAG(("MEM: %s", Hardware::Memory::GetDesc()))
        CON_DIAG(("OS : %s", Hardware::OS::GetDesc()))
        break;

      case 0x65CDFB1A: // "sys.uptime"
        CON_ERR(("I fell off my bike and hurt my knee :("))
        break;

      case 0x9FE06237: // "sys.profile"
        break;

      case 0x1C3D54FD: // "sys.ver"
        CON_DIAG((Version::GetBuildString()))
        CON_DIAG(("Compiler flags: %s", Version::GetBuildDefs()))
        CON_DIAG(("Compiled by %s\\%s on %s", Version::GetBuildMachine(), Version::GetBuildUser(), Version::GetBuildOS()))
        CON_DIAG(("Executed by %s\\%s on %s", Hardware::OS::GetComputer(), Hardware::OS::GetUser(), Hardware::OS::GetDesc()))
        break;

      case 0x27988902: // "sys.runcode"
      {
        const char *s;

        if (Console::ArgCount() == 2 && Console::GetArgString(1, s))
        {
          runCodes.Set(s);
        }
        else
        {
          CON_ERR((Console::ARGS))
        }
        break;
      }

      case 0x94908FF0: // "sys.runonce"
      {
        const char *s;

        if (Console::GetArgString(1, s))
        {
          AddRunOnceCmd(s);
        }
        else
        {
          CON_ERR((Console::ARGS))
        }
        break;
      }

      case 0xEBB16C2F: // "sys.buildfileindexes"
        FileSys::BuildIndexes();
        break;

      //
      // Profile commands
      //
      case 0xC20C046F: // "profile.init"
      {
        S32 max;
        S32 interval;

        if (!Console::GetArgInteger(1, max) || !Console::GetArgInteger(2, interval))
        {
          CON_ERR(("profile.init max interval"))
        }
        else
        {
          Profile::Init(max, interval);
          profileOn = TRUE;
        }
        break;
      }

      case 0x484CCBF7: // "profile.reset"
        if (!profileOn)
        {
          CON_ERR(("Profiling is not initialized, use profile.init"))
        }
        else
        {
          Profile::Reset();
        }
        break;

      case 0x139D6F79: // "profile.start"
        if (!profileOn)
        {
          CON_ERR(("Profiling is not initialized, use profile.init"))
        }
        else
        {
          Profile::Start();
        }
        break;

      case 0x96C4A523: // "profile.stop"
        if (!profileOn)
        {
          CON_ERR(("Profiling is not initialized, use profile.init"))
        }
        else
        {
          Profile::Stop();
        }
        break;

      //
      // Debug commands
      //
      case 0x7C6C010C: // "debug.break"
        DebugBreak();
        break;

      case 0xE7123308: // "debug.assert"
      {
        CON_DIAG(("Calling ASSERT(0)"))
        Bool fatal = 0;
        fatal;
        ASSERT(fatal);
        break;
      }
  
      case 0x406C755D: // "debug.stackoverflow"
        CmdHandler(0x406C755D);
        break;

      case 0x019C9670: // "debug.filesys"
        CON_DIAG(("Logging all file sources"))
        FileSys::LogAllSources();
        break;

      case 0x72E8EE93: // "debug.infiniteloop"
      {
        for (;;)
        {
        }
      }

      case 0xB67F90C3: // "debug.loop"
      {
        S32 time;

        if (Console::GetArgInteger(1, time) && (time > 0))
        {
          U32 start = Clock::Time::Ms();

          for (;;)
          {
            if (Clock::Time::Ms() > (start + U32(time)))
            {
              break;
            }
          }
        }
        break;
      }

      case 0x329B7354: // "debug.zerodiv"
      {
        Utils::FP::UnmaskException(Utils::FP::EX_ZERODIVIDE);
        F32 a = 0.0F;
        F32 b = 5.0F / a;
        b;
        break;
      }

      case 0x9C3DECF8: // "debug.intzerodiv"
      {
        S32 a = 0;
        S32 b = 5 / a;
        b;
        break;
      }

      case 0x0C887FB2: // "debug.overflow"
      {
        Utils::FP::UnmaskException(Utils::FP::EX_OVERFLOW);
        F32 a = F32_MAX;
        a *= 2.0F;
        break;
      }

      case 0x3B8C9F71: // "debug.underflow"
      {
        Utils::FP::UnmaskException(Utils::FP::EX_UNDERFLOW);
        F32 a = F32_EPSILON;
        a *= F32_EPSILON;
        break;
      }

      case 0x4A533750: // "debug.dircrc"
      {
        // Dump Directory Crc
        U32 crc = Dir::Crc(".\\packs");
        CON_DIAG(("Data Crc: [%08X]", crc))
        break;
      }

      case 0xD30DA7AC: // "debug.dumpsymbols"
        Debug::Symbol::Dump();
        break;

      case 0x21237FCF: // "debug.memory.accessviolation"
      {
        U8 *p = NULL;
        *(p+0xFFFFFFFF) = 0;
        break;
      }

      case 0xF0BA78F5: // "debug.memory.overwritehead"
      {
        U8 *p = new U8[24];
        *(p - 2) = 0x00;
        delete p;
        break;
      }

      case 0x29939DAF: // "debug.memory.overwritetail"
      {
        U8 *p = new U8[24];
        *(p + 26) = 0x00;
        delete p;
        break;
      }

      case 0x1C7E4D06: // "debug.memory.useall"
      {
        U32 meg = 0;

        for (;;)
        {
          char *mem = new char[1048576 * 5];
          memset(mem, 0, 1048576 * 5);
          meg+=5;
          LOG_DIAG(("Allocated %d megs", meg));
        }
        break;
      }

      case 0x137FF882: // "debug.memory.snapshot"
      {
        Debug::Memory::SnapShot();
        break;
      }

      case 0x24D608EF: // "debug.memory.report"
      {
        CON_DIAG(("Memory Report"))
        CON_DIAG(("-------------"))
        CON_DIAG(("Current Memory Usage:"))
        CON_DIAG(("Allocated Blocks : %d", Debug::Memory::GetAllocatedBlocks()))
        CON_DIAG(("Allocated Bytes  : %d", Debug::Memory::GetAllocatedBytes()))
        CON_DIAG(("Overhead Bytes   : %d", Debug::Memory::GetOverheadBytes()))
        CON_DIAG(("Cache Blocks     : %d", Debug::Memory::GetCacheBlocks()))
        CON_DIAG(("Cache Bytes      : %d", Debug::Memory::GetCacheBytes()))
        CON_DIAG(("Maximum Memory Usage:"))
        CON_DIAG(("Allocated Blocks : %d", Debug::Memory::GetMaxAllocatedBlocks()))
        CON_DIAG(("Allocated Bytes  : %d", Debug::Memory::GetMaxAllocatedBytes()))
        CON_DIAG(("Overhead Bytes   : %d", Debug::Memory::GetMaxOverheadBytes()))
        CON_DIAG(("Cache Blocks     : %d", Debug::Memory::GetMaxCacheBlocks()))
        CON_DIAG(("Cache Bytes      : %d", Debug::Memory::GetMaxCacheBytes()))
        break;
      }

      case 0x46B0E840: // "debug.memory.flushcache"
        Debug::Memory::FlushCache();
        break;

      case 0x238DA5B4: // "debug.memory.validateall"
        CON_DIAG(("Validating Memory ..."))
        Debug::Memory::ValidateAll();
        break;

      case 0x1C2EF73F: // "debug.memory.examine"
        Debug::Memory::Examine();
        break;

    }