Bool PNMisNew(Int16 idx) { if(PNMok!=TRUE)Bug("PNMok"); if(idx>=PNMtop)Bug("PnmIN>"); /*check if patch was added after initial definition*/ if(idx>=PNMknown) return TRUE; return FALSE; }
int ProtectMemory(LogicalAddress addr, natural nbytes) { #if DEBUG_MEMORY fprintf(dbgout, "Protecting memory at 0x" LISP ", size 0x" LISP "\n", addr, nbytes); #endif #ifdef WINDOWS DWORD oldProtect; BOOL status = VirtualProtect(addr, nbytes, MEMPROTECT_RX, &oldProtect); if(!status) { wperror("ProtectMemory VirtualProtect"); Bug(NULL, "couldn't protect " DECIMAL " bytes at 0x" LISP ", errno = %d", nbytes, addr, status); } return status; #else int status = mprotect(addr, nbytes, PROT_READ | PROT_EXEC); if (status) { status = errno; if (status == ENOMEM) { void *mapaddr = mmap(addr,nbytes, PROT_READ | PROT_EXEC, MAP_ANON|MAP_PRIVATE|MAP_FIXED,-1,0); if (mapaddr != MAP_FAILED) { return 0; } } Bug(NULL, "couldn't protect " DECIMAL " bytes at " LISP ", errno = %d", nbytes, addr, status); } return status; #endif }
/* ** write texture as text file */ void TXUwriteTexFile(const char *file) { Int16 t,p,pat,top; char pname[8]; FILE *out; if(TXUok!=TRUE) Bug("TXUok"); if(TXUtexTop<1) Bug("TxunTx"); out=fopen(file,FOPEN_WT); if(out==NULL) ProgError("Can't write file %s\n",file); TXUrealTexture(); fprintf(out,";Format of textures:\n"); fprintf(out,";TextureName\tWidth\tHeight\n"); fprintf(out,";*\tPatchName\tXoffset\tYoffset\n"); for (pat=0, t= 0; t <TXUtexTop; t++) { if(TXUtex[t].Name[0]!='\0') /*if tex was not redefined*/ { fprintf(out,"%-8.8s ",TXUtex[t].Name); fprintf(out,"\t\t%d\t%d\n",TXUtex[t].szX,TXUtex[t].szY); for (p = 0; p < TXUtex[t].Npatches; p++) { top=pat+p; if(top>=TXUpatTop) Bug("TxuP>D"); PNMgetPatchName(pname,TXUpat[pat+p].Pindex); fprintf(out,"*\t%-8.8s ",pname); fprintf(out,"\t%d\t%d\n",TXUpat[pat+p].ofsX,TXUpat[pat+p].ofsY); } } pat+=TXUtex[t].Npatches; } fprintf(out,";End\n"); fclose(out); }
void Bug::move(){ if(ground->canMove(pos_x+1, pos_y) == true) Bug(pos_x+1, pos_y, ground); if(ground->canMove(pos_x-1, pos_y) == true) Bug(pos_x-1, pos_y, ground); if(ground->canMove(pos_x, pos_y+1) == true) Bug(pos_x, pos_y+1, ground); if(ground->canMove(pos_x, pos_y-1) == true) Bug(pos_x, pos_y-1, ground); }
void* Store::getVolatileArea () { Lock lock(volatileAreasMutex); if (!volatileAreas.empty()) { void* area = volatileAreas.front(); volatileAreas.pop_front(); Log_VolatileArea ( "Providing area=%p from volatileAreas cache, volatileAreas size=%lu.\n", area, (unsigned long) volatileAreas.size() ); stats.numberOfVolatileAreasProvided++; return area; } #ifdef __XEM_STORE_VOLATILEAREAS_USE_MMAP if (volatileAreasFD == -1) { static const char* tempFile = "/dev/zero"; volatileAreasFD = open(tempFile, O_RDWR); if (volatileAreasFD == -1) { Bug ( "Could not open volatileAreasFD ! error=%d:%s\n", errno, strerror(errno) ); } } void* area = mmap(NULL, DocumentAllocator::getAreaSize(), #ifdef XEM_MEM_PROTECT_SYS PROT_READ #else PROT_READ | PROT_WRITE #endif , MAP_PRIVATE, volatileAreasFD, 0); if (area == MAP_FAILED) { Bug ( "Could not map VolatileArea. error = %d:%s\n", errno, strerror(errno) ); } #else // void* area = malloc(DocumentAllocator::getAreaSize()); void* area = NULL; int res = posix_memalign(&area, PageSize, DocumentAllocator::getAreaSize()); if ( res != 0 ) { Bug ("Could not posix_memalign (PagSize=%llx, getAreaSize()=%llx, res=%d\n", PageSize, DocumentAllocator::getAreaSize(), res); } #endif #if 0 // INJECTING RANDOM STUFF HERE int randomFd = open ( "/dev/urandom", O_RDONLY ); read ( randomFd, area, DocumentAllocator::getAreaSize() ); ::close ( randomFd ); #endif stats.numberOfVolatileAreasCreated++; Log_VolatileArea ( "Providing area=%p, stats.numberOfVolatileAreasCreated=%llu, stats.numberOfVolatileAreasDeleted=%llu\n", area, stats.numberOfVolatileAreasCreated, stats.numberOfVolatileAreasDeleted ); return area; }
/********** TEXTURE entry in WAD ********/ Int32 TXUwriteTEXTUREtoWAD(struct WADINFO *info) { Int16 t,tt,p,pat; Int32 size,ofsTble; Int32 NbOfTex; if(TXUok!=TRUE) Bug("TXUok"); if(TXUtexTop<1) Bug("TxuNTx"); /*count real textures*/ NbOfTex=TXUrealTexture(); size=WADRwriteLong(info,NbOfTex); /*number of entries*/ ofsTble=WADRposition(info); for(tt=0;tt<NbOfTex;tt++) { size+=WADRwriteLong(info,-1); /*pointer, to be corrected later*/ } for(pat=0,tt=0,t=0; t<TXUtexTop; t++) { if(TXUtex[t].Name[0]!='\0') { /*set texture direct pointer*/ if(tt>=NbOfTex)Bug("TxuRT"); WADRsetLong(info,ofsTble+tt*4,size); tt++; /*write the begining of texture definition*/ fseek (info->fd, info->wposit, SEEK_SET); /* Ugly */ if (output_texture_format != TF_NAMELESS) wad_write_name (info->fd, TXUtex[t].Name); size += 8; wad_write_i16 (info->fd, 0); size += 2; wad_write_i16 (info->fd, 0); size += 2; wad_write_i16 (info->fd, TXUtex[t].szX); size += 2; wad_write_i16 (info->fd, TXUtex[t].szY); size += 2; if (output_texture_format != TF_STRIFE11) { wad_write_i16 (info->fd, 0); size += 2; wad_write_i16 (info->fd, 0); size += 2; } wad_write_i16 (info->fd, TXUtex[t].Npatches); size += 2; for(p=0; p<(TXUtex[t].Npatches); p++) { if(pat+p>=TXUpatTop) Bug("TxuP>D");/*number of patches exceeds definitions*/ wad_write_i16 (info->fd, TXUpat[pat+p].ofsX); size += 2; wad_write_i16 (info->fd, TXUpat[pat+p].ofsY); size += 2; wad_write_i16 (info->fd, TXUpat[pat+p].Pindex); size += 2; if (output_texture_format != TF_STRIFE11) { wad_write_i16 (info->fd, 0); size += 2; wad_write_i16 (info->fd, 0); size += 2; } } info->wposit = ftell (info->fd); /* Ugly */ } pat+=TXUtex[t].Npatches; } return size; }
static void TXUaddPatchToCurTex(Int16 pindex,Int16 ofsX,Int16 ofsY) { char pname[8]; if(TXUok!=TRUE) Bug("TXUok"); if(TXUpatTop>=TXUpatMax) { TXUpatMax+=NEWPATCHESDEF; TXUpat=(struct PATCH *) Realloc(TXUpat,TXUpatMax*sizeof(struct PATCH)); } if(TXUtexCur<0) Bug("TXUTxC"); PNMgetPatchName(pname,pindex); /*check if index correct*/ TXUtex[TXUtexCur].Npatches+=1; /*increase texture's patch counter*/ TXUpat[TXUpatTop].Pindex=pindex;/*declare patch*/ TXUpat[TXUpatTop].ofsX=ofsX; TXUpat[TXUpatTop].ofsY=ofsY; TXUpatTop+=1; }
static void TXUdefineCurTex(char name[8],Int16 X,Int16 Y,Bool Redefn) { int t; if(TXUok!=TRUE) Bug("TXUok"); TXUtexCur=TXUtexTop; /*set current entry*/ TXUtexTop+=1; /*find a free position*/ if(TXUtexTop>=TXUtexMax) { TXUtexMax+=NEWTEXTURES; TXUtex=(struct TEXTUR *)Realloc(TXUtex,TXUtexMax*sizeof(struct TEXTUR)); } Normalise(TXUtex[TXUtexCur].Name,name); /*declare texture*/ TXUtex[TXUtexCur].szX=X; TXUtex[TXUtexCur].szY=Y; TXUtex[TXUtexCur].Npatches=0; /*check if we redefine other textures, and overide them.*/ for(t=0;t<TXUtexCur;t++) { if(strncmp(TXUtex[t].Name,name,8)==0) { if(Redefn==TRUE) { TXUtex[t].Name[0]='\0'; Detail("Warning: Texture %s is redefined\n", lump_name (name)); } else /*don't redefine textures*/ { TXUtex[TXUtexCur].Name[0]='\0'; break; } } } }
/* * dump_field - write a field of a page to file */ static void dump_field(FILE * fp, const unsigned char *buf, unsigned long *ofs, enum field_type_t type, const char *desc) { fprintf(fp, "%-10s ", desc); if (type == FT_I32) { fprintf(fp, "%ld", (long) peek_i32_le(buf + *ofs)); *ofs += 4; } else if (type == FT_NAME) { int n; putc('"', fp); for (n = 0; n < 8 && buf[*ofs + n] != '\0'; n++) putc(tolower(buf[*ofs + n]), fp); putc('"', fp); *ofs += 8; } else if (type == FT_S16) { fprintf(fp, "\"%.16s\"", buf + *ofs); *ofs += 16; } else if (type == FT_S32) { fprintf(fp, "\"%.32s\"", buf + *ofs); *ofs += 32; } else if (type == FT_S80) { fprintf(fp, "\"%.80s\"", buf + *ofs); *ofs += 80; } else if (type == FT_S320) { fprintf(fp, "\"%.320s\"", buf + *ofs); *ofs += 320; } else { Bug("SS25", "bad field type %d", (int) type); } fputs(";\n", fp); }
void TXTaddComment(struct TXTFILE *TXT,const char *text) { if (TXT == &TXTdummy) return; if(TXTok!=TRUE) Bug("TW31", "TxtAdC"); fprintf(TXT->fp,"# %.256s\n",text); }
void XemProcessor::xemFunctionTransmittable ( __XProcFunctionArgs__ ) { NodeSet& res0 = *(args[0]); bool separator = false; String trans; for ( NodeSet::iterator iter0 ( res0 ) ; iter0 ; iter0++ ) { if ( separator ) trans += ";"; Item& item = *iter0; switch ( item.getItemType() ) { case Item::Type_Null: Bug ( "Null Item !\n" ); break; case Item::Type_Element: case Item::Type_Attribute: trans += item.toNode().generateId (); break; case Item::Type_Bool: case Item::Type_Integer: case Item::Type_Number: case Item::Type_String: trans += item.toString(); break; } } result.setSingleton ( trans ); Log_XemRoleBased ( "Transmittable : returned '%s'\n", trans.c_str() ); }
TInt CJuikIconManagerImpl::AddIconL(TInt aProviderId, CGulIcon* aIcon) { CALLSTACKITEM_N(_CL("CJuikIconManagerImpl"), _CL("AddIconL")); auto_ptr<CGulIcon> icon( aIcon ); CArrayFix<TInt>& map = ProviderIconIndexL(aProviderId); TInt ix = KErrNotFound; if ( iEmptySlotCount > 0 ) ix = FindEmptySlotL(); if ( ix == KErrNotFound ) { iIconArray->AppendL( icon.release() ); map.AppendL( LastIndex( *iIconArray ) ); } else { iEmptySlotCount--; if ( iEmptySlotCount < 0 ) Bug( _L("Empty slot count underflow") ).Raise(); (*iIconArray)[ix] = icon.release(); map.AppendL( ix ); } return LastIndex( map ); }
/* ** Set memory */ void Memset(void *dest,char car, long n) { if(n<0) Bug("MStInf"); /*set inf to zero*/ if(n==0)return; #if DT_OS == 'd' # if DT_CC == 'd' memset(dest,car,(size_t)n); # else if(n>0x10000L) Bug("MStSup"); /*DOS limit: not more than 0x10000*/ _fmemset(dest,car,(size_t)n); # endif #elif DT_OS == 'o' memset(dest,car,(size_t)n); #else memset(dest,car,(size_t)n); #endif }
void TGSettingsGUI::on_reset_clicked() { if(pthread_mutex_lock(&SimParams::Lock) != 0) Bug(true, "Failed to lock mutex"); myParams.Reset = true; pthread_mutex_unlock(&SimParams::Lock); }
void TXTcloseR(struct TXTFILE *TXT) { if (!TXTok) Bug("TR91", "TxtClo"); fclose(TXT->fp); free(TXT); }
JNIEXPORT jobject JNICALL Java_org_xemeiah_dom_xpath_XPathEvaluator_createExpression (JNIEnv *ev, jobject jXPathEvaluator, jstring jExpression, jobject resolverObject) { Xem::String expression = jstring2XemString(ev, jExpression); Log("createExpression(%s)\n", expression.c_str()); try { Xem::XPathParser* xPathParser; jobject jFactory; if (isJElement(ev, resolverObject)) { Xem::ElementRef resolver = jElement2ElementRef(ev, resolverObject); xPathParser = new Xem::XPathParser(resolver, expression); jobject jDocument = jNode2JDocument(ev, resolverObject); jFactory = jDocument2JDocumentFactory(ev, jDocument); } else { jFactory = jXPathEvaluator2JDocumentFactory(ev, jXPathEvaluator); AssertBug(jFactory != NULL, "Null documentFactory provided !"); Xem::Store* store = jDocumentFactory2Store(ev, jFactory); AssertBug(store != NULL, "Invalid Null Store (not initialized ?)"); Xem::KeyCache& keyCache = store->getKeyCache(); Xem::JNamespaceAlias nsAlias(keyCache, ev, resolverObject); xPathParser = new Xem::XPathParser(keyCache, nsAlias, expression); } // Xem::XProcessor* xprocessor = jDocumentFactory2XProcessor(ev, jFactory); // // Xem::XPath* xpath = new Xem::XPath(*xprocessor, xPathParser, true); return createJXPathExpression(ev, xPathParser, jFactory); } catch (Xem::XPathException * e) { Error("Catched Xem::XPathException : %s\n", e->getMessage().c_str()); jthrowable jException = exception2JXPathException(ev, e); ev->Throw(jException); } catch (Xem::Exception * e) { Error("Catched Xem::Exception : %s\n", e->getMessage().c_str()); jthrowable jException = exception2JXPathException(ev, e); ev->Throw(jException); return NULL; } catch (void * e) { Bug("Catched : %p\n", e); } return NULL; }
/* ** To write entries */ void TXTaddSection(struct TXTFILE *TXT,const char *def) { if (TXT == &TXTdummy) return; if(TXTok!=TRUE) Bug("TW11", "TxtAdS"); fprintf(TXT->fp,"[%.8s]\n",def); }
/* ** try to save entry as BitMap .BMP */ static Bool XTRbmpSave(Int16 *pinsrX,Int16 *pinsrY,struct WADDIR *entry, PICTYPE type,const char *DataDir,const char *dir,struct WADINFO *info,IMGTYPE Picture,Bool WSafe, cusage_t *cusage) { Bool res; Int32 start=entry->start; Int32 size =entry->size; char *name=entry->name; char *buffer; char *extens=NULL; if(size<8L) return FALSE; switch(Picture) { case PICGIF: extens="GIF";break; case PICBMP: extens="BMP";break; case PICPPM: extens="PPM";break; case PICTGA: extens="TGA";break; default: Bug("EX47", "Invalid img type %d", (int) Picture); } res = MakeFileName(file,DataDir,dir,"",name,extens); if((WSafe==TRUE)&&(res==TRUE)) { Warning("EX48", "Will not overwrite file %s",file); return TRUE; } buffer=(char *)Malloc(size); WADRseek(info,start); WADRreadBytes(info,buffer,size); res = PICsaveInFile(file,type,buffer,size,pinsrX,pinsrY,Picture, name, cusage); if(res==TRUE)Detail("EX49", "Saved picture as %s", fname (file)); Free(buffer); return res; }
/* ** Copy memory */ void Memcpy(void *dest,const void *src, long n) { if(n<0) Bug("MovInf"); /*move inf to zero*/ if(n==0)return; #if DT_OS == 'd' # if DT_CC == 'd' memcpy((char *)dest,(char *)src,(size_t)n); # else if(n>0x10000L) Bug("MovSup"); /*DOS limit: not more than 0x10000*/ _fmemcpy(dest,src,(size_t)n); # endif #elif DT_OS == 'o' memcpy((char *)dest,(char *)src,(size_t)n); #else memcpy((char *)dest,(char *)src,(size_t)n); #endif }
void XProcessorModule::registerDomEventHandler ( KeyId keyId, DomEventHandler handler ) { if ( KeyCache::getNamespaceId(keyId) != moduleForge.getModuleNamespaceId() ) { Bug ( "Diverging namespaces !\n" ); } localDomEventMap[KeyCache::getLocalKeyId(keyId)] = handler; }
void MoveToFreePoolL( CCoeControl* aControl ) { TInt ix = iUsedPool.Find( aControl ); if ( ix < 0 ) Bug( _L("Visible control not in used pool") ).Raise(); iFreePool.AppendL( aControl ); iUsedPool.Remove(ix); }
void XProcessorModule::registerHandler ( KeyId keyId, XProcessorHandler handler, bool checkNamespace ) { if ( checkNamespace && KeyCache::getNamespaceId(keyId) != moduleForge.getModuleNamespaceId() ) { Bug ( "Diverging namespaces !\n" ); } localHandlerMap[KeyCache::getLocalKeyId(keyId)] = handler; }
void TXTcloseW(struct TXTFILE *TXT) { if (TXT == &TXTdummy) return; if(TXTok!=TRUE) Bug("TW91", "TxtClo"); fclose(TXT->fp); Free(TXT); }
/* ** list the names of the textures defined */ void TXUlistTex(void) { Int16 t; if(TXUok!=TRUE) Bug("TXUok"); for (t= 0; t <TXUtexTop; t++) { if(TXUtex[t].Name[0]!='\0') Output("%s\n", lump_name (TXUtex[t].Name)); } }
void XProcessorModule::registerFunction ( KeyId keyId, XProcessorFunction function ) { if ( KeyCache::getNamespaceId(keyId) != moduleForge.getModuleNamespaceId() ) { Bug ( "Diverging namespaces !\n" ); } localFunctionMap[KeyCache::getLocalKeyId(keyId)] = function; }
void TXTaddEmptyLine(struct TXTFILE *TXT) { if (TXT == &TXTdummy) return; if (!TXTok) Bug("TW41", "TxtAdL"); putc('\n', TXT->fp); }
/************** merge PWAD IWAD directory module ****************/ void ADDallSpriteFloor(const char *wadout, const char *doomwad, const char *wadres,NTRYB select) { struct WADINFO iwad; struct WADINFO pwad; struct WADINFO rwad; Int16 n; ENTRY *iiden; /*identify entry in IWAD*/ ENTRY *piden; /*identify entry in PWAD*/ Int32 start,size,ostart,osize; Int16 pnm;char *Pnam;Int32 Pnamsz; struct WADDIR *NewDir;Int32 NewNtry; Phase("ME88", "Copying sprites and/or flats"); Phase("ME88", " from iwad %s", fname (doomwad)); Phase("ME88", " and pwad %s", fname (wadres)); Phase("ME88", " into pwad %s", fname (wadout)); /* get iwad directory, and identify */ iwad.ok=0; WADRopenR(&iwad,doomwad); /*find PNAMES*/ pnm=WADRfindEntry(&iwad,"PNAMES"); if(pnm<0) ProgError("ME91", "Can't find PNAMES in main WAD"); Pnam=WADRreadEntry(&iwad,pnm,&Pnamsz); /* identify iwad*/ iiden=IDENTentriesIWAD(&iwad, Pnam, Pnamsz,TRUE); /* get pwad directory, and identify*/ pwad.ok=0; WADRopenR(&pwad,wadres); piden=IDENTentriesPWAD(&pwad, Pnam, Pnamsz); /**/ Free(Pnam); /*where to put pwad? at pwadstart*/ if((iwad.maxpos|pwad.maxpos)&EXTERNAL )Bug("ME94", "AddExt"); /* merge the two directories */ NewDir=LISmergeDir(&NewNtry,TRUE,TRUE,select,&iwad,iiden,EXTERNAL,&pwad,piden,0); /* create a new PWAD*/ rwad.ok=0; WADRopenW(&rwad,wadout,PWAD, 1); for(n=0;n<NewNtry;n++) { ostart=NewDir[n].start; osize=NewDir[n].size; WADRalign4(&rwad); start=WADRposition(&rwad); if(ostart&EXTERNAL) size=WADRwriteWADbytes(&rwad,&iwad,ostart&(~EXTERNAL),osize); else size=WADRwriteWADbytes(&rwad,&pwad,ostart,osize); WADRdirAddEntry(&rwad,start,size,NewDir[n].name); } Free(NewDir); /*close files memory*/ WADRclose(&iwad); WADRclose(&pwad); WADRwriteDir(&rwad, 1); WADRclose(&rwad); Phase("ME98", "Addition of sprites and floors is complete"); }
CCoeControl* PopFromFreePool() { TInt last = LastIxFreePool(); if ( last < 0 ) Bug( _L("Pool of free list controls is empty") ).Raise(); auto_ptr<CCoeControl> c( iFreePool[last] ); iFreePool.Remove(last); return c.release(); }
Bool TXUexist(char *Name) { int t; if(TXUok!=TRUE) Bug("TXUok"); for(t=0;t<TXUtexTop;t++) { if(strncmp(TXUtex[t].Name,Name,8)==0) return TRUE; } return FALSE; }
TAny* DataAt(TInt aId) const { CALLSTACKITEM_N(_CL("CAutoSettingsImpl"), _CL("DataAt")); if ( 0 <= aId && aId < SETTINGS_COUNT ) return iData[aId]; Bug( _L("Index out of range") ).Raise(); return NULL; // to please compiler }