Exemplo n.º 1
0
void bmx_roomquery_AddQuery_STRING(RakNet::RoomQuery * query, BBString * columnName, BBString * charValue, int op) {
	char * c = bbStringToCString(columnName);
	char * v = bbStringToCString(charValue);
	query->AddQuery_STRING(c, v, static_cast<DataStructures::Table::FilterQueryType>(op));
	bbMemFree(c);
	bbMemFree(v);
}
Exemplo n.º 2
0
Arquivo: map.c Projeto: 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);
}
Exemplo n.º 3
0
/* Deallocates the internal list of closures */
void lugi_free_info() {
    glueinfo_t *info;
    while (lugi_g_infohead != NULL)
    {
        info = lugi_g_infohead;
        lugi_g_infohead = info->next;
        bbMemFree(info->name);	/* note: Use bbMemFree because ToCString uses bbMemAlloc, and its blocks have a small header attached to them */
        bbMemFree(info);
    }
}
Exemplo n.º 4
0
int bmx_libwebsockets_serve_http_file(struct libwebsocket_context * context, struct libwebsocket * wsi, BBString * file, BBString * contentType) {
	char * f = bbStringToUTF8String(file);
	char * c = bbStringToUTF8String(contentType);
	
	int ret = libwebsockets_serve_http_file(context, wsi, f, c);
	
	bbMemFree(c);
	bbMemFree(f);
	
	return ret;
}
Exemplo n.º 5
0
Arquivo: map.c Projeto: mrhill/babel
void bbMapDestroy(bbMapRec* pMap)
{
    struct bbMapKeyChunk* pChunk = pMap->mpKeyChunk;
    while(pChunk)
    {
        struct bbMapKeyChunk* pNext = pChunk->next;
        bbMemFree(pChunk);
        pChunk = pNext;
    }

    bbMemFree(pMap->mpPairs);

    bbMemClear(pMap, sizeof(bbMapRec));
}
Exemplo n.º 6
0
/* 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;
}
void *bbMemExtend( void *mem,int size,int new_size ){
	void *p;
	p=bbMemAlloc( new_size );
	bbMemCopy( p,mem,size );
	bbMemFree( mem );
	return p;
}
Exemplo n.º 8
0
int bmx_wxiobase_open(wxIOBase * base, BBString * deviceName, void * dcs) {
	char * p = bbStringToCString( deviceName );
	int ret = base->Open(p, dcs);
	
	bbMemFree( p );
	return ret;
}
Exemplo n.º 9
0
BBString *bbReadStdin(){

#define BUF_SIZE 256
	int sz=0;
	char *str=0;
	BBString *t;
	for(;;){
		int t_sz;
		char buf[BUF_SIZE],*p;
		fgets( buf,BUF_SIZE,stdin );
		buf[BUF_SIZE-1]=0;
		if( p=strchr( buf,'\n' ) ){
			t_sz=p-buf;
			if( t_sz && isspace(buf[t_sz-1]) ) --t_sz;
		}else{
			t_sz=strlen( buf );
		}
		str=(char*)bbMemExtend( str,sz,sz+t_sz );
		bbMemCopy( str+sz,buf,t_sz );
		sz+=t_sz;
		if( t_sz<BUF_SIZE-1 ) break;
	}
	if( sz ) t=bbStringFromBytes( str,sz );
	else t=&bbEmptyString;
	bbMemFree( str );
	return t;
}
Exemplo n.º 10
0
BBString * bmx_gme_open_file( MaxMusicEmu * emu, BBString * path, long sample_rate) {

	char *p = bbStringToCString( path );
	BBString * ret = bbStringFromCString(gme_open_file(p, &emu->emu, sample_rate));
	bbMemFree( p );
	
	return ret;
}
Exemplo n.º 11
0
XML_Status bmx_expat_XML_Parse(XML_Parser parser, BBString * text, int isFinal) {

	char * c = bbStringToUTF8String(text);

	XML_Status res = XML_Parse(parser, c, strlen(c), isFinal);
	
	bbMemFree(c);
	return res;
}
Exemplo n.º 12
0
XML_Status bmx_expat_XML_SetBase(XML_Parser parser, BBString * base) {

	char * c = bbStringToUTF8String(base);

	XML_Status res = XML_SetBase(parser, c);
	
	bbMemFree(c);
	return res;
}
Exemplo n.º 13
0
int bmx_volumes_volspace_refresh(BBString * vol, BBInt64 * _size, BBInt64 * _free) {
	struct statvfs buf;
	char * v = bbStringToUTF8String(vol);
	int res = statvfs(v, &buf);
	bbMemFree(v);
	*_size = buf.f_frsize * buf.f_blocks;
	*_free = buf.f_frsize * buf.f_bavail;
	return res;
}
Exemplo n.º 14
0
XML_Status bmx_expat_XML_SetEncoding(XML_Parser parser, BBString * encoding) {

	char * c = bbStringToUTF8String(encoding);

	XML_Status res = XML_SetEncoding(parser, c);
	
	bbMemFree(c);
	return res;
}
Exemplo n.º 15
0
void bbStrBufClear(bbStrBuf* p)
{
    if (p->mpStr != p->mBuf)
        bbMemFree(p->mpStr);

    p->mpStr = p->mBuf;
    p->mLen = 0;
    p->mBuf[0] = 0;
    p->mCapacity = bbARRSIZE(p->mBuf);
}
Exemplo n.º 16
0
MaxLocale * bmx_boostlocale_generator_generate(boost::locale::generator * gen, BBString * id) {

	char * d = bbStringToUTF8String(id);
	
	MaxLocale * loc = new MaxLocale(gen->generate(d));
	
	bbMemFree(d);
	
	return loc;
}
Exemplo n.º 17
0
XML_Parser bmx_expat_XML_ParserCreate(BBString * encoding) {
	char * c = NULL;
	if (encoding != &bbEmptyString) {
		c = bbStringToCString(encoding);
	}
	
	XML_Parser parser = XML_ParserCreate(c);
	
	if (c) bbMemFree(c);
	
	return parser;
}
Exemplo n.º 18
0
bbCHAR* uiDlgFileNameNext(bbCHAR* pFileNames, bbCHAR* pBuffer)
{
#if (bbOS == bbOS_WIN32) || (bbOS == bbOS_WINCE)

    uiDlgFileNameBlock* pBlock = (uiDlgFileNameBlock*)pFileNames;
    pFileNames = (bbCHAR*)((bbU8*)pFileNames + sizeof(uiDlgFileNameBlock));

    bbCHAR* pNewBuffer;
    bbU32 pathlen = pBlock->FirstFileOffset - 1;
    bbU32 offset  = pBlock->CurFileOffset;
    bbU32 filelen = bbStrLen(pFileNames + offset);

    if (filelen == 0)
    {
        pBlock->CurFileOffset = pBlock->FirstFileOffset;
        bbMemFree(pBuffer);
        return (bbCHAR*)-1;
    }

    pNewBuffer = pBuffer;
    if (bbMemRealloc(sizeof(bbCHAR) * (filelen + pathlen + 2), (void**)&pNewBuffer) != bbEOK) // space for path + '\' + file + 0-terminator
    {
        bbMemFree(pBuffer);
        return NULL;
    }

    if (!pBuffer)
    {
        bbStrCpy(pNewBuffer, pFileNames); // copy path
        pNewBuffer[pathlen] = bbDIRDELIM;
    }
    bbStrCpy(pNewBuffer + pathlen + 1, pFileNames + offset); // copy filename

    pBlock->CurFileOffset = offset + filelen + 1;

    return pNewBuffer;
#else
#endif
}
Exemplo n.º 19
0
BBString * bmx_userdirlookup(BBString * type) {

	char * t = bbStringToUTF8String(type);
	
	char * lookup = xdg_user_dir_lookup(t);
	
	bbMemFree(t);

	BBString * dir = bbStringFromUTF8String(lookup);
	
	free(lookup);
	
	return dir;
}
Exemplo n.º 20
0
int bmx_wxiobase_readuntileos(wxIOBase * base, char * buffer, int * bytesRead, BBString * eos, int timeout, int quota) {
	char * p = bbStringToCString( eos );
	char * newbuff = NULL;
	
	size_t size;
	int ret = base->ReadUntilEOS(newbuff, &size, p, timeout, static_cast<char>(quota));
	*bytesRead = static_cast<int>(size);
	
	if (bytesRead > 0) {
		memcpy(buffer, newbuff, size);
	}
	delete newbuff;

	bbMemFree( p );
	return ret;
}
Exemplo n.º 21
0
BBString * _formatDate(BBString * format, int y, int m, int d, int hh, int mm, int ss) {

	char buffer [1024];
	tm stm;
	char * p = bbStringToCString(format);

	stm.tm_year = y - 1900;
	stm.tm_mon = m - 1;
	stm.tm_mday = d;
	stm.tm_hour = hh;
	stm.tm_min = mm;
	stm.tm_sec = ss;

	strftime (buffer, 1024, p, &stm);
	
	bbMemFree(p);
	
	return bbStringFromCString(buffer);
}
Exemplo n.º 22
0
Arquivo: map.c Projeto: mrhill/babel
static void bbMapDerefChunkForKey(bbMapRec* pMap, const bbCHAR* pKey)
{
    struct bbMapKeyChunk** pParent = &pMap->mpKeyChunk;
    struct bbMapKeyChunk* pChunk = pMap->mpKeyChunk;
    while(pChunk)
    {
        if (((bbUPTR)pKey - (bbUPTR)pChunk) < sizeof(struct bbMapKeyChunk))
        {
            if (--pChunk->refct == 0)
            {
                *pParent = pChunk->next;
                bbMemFree(pChunk);
            }
            return;
        }
        pParent = &pChunk->next;
        pChunk = pChunk->next;
    }
}
Exemplo n.º 23
0
BBString * bmx_profanityfilter_FilterProfanity(ProfanityFilter * filter, BBString * text, int f, int * ret) {
	char * t = bbStringToCString(text);

	char * output = 0;
	if (filter) {
		output = (char *) malloc(strlen(t) + 1);
	}
	
	*ret = filter->FilterProfanity(t, output, static_cast<bool>(f));
	
	bbMemFree(t);
	
	BBString * o = 0;
	if (output) {
		o = bbStringFromCString(output);
		free(output);
	} else {
		o = text;
	}
	
	return o;
}
Exemplo n.º 24
0
/* 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;
}
Exemplo n.º 25
0
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
}
Exemplo n.º 26
0
CFStringRef CFStringFromBBString( const BBString *str ){
	UniChar *p = bbStringToWString( (BBString*)str );
	CFStringRef t = CFStringFromWString(p);
	bbMemFree( p );
	return t;
}
Exemplo n.º 27
0
Arquivo: glue.c Projeto: GWRon/sdl.mod
SDL_Surface * bmx_sdl_LoadBMP(BBString * file) {
	char * f = bbStringToUTF8String(file);
	SDL_Surface * surface = SDL_LoadBMP(f);
	bbMemFree(f);
	return surface;
}
Exemplo n.º 28
0
/* table[key]  OR  table.key */
static int lugi_index_object(lua_State *state) {

#ifdef BMX_TABLE_SUPPORT > 1
    /* prior table behavior for BMax objects */
    lua_getfenv(state, 1);
    lua_pushvalue(state, 2);
    lua_gettable(state, -2);
    if ( lua_isnil(state, -1) == 0 ) {
        return 1;
    }

    lua_settop(state, 2);
#endif

    if (lua_type(state, 2) == LUA_TSTRING) {

        BBObject *obj = lua_tobmaxobject(state, 1);
        BBClass *clas = obj->clas;

        /* while class */
        do {

            /* get class VMT */
            lua_pushlightuserdata(state, clas);
            lua_gettable(state, LUA_REGISTRYINDEX);

            if ( lua_type(state, -1) == LUA_TTABLE ) /* there's a lookup table for the class.. */
            {

                lua_pushvalue(state, 2);
                lua_rawget(state, -2);

                int type = lua_type(state, -1);

                if (type == LUA_TUSERDATA) {		/* getting the value of a field */
                    fieldinfo_t *info = (fieldinfo_t*)lua_touserdata(state, -1);
                    bmx_field *field = (bmx_field*)((char*)obj+info->offset);

                    switch (info->type&(~BOOLFIELDOPT)) {
                    case BYTEFIELD:
                        if (info->type&BOOLFIELDOPT) {
                            lua_pushboolean(state, field->byte_value);
                        }
                        else {
                            lua_pushinteger(state, field->byte_value);
                        }
                        break;

                    case SHORTFIELD:
                        if (info->type&BOOLFIELDOPT) {
                            lua_pushboolean(state, field->short_value);
                        }
                        else {
                            lua_pushinteger(state, field->short_value);
                        }
                        break;

                    case INTFIELD:
                        if (info->type&BOOLFIELDOPT) {
                            lua_pushboolean(state, field->int_value);
                        }
                        else {
                            lua_pushinteger(state, field->int_value);
                        }
                        break;

                    case FLOATFIELD:
                        lua_pushnumber(state, field->float_value);
                        break;

                    case DOUBLEFIELD:
                        lua_pushnumber(state, field->double_value);
                        break;

                    case LONGFIELD:
                        if (info->type&BOOLFIELDOPT) {
                            lua_pushboolean(state, field->long_value);
                        }
                        else {
                            lua_pushinteger(state, field->long_value);
                        }
                        break;

                    case STRINGFIELD: {
                        char *strbuf = bbStringToCString(field->string_value);
                        lua_pushlstring(state, strbuf, field->string_value->length);
                        bbMemFree(strbuf);
                    }
                    break;

                    case ARRAYFIELD:
                        lua_pushbmaxarray(state, field->arr_value);
                        break;

                    case OBJECTFIELD:
                        lua_pushbmaxobject(state, field->obj_value);
                        break;

                    default:
                        return luaL_error(state, ERRORSTR("@lugi_index_object: Unrecognized field type (%d)."), info->type);
                        break;
                    }
                    return 1;

                    /** method **/
                }
                else if (type ==  LUA_TFUNCTION) {
                    return 1;
                }
                else {
                    lua_pop(state, 1);
                }
            } /* VMT found */

            /* pop previous VMT/nil */
            lua_pop(state, 1);

            /* iterate to the superclass */
            clas = clas->super;

        } while (clas != NULL);

    } /* key is string */

#if BMX_TABLE_SUPPORT < 1
    /* notify that there was an error accessing a field or method that does not exist */
    const char *objtype="invalid object";
    if (lua_isbmaxobject(state, 1))
        objtype = lua_tobmaxobject(state, 1)->clas->debug_scope->name;

    if ( (LUA_TNUMBER|LUA_TSTRING)&lua_type(state, 2) )
        return luaL_error(state, ERRORSTR("@lugi_index_object: Index (%s) for object<%s> is not a valid field or method."), lua_tostring(state, 2), objtype);
    else
        return luaL_error(state, ERRORSTR("@lugi_index_object: Index for object<%s> is not a valid field or method."), objtype);
#else
    lua_pushnil(state);
    return 1;
#endif
} /* lugi_index_object */
Exemplo n.º 29
0
double bbStringToDouble( BBString *t ){
	char *p=bbStringToCString( t );
	double n=atof( p );
	bbMemFree( p );
	return n;
}
Exemplo n.º 30
0
float bbStringToFloat( BBString *t ){
	char *p=bbStringToCString( t );
	float n=atof( p );
	bbMemFree( p );
	return n;
}