bool MMSMessage::decode(QIODevice *dev) { bool ok = true; QWspPduDecoder dec(dev); // MMS headers not encoded using code page, but we can still use the // mechanism. MMSHeaderCodec *mmsCodec = new MMSHeaderCodec; dec.setHeaderCodec(mmsCodec); while (!dev->atEnd()) { quint8 octet = dec.peekOctet(); if (octet >= 32) { QWspField field = dec.decodeField(); fields.append(field); } else { if (type() == MSendReq || type() == MRetrieveConf) { const QWspField *f = field("Content-Type"); if (f && (f->value.indexOf("application/vnd.wap.multipart.related") == 0 || f->value.indexOf("application/vnd.wap.multipart.mixed") == 0)) { dec.setHeaderCodec(0); multiPartData = dec.decodeMultipart(); continue; } } // ### handle other types qWarning("Don't understand format: %d", octet); ok = false; break; } } if (dec.status() != QWspPduDecoder::OK && dec.status() != QWspPduDecoder::Unhandled) ok = false; delete mmsCodec; return ok; }
Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { const std::vector<uint8_t> key = get_req_bin(vars, "Key"); const std::vector<uint8_t> nonce = get_opt_bin(vars, "Nonce"); const std::vector<uint8_t> input = get_req_bin(vars, "In"); const std::vector<uint8_t> expected = get_req_bin(vars, "Out"); Test::Result result(algo); std::unique_ptr<Botan::Cipher_Mode> enc(Botan::get_cipher_mode(algo, Botan::ENCRYPTION)); std::unique_ptr<Botan::Cipher_Mode> dec(Botan::get_cipher_mode(algo, Botan::DECRYPTION)); if(!enc || !dec) { result.note_missing(algo); return result; } result.test_eq("mode not authenticated", enc->authenticated(), false); enc->set_key(key); enc->start(nonce); Botan::secure_vector<uint8_t> buf(input.begin(), input.end()); // TODO: should first update if possible enc->finish(buf); result.test_eq("encrypt", buf, expected); buf.assign(expected.begin(), expected.end()); dec->set_key(key); dec->start(nonce); dec->finish(buf); result.test_eq("decrypt", buf, input); return result; }
int main(int argc, char ** argv) { // Initialize the global VCluster openfpm_init(&argc,&argv); // Vcluster Vcluster & vcl = create_vcluster(); //! [Create CartDecomposition vtk gen] CartDecomposition<2,float> dec(vcl); // Physical domain Box<2,float> box({0.0,0.0},{1.0,1.0}); // division on each direction size_t div[2] = {20,20}; // Define ghost Ghost<2,float> g(0.01); // boundary conditions size_t bc[2] = {PERIODIC,PERIODIC}; // Decompose and write the decomposed graph dec.setParameters(div,box,bc,g); dec.decompose(); // create a ghost border dec.calculateGhostBoxes(); // Write the decomposition dec.write("CartDecomposition/out_"); //! [Create CartDecomposition] // deinitialize the library openfpm_finalize(); }
void ut_class_test(void) { al::AudioIO io(64, 44100, 0, 0, 2, 2, al::AudioIO::DUMMY); // Dummy Audio Backend al::Decorrelation dec(32, 1, 1, false); dec.configure(io, 1000); assert(dec.getCurrentSeed() == 1000); assert(dec.getSize() == 32); float *ir = dec.getIR(0); double expected[] = {0.65027274, -0.16738815, 0.1617437 , 0.18901241, 0.01768662, -0.0802799 , -0.12612745, 0.09564361, 0.00803435, 0.07643685, -0.030273 , 0.26991193, -0.03412993, -0.05709789, 0.05474607, -0.12850219, 0.03040506, -0.05887395, 0.05779415, 0.12589107, 0.0778308 , -0.19303948, 0.16970104, -0.34332016, -0.14030879, 0.02862106, 0.18978155, 0.02629568, -0.09265464, -0.04808504, 0.00549774, 0.26477413}; for (int i = 0; i < 32; i++) { // std::cout << ir[i] << "..." << expected[i]; assert(fabs(ir[i] - expected[i]) < 0.000001); } std::cout << std::endl; al::Decorrelation dec2(1024, 1, 32, false); dec2.configure(io, 1001); assert(dec2.getCurrentSeed() == 1001); assert(dec2.getSize() == 1024); al::Decorrelation dec3(10, 1, 8, false); dec3.configure(io, 1001); assert(dec3.getCurrentSeed() == 1001); assert(dec3.getSize() == 0); // Size of 10 is too small al::Decorrelation dec4(32, 1, 0); dec4.configure(io, 1001); assert(dec4.getSize() == 0); // Num Outs is 0 }
template <typename PointInT, typename PointOutT> void pcl::AgastKeypoint2D<PointInT, PointOutT>::detectKeypoints (PointCloudOut &output) { // image size const size_t width = input_->width; const size_t height = input_->height; // destination for intensity data; will be forwarded to AGAST std::vector<unsigned char> image_data (width*height); for (size_t row_index = 0; row_index < height; ++row_index) for (size_t col_index = 0; col_index < width; ++col_index) image_data[row_index*width + col_index] = static_cast<unsigned char> (intensity_ ((*input_) (col_index, row_index))); if (!detector_) detector_.reset (new pcl::keypoints::agast::AgastDetector7_12s (width, height, threshold_, bmax_)); detector_->setMaxKeypoints (nr_max_keypoints_); if (apply_non_max_suppression_) { pcl::PointCloud<pcl::PointUV> tmp_cloud; detector_->detectKeypoints (image_data, tmp_cloud); pcl::keypoints::internal::AgastApplyNonMaxSuppresion<PointOutT> anms ( image_data, tmp_cloud, detector_, output); } else { pcl::keypoints::internal::AgastDetector<PointOutT> dec ( image_data, detector_, output); } // we do not change the denseness output.is_dense = true; }
Poco::Path CExtract::to(Poco::Path & downloadedPackage, Poco::Path extractPath) { //verification of the extension std::string extension = downloadedPackage.getExtension(); if ((!boost::iends_with(extension, "zip")) && (!boost::iends_with(extension, "tar.gz"))) throw exception::CNotSupported("Invalid extension package : " + downloadedPackage.toString() + ". Only zip or tar.gz supported. " + extension); Poco::FileStream inp(downloadedPackage.toString(), std::ios::binary); // decompress to current working dir Poco::Zip::Decompress dec(inp, extractPath); // if an error happens invoke the ZipTest::onDecompressError method m_unzipError = false; dec.EError += Poco::Delegate<CExtract, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &CExtract::onDecompressError); dec.decompressAllFiles(); dec.EError -= Poco::Delegate<CExtract, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &CExtract::onDecompressError); inp.close(); if (m_unzipError) { throw shared::exception::CExtract("Fail to uncompress package : " + m_unzipErrorMessage); } return extractPath; }
int main (){ BYTE plainText[MAX_BLK_CNT*(BLOCK_SIZE/8)]; BYTE *tmp; BYTE *ret_tmp; int i = 0; printf("*********************************************************************\n"); printf("*********************************************************************\n"); srand((unsigned) time(NULL)); key_and_cipher_init(&ki,&ci); printf("byteCnt: %d\n",byteCnt); printf("-----------------------------------------------------------------------------\n"); for (i=0;i<25;i++) plainText[i]=(BYTE)((rand()%94)+32); tmp=enc(plainText,25); ret_tmp=dec(tmp,25); free(tmp); free(ret_tmp); /*printf("\n\n");printf("-----------------------------------------------------------------------------\n"); int new_byteCnt=28; for (i=0;i<new_byteCnt;i++) plainText[i]=(BYTE)('a'); tmp=enc(plainText,new_byteCnt); ret_tmp=dec(tmp); free(tmp); free(ret_tmp); */ return 1; }
QString Utils::get_file_music_key(const QString &path) { // Init result. QString result = ""; // Decode the audio track. QSharedPointer<Audio_track> at(new Audio_track(10, 44100)); // Force 44100 to calculate music key. QScopedPointer<Audio_file_decoding_process> dec(new Audio_file_decoding_process(at, false)); dec->run(path, "", ""); // Compute the music key. QScopedPointer<Audio_track_key_process> key_proc(new Audio_track_key_process(at)); if (key_proc->run() == true) { result = at->get_music_key(); } else { qCWarning(DS_FILE) << "cannot get music key for " << path; } // Return result. return result; }
void DL_PrivateKey_EC<EC>::BERDecodeKey2(BufferedTransformation &bt, bool parametersPresent, unsigned int size) { BERSequenceDecoder seq(bt); word32 version; BERDecodeUnsigned<word32>(seq, version, INTEGER, 1, 1); // check version BERGeneralDecoder dec(seq, OCTET_STRING); if (!dec.IsDefiniteLength()) BERDecodeError(); Integer x; x.Decode(dec, dec.RemainingLength()); dec.MessageEnd(); if (!parametersPresent && seq.PeekByte() != (CONTEXT_SPECIFIC | CONSTRUCTED | 0)) BERDecodeError(); if (!seq.EndReached() && seq.PeekByte() == (CONTEXT_SPECIFIC | CONSTRUCTED | 0)) { BERGeneralDecoder parameters(seq, CONTEXT_SPECIFIC | CONSTRUCTED | 0); AccessGroupParameters().BERDecode(parameters); parameters.MessageEnd(); } if (!seq.EndReached()) { // skip over the public element SecByteBlock subjectPublicKey; unsigned int unusedBits; BERGeneralDecoder publicKey(seq, CONTEXT_SPECIFIC | CONSTRUCTED | 1); BERDecodeBitString(publicKey, subjectPublicKey, unusedBits); publicKey.MessageEnd(); Element Q; if (!(unusedBits == 0 && GetGroupParameters().GetCurve().DecodePoint(Q, subjectPublicKey, subjectPublicKey.size()))) BERDecodeError(); } seq.MessageEnd(); SetPrivateExponent(x); }
static int dok(int f,lua_State*L) { int c, n = lua_gettop(L); /* k [int] "kcode" [x [y [z]]] */ if (n>0 && lua_type(L, 1) == LUA_TNUMBER) { c = (int)lua_tonumber(L,1); --n; } else { c = last_connection; } /* k "kcode" [x [y [z]]] */ if(!n) {luaL_argcheck(L, 0, 1, "expected 1 argument"); R -1;} K x=0,y=0,z=0; if(n>1) { enc(&x,L);lua_pop(L,1);--n; } if(n>1) { y=x;enc(&x,L);lua_pop(L,1);--n; } if(n>1) { z=y;y=x;enc(&x,L);lua_pop(L,1);--n; } if(n>1) { luaL_argcheck(L,0,lua_gettop(L), "too many arguments (nyi?)"); r0(x);r0(y);r0(z); R -1; } const char *code = lua_tostring(L,-1); K r=k(c*f,code,x,y,z,(K)0); if(f==-1){/*async*/ lua_pushnil(L); R 1; } dec(L,r);r0(r); R 1; }
bool CryptoDoc::encrypt() { if( isNull() ) { setLastError( tr("Container is not open") ); return false; } if( isEncrypted() ) return true; if( d->enc->nEncryptedKeys < 1 ) { setLastError( tr("No keys specified") ); return false; } CryptoDocThread dec( true, d ); dec.waitForFinished(); if( dec.err != ERR_OK ) setLastError( dec.lastError.isEmpty() ? tr("Failed to encrypt data") : dec.lastError, dec.err ); else if( !dec.lastError.isEmpty() ) setLastError( dec.lastError ); d->documents->revert(); return isEncrypted(); }
template<typename Dest> void evalTo(Dest& dst) const { dec()._solve(rhs(),dst); }
static krb5_error_code krb5int_aes_decrypt_iov(const krb5_keyblock *key, const krb5_data *ivec, krb5_crypto_iov *data, size_t num_data) { aes_ctx ctx; char tmp[BLOCK_SIZE], tmp2[BLOCK_SIZE], tmp3[BLOCK_SIZE]; int nblocks = 0, blockno, i; size_t input_length; struct iov_block_state input_pos, output_pos; CHECK_SIZES; if (aes_dec_key(key->contents, key->length, &ctx) != aes_good) abort(); if (ivec != NULL) memcpy(tmp, ivec->data, BLOCK_SIZE); else memset(tmp, 0, BLOCK_SIZE); for (i = 0, input_length = 0; i < num_data; i++) { krb5_crypto_iov *iov = &data[i]; if (ENCRYPT_IOV(iov)) input_length += iov->data.length; } IOV_BLOCK_STATE_INIT(&input_pos); IOV_BLOCK_STATE_INIT(&output_pos); nblocks = (input_length + BLOCK_SIZE - 1) / BLOCK_SIZE; if (nblocks == 1) { krb5int_c_iov_get_block((unsigned char *)tmp, BLOCK_SIZE, data, num_data, &input_pos); dec(tmp2, tmp, &ctx); krb5int_c_iov_put_block(data, num_data, (unsigned char *)tmp2, BLOCK_SIZE, &output_pos); } else if (nblocks > 1) { char blockN2[BLOCK_SIZE]; /* second last */ char blockN1[BLOCK_SIZE]; /* last block */ for (blockno = 0; blockno < nblocks - 2; blockno++) { char blockN[BLOCK_SIZE]; krb5int_c_iov_get_block((unsigned char *)blockN, BLOCK_SIZE, data, num_data, &input_pos); dec(tmp2, blockN, &ctx); xorblock(tmp2, tmp); krb5int_c_iov_put_block(data, num_data, (unsigned char *)tmp2, BLOCK_SIZE, &output_pos); memcpy(tmp, blockN, BLOCK_SIZE); } /* Do last two blocks, the second of which (next-to-last block of plaintext) may be incomplete. */ /* First, get the last two encrypted blocks */ memset(blockN1, 0, sizeof(blockN1)); /* pad last block with zeros */ krb5int_c_iov_get_block((unsigned char *)blockN2, BLOCK_SIZE, data, num_data, &input_pos); krb5int_c_iov_get_block((unsigned char *)blockN1, BLOCK_SIZE, data, num_data, &input_pos); /* Decrypt second last block */ dec(tmp2, blockN2, &ctx); /* Set tmp2 to last (possibly partial) plaintext block, and save it. */ xorblock(tmp2, blockN1); memcpy(blockN2, tmp2, BLOCK_SIZE); /* Maybe keep the trailing part, and copy in the last ciphertext block. */ input_length %= BLOCK_SIZE; memcpy(tmp2, blockN1, input_length ? input_length : BLOCK_SIZE); dec(tmp3, tmp2, &ctx); xorblock(tmp3, tmp); /* Copy out ivec first before we clobber blockN1 with plaintext */ if (ivec != NULL) memcpy(ivec->data, blockN1, BLOCK_SIZE); memcpy(blockN1, tmp3, BLOCK_SIZE); /* Put the last two blocks back into the iovec */ krb5int_c_iov_put_block(data, num_data, (unsigned char *)blockN1, BLOCK_SIZE, &output_pos); krb5int_c_iov_put_block(data, num_data, (unsigned char *)blockN2, BLOCK_SIZE, &output_pos); } return 0; }
std::string RaDec::toString() const { return ra().hms() + " " + dec().dms(); }
////////////////////////////////////////////////////////////////////// // Comparison operators for RaDec ////////////////////////////////////////////////////////////////////// RaDec::RaDec(const Vector& vector) { ra() = Angle(atan2(vector.y(), vector.x())); dec() = Angle(asin(vector.z() / vector.abs())); }
const_iterator& operator--() { dec(); return *this; }
int bamclipreinsert(::libmaus2::util::ArgInfo const & arginfo) { if ( isatty(STDIN_FILENO) ) { ::libmaus2::exception::LibMausException se; se.getStream() << "Refusing to read binary data from terminal, please redirect standard input to pipe or file." << std::endl; se.finish(); throw se; } if ( isatty(STDOUT_FILENO) ) { ::libmaus2::exception::LibMausException se; se.getStream() << "Refusing write binary data to terminal, please redirect standard output to pipe or file." << std::endl; se.finish(); throw se; } int const level = libmaus2::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",getDefaultLevel())); int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose()); ::libmaus2::bambam::BamDecoder dec(std::cin,false); ::libmaus2::bambam::BamHeader const & header = dec.getHeader(); std::string const headertext(header.text); // add PG line to header std::string const upheadtext = ::libmaus2::bambam::ProgramHeaderLineSet::addProgramLine( headertext, "bamclipreinsert", // ID "bamclipreinsert", // PN arginfo.commandline, // CL ::libmaus2::bambam::ProgramHeaderLineSet(headertext).getLastIdInChain(), // PP std::string(PACKAGE_VERSION) // VN ); // construct new header libmaus2::bambam::BamHeader const uphead(upheadtext); /* * start index/md5 callbacks */ std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName()); std::string const tmpfileindex = tmpfilenamebase + "_index"; ::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex); std::string md5filename; std::string indexfilename; std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs; ::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb; if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) ) { if ( arginfo.hasArg("md5filename") && arginfo.getUnparsedValue("md5filename","") != "" ) md5filename = arginfo.getUnparsedValue("md5filename",""); else std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl; if ( md5filename.size() ) { ::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5); Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb); cbs.push_back(Pmd5cb.get()); } } libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex; if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) ) { if ( arginfo.hasArg("indexfilename") && arginfo.getUnparsedValue("indexfilename","") != "" ) indexfilename = arginfo.getUnparsedValue("indexfilename",""); else std::cerr << "[V] no filename for index given, not creating index" << std::endl; if ( indexfilename.size() ) { libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex)); Pindex = UNIQUE_PTR_MOVE(Tindex); cbs.push_back(Pindex.get()); } } std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0; if ( cbs.size() ) Pcbs = &cbs; /* * end md5/index callbacks */ ::libmaus2::bambam::BamWriter::unique_ptr_type writer(new ::libmaus2::bambam::BamWriter(std::cout,uphead,level,Pcbs)); libmaus2::bambam::BamAuxFilterVector bafv; // bafv.set('z','z'); // std::vector<uint8_t> R(8); // std::string const zz("zz"); libmaus2::bambam::BamAlignment & algn = dec.getAlignment(); uint64_t c = 0; libmaus2::autoarray::AutoArray < std::pair<uint8_t,uint8_t> > auxtags; libmaus2::autoarray::AutoArray<libmaus2::bambam::cigar_operation> cigop; std::stack < libmaus2::bambam::cigar_operation > hardstack; libmaus2::bambam::BamAlignment::D_array_type Tcigar; libmaus2::bambam::BamAuxFilterVector auxfilterout; auxfilterout.set('q','s'); auxfilterout.set('q','q'); while ( dec.readAlignment() ) { // reinsert clipped parts and attach soft clipping cigar operations as needed clipReinsert(algn,auxtags,bafv,cigop,Tcigar,hardstack,auxfilterout); algn.serialise(writer->getStream()); ++c; if ( verbose && (c & (1024*1024-1)) == 0 ) std::cerr << "[V] " << c/(1024*1024) << std::endl; } writer.reset(); if ( Pmd5cb ) { Pmd5cb->saveDigestAsFile(md5filename); } if ( Pindex ) { Pindex->flush(std::string(indexfilename)); } return EXIT_SUCCESS; }
//! Performs an atomic decrement by 'val', returning the new value T operator-=(const T val) { return dec(val); }
//! Performs an atomic decrement by 1, returning the new value T dec() { return dec(1); }
char lmp_json_callback_board_sdmux(struct lejp_ctx *ctx, char reason) { static int q; static char mul; static char masked; static char update; static unsigned char old_muxmode; char str[10]; const char SET_DUT_PWR = 99; const char UPDATE_MUX = 1; const char UPDATE_RLY = 2; if (!ctx) { /* idle processing */ q++; reason = REASON_SEND_REPORT; if (idle_ok && (q & 0x7fff)) return 0; } switch (reason) { case LEJPCB_START: mul = -1; update = 0; old_muxmode = muxmode; break; case LEJPCB_VAL_STR_END: switch (ctx->path_match) { case 1: /* schema */ if (strcmp(&ctx->buf[15], "sdmux")) return -1; /* fail it */ break; default: if (!strcmp(ctx->path, "modes[].name")) { if (!strcmp(ctx->buf, "dut")) { mul = 1; masked = muxmode - (muxmode % 3); } else if (!strcmp(ctx->buf, "host")) { mul = 3; masked = muxmode % 3; } else if (!strcmp(ctx->buf, "dut-power")) { mul = SET_DUT_PWR; } else /* illegal name */ return -1; } if (!strcmp(ctx->path, "modes[].option")) { /* require a previous name */ if (mul == -1) return -1; update |= UPDATE_MUX; if (mul == SET_DUT_PWR) { if (!strcmp(ctx->buf, "short-for-off")) { if (dut_power_polarity) { dut_power_polarity = 0; update |= UPDATE_RLY; } break; } if (!strcmp(ctx->buf, "short-for-on")) { if (!dut_power_polarity) { dut_power_polarity = 1; update |= UPDATE_RLY; } break; } /* illegal option */ return -1; } if (!strcmp(ctx->buf, "disconnect")) { muxmode = masked; break; } if (!strcmp(ctx->buf, "uSDA")) { muxmode = masked + mul; break; } if (!strcmp(ctx->buf, "uSDB")) { muxmode = masked + (2 * mul); break; } /* illegal option */ return -1; } break; } break; case LEJPCB_COMPLETE: if (update & UPDATE_RLY) { if (muxmode % 3) { if (dut_power_polarity) lava_lmp_actuate_relay(RL1_CLR); else lava_lmp_actuate_relay(RL1_SET); } else { if (dut_power_polarity) lava_lmp_actuate_relay(RL1_SET); else lava_lmp_actuate_relay(RL1_CLR); } } if (!(update & UPDATE_MUX)) break; if ((old_muxmode / 3) != (muxmode / 3)) { /* changed host, so remove power from Host SD Reader */ LPC_GPIO->CLR[0] = 1 << 17; } if ((old_muxmode % 3) != (muxmode % 3)) { /* any change in DUT card --> disconnect CD / power */ if (dut_power_polarity) lava_lmp_actuate_relay(RL1_SET); else lava_lmp_actuate_relay(RL1_CLR); } /* actually change the power and mux arrangements */ lava_lmp_bus_write(0, busa_modes[muxmode]); /* if host has a new card now, power the reader... */ if ((old_muxmode / 3) != (muxmode / 3) && (muxmode / 3)) { /* wait for DUT leakage to card in reader to fade */ lmp_delay(3000000); /* ...allow power to Host SD Reader */ LPC_GPIO->SET[0] = 1 << 17; } /* if DUT has a card now... */ if ((muxmode % 3) && (old_muxmode % 3) != (muxmode % 3)) { /* wait for disconnect to go through */ lmp_delay(1000000); /* DUT has a card, connect CD / power */ if (dut_power_polarity) lava_lmp_actuate_relay(RL1_CLR); else lava_lmp_actuate_relay(RL1_SET); } /* fallthru */ case REASON_SEND_REPORT: lmp_issue_report_header("DUT.pwr\",\"val\":\""); lava_lmp_write_voltage(); usb_queue_string("\",\"unit\":\"mV\"},{\"name\":\"modes\",\"modes\":[{\"name\":\"host\",\"mode\":\""); usb_queue_string(sides[muxmode / 3]); usb_queue_string("\"},{\"name\":\"dut\",\"mode\":\""); usb_queue_string(sides[muxmode % 3]); usb_queue_string("\"},{\"name\":\"dut-power\",\"mode\":\""); if (dut_power_polarity) usb_queue_string("short-for-off"); else usb_queue_string("short-for-on"); usb_queue_string("\"}]},{\"name\":\"DUT.muxmode\",\"val\":\""); dec(muxmode,str); usb_queue_string(str); usb_queue_string("\"}]}\x04"); break; default: break; } return 0; }
void edit() { extern bool_t need_redraw; int c; register char *p, *q; Prenum = 0; /* position the display and the cursor at the top of the file. */ *Topchar = *Filemem; *Curschar = *Filemem; Cursrow = Curscol = 0; do_mlines(); /* check for mode lines before starting */ updatescreen(); for ( ;; ) { /* Figure out where the cursor is based on Curschar. */ cursupdate(); if (need_redraw && !anyinput()) { updatescreen(); need_redraw = FALSE; } if (!anyinput()) windgoto(Cursrow,Curscol); c = vgetc(); if (State == NORMAL) { /* We're in the normal (non-insert) mode. */ /* Pick up any leading digits and compute 'Prenum' */ if ( (Prenum>0 && isdigit(c)) || (isdigit(c) && c!='0') ){ Prenum = Prenum*10 + (c-'0'); continue; } /* execute the command */ normal(c); Prenum = 0; } else { /* * Insert or Replace mode. */ switch (c) { case ESC: /* an escape ends input mode */ /* * If we just did an auto-indent, truncate the * line, and put the cursor back. */ if (did_ai) { Curschar->linep->s[0] = NUL; Curschar->index = 0; did_ai = FALSE; } set_want_col = TRUE; /* Don't end up on a '\n' if you can help it. */ if (gchar(Curschar) == NUL && Curschar->index != 0) dec(Curschar); /* * The cursor should end up on the last inserted * character. This is an attempt to match the real * 'vi', but it may not be quite right yet. */ if (Curschar->index != 0 && !endofline(Curschar)) dec(Curschar); State = NORMAL; msg(""); /* construct the Redo buffer */ p=Redobuff; q=Insbuff; while ( q < Insptr ) *p++ = *q++; *p++ = ESC; *p = NUL; updatescreen(); break; case CTRL('D'): /* * Control-D is treated as a backspace in insert * mode to make auto-indent easier. This isn't * completely compatible with vi, but it's a lot * easier than doing it exactly right, and the * difference isn't very noticeable. */ case BS: /* can't backup past starting point */ if (Curschar->linep == Insstart->linep && Curschar->index <= Insstart->index) { beep(); break; } /* can't backup to a previous line */ if (Curschar->linep != Insstart->linep && Curschar->index <= 0) { beep(); break; } did_ai = FALSE; dec(Curschar); if (State == INSERT) delchar(TRUE); /* * It's a little strange to put backspaces into * the redo buffer, but it makes auto-indent a * lot easier to deal with. */ *Insptr++ = BS; Ninsert++; cursupdate(); updateline(); break; case CR: case NL: if (State == REPLACE) /* DMT added, 12/89 */ delchar(FALSE); *Insptr++ = NL; Ninsert++; opencmd(FORWARD, TRUE); /* open a new line */ break; default: did_ai = FALSE; insertchar(c); break; } } } }
bitcount_t & operator -=(const bitfield_t &other) throw() { return dec(other); }
//! Performs an atomic decrement by 1, returning the new value T operator--() { return dec(); }
~handle() { if (h_ != 0) dec(); }
void dec_cr() { dec(); cr(); }
/** @brief Wraps an OpenCL handle. Decreases the reference count if the handle object is destroyed or another OpenCL handle is assigned. */ handle & operator=(const OCL_TYPE & something) { if (h_ != 0) dec(); h_ = something; return *this; }
int main(int argc, char *argv[]) { json_auto_t *jwke = json_pack("{s:s}", "alg", "ECDH-ES+A128KW"); json_auto_t *jwkr = json_pack("{s:s}", "alg", "RSA1_5"); json_auto_t *jwko = json_pack("{s:s}", "alg", "A128KW"); json_auto_t *set0 = json_pack("{s:[O,O]}", "keys", jwke, jwko); json_auto_t *set1 = json_pack("{s:[O,O]}", "keys", jwkr, jwko); json_auto_t *set2 = json_pack("{s:[O,O]}", "keys", jwke, jwkr); json_auto_t *jwe = NULL; assert(jose_jwk_gen(NULL, jwke)); assert(jose_jwk_gen(NULL, jwkr)); assert(jose_jwk_gen(NULL, jwko)); json_decref(jwe); assert((jwe = json_object())); assert(jose_jwe_enc(NULL, jwe, NULL, jwke, "foo", 4)); assert(dec(jwe, jwke)); assert(!dec(jwe, jwkr)); assert(!dec(jwe, jwko)); assert(dec(jwe, set0)); assert(!dec(jwe, set1)); assert(dec(jwe, set2)); json_decref(jwe); assert((jwe = json_object())); assert(jose_jwe_enc(NULL, jwe, NULL, jwkr, "foo", 4)); assert(!dec(jwe, jwke)); assert(dec(jwe, jwkr)); assert(!dec(jwe, jwko)); assert(!dec(jwe, set0)); assert(dec(jwe, set1)); assert(dec(jwe, set2)); json_decref(jwe); assert((jwe = json_object())); assert(jose_jwe_enc(NULL, jwe, NULL, jwko, "foo", 4)); assert(!dec(jwe, jwke)); assert(!dec(jwe, jwkr)); assert(dec(jwe, jwko)); assert(dec(jwe, set0)); assert(dec(jwe, set1)); assert(!dec(jwe, set2)); json_decref(jwe); assert((jwe = json_object())); assert(jose_jwe_enc(NULL, jwe, NULL, set0, "foo", 4)); assert(dec(jwe, jwke)); assert(!dec(jwe, jwkr)); assert(dec(jwe, jwko)); assert(dec(jwe, set0)); assert(dec(jwe, set1)); assert(dec(jwe, set2)); return EXIT_SUCCESS; }
DLLEXPORT long double sqrtl(long double x) { union IEEEl2bits u; int k, r; long double lo, xn; fenv_t env; u.e = x; /* If x = NaN, then sqrt(x) = NaN. */ /* If x = Inf, then sqrt(x) = Inf. */ /* If x = -Inf, then sqrt(x) = NaN. */ if (u.bits.exp == LDBL_MAX_EXP * 2 - 1) return (x * x + x); /* If x = +-0, then sqrt(x) = +-0. */ if ((u.bits.manh | u.bits.manl | u.bits.exp) == 0) return (x); /* If x < 0, then raise invalid and return NaN */ if (u.bits.sign) return ((x - x) / (x - x)); feholdexcept(&env); if (u.bits.exp == 0) { /* Adjust subnormal numbers. */ u.e *= 0x1.0p514; k = -514; } else { k = 0; } /* * u.e is a normal number, so break it into u.e = e*2^n where * u.e = (2*e)*2^2k for odd n and u.e = (4*e)*2^2k for even n. */ if ((u.bits.exp - 0x3ffe) & 1) { /* n is odd. */ k += u.bits.exp - 0x3fff; /* 2k = n - 1. */ u.bits.exp = 0x3fff; /* u.e in [1,2). */ } else { k += u.bits.exp - 0x4000; /* 2k = n - 2. */ u.bits.exp = 0x4000; /* u.e in [2,4). */ } /* * Newton's iteration. * Split u.e into a high and low part to achieve additional precision. */ xn = sqrt(u.e); /* 53-bit estimate of sqrtl(x). */ #if LDBL_MANT_DIG > 100 xn = (xn + (u.e / xn)) * 0.5; /* 106-bit estimate. */ #endif lo = u.e; u.bits.manl = 0; /* Zero out lower bits. */ lo = (lo - u.e) / xn; /* Low bits divided by xn. */ xn = xn + (u.e / xn); /* High portion of estimate. */ u.e = xn + lo; /* Combine everything. */ u.bits.exp += (k >> 1) - 1; feclearexcept(FE_INEXACT); r = fegetround(); fesetround(FE_TOWARDZERO); /* Set to round-toward-zero. */ xn = x / u.e; /* Chopped quotient (inexact?). */ if (!fetestexcept(FE_INEXACT)) { /* Quotient is exact. */ if (xn == u.e) { fesetenv(&env); return (u.e); } /* Round correctly for inputs like x = y**2 - ulp. */ xn = dec(xn); /* xn = xn - ulp. */ } if (r == FE_TONEAREST) { xn = inc(xn); /* xn = xn + ulp. */ } else if (r == FE_UPWARD) { u.e = inc(u.e); /* u.e = u.e + ulp. */ xn = inc(xn); /* xn = xn + ulp. */ } u.e = u.e + xn; /* Chopped sum. */ feupdateenv(&env); /* Restore env and raise inexact */ u.bits.exp--; return (u.e); }
const_iterator operator--(int) { const_iterator ret(*this); dec(); return ret; }
void Walker::walk() { if (D_NONE == _action._direction ) { // nothing to do return; } Tile& tile = Scenario::instance().getCity().getTilemap().at( getIJ() ); switch (_action._direction) { case D_NORTH: case D_SOUTH: _remainMoveJ += _d->getSpeed(); break; case D_EAST: case D_WEST: _remainMoveI += _d->getSpeed(); break; case D_NORTH_EAST: case D_SOUTH_WEST: case D_SOUTH_EAST: case D_NORTH_WEST: _remainMoveI += _d->getSpeed() * 0.7f; _remainMoveJ += _d->getSpeed() * 0.7f ; break; default: THROW("Invalid move direction: " << _action._direction); break; } bool newTile = false; bool midTile = false; int amountI = int(_remainMoveI); int amountJ = int(_remainMoveJ); _remainMoveI -= amountI; _remainMoveJ -= amountJ; // std::cout << "walker step, amount :" << amount << std::endl; while (amountI+amountJ > 0) { switch (_action._direction) { case D_NORTH: inc(_sj, _d->pos.rj(), amountJ, _d->midTile.getJ(), newTile, midTile); break; case D_NORTH_EAST: inc(_sj, _d->pos.rj(), amountJ, _d->midTile.getJ(), newTile, midTile); inc(_si, _d->pos.ri(), amountI, _d->midTile.getI(), newTile, midTile); break; case D_EAST: inc(_si, _d->pos.ri(), amountI, _d->midTile.getI(), newTile, midTile); break; case D_SOUTH_EAST: dec(_sj, _d->pos.rj(), amountJ, _d->midTile.getJ(), newTile, midTile); inc(_si, _d->pos.ri(), amountI, _d->midTile.getI(), newTile, midTile); break; case D_SOUTH: dec(_sj, _d->pos.rj(), amountJ, _d->midTile.getJ(), newTile, midTile); break; case D_SOUTH_WEST: dec(_sj, _d->pos.rj(), amountJ, _d->midTile.getJ(), newTile, midTile); dec(_si, _d->pos.ri(), amountI, _d->midTile.getI(), newTile, midTile); break; case D_WEST: dec(_si, _d->pos.ri(), amountI, _d->midTile.getI(), newTile, midTile); break; case D_NORTH_WEST: inc(_sj, _d->pos.rj(), amountJ, _d->midTile.getJ(), newTile, midTile); dec(_si, _d->pos.ri(), amountI, _d->midTile.getI(), newTile, midTile); break; default: THROW("Invalid move direction: " << _action._direction); break; } if (newTile) { // walker is now on a new tile! onNewTile(); } if (midTile) { // walker is now on the middle of the tile! onMidTile(); } // if (midTile) std::cout << "walker mid tile" << std::endl; // if (newTile) std::cout << "walker new tile" << std::endl; // if (amount != 0) std::cout << "walker remaining step :" << amount << std::endl; } _ii = _d->pos.getI()*15+_si; _jj = _d->pos.getJ()*15+_sj; }