//-------------------------------------- void _StringTable::resize(const U32 newSize) { Node *head = NULL, *walk, *temp; U32 i; // reverse individual bucket lists // we do this because new strings are added at the end of bucket // lists so that case sens strings are always after their // corresponding case insens strings for(i = 0; i < numBuckets; i++) { walk = buckets[i]; while(walk) { temp = walk->next; walk->next = head; head = walk; walk = temp; } } buckets = (Node **) dRealloc(buckets, newSize * sizeof(Node)); for(i = 0; i < newSize; i++) { buckets[i] = 0; } numBuckets = newSize; walk = head; while(walk) { U32 key; Node *temp = walk; walk = walk->next; key = hashString(temp->val); temp->next = buckets[key % newSize]; buckets[key % newSize] = temp; } }
U32 MemFile::write(const void* src, U32 size) { if ((mStatus != Open && mStatus != EndOfFile) || !size) return 0; if (mFileData->mFileSize + size > mFileData->mBufferSize) { // Keep doubling our buffer size until we're big enough. while (mFileData->mFileSize + size > mFileData->mBufferSize) mFileData->mBufferSize *= 2; mFileData->mBuffer = dRealloc(mFileData->mBuffer, mFileData->mBufferSize); if (!mFileData->mBuffer) { mStatus = FileSystemFull; return 0; } } dMemcpy((U8*)mFileData->mBuffer + mCurrentPos, src, size); mCurrentPos += size; mFileData->mFileSize = getMax(mFileData->mFileSize, mCurrentPos); mFileData->mLastAccess = Time::getCurrentTime(); mFileData->mModified = mFileData->mLastAccess; return size; }
void dArrayBase::_setSize (int newsize, int sizeofT) { if (newsize < 0) return; if (newsize > _anum) { if (_data == this+1) { // this is a no-no, because constructLocalArray() was called dDebug (0,"setSize() out of space in LOCAL array"); } int newanum = roundUpToPowerOfTwo (newsize); if (_data) _data = dRealloc (_data, _anum*sizeofT, newanum*sizeofT); else _data = dAlloc (newanum*sizeofT); _anum = newanum; } _size = newsize; }
void TCPObject::parseLine(U8 *buffer, U32 *start, U32 bufferLen) { // find the first \n in buffer U32 i; U8 *line = buffer + *start; for(i = *start; i < bufferLen; i++) if(buffer[i] == '\n' || buffer[i] == 0) break; U32 len = i - *start; if(i == bufferLen || mBuffer) { // we've hit the end with no newline mBuffer = (U8 *) dRealloc(mBuffer, mBufferSize + len + 1); dMemcpy(mBuffer + mBufferSize, line, len); mBufferSize += len; *start = i; // process the line if(i != bufferLen) { mBuffer[mBufferSize] = 0; if(mBufferSize && mBuffer[mBufferSize-1] == '\r') mBuffer[mBufferSize - 1] = 0; U8 *temp = mBuffer; mBuffer = 0; mBufferSize = 0; processLine((UTF8*)temp); dFree(temp); } } else if(i != bufferLen) { line[len] = 0; if(len && line[len-1] == '\r') line[len-1] = 0; processLine((UTF8*)line); } if(i != bufferLen) *start = i + 1; }
U32 NetStringTable::addString(const char *string) { U32 hash = _StringTable::hashString(string); U32 bucket = hash % HashTableSize; for(U32 walk = hashTable[bucket];walk; walk = table[walk].next) { if(!dStrcmp(table[walk].string, string)) { table[walk].refCount++; return walk; } } U32 e = firstFree; firstFree = table[e].next; if(firstFree == InvalidEntry) { // in this case, we should expand the table for next time... U32 newSize = size * 2; table = (Entry *) dRealloc(table, newSize * sizeof(Entry)); for(U32 i = size; i < newSize; i++) { table[i].next = i + 1; table[i].refCount = 0; table[i].scriptRefCount = 0; } firstFree = size; table[newSize - 1].next = InvalidEntry; size = newSize; } table[e].refCount++; table[e].string = (char *) allocator->alloc(dStrlen(string) + 1); dStrcpy(table[e].string, string); table[e].next = hashTable[bucket]; hashTable[bucket] = e; table[e].link = firstValid; table[firstValid].prevLink = e; firstValid = e; table[e].prevLink = 0; return e; }
static void *_OU_CONVENTION_CALLBACK ForwardOUMemoryRealloc(void *pv_ExistingBlock, size_t nBlockNewSize) { return dRealloc(pv_ExistingBlock, 0, nBlockNewSize); }
void PlatformFont::enumeratePlatformFonts( Vector< StringTableEntry >& fonts, UTF16* fontFamily ) { if( fontFamily ) { // Determine the font ID from the family name. ATSUFontID fontID; if( ATSUFindFontFromName( fontFamily, dStrlen( fontFamily ) * 2, kFontFamilyName, kFontMicrosoftPlatform, kFontNoScriptCode, kFontNoLanguageCode, &fontID ) != kATSUInvalidFontErr ) { // Get the number of fonts in the family. ItemCount numFonts; ATSUCountFontNames( fontID, &numFonts ); // Read out font names. U32 bufferSize = 512; char* buffer = ( char* ) dMalloc( bufferSize ); for( U32 i = 0; i < numFonts; ++ i ) { for( U32 n = 0; n < 2; ++ n ) { ByteCount actualNameLength; FontNameCode fontNameCode; FontPlatformCode fontPlatformCode; FontScriptCode fontScriptCode; FontLanguageCode fontLanguageCode; if( ATSUGetIndFontName( fontID, i, bufferSize - 2, buffer, &actualNameLength, &fontNameCode, &fontPlatformCode, &fontScriptCode, &fontLanguageCode ) == noErr ) { *( ( UTF16* ) &buffer[ actualNameLength ] ) = '\0'; char* utf8 = convertUTF16toUTF8( ( UTF16* ) buffer ); fonts.push_back( StringTable->insert( utf8 ) ); delete [] utf8; break; } // Allocate larger buffer. bufferSize = actualNameLength + 2; buffer = ( char* ) dRealloc( buffer, bufferSize ); } } dFree( buffer ); } } else { // Get the number of installed fonts. ItemCount numFonts; ATSUFontCount( &numFonts ); // Get all the font IDs. ATSUFontID* fontIDs = new ATSUFontID[ numFonts ]; if( ATSUGetFontIDs( fontIDs, numFonts, &numFonts ) == noErr ) { U32 bufferSize = 512; char* buffer = ( char* ) dMalloc( bufferSize ); // Read all family names. for( U32 i = 0; i < numFonts; ++ i ) { for( U32 n = 0; n < 2; ++ n ) { ByteCount actualNameLength; ItemCount fontIndex; OSStatus result = ATSUFindFontName( fontIDs[ i ], kFontFamilyName, kFontMicrosoftPlatform, kFontNoScriptCode, kFontNoLanguageCode, bufferSize - 2, buffer, &actualNameLength, &fontIndex ); if( result == kATSUNoFontNameErr ) break; else if( result == noErr ) { *( ( UTF16* ) &buffer[ actualNameLength ] ) = '\0'; char* utf8 = convertUTF16toUTF8( ( UTF16* ) buffer ); StringTableEntry name = StringTable->insert( utf8 ); delete [] utf8; // Avoid duplicates. bool duplicate = false; for( U32 i = 0, num = fonts.size(); i < num; ++ i ) if( fonts[ i ] == name ) { duplicate = true; break; } if( !duplicate ) fonts.push_back( name ); break; } // Allocate larger buffer. bufferSize = actualNameLength + 2; buffer = ( char* ) dRealloc( buffer, bufferSize ); } } dFree( buffer ); } delete [] fontIDs; } }
/*! * Create dpi directory for available * plugins and create plugin list. * \Return * \li Returns number of available plugins on success * \li -1 on failure */ int register_all(struct dp **attlist) { DIR *user_dir_stream, *sys_dir_stream; char *user_dpidir = NULL, *sys_dpidir = NULL, *dpidrc = NULL; struct dirent *user_dirent, *sys_dirent; int st; int snum; size_t dp_sz = sizeof(struct dp); if (*attlist != NULL) { ERRMSG("register_all", "attlist parameter should be NULL", 0); return -1; } user_dpidir = dStrconcat(dGethomedir(), "/", dotDILLO_DPI, NULL); if (access(user_dpidir, F_OK) == -1) { /* no dpis in user's space */ dFree(user_dpidir); user_dpidir = NULL; } dpidrc = dStrconcat(dGethomedir(), "/", dotDILLO_DPIDRC, NULL); if (access(dpidrc, F_OK) == -1) { dFree(dpidrc); dpidrc = dStrdup(DPIDRC_SYS); if (access(dpidrc, F_OK) == -1) { dFree(dpidrc); dpidrc = NULL; } } if (!dpidrc || (sys_dpidir = get_dpi_dir(dpidrc)) == NULL) sys_dpidir = NULL; dFree(dpidrc); if (!user_dpidir && !sys_dpidir) { ERRMSG("register_all", "Fatal error ", 0); MSG_ERR("\n - Can't find the directory for dpis.\n"); exit(1); } /* Get list of services in user's .dillo/dpi directory */ snum = 0; if (user_dpidir && (user_dir_stream = opendir(user_dpidir)) != NULL) { while ((user_dirent = readdir(user_dir_stream)) != NULL) { if (user_dirent->d_name[0] == '.') continue; *attlist = (struct dp *) dRealloc(*attlist, (snum + 1) * dp_sz); st=get_dpi_attr(user_dpidir, user_dirent->d_name, &(*attlist)[snum]); if (st == 0) snum++; } closedir(user_dir_stream); } if (sys_dpidir && (sys_dir_stream = opendir(sys_dpidir)) != NULL) { /* if system service is not in user list then add it */ while ((sys_dirent = readdir(sys_dir_stream)) != NULL) { if (sys_dirent->d_name[0] == '.') continue; *attlist = (struct dp *) dRealloc(*attlist, (snum + 1) * dp_sz); st=get_dpi_attr(sys_dpidir, sys_dirent->d_name, &(*attlist)[snum]); if (st == 0) snum++; } closedir(sys_dir_stream); } dFree(sys_dpidir); dFree(user_dpidir); /* TODO: do we consider snum == 0 an error? * (if so, we should return -1 ) */ return (snum); }