Ejemplo n.º 1
0
//------------------------------------------------------------------------------
void DisplayErrorAlert(const char* errMsg, bool showSDLError)
{
   char fullErrMsg[2048];
   dStrncpy(fullErrMsg, errMsg, sizeof(fullErrMsg));
   
   if (showSDLError)
   {
      char* sdlerror = SDL_GetError();
      if (sdlerror != NULL && dStrlen(sdlerror) > 0)
      {
         dStrcat(fullErrMsg, "  (Error: ");
         dStrcat(fullErrMsg, sdlerror);
         dStrcat(fullErrMsg, ")");
      }
   }
   
   Platform::AlertOK("Error", fullErrMsg);
}
Ejemplo n.º 2
0
   const char* setUnit(const char *string, U32 index, const char *replace, const char *set)
   {
      U32 sz;
      const char *start = string;

      AssertFatal( dStrlen(string) + dStrlen(replace) + 1 < sizeof( _returnBuffer ), "Size of returned string too large for return buffer" );

      char *ret = &_returnBuffer[0];
      ret[0] = '\0';
      U32 padCount = 0;

      while(index--)
      {
         sz = dStrcspn(string, set);
         if(string[sz] == 0)
         {
            string += sz;
            padCount = index + 1;
            break;
         }
         else
            string += (sz + 1);
      }
      // copy first chunk
      sz = string-start;
      dStrncpy(ret, start, sz);
      for(U32 i = 0; i < padCount; i++)
         ret[sz++] = set[0];

      // replace this unit
      ret[sz] = '\0';
      dStrcat(ret, replace);

      // copy remaining chunks
      sz = dStrcspn(string, set);         // skip chunk we're replacing
      if(!sz && !string[sz])
         return ret;

      string += sz;
      dStrcat(ret, string);
      return ret;
   }
