コード例 #1
0
ファイル: map.c プロジェクト: mrhill/babel
void bbMapDump(const bbMapRec* pMap)
{
    bbUINT i = 0, keychunks = 0;
    bbU32 datasize = 0, memsize = 0, chunksize;
    const struct bbMapKeyChunk* pChunk;
    const struct bbMapKeyChunk** chunkPtrs;
    const bbCHAR** chunkEnds;
    const bbCHAR* pStr;

    bbPrintf("bbMap mSize:%u\n", pMap->mSize);

    for(keychunks = 0, pChunk = pMap->mpKeyChunk; pChunk; pChunk = pChunk->next)
        keychunks++;
    chunkPtrs = bbMemAlloc(keychunks * sizeof(void*));
    chunkEnds = bbMemAlloc(keychunks * sizeof(void*));

    for(i = 0, pChunk = pMap->mpKeyChunk; pChunk; i++, pChunk = pChunk->next)
    {
        chunkPtrs[i] = pChunk;
        chunkEnds[i] = pChunk->str;
    }

    for(i=0; i<pMap->mSize; i++)
    {
        bbUINT keylen = bbStrLen(pMap->mpPairs[i].key) + 1;
        bbUINT keychunk = bbMapGetChunkNumberForKey(pMap, pMap->mpPairs[i].key);

        if (keychunk < keychunks)
        {
            const bbCHAR* pKeyEnd = pMap->mpPairs[i].key + keylen;
            if (chunkEnds[keychunk] < pKeyEnd)
                chunkEnds[keychunk] = pKeyEnd;
            datasize += keylen * sizeof(bbCHAR);
        }

        datasize += sizeof(bbMapPair);
        memsize += sizeof(bbMapPair);
        bbPrintf(" \"%s\":0x%"bbI64"u chunk %d\n", pMap->mpPairs[i].key, pMap->mpPairs[i].val, keychunk);
    }

    for(i=0; i<keychunks; i++)
    {
        pChunk = chunkPtrs[i];
        chunksize = (chunkEnds[i] - pChunk->str) * sizeof(bbCHAR);
        memsize += chunksize;
        bbPrintf(" keychunk %u, size %u, used %u, refct %u, \"", i, chunksize, pChunk->used, pChunk->refct);
        for(pStr = pChunk->str; pStr<chunkEnds[i]; )
            pStr += bbPrintf("%s.", pStr);
        bbPrintf("\"\n");
    }

    bbPrintf(" datasize %u, memsize %u\n", datasize, memsize);

    bbMemFree((void*)chunkEnds);
    bbMemFree((void*)chunkPtrs);
}
コード例 #2
0
void *bbMemExtend( void *mem,int size,int new_size ){
	void *p;
	p=bbMemAlloc( new_size );
	bbMemCopy( p,mem,size );
	bbMemFree( mem );
	return p;
}
コード例 #3
0
ファイル: lgcore.cpp プロジェクト: EdibleGhost/lugi.mod
/* Internal
  Places the offset of an instance variable for a class into the global list of glue info
  An exception is thrown if you pass a NULL pointer for the class
*/
void p_lugi_register_field(int offset, int type, BBString *name, BBClass *clas) {
    if ( clas == NULL )
        bbExThrowCString(ERRORSTR("@lugi_register_field: Cannot pass Null BBClass for field."));
    glueinfo_t *info;
    char *cname = bbStringToCString(name);

    info = lugi_g_infohead;
    while (info != NULL) {
        if ( info->type == FIELDTYPE && info->clas == clas &&
                strcmp(cname, info->name) == 0 && info->data.field.offset == offset &&
                info->data.field.type == type ) {
            // then
            bbMemFree(cname);
            return;
        }

        info = info->next;
    }


    info = (glueinfo_t*)bbMemAlloc(sizeof(glueinfo_t));
    info->type = FIELDTYPE;
    info->data.field.offset = static_cast<ptrdiff_t>(offset);
    info->data.field.type = static_cast<fieldtype_e>(type);
    info->clas = clas;
    info->name = cname;
    info->next = lugi_g_infohead;
    lugi_g_infohead = info;
}
コード例 #4
0
ファイル: strbuf.c プロジェクト: mrhill/babel
bbCHAR* bbStrBufEnsure(bbStrBuf* p, bbUINT str_len)
{
    str_len++; // 0-term

    if ((p->mCapacity - p->mLen) < str_len)
    {
        bbUINT capacity = p->mCapacity;
        do { capacity<<=1; } while ((capacity - p->mLen) < str_len);

        if (p->mpStr == p->mBuf)
        {
            bbCHAR* pNew = (bbCHAR*)bbMemAlloc(capacity * sizeof(bbCHAR));
            if (!pNew)
                return NULL;
            p->mpStr = pNew;
            bbMemMove(pNew, p->mBuf, p->mLen * sizeof(bbCHAR));
        }
        else
        {
            if (bbEOK != bbMemRealloc(capacity * sizeof(bbCHAR), (void**)&p->mpStr))
                return NULL;
        }

        p->mCapacity = capacity;
    }

    return p->mpStr + p->mLen;
}
コード例 #5
0
ファイル: blitz_string.c プロジェクト: kfprimm/brl.mod
BBChar *bbStringToWString( BBString *str ){
	BBChar *p;
	int k,sz=str->length;
	p=(BBChar*)bbMemAlloc( (sz+1)*sizeof(BBChar) );
	memcpy(p,str->buf,sz*sizeof(BBChar));
	p[sz]=0;
	return p;
}
コード例 #6
0
ファイル: blitz_string.c プロジェクト: kfprimm/brl.mod
char *bbStringToCString( BBString *str ){
	char *p;
	int k,sz=str->length;
	p=(char*)bbMemAlloc( sz+1 );
	for( k=0;k<sz;++k ) p[k]=str->buf[k];
	p[sz]=0;
	return p;
}
コード例 #7
0
ファイル: blitz_string.c プロジェクト: kfprimm/brl.mod
char *bbStringToUTF8String( BBString *str ){
	int i,len=str->length;
	char *buf=(char*)bbMemAlloc( len*3+1 );
	char *q=buf;
	unsigned short *p=str->buf;
	for( i=0;i<len;++i ){
		unsigned int c=*p++;
		if( c<0x80 ){
			*q++=c;
		}else if( c<0x800 ){
			*q++=0xc0|(c>>6);
			*q++=0x80|(c&0x3f);
		}else{
コード例 #8
0
ファイル: ptGCGDI.cpp プロジェクト: mrhill/picotype
bbERR ptGCGDI::Init()
{
    if ((mpBMI = (BITMAPINFO*) bbMemAlloc(sizeof(BITMAPINFOHEADER) + 256*4)) == NULL)
        return bbELAST;

    bbMemClear(mpBMI, sizeof(BITMAPINFOHEADER));
    mpBMI->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    mpBMI->bmiHeader.biPlanes = 1;

    mhDotPen = CreatePen(PS_DOT, 1,RGB(0, 0, 0));
    if (!mhDotPen)
        return bbErrSet(bbESYS);

    return bbEOK;
}
コード例 #9
0
ファイル: map.c プロジェクト: mrhill/babel
static struct bbMapKeyChunk* bbMapAddKeyChunk(bbMapRec* pMap, bbUINT keylen)
{
    struct bbMapKeyChunk* pNewChunk;

    if ((int)(keylen -= bbMAP_KEYCHUNKSIZE) < 0)
        keylen = 0;

    pNewChunk = bbMemAlloc(sizeof(struct bbMapKeyChunk) + keylen);
    if (pNewChunk)
    {
        pNewChunk->next = pMap->mpKeyChunk;
        pNewChunk->refct = 0;
        pNewChunk->used = 0;
        pMap->mpKeyChunk = pNewChunk;
    }

    return pNewChunk;
}
コード例 #10
0
ファイル: lgcore.cpp プロジェクト: EdibleGhost/lugi.mod
/* Internal
  Places a glue function with the name specified into the global list of glue info
  If it's a method of a class, pass a pointer to the object's BBClass to insert it into
  the class's Lua method table
  If you're registering a global function (e.g., just a regular glue function), pass a NULL pointer
  for the class
*/
void p_lugi_register_method(lua_CFunction fn, BBString *name, BBClass *clas) {
    glueinfo_t *info;
    char *cname = bbStringToCString(name);

    info = lugi_g_infohead;
    while (info != NULL) {
        if ( info->type == METHODTYPE && info->clas == clas &&
                strcmp(cname, info->name) == 0 && info->data.fn == fn ) {
            // then
            bbMemFree(cname);
            return;
        }

        info = info->next;
    }

    info = (glueinfo_t*)bbMemAlloc(sizeof(glueinfo_t));
    info->type = METHODTYPE;
    info->data.fn = fn;
    info->clas = clas;
    info->name = cname;
    info->next = lugi_g_infohead;
    lugi_g_infohead = info;
}
コード例 #11
0
ファイル: uiDlg.cpp プロジェクト: SummerSut/ui
bbCHAR* uiDlgFileName(uiWINH hWin, const bbCHAR* pPath, bbUINT opt, uiDlgFileNameFilter* const pFilter)
{
#if (bbOS == bbOS_WIN32) || (bbOS == bbOS_WINCE)

    bbCHAR* pFileNameBuffer;
    bbUINT const bufferstart = (opt & uiDLGFILEOPT_MULTISELECT) ? sizeof(uiDlgFileNameBlock)/sizeof(bbCHAR) : 0;
    OPENFILENAME ofn;

    bbMemClear(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner   = hWin;

    if (pPath)
        ofn.nMaxFile = bbStrLen(pPath) + 1;

    if (ofn.nMaxFile < 512)
        ofn.nMaxFile = 512;

    if ((pFileNameBuffer = (bbCHAR*) bbMemAlloc(sizeof(bbCHAR) * ofn.nMaxFile + sizeof(uiDlgFileNameBlock))) == NULL)
        return NULL;

    ofn.lpstrFile = pFileNameBuffer + bufferstart;

    if (pPath)
        bbStrCpy(ofn.lpstrFile, pPath);
    else
        *ofn.lpstrFile = 0;

    if (pFilter)
    {
        ofn.nFilterIndex = pFilter->FilterIndex;
        ofn.lpstrFilter  = pFilter->pFilter;
    }

    ofn.Flags = (opt & (uiDLGFILEOPT_MULTISELECT|uiDLGFILEOPT_NODEREFERENCELINKS|uiDLGFILEOPT_OVERWRITEPROMPT))
        | OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_NOTESTFILECREATE | OFN_HIDEREADONLY | OFN_EXPLORER;

    BOOL (__stdcall *fnGetFileName)(LPOPENFILENAME) = (opt & uiDLGFILEOPT_SAVE) ? GetSaveFileName : GetOpenFileName;

    if (fnGetFileName(&ofn) == 0)
    {
        DWORD err = CommDlgExtendedError();

        if (err == FNERR_BUFFERTOOSMALL)
        {
            ofn.nMaxFile = *(WORD*)ofn.lpstrFile;
            if (bbMemRealloc(sizeof(bbCHAR) * ofn.nMaxFile + sizeof(uiDlgFileNameBlock), (void**)&pFileNameBuffer) != bbEOK)
                goto uiDlgFileSave_err;
            ofn.lpstrFile = pFileNameBuffer + bufferstart;

            if (fnGetFileName(&ofn))
                goto uiDlgFileSave_ok;
            err = CommDlgExtendedError();
        }

        if (err == 0)
        {
            bbErrSet(bbEEND);
        }
        else
        {
            bbErrSet(bbESYS); //xxx add error codes
            bbLog(bbErr, bbT("uiDlgFileSave: error %X\n"), err);
        }

        goto uiDlgFileSave_err;
    }

    uiDlgFileSave_ok:

    if (pFilter)
    {
        pFilter->FilterIndex = ofn.nFilterIndex;
    }

    if (opt & uiDLGFILEOPT_MULTISELECT)
    {
        ((uiDlgFileNameBlock*)pFileNameBuffer)->CurFileOffset = 
        ((uiDlgFileNameBlock*)pFileNameBuffer)->FirstFileOffset = ofn.nFileOffset;

        if (ofn.nFileOffset > 0)
            pFileNameBuffer[ofn.nFileOffset + bufferstart - 1] = '\0'; // 0-term path also for single-selection case
    }

    return pFileNameBuffer;

    uiDlgFileSave_err:
    bbMemFree(pFileNameBuffer);
    return NULL;
#else
#endif
}