bool operator>(const Value& v1, const Value& v2) { boost::scoped_ptr<NumericPairBase> nbp(promoteNumeric(v1, v2)); if (nbp) return nbp->gr(); return false; }
void RopeImpl::append_string_impl( string_ptr& dest, string_ptr const& one, string_ptr const& two) { /*trivial cases where one string is empty*/ if(one->length() == 0) { dest = two; return; } else if(two->length() == 0){ dest = one; return; } /*check for catting two short Ascii strings.*/ AsciiImpl* as1 = dynamic_cast<AsciiImpl*>(one.get()); if(as1 && as1->length() < (ASCII_BUFFER_LEVEL / 2)) { AsciiImpl* as2 = dynamic_cast<AsciiImpl*>(two.get()); if(as2 && as2->length() < (ASCII_BUFFER_LEVEL / 2)) { size_t l1 = as1->length(); size_t l2 = as2->length(); /*create a single buffer and concat them*/ boost::shared_array<BYTE> nbp(new BYTE(l1 + l2)); std::copy(as2->start, &as2->start[l2], std::copy(as1->start, &as1->start[l1], &nbp[0] ) ); dest.reset(new AsciiImpl(nbp, &nbp[0], l1 + l2)); return; } } size_t d1 = one->rope_depth(); size_t d2 = two->rope_depth(); if(d1 > d2 + 1) { /*first subtree is pretty heavy, check if: one two /\ | /\ c d a b If so, do this: /\ / \ /\ /\ a b c d */ RopeImpl& r1 = static_cast<RopeImpl&>(*one); size_t d1_2 = r1.two->rope_depth(); if(d1_2 <= d2 + 1) { string_ptr tmp; base_append_string_impl(tmp, r1.two, two, d1_2, d2); append_string_impl(dest, r1.one, tmp); return; } } base_append_string_impl(dest, one, two, d1, d2); }
bool operator!=(const Value& v1, const Value& v2) { boost::scoped_ptr<NumericPairBase> nbp(promoteNumeric(v1, v2)); if (nbp) return nbp->ne(); if (v1.type != v2.type) return false; switch (v1.type) { case Value::T_BOOL: return v1.b != v2.b; case Value::T_STRING: return *v1.s != *v2.s; default: // Cannot ever get here return false; } }
/*========================================================================== * TFTP Read File command. */ static long NBPLoadFile(CICell ih, char * filePath) { nbpCommandTFTPReadFile_s cmd; UInt32 ret; strcpy((char *)cmd.filename, filePath); cmd.status = nbpStatusFailed; cmd.bufferSize = TFTP_LEN; cmd.buffer = TFTP_ADDR; verbose("Loading file: %s\n", filePath); ret = nbp(nbpCommandTFTPReadFile, (nbpCommand_u *) &cmd); return (ret == nbpStatusSuccess) ? (long)cmd.bufferSize : -1; }
bool ModificationMap::addModification(ByteContainer &bc, unsigned __int64 addr, BYTE to, BYTE &old) { BytePair *bpp = get(addr); if(bpp) { if(to == bpp->getFrom()) { old = to; remove(addr); return true; } else if(to != bpp->getTo()) { BytePair nbp(bpp->getFrom(), to); old = bpp->getTo(); remove(addr); put(addr, nbp); return true; } } else { // addr not found in map const BYTE from = bc.getByte(addr); if(to != from) { old = from; put(addr, BytePair(from, to)); return true; } } return false; }
/*========================================================================== * Unload Base Code Stack command. */ UInt32 nbpUnloadBaseCode() { return nbp(nbpCommandUnloadBaseCode, (nbpCommand_u *) 0); }