void SimFieldDictionary::writeFields(SimObject *obj, Stream &stream, U32 tabStop)
{
   const AbstractClassRep::FieldList &list = obj->getFieldList();
   Vector<Entry *> flist(__FILE__, __LINE__);

   for(U32 i = 0; i < HashTableSize; i++)
   {
      for(Entry *walk = mHashTable[i];walk; walk = walk->next)
      {
         // make sure we haven't written this out yet:
         U32 i;
         for(i = 0; i < list.size(); i++)
            if(list[i].pFieldname == walk->slotName)
               break;

         if(i != list.size())
            continue;


         if (!obj->writeField(walk->slotName, walk->value))
            continue;

         flist.push_back(walk);
      }
   }

   // Sort Entries to prevent version control conflicts
   dQsort(flist.address(),flist.size(),sizeof(Entry *),compareEntries);

   // Save them out
   for(Vector<Entry *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
   {
      U32 nBufferSize = (dStrlen( (*itr)->value ) * 2) + dStrlen( (*itr)->slotName ) + 16;
      FrameTemp<char> expandedBuffer( nBufferSize );

      stream.writeTabs(tabStop+1);

      const char *typeName = (*itr)->type && (*itr)->type->getTypeID() != TypeString ? (*itr)->type->getTypeName() : "";
      dSprintf(expandedBuffer, nBufferSize, "%s%s%s = \"", typeName, *typeName ? " " : "", (*itr)->slotName);
      if ( (*itr)->value )
         expandEscape((char*)expandedBuffer + dStrlen(expandedBuffer), (*itr)->value);
      dStrcat(expandedBuffer, "\";\r\n");

      stream.write(dStrlen(expandedBuffer),expandedBuffer);
   }

}
Ejemplo n.º 4
0
void NetStringTable::expandString(NetStringHandle &inString, char *buf, U32 bufSize, U32 argc, const char **argv)
{
   buf[0] = StringTagPrefixByte;
   dSprintf(buf + 1, bufSize - 1, "%d ", inString.getIndex());

   const char *string = inString.getString();
   if (string != NULL) {
      U32 index = dStrlen(buf);
      while(index < bufSize)
      {
         char c = *string++;
         if(c == '%')
         {
            c = *string++;
            if(c >= '1' && c <= '9')
            {
               U32 strIndex = c - '1';
               if(strIndex >= argc)
                  continue;
               // start copying out of arg index
               const char *copy = argv[strIndex];
               // skip past any tags:
               if(*copy == StringTagPrefixByte)
               {
                  while(*copy && *copy != ' ')
                     copy++;
                  if(*copy)
                     copy++;
               }

               while(*copy && index < bufSize)
                  buf[index++] = *copy++;
               continue;
            }
         }
         buf[index++] = c;
         if(!c)
            break;
      }
      buf[bufSize - 1] = 0;
   } else {
      dStrcat(buf, "<NULL>");
   }
}
Ejemplo n.º 5
0
void ConsoleObject::endArray( const char *arrayName )
{
   char *nameBuff = suppressSpaces(arrayName);
   dStrcat(nameBuff, "_endarray");

   // Create Field.
   AbstractClassRep::Field f;
   f.pFieldname   = StringTable->insert(nameBuff);
   f.pGroupname   = arrayName;
   f.type         = AbstractClassRep::EndArrayFieldType;
   f.groupExpand  = false;
   f.validator    = NULL;
   f.setDataFn    = &defaultProtectedSetFn;
   f.getDataFn    = &defaultProtectedGetFn;
   f.elementCount = 0;

   // Add to field list.
   sg_tempFieldList.push_back(f);
}
Ejemplo n.º 6
0
bool GuiFormCtrl::resize(const Point2I &newPosition, const Point2I &newExtent)
{
   if( !Parent::resize(newPosition, newExtent) ) 
      return false;

   if( !mAwake || !mProfile->mBitmapArrayRects.size() )
      return false;

   // Should the caption be modified because the title bar is too small?
   S32 textWidth = mProfile->mFont->getStrWidth(mCaption);
   S32 newTextArea = getWidth() - mThumbSize.x - mProfile->mBitmapArrayRects[4].extent.x;
   if(newTextArea < textWidth)
   {
      static char buf[256];

      mUseSmallCaption = true;
      mSmallCaption = StringTable->insert("");

      S32 strlen = dStrlen((const char*)mCaption);
      for(S32 i=strlen; i>=0; --i)
      {
         dStrcpy(buf, "");
         dStrncat(buf, (const char*)mCaption, i);
         dStrcat(buf, "...");

         textWidth = mProfile->mFont->getStrWidth(buf);

         if(textWidth < newTextArea)
         {
            mSmallCaption = StringTable->insert(buf, true);
            break;
         }
      }

   } else
   {
      mUseSmallCaption = false;
   }

   onResize_callback();

   return true;
}
/// Function invoked by the kernel layer to install OS specific
/// file systems.
bool Platform::FS::InstallFileSystems()
{
   Platform::FS::Mount( "/", Platform::FS::createNativeFS( String() ) );

   // Setup the current working dir.
   char buffer[PATH_MAX];
   if (::getcwd(buffer,sizeof(buffer)))
   {
      // add trailing '/' if it isn't there
      if (buffer[dStrlen(buffer) - 1] != '/')
         dStrcat(buffer, "/");
         
      Platform::FS::SetCwd(buffer);
   }
   
   // Mount the home directory
   if (char* home = getenv("HOME"))
      Platform::FS::Mount( "home", Platform::FS::createNativeFS(home) );

   return true;
}
Ejemplo n.º 8
0
void ConsoleObject::endGroup(const char*  in_pGroupname)
{
   // Remove spaces.
   char* pFieldNameBuf = suppressSpaces(in_pGroupname);

   // Append group type to fieldname.
   dStrcat(pFieldNameBuf, "_endgroup");

   // Create Field.
   AbstractClassRep::Field f;
   f.pFieldname   = StringTable->insert(pFieldNameBuf);
   f.pGroupname   = in_pGroupname;
   f.type         = AbstractClassRep::EndGroupFieldType;
   f.groupExpand  = false;
   f.validator    = NULL;
   f.setDataFn    = &defaultProtectedSetFn;
   f.getDataFn    = &defaultProtectedGetFn;
   f.elementCount = 0;

   // Add to field list.
   sg_tempFieldList.push_back(f);
}
Ejemplo n.º 9
0
   const char* removeUnit(const char *string, U32 index, const char *set)
   {
      U32 sz;
      const char *start = string;
      AssertFatal( dStrlen(string) + 1 < sizeof( _returnBuffer ), "Size of returned string too large for return buffer" );

      char *ret = &_returnBuffer[0];
      ret[0] = '\0';

      while(index--)
      {
         sz = dStrcspn(string, set);
         // if there was no unit out there... return the original string
         if(string[sz] == 0)
            return start;
         else
            string += (sz + 1);
      }
      // copy first chunk
      sz = string-start;
      dStrncpy(ret, start, sz);
      ret[sz] = 0;

      // copy remaining chunks
      sz = dStrcspn(string, set);         // skip chunk we're removing

      if(string[sz] == 0) {               // if that was the last...
         if(string != start) {
            ret[string - start - 1] = 0;  // then kill any trailing delimiter
         }
         return ret;                      // and bail
      }

      string += sz + 1; // skip the extra field delimiter
      dStrcat(ret, string);
      return ret;
   }
Ejemplo n.º 10
0
bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite)
{
   AssertFatal( fromName != NULL && toName != NULL, "dPathCopy - NULL file name" );

   TempAlloc< TCHAR > from( dStrlen( fromName ) + 1 );
   TempAlloc< TCHAR > to( dStrlen( toName ) + 1 );

#ifdef UNICODE
   convertUTF8toUTF16( fromName, from, from.size );
   convertUTF8toUTF16( toName, to, to.size );
#else
   dStrcpy( from, fromName );
   dStrcpy( to, toName );
#endif

   backslash( from );
   backslash( to );

   // Copy File
   if (Platform::isFile(fromName))
      return CopyFile( from, to, nooverwrite );
   // Copy Path
   else if (Platform::isDirectory(fromName))
   {
      // If the destination path exists and we don't want to overwrite, return.
      if ((Platform::isDirectory(toName) || Platform::isFile(toName)) && nooverwrite)
         return false;

      Vector<StringTableEntry> directoryInfo;
      Platform::dumpDirectories(fromName, directoryInfo, -1);

      Vector<Platform::FileInfo> fileInfo;
      Platform::dumpPath(fromName, fileInfo);

      Platform::clearExcludedDirectories();

      TempAlloc< char > tempBuf( to.size * 3 + MAX_PATH * 3 );

      // Create all the directories.
      for (S32 i = 0; i < directoryInfo.size(); i++)
      {
         const char* fromDir = directoryInfo[i];

         char* toDir = tempBuf;
         Platform::makeFullPathName(fromDir + dStrlen(fromName) + (dStricmp(fromDir, fromName) ? 1 : 0), tempBuf, tempBuf.size, toName);
         if(*(toDir + dStrlen(toDir) - 1) != '/')
            dStrcat(toDir, "/");
         forwardslash(toDir);

         if (!Platform::createPath(toDir))
         {
            //TODO: New directory should be deleted here.
            return false;
         }
      }

      TempAlloc< char > tempBuf1( from.size * 3 + MAX_PATH * 3 );
#ifdef UNICODE
      TempAlloc< WCHAR > wtempBuf( tempBuf.size / 3 );
      TempAlloc< WCHAR > wtempBuf1( tempBuf1.size / 3 );
#endif

      for (S32 i = 0; i < fileInfo.size(); i++)
      {
         char* fromFile = tempBuf1;
         dSprintf( tempBuf1, tempBuf1.size, "%s/%s", fileInfo[i].pFullPath, fileInfo[i].pFileName);

         char* toFile = tempBuf;
         Platform::makeFullPathName(fileInfo[i].pFullPath + dStrlen(fromName) + (dStricmp(fileInfo[i].pFullPath, fromName) ? 1 : 0), tempBuf, tempBuf.size, toName);
         dStrcat(toFile, "/");
         dStrcat(toFile, fileInfo[i].pFileName);

         backslash(fromFile);
         backslash(toFile);
         
#ifdef UNICODE
         convertUTF8toUTF16( tempBuf, wtempBuf, wtempBuf.size );
         convertUTF8toUTF16( tempBuf1, wtempBuf1, wtempBuf1.size );
         WCHAR* f = wtempBuf1;
         WCHAR* t = wtempBuf;
#else
         char *f = (char*)fromFile;
         char *t = (char*)toFile;
#endif

         if (!::CopyFile(f, t, nooverwrite))
         {
            // New directory should be deleted here.
            return false;
         }

      }

      return true;
   }

   return false;
}
Ejemplo n.º 11
0
bool PxSingleActorData::preload( bool server, String &errorBuffer )
{
   if ( !Parent::preload( server, errorBuffer ) )
      return false;

   // If the stream is null, exit.
   if ( !physXStream || !physXStream[0] )
   {
      errorBuffer = "PxSingleActorData::preload: physXStream is unset!";
      return false;
   }

   // Set up our buffer for the binary stream filename path.
   UTF8 binPhysXStream[260] = { 0 };
   const UTF8* ext = dStrrchr( physXStream, '.' );

   // Copy the xml stream path except for the extension.
   if ( ext )
      dStrncpy( binPhysXStream, physXStream, getMin( 260, ext - physXStream ) );
   else
      dStrncpy( binPhysXStream, physXStream, 260 );

   // Concatenate the binary extension.
   dStrcat( binPhysXStream, ".nxb" );

   // Get the modified times of the two files.
   FileTime xmlTime = {0}, binTime = {0};
   Platform::getFileTimes( physXStream, NULL, &xmlTime );
   Platform::getFileTimes( binPhysXStream, NULL, &binTime );

   // If the binary is newer... load that.
   if ( Platform::compareFileTimes( binTime, xmlTime ) >= 0 )
      _loadCollection( binPhysXStream, true );

   // If the binary failed... then load the xml.
   if ( !physicsCollection )
   {
      _loadCollection( physXStream, false );

      // If loaded... resave the xml in binary format
      // for quicker subsequent loads.
      if ( physicsCollection )
         NXU::saveCollection( physicsCollection, binPhysXStream, NXU::FT_BINARY );
   }

   // If it still isn't loaded then we've failed!
   if ( !physicsCollection )
   {
      errorBuffer = String::ToString( "PxSingleActorData::preload: could not load '%s'!", physXStream );
      return false;
   }

   if (!shapeName || shapeName == '\0') 
   {
      errorBuffer = "PxSingleActorData::preload: no shape name!";
      return false;
   }

   // Now load the shape.
   shape = ResourceManager::get().load( shapeName );

   if (bool(shape) == false)
   {
      errorBuffer = String::ToString( "PxSingleActorData::preload: unable to load shape: %s", shapeName );
      return false;
   }

   return true;
}
 //------------------------------------------------------------------------------
 // munge the case of the specified pathName.  This means try to find the actual
 // filename in with case-insensitive matching on the specified pathName, and
 // store the actual found name.
 static void MungeCase(char* pathName, S32 pathNameSize)
 {
    char tempBuf[MaxPath];
    dStrncpy(tempBuf, pathName, pathNameSize);

    AssertFatal(pathName[0] == '/', "PATH must be absolute");

    struct stat filestat;
    const int MaxPathEl = 200;
    char *currChar = pathName;
    char testPath[MaxPath];
    char pathEl[MaxPathEl];
    bool done = false;

    dStrncpy(tempBuf, "/", MaxPath);
    currChar++;

    while (!done)
    {
       char* termChar = dStrchr(currChar, '/');
       if (termChar == NULL)
          termChar = dStrchr(currChar, '\0');
       AssertFatal(termChar, "Can't find / or NULL terminator");

       S32 pathElLen = (termChar - currChar);
       dStrncpy(pathEl, currChar, pathElLen);
       pathEl[pathElLen] = '\0';
       dStrncpy(testPath, tempBuf, MaxPath);
       dStrcat(testPath, pathEl);
       if (stat(testPath, &filestat) != -1)
       {
          dStrncpy(tempBuf, testPath, MaxPath);
       }
       else
       {
          DIR *dir = opendir(tempBuf);
          struct dirent* ent;
          bool foundMatch = false;
          while (dir != NULL && (ent = readdir(dir)) != NULL)
          {
             if (dStricmp(pathEl, ent->d_name) == 0)
             {
                foundMatch = true;
                dStrcat(tempBuf, ent->d_name);
                break;
             }
          }

          if (!foundMatch)
             dStrncpy(tempBuf, testPath, MaxPath);
          if (dir)
             closedir(dir);
       }
       if (*termChar == '/')
       {
          dStrcat(tempBuf, "/");
          termChar++;
          currChar = termChar;
       }
       else
          done = true;
    }

    dStrncpy(pathName, tempBuf, pathNameSize);
 }