void lexerParser::check_parenthese(const std::list<std::list<std::string> >::const_iterator &it, std::list<std::string>::const_iterator &it2, const int &i, const int &line) const { it2++; if (it2 != (*it).end()) if ((*it2).compare("(") == 0) { it2++; if (it2 != (*it).end()) { if ((*it2).compare("(") == 0) throw except(std::string("Too many \"(\""), line); if ((*it2).compare(")") == 0) throw except(std::string("No value between \"()\""), line); it2++; if (it2 != (*it).end()) { if ((*it2).compare(")") == 0 && ++it2 == (*it).end()) { --it2; check_value(--it2, i, line); return ; } throw except(std::string("No value after first parameter for push and assert"), line); } } } throw except(std::string("Parentheses not found"), line); }
template <typename TYPE> TYPE* _create_object(Geant4Kernel& kernel, const TypeName& typ) { Geant4Context* ctxt = kernel.workerContext(); Geant4Action* object = PluginService::Create<Geant4Action*>(typ.first, ctxt, typ.second); if (!object && typ.first == typ.second) { string _t = typeName(typeid(TYPE)); printout(DEBUG, "Geant4Handle", "Object factory for %s not found. Try out %s", typ.second.c_str(), _t.c_str()); object = PluginService::Create<Geant4Action*>(_t, ctxt, typ.second); if (!object) { size_t idx = _t.rfind(':'); if (idx != string::npos) _t = string(_t.substr(idx + 1)); printout(DEBUG, "Geant4Handle", "Try out object factory for %s",_t.c_str()); object = PluginService::Create<Geant4Action*>(_t, ctxt, typ.second); } } if (object) { TYPE* ptr = dynamic_cast<TYPE*>(object); if (ptr) { return ptr; } except("Geant4Handle", "Failed to convert object of type %s to handle of type %s!", typ.first.c_str(),typ.second.c_str()); } except("Geant4Handle", "Failed to create object of type %s!", typ.first.c_str()); return 0; }
void lexerParser::check_type_value(const std::list<std::list<std::string> >::const_iterator &it, std::list<std::string>::const_iterator &it2, const int &line) const { std::string value[5]; int i; value[0] = "int8"; value[1] = "int16"; value[2] = "int32"; value[3] = "float"; value[4] = "double"; it2++; if (it2 == (*it).end()) throw except(std::string("Value type not found"), line); for (i = -1 ; i <= 4 ; ++i) { if ((*it2).compare(value[i]) == 0) { check_parenthese(it, it2, i, line); return ; } if (i == 4) throw except(std::string("Value type \"" + (*it2) + "\" not found"), line); } }
/* * Read the header information from a midi file * * Arguments: * msp - current midi state */ static struct rootElement * read_head(struct midistate *msp) { guint32 magic; int length; struct rootElement *root; root = md_root_new(); /* The first word just identifies the file as a midi file */ magic = read_int(msp, 4); if (magic != MIDI_HEAD_MAGIC) except(formatError, "Bad header (%x), probably not a real midi file", magic); /* The header chunk should be 6 bytes, (perhaps longer in the future) */ length = read_int(msp, 4); if (length < 6) except(formatError, "Bad header length, probably not a real midi file"); root->format = read_int(msp, 2); root->tracks = read_int(msp, 2); root->time_base = read_int(msp, 2); /* Should skip any extra bytes, (may not be seekable) */ while (length > 6) { length--; (void) getc(msp->fp); } return root; }
void irq_check(em8051 *aCPU, int i) { /* * State restore sanity-check */ int psw_bits = PSWMASK_OV | PSWMASK_RS0 | PSWMASK_RS1 | PSWMASK_AC | PSWMASK_C; if (UNLIKELY(aCPU->irql[i].a != aCPU->mSFR[REG_ACC])) except(aCPU, EXCEPTION_IRET_ACC_MISMATCH); if (UNLIKELY(aCPU->irql[i].sp != aCPU->mSFR[REG_SP])) except(aCPU, EXCEPTION_IRET_SP_MISMATCH); if (UNLIKELY((aCPU->irql[i].psw & psw_bits) != (aCPU->mSFR[REG_PSW] & psw_bits))) except(aCPU, EXCEPTION_IRET_PSW_MISMATCH); if (UNLIKELY(aCPU->irql[i].dpl != aCPU->mSFR[REG_DPL] || aCPU->irql[i].dph != aCPU->mSFR[REG_DPH] || aCPU->irql[i].dpl1 != aCPU->mSFR[REG_DPL1] || aCPU->irql[i].dph1 != aCPU->mSFR[REG_DPH1] || (aCPU->irql[i].dps & 1) != (aCPU->mSFR[REG_DPS] & 1))) except(aCPU, EXCEPTION_IRET_DP_MISMATCH); if (UNLIKELY(memcmp(aCPU->irql[i].r, aCPU->mSFR, 8))) except(aCPU, EXCEPTION_IRET_R_MISMATCH); }
Md5() { if (! CryptAcquireContext(&hCryptProv, nullptr, nullptr, PROV_RSA_FULL, 0)) if (! CryptAcquireContext(&hCryptProv, nullptr, nullptr, PROV_RSA_FULL, CRYPT_NEWKEYSET)) except("Md5: CryptAcquireContext failed"); if (! CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash)) except("Md5: CryptCreateHash failed"); }
Sha256() { if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_AES, 0)) if (!CryptAcquireContext( &hCryptProv, NULL, NULL, PROV_RSA_AES, CRYPT_NEWKEYSET)) except("Sha256: CryptAcquireContext failed"); if (!CryptCreateHash(hCryptProv, CALG_SHA_256, 0, 0, &hHash)) except("Sha256: CryptCreateHash failed"); ++Sha256_count; }
extern void b_dot(char **av) { int fd; bool old_i = interactive, i = FALSE; Estack e; Edata star; av++; if (*av == NULL) return; if (streq(*av, "-i")) { av++; i = TRUE; } if (dasheye) { /* rc -i file has to do the right thing. reset the dasheye state to FALSE, though. */ dasheye = FALSE; i = TRUE; } if (*av == NULL) return; fd = rc_open(*av, rFrom); if (fd < 0) { uerror(*av); set(FALSE); return; } starassign(*av, av+1, TRUE); interactive = i; pushfd(fd); star.name = "*"; except(eVarstack, star, &e); doit(TRUE); varrm("*", TRUE); unexcept(); /* eVarstack */ interactive = old_i; }
void Date2::setday(int y) { day=y; if(day<1 || day>31) { throw except(); } }
void Date2::setmonth(int x) { month=x; if(month<1 || month>12) { throw except(); } }
static environment_t* import_set(cons_t* p) { std::string s = symbol_name(car(p)); /* * Each import set can be either of: */ // (rename <import set> (<identifier1> <identifier2>) ...) if ( s == "rename" ) return rename(import_set(cadr(p)), cddr(p)); // (prefix <import set> <identifier>) else if ( s == "prefix" ) return prefix(import_set(cadr(p)), caddr(p)); // (only <import set> <identifier> ...) else if ( s == "only" ) return only(import_set(cadr(p)), cddr(p)); // (except <import set> <identifier> ...) else if ( s == "except" ) return except(import_set(cadr(p)), cddr(p)); // <library name> else if ( !s.empty() ) return import_library(sprint(p)); raise(runtime_exception("Unknown import set: " + sprint(p))); return NULL; }
/** * Takes two images of same width and combines them on top of one another * as a single image. Throws exception if images are not the same height. */ void TBConcat::Execute() { TwoInputCheck(); if(inputImg1->GetWidth() != inputImg2->GetWidth()){ char msg[1028]; sprintf(msg, "TBConcat: widths must match: %d, %d", inputImg1->GetWidth(), inputImg2->GetWidth()); DataFlowException except("TBConcat", msg); throw except; } int topHeight = inputImg1->GetHeight(); int bottomHeight = inputImg2->GetHeight(); int newWidth = inputImg1->GetWidth(); int newHeight = topHeight + bottomHeight; Pixel *topBuffer = inputImg1->GetBuffer(); Pixel *bottomBuffer = inputImg2->GetBuffer(); Pixel *combinedBuffer = new Pixel[ newWidth * newHeight]; for(int i = 0; i < newHeight; i++) { for(int j = 0; j < newWidth; j++) { if( i < topHeight) { combinedBuffer[i*newWidth + j] = topBuffer[i * newWidth + j]; }else{ combinedBuffer[i*newWidth + j] = bottomBuffer[(i - topHeight) * newWidth + j]; } } } outputImg.ResetSize(newWidth, newHeight); outputImg.SetBuffer(combinedBuffer); }
CharMatcher* RxCompile::posixClass() { if (match("alpha:]")) return alpha; else if (match("alnum:]")) return alnum; else if (match("blank:]")) return blank; else if (match("cntrl:]")) return cntrl; else if (match("digit:]")) return digit; else if (match("graph:]")) return graph; else if (match("lower:]")) return lower; else if (match("print:]")) return print; else if (match("punct:]")) return punct; else if (match("space:]")) return space; else if (match("upper:]")) return upper; else if (match("xdigit:]")) return xdigit; else except("regex: bad posix class"); }
// TODO: See about moving this to record.cpp void create_btree_uid2record_pointer(RecordIndex & uid_tree, const list<Record> & record_list, const string & uid_name ) { uid_tree.clear(); const uint32_t uid_index = Record::get_index_by_name(uid_name); cException_Vector_Data except(uid_name.c_str()); RecordIndex::iterator pm; list<Record>::const_iterator record; for (record = record_list.begin(); record != record_list.end(); ++record ) { const Attribute * pattrib = record->get_attrib_pointer_by_index(uid_index); //if ( pattrib->get_data().size() != 1 ) throw except; const string & label = *pattrib->get_data().at(0); pm = uid_tree.find(label); if (pm != uid_tree.end()) { // This will throw on two records having the same Unique_Record_ID // TODO: Document where Unique_Record_ID is assigned (probably // in preprocessing consolidation. throw cException_Duplicate_Attribute_In_Tree(label.c_str()); } uid_tree.insert(std::pair<string, const Record *>(label, &(*record))); } }
/// Callback to construct processes (uses the G4 particle table) virtual void constructProcesses(G4VUserPhysicsList* physics_list) { this->Geant4PhysicsList::constructProcesses(physics_list); info("+++ Constructing optical_photon processes:"); info("+++ G4OpAbsorption G4OpRayleigh G4OpMieHG G4OpBoundaryProcess"); G4ParticleTable* table = G4ParticleTable::GetParticleTable(); G4ParticleDefinition* particle = table->FindParticle("opticalphoton"); if (0 == particle) { except("++ Cannot resolve 'opticalphoton' particle definition!"); } G4OpBoundaryProcess* fBoundaryProcess = new G4OpBoundaryProcess(); G4OpAbsorption* fAbsorptionProcess = new G4OpAbsorption(); G4OpRayleigh* fRayleighScatteringProcess = new G4OpRayleigh(); G4OpMieHG* fMieHGScatteringProcess = new G4OpMieHG(); fAbsorptionProcess->SetVerboseLevel(m_verbosity); fRayleighScatteringProcess->SetVerboseLevel(m_verbosity); fMieHGScatteringProcess->SetVerboseLevel(m_verbosity); fBoundaryProcess->SetVerboseLevel(m_verbosity); G4ProcessManager* pmanager = particle->GetProcessManager(); pmanager->AddDiscreteProcess(fAbsorptionProcess); pmanager->AddDiscreteProcess(fRayleighScatteringProcess); pmanager->AddDiscreteProcess(fMieHGScatteringProcess); pmanager->AddDiscreteProcess(fBoundaryProcess); }
void test( int expecting ) { scarce *p = NULL; try { p = new scarce(); p->use(); p->validate(); } catch( except1 const &r ) { if( expecting != 1 ) fail(__LINE__); delete p; throw except1(); } catch( except2 const &r ) { if( expecting != 2 ) fail(__LINE__); delete p; throw except2(); } catch( except3 const &r ) { if( expecting != 3 ) fail(__LINE__); delete p; throw except3(); } catch( except const &r ) { if( expecting != 0 ) fail(__LINE__); delete p; throw except(); } catch( ... ) { fail(__LINE__); delete p; throw __LINE__; } }
extern void funcall(char **av) { Jbwrap j; Edata jreturn, star; Estack e1, e2; if (sigsetjmp(j.j, 1)) return; starassign(*av, av+1, TRUE); jreturn.jb = &j; star.name = "*"; except(eReturn, jreturn, &e1); except(eVarstack, star, &e2); walk(treecpy(fnlookup(*av), nalloc), TRUE); varrm("*", TRUE); unexcept(eVarstack); unexcept(eReturn); }
static List *mkcmdarg(Node *n) { int fd; char *name; Edata efifo; Estack *e = enew(Estack); List *ret = nnew(List); static int fifonumber = 0; name = nprint("/tmp/rc%d.%d", getpid(), fifonumber++); if (mkfifo(name, 0666) < 0) { uerror("mkfifo"); return NULL; } if (rc_fork() == 0) { setsigdefaults(FALSE); fd = rc_open(name, (n->u[0].i != rFrom) ? rFrom : rCreate); /* stupid hack */ if (fd < 0) { uerror("open"); exit(1); } if (mvfd(fd, (n->u[0].i == rFrom)) < 0) /* same stupid hack */ exit(1); redirq = NULL; walk(n->u[2].p, FALSE); exit(getstatus()); } efifo.name = name; except(eFifo, efifo, e); ret->w = name; ret->m = NULL; ret->n = NULL; return ret; }
std::vector<DomainAndId2D> getNonOverlapingBlocks(std::vector<DomainAndId2D> const& domainsWithId) { std::vector<DomainAndId2D> nonOverlapingBlocks; // Start with the first domain, which is taken without modification. if (!domainsWithId.empty()) { nonOverlapingBlocks.push_back(domainsWithId[0]); } // All subsequent domains get special treatment, as their overlap // with previously adopted domains are cut out. for (pluint iDomain=1; iDomain<domainsWithId.size(); ++iDomain) { std::vector<Box2D> newDomains; newDomains.push_back(domainsWithId[iDomain].domain); for (pluint iPrevious=0; iPrevious<iDomain; ++iPrevious) { std::vector<Box2D> exceptedDomains; for (pluint iNewPart=0; iNewPart<newDomains.size(); ++iNewPart) { except(newDomains[iNewPart], domainsWithId[iPrevious].domain, exceptedDomains); } newDomains.swap(exceptedDomains); } for (pluint iNew=0; iNew<newDomains.size(); ++iNew) { nonOverlapingBlocks.push_back(DomainAndId2D( newDomains[iNew], domainsWithId[iDomain].id) ); } } return nonOverlapingBlocks; }
static List *mkcmdarg(Node *n) { char *name; List *ret = nnew(List); Estack *e = nnew(Estack); Edata efd; int p[2]; if (pipe(p) < 0) { uerror("pipe"); return NULL; } if (rc_fork() == 0) { setsigdefaults(FALSE); if (mvfd(p[n->u[0].i == rFrom], n->u[0].i == rFrom) < 0) /* stupid hack */ exit(1); close(p[n->u[0].i != rFrom]); redirq = NULL; walk(n->u[2].p, FALSE); exit(getstatus()); } #if HAVE_DEV_FD name = nprint("/dev/fd/%d", p[n->u[0].i != rFrom]); #else name = nprint("/proc/self/fd/%d", p[n->u[0].i != rFrom]); #endif efd.fd = p[n->u[0].i != rFrom]; except(eFd, efd, e); close(p[n->u[0].i == rFrom]); ret->w = name; ret->m = NULL; ret->n = NULL; return ret; }
char *ft_itoa(int n) { char *nb; int i; int j; int len; int sign; i = 0; len = ft_nbrlen(n); sign = n < 0 ? -1 : 1; n < 0 ? n = -n : 0; n < 0 ? len++ : 0; j = (sign < 0) ? len + 1 : len; nb = ft_strnew(len + 2); if (n < -2147483647 || n == 0) return (except(n, nb)); nb[j--] = '\0'; while (i < len) { nb[j--] = n % 10 + '0'; n /= 10; i++; } (sign == -1) ? nb[j] = '-' : 0; return (nb); }
/** * Takes two images of same height and combines them side by side as a single * image. Throws exception if images are not the same height. */ void LRConcat::Execute() { TwoInputCheck(); if(inputImg1->GetHeight() != inputImg2->GetHeight()){ char msg[1028]; sprintf(msg, "LRConcat: heights must match: %d, %d", inputImg1->GetHeight(), inputImg2->GetHeight()); DataFlowException except("LRConcat", msg); throw except; } int leftWidth = inputImg1->GetWidth(); int rightWidth = inputImg2->GetWidth(); int newWidth = leftWidth + rightWidth; int newHeight = inputImg1->GetHeight(); Pixel *leftBuffer = inputImg1->GetBuffer(); Pixel *rightBuffer = inputImg2->GetBuffer(); Pixel *combinedBuffer = new Pixel[ newWidth * newHeight]; for(int i = 0; i < newHeight; i++) { for(int j = 0; j < newWidth; j++) { if( j < leftWidth) { combinedBuffer[i*newWidth + j] = leftBuffer[i * leftWidth + j]; }else{ combinedBuffer[i*newWidth + j] = rightBuffer[i * rightWidth + j - leftWidth]; } } } outputImg.ResetSize(newWidth, newHeight); outputImg.SetBuffer(combinedBuffer); }
scarce() : h(handles), open(0) { if( handles == 0 ) { throw except(); } else { --handles; } }
void openfile(FILE* &file,const char* filename,const char* openmode) { file = fopen(filename, openmode); except(NULL==file, "Cannot open file!\n"); flockfile(file); }
/* * Read in one track from the file, and return an element tree * describing it. * * Arguments: * msp - Midi state */ static struct trackElement * read_track(struct midistate *msp) { int status, laststatus; int head; int length; int delta_time; struct trackElement *track; int i; laststatus = 0; head = read_int(msp, 4); if (head != MIDI_TRACK_MAGIC) except(formatError, "Bad track header (%x), probably not a midi file", head); length = read_int(msp, 4); msp->chunk_size = length; msp->chunk_count = 0; /* nothing read yet */ track = md_track_new(); msp->current_time = 0; while (msp->chunk_count < msp->chunk_size) { delta_time = read_var(msp); msp->current_time += delta_time; status = read_int(msp, 1); if ((status & 0x80) == 0) { /* * This is not a status byte and so running status is being * used. Re-use the previous status and push back this byte. */ put_back(msp, status); status = laststatus; } else { laststatus = status; } handle_status(msp, track, status); } restart: for (i = 0; i < msp->notes->len; i++) { struct noteElement *ns; ns = g_ptr_array_index(msp->notes, i); msp->device = MD_ELEMENT(ns)->device_channel; printf("Left over note, finishing\n"); finish_note(msp, ns->note, 0); goto restart; } msp->track_count++; return track; }
void EntityFixture::Run(std::function<void (EntityFixture &, const sf::Time &)> callback, std::function<void (EntityFixture &, const sf::Event &)> handler, std::function<void (EntityFixture &)> draw) { sf::Clock frameClock; sf::Time frameTime; sf::Time secTime; sf::Text fpsText; fpsText.setCharacterSize(10); try { while (mWindow.isOpen()) { // Check for exit events sf::Event event; mInput.preUpdate(); while (mWindow.pollEvent(event)) { mInput.handleEvent(event); if (event.type == sf::Event::Closed) { mWindow.close(); } handler(*this, event); } mInput.postUpdate(); // Update delta time frameTime = frameClock.restart(); secTime += frameTime; if (secTime > sf::seconds(1.f)) { secTime = sf::Time::Zero; std::stringstream ss; ss << "FPS: " << (1.f / frameTime.asSeconds()); fpsText.setString(ss.str()); } mWindow.clear(); mWindow.setView(mView); // Call the provided custom loop function callback(*this, frameTime); // Update Spatial Renderer mRenderer->update(frameTime); draw(*this); mWindow.setView(mWindow.getDefaultView()); mWindow.draw(fpsText); mWindow.display(); } } catch (da::DAException &e) { da::DAException except(__EXCEPTSRC__, ""); except.pushMessage(e); throw except; } }
/** * This registers source pointers with the static set for circular * reference prevention */ void Source::updateSourceRefs(Source *ref) { if(Source::sourceRefLog.count(ref) > 0){ DataFlowException except("Source", "Circular Reference in DataFlow"); throw except; } Source::sourceRefLog.insert(ref); }
template <typename TYPE> static inline TYPE* checked_value(TYPE* p) { if (p) { return p; } except("Geant4Handle","Attempt to access an invalid object of type:%s!", typeName(typeid(TYPE)).c_str()); return 0; }
gcstring Md5::value() { DWORD dwHashLen = MD5_SIZE; gcstring out(dwHashLen); if (! CryptGetHashParam(hHash, HP_HASHVAL, (BYTE*) out.ptr(), &dwHashLen, 0)) except("Md5: CryptGetHashParam failed"); verify(dwHashLen == MD5_SIZE); return out; }
gcstring Sha256::value() { DWORD dwHashLen = SHA256_SIZE; gcstring out(dwHashLen); if (!CryptGetHashParam(hHash, HP_HASHVAL, (BYTE*) out.ptr(), &dwHashLen, 0)) except("Sha256: CryptGetHashParam failed"); verify(dwHashLen == SHA256_SIZE); close(); return out; }