// todo: lightmap support for PSP and ES bool Texture::loadMipmap(std::string strFn) { bool isJpgTexture = false; if( strncmp((strFn.c_str()+strFn.length()-3), "JPG", 3)==0 || strncmp((strFn.c_str()+strFn.length()-3), "jpg", 3)==0) isJpgTexture = true; //if a jpg texture, need to set UNPACK_ALIGNMENT to 1 if (img.Load((char *)strFn.c_str())) { generate(); glEnable(GL_TEXTURE_2D); #ifdef OPENGL_ES glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); #else //Set Parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); #endif #ifndef ARCH_DC if(isJpgTexture) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); #endif #ifdef OPENGL_ES //Create texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.width, img.height, 0, img.format, GL_UNSIGNED_BYTE, img.data); #else gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, img.width, img.height, img.format, GL_UNSIGNED_BYTE, img.data); #endif #ifndef ARCH_DC glPixelStorei(GL_UNPACK_ALIGNMENT, 4); #endif return true; } else { return false; } // char c = toupper(strFn[strFn.length()-3]); // // if (c == 'T') // { // load(strFn,FORMAT_TGA); // } // else // if (c == 'P') // { // load(strFn,FORMAT_PNG); // } }
void generate_NEWTABLE(quad *q) { generate(newtable_v, q); }
void generate_ASSIGN(quad *q) { generate(assign_v, q); }
void generate_SUB(quad *q) { generate(sub_v, q); }
void generate_DIV(quad *q) { generate(div_v, q); }
size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) { PseudoRandom ps(blockseed + 53); int carea_size = nmax.X - nmin.X + 1; // Divide area into parts if (carea_size % sidelen) { errorstream << "Decoration::placeDeco: chunk size is not divisible by " "sidelen; setting sidelen to " << carea_size << std::endl; sidelen = carea_size; } s16 divlen = carea_size / sidelen; int area = sidelen * sidelen; for (s16 z0 = 0; z0 < divlen; z0++) for (s16 x0 = 0; x0 < divlen; x0++) { v2s16 p2d_center( // Center position of part of division nmin.X + sidelen / 2 + sidelen * x0, nmin.Z + sidelen / 2 + sidelen * z0 ); v2s16 p2d_min( // Minimum edge of part of division nmin.X + sidelen * x0, nmin.Z + sidelen * z0 ); v2s16 p2d_max( // Maximum edge of part of division nmin.X + sidelen + sidelen * x0 - 1, nmin.Z + sidelen + sidelen * z0 - 1 ); // Amount of decorations float nval = (flags & DECO_USE_NOISE) ? NoisePerlin2D(&np, p2d_center.X, p2d_center.Y, mapseed) : fill_ratio; u32 deco_count = area * MYMAX(nval, 0.f); for (u32 i = 0; i < deco_count; i++) { s16 x = ps.range(p2d_min.X, p2d_max.X); s16 z = ps.range(p2d_min.Y, p2d_max.Y); int mapindex = carea_size * (z - nmin.Z) + (x - nmin.X); s16 y = mg->heightmap ? mg->heightmap[mapindex] : mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y); if (y < nmin.Y || y > nmax.Y || y < y_min || y > y_max) continue; if (y + getHeight() >= mg->vm->m_area.MaxEdge.Y) { continue; #if 0 printf("Decoration at (%d %d %d) cut off\n", x, y, z); //add to queue JMutexAutoLock cutofflock(cutoff_mutex); cutoffs.push_back(CutoffData(x, y, z, height)); #endif } if (mg->biomemap) { std::set<u8>::iterator iter; if (!biomes.empty()) { iter = biomes.find(mg->biomemap[mapindex]); if (iter == biomes.end()) continue; } } v3s16 pos(x, y, z); if (generate(mg->vm, &ps, pos)) mg->gennotify.addEvent(GENNOTIFY_DECORATION, pos, index); } } return 0; }
/// Generates \p z random numbers and discards them. void discard(size_t z, command_queue &queue) { generate(discard_iterator(0), discard_iterator(z), queue); }
friend object generate(object const*, random_generator g) { int* x = 0; return object(generate(x, g), generate(x, g)); }
int main(void) { isc_mem_t *mctx = NULL; isc_entropy_t *ectx = NULL; isc_buffer_t b; dns_fixedname_t fname; dns_name_t *name; isc_result_t result; result = isc_mem_create(0, 0, &mctx); if (result != ISC_R_SUCCESS) return (1); current = isc_mem_get(mctx, 256); if (current == NULL) return (1); if (getcwd(current, 256) == NULL) { perror("getcwd"); return (1); } dns_result_register(); result = isc_entropy_create(mctx, &ectx); if (result != ISC_R_SUCCESS) return (1); result = isc_entropy_createfilesource(ectx, "randomfile"); if (result != ISC_R_SUCCESS) return (1); dst_lib_init(mctx, ectx, ISC_ENTROPY_BLOCKING|ISC_ENTROPY_GOODONLY); dns_fixedname_init(&fname); name = dns_fixedname_name(&fname); isc_buffer_init(&b, "test.", 5); isc_buffer_add(&b, 5); result = dns_name_fromtext(name, &b, NULL, 0, NULL); if (result != ISC_R_SUCCESS) return (1); io(name, 23616, DST_ALG_DSA, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx); io(name, 54622, DST_ALG_RSAMD5, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx); io(name, 49667, DST_ALG_DSA, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx); io(name, 2, DST_ALG_RSAMD5, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx); isc_buffer_init(&b, "dh.", 3); isc_buffer_add(&b, 3); result = dns_name_fromtext(name, &b, NULL, 0, NULL); if (result != ISC_R_SUCCESS) return (1); dh(name, 18602, name, 48957, mctx); generate(DST_ALG_RSAMD5, mctx); generate(DST_ALG_DH, mctx); generate(DST_ALG_DSA, mctx); generate(DST_ALG_HMACMD5, mctx); dst_lib_destroy(); isc_entropy_detach(&ectx); isc_mem_put(mctx, current, 256); /* isc_mem_stats(mctx, stdout);*/ isc_mem_destroy(&mctx); return (0); }
static void TestAlgorithms (void) { static const int c_TestNumbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16, 17, 18 }; const int* first = c_TestNumbers; const int* last = first + VectorSize(c_TestNumbers); intvec_t v, buf; v.assign (first, last); PrintVector (v); cout << "swap(1,2)\n"; swap (v[0], v[1]); PrintVector (v); v.assign (first, last); cout << "copy(0,8,9)\n"; copy (v.begin(), v.begin() + 8, v.begin() + 9); PrintVector (v); v.assign (first, last); cout << "copy with back_inserter\n"; v.clear(); copy (first, last, back_inserter(v)); PrintVector (v); v.assign (first, last); cout << "copy with inserter\n"; v.clear(); copy (first, first + 5, inserter(v, v.begin())); copy (first, first + 5, inserter(v, v.begin() + 3)); PrintVector (v); v.assign (first, last); cout << "copy_n(0,8,9)\n"; copy_n (v.begin(), 8, v.begin() + 9); PrintVector (v); v.assign (first, last); cout << "copy_if(is_even)\n"; intvec_t v_even; copy_if (v, back_inserter(v_even), &is_even); PrintVector (v_even); v.assign (first, last); cout << "for_each(printint)\n{ "; for_each (v, &printint); cout << "}\n"; cout << "for_each(reverse_iterator, printint)\n{ "; for_each (v.rbegin(), v.rend(), &printint); cout << "}\n"; cout << "find(10)\n"; cout.format ("10 found at offset %zd\n", abs_distance (v.begin(), find (v, 10))); cout << "count(13)\n"; cout.format ("%zu values of 13, %zu values of 18\n", count(v,13), count(v,18)); cout << "transform(sqr)\n"; transform (v, &sqr); PrintVector (v); v.assign (first, last); cout << "replace(13,666)\n"; replace (v, 13, 666); PrintVector (v); v.assign (first, last); cout << "fill(13)\n"; fill (v, 13); PrintVector (v); v.assign (first, last); cout << "fill_n(5, 13)\n"; fill_n (v.begin(), 5, 13); PrintVector (v); v.assign (first, last); cout << "fill 64083 uint8_t(0x41) "; TestBigFill<uint8_t> (64083, 0x41); cout << "fill 64083 uint16_t(0x4142) "; TestBigFill<uint16_t> (64083, 0x4142); cout << "fill 64083 uint32_t(0x41424344) "; TestBigFill<uint32_t> (64083, 0x41424344); cout << "fill 64083 float(0.4242) "; TestBigFill<float> (64083, 0x4242f); #if HAVE_INT64_T cout << "fill 64083 uint64_t(0x4142434445464748) "; TestBigFill<uint64_t> (64083, UINT64_C(0x4142434445464748)); #else cout << "No 64bit types available on this platform\n"; #endif cout << "copy 64083 uint8_t(0x41) "; TestBigCopy<uint8_t> (64083, 0x41); cout << "copy 64083 uint16_t(0x4142) "; TestBigCopy<uint16_t> (64083, 0x4142); cout << "copy 64083 uint32_t(0x41424344) "; TestBigCopy<uint32_t> (64083, 0x41424344); cout << "copy 64083 float(0.4242) "; TestBigCopy<float> (64083, 0.4242f); #if HAVE_INT64_T cout << "copy 64083 uint64_t(0x4142434445464748) "; TestBigCopy<uint64_t> (64083, UINT64_C(0x4142434445464748)); #else cout << "No 64bit types available on this platform\n"; #endif cout << "generate(genint)\n"; generate (v, &genint); PrintVector (v); v.assign (first, last); cout << "rotate(4)\n"; rotate (v, 7); rotate (v, -3); PrintVector (v); v.assign (first, last); cout << "merge with (3,5,10,11,11,14)\n"; const int c_MergeWith[] = { 3,5,10,11,11,14 }; intvec_t vmerged; merge (v.begin(), v.end(), VectorRange(c_MergeWith), back_inserter(vmerged)); PrintVector (vmerged); v.assign (first, last); cout << "inplace_merge with (3,5,10,11,11,14)\n"; v.insert (v.end(), VectorRange(c_MergeWith)); inplace_merge (v.begin(), v.end() - VectorSize(c_MergeWith), v.end()); PrintVector (v); v.assign (first, last); cout << "remove(13)\n"; remove (v, 13); PrintVector (v); v.assign (first, last); cout << "remove (elements 3, 4, 6, 15, and 45)\n"; vector<uoff_t> toRemove; toRemove.push_back (3); toRemove.push_back (4); toRemove.push_back (6); toRemove.push_back (15); toRemove.push_back (45); typedef index_iterate<intvec_t::iterator, vector<uoff_t>::iterator> riiter_t; riiter_t rfirst = index_iterator (v.begin(), toRemove.begin()); riiter_t rlast = index_iterator (v.begin(), toRemove.end()); remove (v, rfirst, rlast); PrintVector (v); v.assign (first, last); cout << "unique\n"; unique (v); PrintVector (v); v.assign (first, last); cout << "reverse\n"; reverse (v); PrintVector (v); v.assign (first, last); cout << "lower_bound(10)\n"; PrintVector (v); cout.format ("10 begins at position %zd\n", abs_distance (v.begin(), lower_bound (v, 10))); v.assign (first, last); cout << "upper_bound(10)\n"; PrintVector (v); cout.format ("10 ends at position %zd\n", abs_distance (v.begin(), upper_bound (v, 10))); v.assign (first, last); cout << "equal_range(10)\n"; PrintVector (v); TestEqualRange (v); v.assign (first, last); cout << "sort\n"; reverse (v); PrintVector (v); random_shuffle (v); sort (v); PrintVector (v); v.assign (first, last); cout << "stable_sort\n"; reverse (v); PrintVector (v); random_shuffle (v); stable_sort (v); PrintVector (v); v.assign (first, last); cout << "is_sorted\n"; random_shuffle (v); const bool bNotSorted = is_sorted (v.begin(), v.end()); sort (v); const bool bSorted = is_sorted (v.begin(), v.end()); cout << "unsorted=" << bNotSorted << ", sorted=" << bSorted << endl; v.assign (first, last); cout << "find_first_of\n"; static const int c_FFO[] = { 10000, -34, 14, 27 }; cout.format ("found 14 at position %zd\n", abs_distance (v.begin(), find_first_of (v.begin(), v.end(), VectorRange(c_FFO)))); v.assign (first, last); static const int LC1[] = { 3, 1, 4, 1, 5, 9, 3 }; static const int LC2[] = { 3, 1, 4, 2, 8, 5, 7 }; static const int LC3[] = { 1, 2, 3, 4 }; static const int LC4[] = { 1, 2, 3, 4, 5 }; cout << "lexicographical_compare"; cout << "\nLC1 < LC2 == " << lexicographical_compare (VectorRange(LC1), VectorRange(LC2)); cout << "\nLC2 < LC2 == " << lexicographical_compare (VectorRange(LC2), VectorRange(LC2)); cout << "\nLC3 < LC4 == " << lexicographical_compare (VectorRange(LC3), VectorRange(LC4)); cout << "\nLC4 < LC1 == " << lexicographical_compare (VectorRange(LC4), VectorRange(LC1)); cout << "\nLC1 < LC4 == " << lexicographical_compare (VectorRange(LC1), VectorRange(LC4)); cout << "\nmax_element\n"; cout.format ("max element is %d\n", *max_element (v.begin(), v.end())); v.assign (first, last); cout << "min_element\n"; cout.format ("min element is %d\n", *min_element (v.begin(), v.end())); v.assign (first, last); cout << "partial_sort\n"; reverse (v); partial_sort (v.begin(), v.iat(v.size() / 2), v.end()); PrintVector (v); v.assign (first, last); cout << "partial_sort_copy\n"; reverse (v); buf.resize (v.size()); partial_sort_copy (v.begin(), v.end(), buf.begin(), buf.end()); PrintVector (buf); v.assign (first, last); cout << "partition\n"; partition (v.begin(), v.end(), &is_even); PrintVector (v); v.assign (first, last); cout << "stable_partition\n"; stable_partition (v.begin(), v.end(), &is_even); PrintVector (v); v.assign (first, last); cout << "next_permutation\n"; buf.resize (3); iota (buf.begin(), buf.end(), 1); PrintVector (buf); while (next_permutation (buf.begin(), buf.end())) PrintVector (buf); cout << "prev_permutation\n"; reverse (buf); PrintVector (buf); while (prev_permutation (buf.begin(), buf.end())) PrintVector (buf); v.assign (first, last); cout << "reverse_copy\n"; buf.resize (v.size()); reverse_copy (v.begin(), v.end(), buf.begin()); PrintVector (buf); v.assign (first, last); cout << "rotate_copy\n"; buf.resize (v.size()); rotate_copy (v.begin(), v.iat (v.size() / 3), v.end(), buf.begin()); PrintVector (buf); v.assign (first, last); static const int c_Search1[] = { 5, 6, 7, 8, 9 }, c_Search2[] = { 10, 10, 11, 14 }; cout << "search\n"; cout.format ("{5,6,7,8,9} at %zd\n", abs_distance (v.begin(), search (v.begin(), v.end(), VectorRange(c_Search1)))); cout.format ("{10,10,11,14} at %zd\n", abs_distance (v.begin(), search (v.begin(), v.end(), VectorRange(c_Search2)))); cout << "find_end\n"; cout.format ("{5,6,7,8,9} at %zd\n", abs_distance (v.begin(), find_end (v.begin(), v.end(), VectorRange(c_Search1)))); cout.format ("{10,10,11,14} at %zd\n", abs_distance (v.begin(), find_end (v.begin(), v.end(), VectorRange(c_Search2)))); cout << "search_n\n"; cout.format ("{14} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 1, 14))); cout.format ("{13,13} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 2, 13))); cout.format ("{10,10,10} at %zd\n", abs_distance (v.begin(), search_n (v.begin(), v.end(), 3, 10))); v.assign (first, last); cout << "includes\n"; static const int c_Includes[] = { 5, 14, 15, 18, 20 }; cout << "includes=" << includes (v.begin(), v.end(), VectorRange(c_Includes)-1); cout << ", not includes=" << includes (v.begin(), v.end(), VectorRange(c_Includes)); cout << endl; static const int c_Set1[] = { 1, 2, 3, 4, 5, 6 }, c_Set2[] = { 4, 4, 6, 7, 8 }; intvec_t::iterator setEnd; cout << "set_difference\n"; v.resize (4); setEnd = set_difference (VectorRange(c_Set1), VectorRange(c_Set2), v.begin()); PrintVector (v); assert (setEnd == v.end()); cout << "set_symmetric_difference\n"; v.resize (7); setEnd = set_symmetric_difference (VectorRange(c_Set1), VectorRange(c_Set2), v.begin()); PrintVector (v); assert (setEnd == v.end()); cout << "set_intersection\n"; v.resize (2); setEnd = set_intersection (VectorRange(c_Set1), VectorRange(c_Set2), v.begin()); PrintVector (v); assert (setEnd == v.end()); cout << "set_union\n"; v.resize (9); setEnd = set_union (VectorRange(c_Set1), VectorRange(c_Set2), v.begin()); PrintVector (v); assert (setEnd == v.end()); v.assign (first, last); }
MainWindow::MainWindow() : DemosMainWindow() { setupUi(this); this->graphicsView->setAcceptDrops(false); // Add a GraphicItem for the Periodic triangulation pt_gi = new CGAL::Qt::PeriodicTriangulationGraphicsItem<Periodic_DT>(&triang); QObject::connect(this, SIGNAL(changed()), pt_gi, SLOT(modelChanged())); pt_gi->setVerticesPen(QPen(Qt::red, 5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); scene.addItem(pt_gi); // Add a GraphicItem for the Voronoi diagram vgi = new CGAL::Qt::PeriodicTriangulationVoronoiGraphicsItem<Periodic_DT>(&triang); QObject::connect(this, SIGNAL(changed()), vgi, SLOT(modelChanged())); vgi->setEdgesPen(QPen(Qt::blue, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); scene.addItem(vgi); vgi->hide(); // Setup input handlers. They get events before the scene gets them // and the input they generate is passed to the triangulation with // the signal/slot mechanism pt_pi = new CGAL::Qt::TriangulationPointInputAndConflictZone<Periodic_DT>(&scene, &triang, this ); QObject::connect(pt_pi, SIGNAL(generate(CGAL::Object)), this, SLOT(processInput(CGAL::Object))); pt_mp = new CGAL::Qt::TriangulationMovingPoint<Periodic_DT>(&triang, this); // TriangulationMovingPoint<Periodic_DT> emits a modelChanged() signal each // time the moving point moves. // The following connection is for the purpose of emitting changed(). QObject::connect(pt_mp, SIGNAL(modelChanged()), this, SIGNAL(changed())); pt_cz = new CGAL::Qt::TriangulationConflictZone<Periodic_DT>(&scene, &triang, this); QObject::connect(pt_cz, SIGNAL(modelChanged()), this, SIGNAL(changed())); pt_rv = new CGAL::Qt::TriangulationRemoveVertex<Periodic_DT>(&triang, this); QObject::connect(pt_rv, SIGNAL(modelChanged()), this, SIGNAL(changed())); pt_cc = new CGAL::Qt::TriangulationCircumcircle<Periodic_DT>(&scene, &triang, this); pt_cc ->setPen(QPen(::Qt::black, .01)); QObject::connect(pt_cc, SIGNAL(modelChanged()), this, SIGNAL(changed())); // // Manual handling of actions // QObject::connect(this->actionQuit, SIGNAL(triggered()), this, SLOT(close())); // We put mutually exclusive actions in an QActionGroup QActionGroup* ag = new QActionGroup(this); ag->addAction(this->actionInsertPoint); ag->addAction(this->actionMovingPoint); ag->addAction(this->actionCircumcenter); ag->addAction(this->actionShowConflictZone); // Check two actions this->actionInsertPoint->setChecked(true); this->actionShowDelaunay->setChecked(true); // // Setup the scene and the view // scene.setItemIndexMethod(QGraphicsScene::NoIndex); scene.setSceneRect(0, 0, 1, 1); this->graphicsView->setScene(&scene); this->graphicsView->setMouseTracking(true); // Turn the vertical axis upside down this->graphicsView->matrix().scale(1, -1); // The navigation adds zooming and translation functionality to the // QGraphicsView this->addNavigation(this->graphicsView); this->setupStatusBar(); this->setupOptionsMenu(); this->addAboutDemo(":/cgal/help/about_Periodic_2_triangulation_2.html"); this->addAboutCGAL(); this->addRecentFiles(this->menuFile, this->actionQuit); connect(this, SIGNAL(openRecentFile(QString)), this, SLOT(open(QString))); on_actionRecenter_triggered(); }
void operator()(const tbb::blocked_range<size_t>& r) const { generate(r.begin(), r.end()); }
static int sign(const char *msgfile) { struct seckey skey; struct sig sig = { .pkalg = "Ed", }; struct stat st; char buf[512]; void *pubkey = buf; long mlen; void *m; int mfd; if (!get_base64_file(seckeyfile, &skey, sizeof(skey), buf, sizeof(buf)) || memcmp(skey.pkalg, "Ed", 2) != 0) { fprintf(stderr, "Failed to decode secret key\n"); return 1; } if (skey.kdfrounds) { fprintf(stderr, "Password protected secret keys are not supported\n"); return 1; } mfd = open(msgfile, O_RDONLY, 0); if (mfd < 0 || fstat(mfd, &st) < 0 || (m = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, mfd, 0)) == MAP_FAILED) { if (mfd >= 0) close(mfd); perror("Cannot open message file"); return 1; } mlen = st.st_size; memcpy(sig.fingerprint, skey.fingerprint, sizeof(sig.fingerprint)); edsign_sec_to_pub(pubkey, skey.seckey); edsign_sign(sig.sig, pubkey, skey.seckey, m, mlen); munmap(m, mlen); close(mfd); if (b64_encode(&sig, sizeof(sig), buf, sizeof(buf)) < 0) return 1; write_file(sigfile, sig.fingerprint, "signed by key", buf); return 0; } static int fingerprint(void) { struct seckey skey; struct pubkey pkey; struct sig sig; char buf[512]; uint8_t *fp; if (seckeyfile && get_base64_file(seckeyfile, &skey, sizeof(skey), buf, sizeof(buf))) fp = skey.fingerprint; else if (pubkeyfile && get_base64_file(pubkeyfile, &pkey, sizeof(pkey), buf, sizeof(buf))) fp = pkey.fingerprint; else if (sigfile && get_base64_file(sigfile, &sig, sizeof(sig), buf, sizeof(buf))) fp = sig.fingerprint; else return 1; fprintf(stdout, "%"PRIx64"\n", fingerprint_u64(fp)); return 0; } static int generate(void) { struct seckey skey = { .pkalg = "Ed", .kdfalg = "BK", .kdfrounds = 0, }; struct pubkey pkey = { .pkalg = "Ed", }; struct sha512_state s; char buf[512]; FILE *f; f = fopen("/dev/urandom", "r"); if (!f || fread(skey.fingerprint, sizeof(skey.fingerprint), 1, f) != 1 || fread(skey.seckey, EDSIGN_SECRET_KEY_SIZE, 1, f) != 1 || fread(skey.salt, sizeof(skey.salt), 1, f) != 1) { fprintf(stderr, "Can't read data from /dev/urandom\n"); return 1; } if (f) fclose(f); ed25519_prepare(skey.seckey); edsign_sec_to_pub(skey.seckey + 32, skey.seckey); sha512_init(&s); sha512_add(&s, skey.seckey, sizeof(skey.seckey)); memcpy(skey.checksum, sha512_final_get(&s), sizeof(skey.checksum)); if (b64_encode(&skey, sizeof(skey), buf, sizeof(buf)) < 0) return 1; write_file(seckeyfile, skey.fingerprint, "public key", buf); memcpy(pkey.fingerprint, skey.fingerprint, sizeof(pkey.fingerprint)); memcpy(pkey.pubkey, skey.seckey + 32, sizeof(pkey.pubkey)); if (b64_encode(&pkey, sizeof(pkey), buf, sizeof(buf)) < 0) return 1; write_file(pubkeyfile, pkey.fingerprint, "private key", buf); return 0; } static int usage(const char *cmd) { fprintf(stderr, "Usage: %s <command> <options>\n" "Commands:\n" " -V: verify (needs at least -m and -p|-P)\n" " -S: sign (needs at least -m and -s)\n" " -F: print key fingerprint of public/secret key or signature\n" " -G: generate a new keypair\n" "Options:\n" " -c <comment>: add comment to keys\n" " -m <file>: message file\n" " -p <file>: public key file (verify/fingerprint only)\n" " -P <path>: public key directory (verify only)\n" " -q: quiet (do not print verification result, use return code only)\n" " -s <file>: secret key file (sign/fingerprint only)\n" " -x <file>: signature file (defaults to <message file>.sig)\n" "\n", cmd); return 1; } static void set_cmd(const char *prog, int val) { if (cmd != CMD_NONE) exit(usage(prog)); cmd = val; } int main(int argc, char **argv) { const char *msgfile = NULL; int ch; while ((ch = getopt(argc, argv, "FGSVc:m:P:p:qs:x:")) != -1) { switch (ch) { case 'V': set_cmd(argv[0], CMD_VERIFY); break; case 'S': set_cmd(argv[0], CMD_SIGN); break; case 'F': set_cmd(argv[0], CMD_FINGERPRINT); break; case 'G': set_cmd(argv[0], CMD_GENERATE); break; case 'c': comment = optarg; break; case 'm': msgfile = optarg; break; case 'P': pubkeydir = optarg; break; case 'p': pubkeyfile = optarg; break; case 's': seckeyfile = optarg; break; case 'x': sigfile = optarg; break; case 'q': quiet = true; break; default: return usage(argv[0]); } } if (!sigfile && msgfile) { char *buf = alloca(strlen(msgfile) + 5); if (!strcmp(msgfile, "-")) { fprintf(stderr, "Need signature file when reading message from stdin\n"); return 1; } sprintf(buf, "%s.sig", msgfile); sigfile = buf; } switch (cmd) { case CMD_VERIFY: if ((!pubkeyfile && !pubkeydir) || !msgfile) return usage(argv[0]); return verify(msgfile); case CMD_SIGN: if (!seckeyfile || !msgfile || !sigfile) return usage(argv[0]); return sign(msgfile); case CMD_FINGERPRINT: if (!!seckeyfile + !!pubkeyfile + !!sigfile != 1) { fprintf(stderr, "Need one secret/public key or signature\n"); return usage(argv[0]); } return fingerprint(); case CMD_GENERATE: if (!seckeyfile || !pubkeyfile) return usage(argv[0]); return generate(); default: return usage(argv[0]); } }
vector<TreeNode *> generateTrees(int n) { return generate(1, n); }
void Star::generate() { generate(time(NULL)); }
void StubRoutines::init() { if (_is_initialized) return; ResourceMark rm; CodeBuffer* code = new CodeBuffer(_code, _code_size); MacroAssembler* masm = new MacroAssembler(code); // add generators here _ic_normal_lookup_entry = generate(masm, "ic_normal_lookup", generate_ic_normal_lookup ); _ic_super_lookup_entry = generate(masm, "ic_super_lookup", generate_ic_super_lookup ); _zombie_nmethod_entry = generate(masm, "zombie_nmethod", generate_zombie_nmethod ); _zombie_block_nmethod_entry = generate(masm, "zombie_block_nmethod", generate_zombie_block_nmethod ); _megamorphic_ic_entry = generate(masm, "megamorphic_ic", generate_megamorphic_ic ); _compile_block_entry = generate(masm, "compile_block", generate_compile_block ); _continue_NLR_entry = generate(masm, "continue_NLR", generate_continue_NLR ); _call_sync_DLL_entry = generate(masm, "call_sync_DLL", generate_call_sync_DLL ); _call_async_DLL_entry = generate(masm, "call_async_DLL", generate_call_async_DLL ); _lookup_sync_DLL_entry = generate(masm, "lookup_sync_DLL", generate_lookup_sync_DLL ); _lookup_async_DLL_entry = generate(masm, "lookup_async_DLL", generate_lookup_async_DLL ); _recompile_stub_entry = generate(masm, "recompile_stub", generate_recompile_stub ); _used_uncommon_trap_entry = generate(masm, "used_uncommon_trap", generate_uncommon_trap ); _unused_uncommon_trap_entry = generate(masm, "unused_uncommon_trap", generate_uncommon_trap ); _verify_context_chain_entry = generate(masm, "verify_context_chain", generate_verify_context_chain ); _deoptimize_block_entry = generate(masm, "deoptimize_block", generate_deoptimize_block ); _call_inspector_entry = generate(masm, "call_inspector", generate_call_inspector ); for (int pic_size = 1; pic_size <= PIC::max_nof_entries; pic_size++) { _PIC_stub_entries[pic_size] = generate(masm, "PIC stub", generate_PIC_stub, pic_size); } for (int size = 0; size <= max_fast_allocate_size; size++) { _allocate_entries[size] = generate(masm, "allocate", generate_allocate, size); } masm->finalize(); _is_initialized = true; if (!Disclaimer::is_product() && PrintStubRoutines) { std->print("%d bytes generated for stub routines\n", masm->offset()); exit(0); } };
CWindowMain::CWindowMain(QWidget *parent) : QMainWindow(parent), m_executThread(NULL) { m_widgetBFGenerate = new CWidgetBFGenerate(this); m_widgetBFList = new CWidgetBFList(this); m_widgetBFView = new CWidgetBFView(this); m_widgetConsol = new CWidgetConsol(this); m_widgetConsol->setVisible(false); m_widgetPanelMode = new CWidgetPanelMode(this); m_widgetTreeSat = new CWidgetTreeSat(this); QWidget *wBFViewBFGenerate = new QWidget(); QVBoxLayout *boxBFViewBFGenerate = new QVBoxLayout(); boxBFViewBFGenerate->addWidget(m_widgetBFGenerate); boxBFViewBFGenerate->addWidget(m_widgetBFView); boxBFViewBFGenerate->setMargin(0); boxBFViewBFGenerate->setSpacing(0); boxBFViewBFGenerate->setStretch(1,100); wBFViewBFGenerate->setLayout(boxBFViewBFGenerate); QSplitter *spListBFTreeAlg = new QSplitter(Qt::Vertical); spListBFTreeAlg->addWidget(m_widgetBFList); spListBFTreeAlg->addWidget(m_widgetTreeSat); QSplitter *spTreeView = new QSplitter(Qt::Horizontal); spTreeView->addWidget(spListBFTreeAlg); spTreeView->addWidget(wBFViewBFGenerate); spTreeView->setStretchFactor(1,100); QSplitter *spMain = new QSplitter(Qt::Vertical); spMain->addWidget(spTreeView); spMain->addWidget(m_widgetConsol); spMain->setStretchFactor(0,100); QWidget *widgetCenter = new QWidget(this); setCentralWidget(widgetCenter); QHBoxLayout *hbox = new QHBoxLayout(); centralWidget()->setLayout(hbox); hbox->addWidget(m_widgetPanelMode); hbox->addWidget(spMain); hbox->setMargin(0); hbox->setSpacing(0); hbox->setStretch(1,100); m_actOpen = new QAction(QIcon(":/ico/main_open.png"),tr("&Открыть"),this); m_actOpen->setShortcut(QKeySequence::Open); connect(m_actOpen,SIGNAL(triggered()),this,SLOT(on_open())); m_actSave = new QAction(QIcon(":/ico/main_save.png"),tr("&Сохранить"),this); m_actSave->setShortcut(QKeySequence::Save); connect(m_actSave,SIGNAL(triggered()),this,SLOT(on_save())); m_actSaveAs = new QAction(QIcon(":/ico/main_save_as.png"),tr("&Сохранить как"),this); m_actSaveAs->setShortcut(QKeySequence::SaveAs); connect(m_actSaveAs,SIGNAL(triggered()),this,SLOT(on_save_as())); m_actQuit = new QAction(QIcon("://ico/main_quit.png"),tr("Выйти"),this); m_actQuit->setShortcut(QKeySequence::Close); m_actQuit->setStatusTip(tr("Выйти из приложения")); connect(m_actQuit, SIGNAL(triggered()), this, SLOT(close())); mainMenu = menuBar()->addMenu(tr("Файл")); mainMenu->addAction(m_actOpen); mainMenu->addAction(m_actSave); mainMenu->addAction(m_actSaveAs); mainMenu->addSeparator(); mainMenu->addAction(m_actQuit); mainMenu = menuBar()->addMenu(tr("Вид")); mainMenu->addAction(m_widgetBFGenerate->actVisible()); mainMenu->addAction(m_widgetConsol->actVisible()); // m_widgetPanelMode connect(m_widgetPanelMode,SIGNAL(run()), m_widgetTreeSat,SLOT(on_runChecked())); connect(m_widgetPanelMode,SIGNAL(run()), m_widgetBFGenerate,SLOT(on_resetTriggered())); connect(m_widgetPanelMode,SIGNAL(runLog()), m_widgetTreeSat,SLOT(on_runLogChecked())); connect(m_widgetPanelMode,SIGNAL(runLog()), m_widgetBFGenerate,SLOT(on_resetTriggered())); connect(m_widgetPanelMode,SIGNAL(terminate()), this,SIGNAL(terminated())); connect(m_widgetPanelMode,SIGNAL(toggledRand(bool)), m_widgetBFList,SLOT(setVisible(bool))); connect(m_widgetPanelMode,SIGNAL(toggledRand(bool)), m_widgetBFList,SLOT(on_disabledHide(bool))); connect(m_widgetPanelMode,SIGNAL(toggledRand(bool)), m_widgetBFGenerate,SLOT(setVisible(bool))); connect(m_widgetPanelMode,SIGNAL(toggledRand(bool)), m_widgetBFGenerate->actVisible(),SLOT(setChecked(bool))); connect(m_widgetPanelMode,SIGNAL(toggledRand(bool)), m_widgetBFGenerate->actVisible(),SLOT(setEnabled(bool))); connect(m_widgetPanelMode,SIGNAL(toggledRand(bool)), m_widgetTreeSat,SLOT(setVisible(bool))); connect(m_widgetPanelMode,SIGNAL(toggledRand(bool)), m_widgetTreeSat,SLOT(on_disabledHide(bool))); // m_widgetBFView connect(m_widgetBFView,SIGNAL(message(QString)), this,SIGNAL(messageAppend(QString))); connect(m_widgetBFView,SIGNAL(getLogSelectSat(bool)), m_widgetTreeSat,SLOT(on_returnLogSelectSat(bool))); // m_widgetBFList connect(m_widgetBFList,SIGNAL(generate()), m_widgetBFGenerate,SLOT(on_generate())); connect(m_widgetBFList,SIGNAL(selected(QString,CBoolFormula*)), m_widgetBFGenerate,SLOT(on_set(QString,CBoolFormula*))); connect(m_widgetBFList,SIGNAL(selected(QString,CBoolFormula*)), m_widgetTreeSat,SLOT(on_set(QString,CBoolFormula*))); connect(m_widgetBFList,SIGNAL(selected(QString,CBoolFormula*)), m_widgetBFView,SLOT(on_set(QString,CBoolFormula*))); connect(m_widgetBFList,SIGNAL(message(QString)), this,SIGNAL(messageAppend(QString))); // m_widgetBFGenerate connect(m_widgetBFGenerate,SIGNAL(append(QString,CBoolFormula*)), m_widgetBFList,SIGNAL(appendgen(QString,CBoolFormula*))); connect(m_widgetBFGenerate,SIGNAL(append(QString,CBoolFormula*)), m_widgetPanelMode,SLOT(on_resetTriggered())); connect(m_widgetBFGenerate,SIGNAL(execut(QList<CExecutObject*>)), this,SLOT(on_execut(QList<CExecutObject*>))); connect(m_widgetBFGenerate,SIGNAL(replace(QString,CBoolFormula*)), m_widgetBFList,SIGNAL(replace(QString,CBoolFormula*))); connect(m_widgetBFGenerate,SIGNAL(replace(QString,CBoolFormula*)), m_widgetPanelMode,SLOT(on_resetTriggered())); connect(m_widgetBFGenerate,SIGNAL(remove(QString)), m_widgetBFList,SIGNAL(remove(QString))); connect(m_widgetBFGenerate,SIGNAL(terminated()), this,SIGNAL(terminated())); // m_widgetTreeSat connect(m_widgetTreeSat,SIGNAL(execut(QList<CExecutObject*>)), this,SLOT(on_execut(QList<CExecutObject*>))); connect(m_widgetTreeSat,SIGNAL(logSelectSat(QString)), m_widgetBFView,SIGNAL(setText(QString))); // main connect(this,SIGNAL(messageAppend(QString)), m_widgetConsol,SLOT(messageAppend(QString))); connect(this,SIGNAL(messageSet(QString)), m_widgetConsol,SLOT(messageSet(QString))); connect(this,SIGNAL(executingOperation(QString)), m_widgetConsol,SLOT(executingOperation(QString))); connect(this,SIGNAL(append(QString,CBoolFormula*)), m_widgetBFList,SIGNAL(append(QString,CBoolFormula*))); connect(this,SIGNAL(locked()),m_widgetPanelMode,SLOT(on_locked())); connect(this,SIGNAL(unlocked()),m_widgetPanelMode,SLOT(on_unlocked())); connect(this,SIGNAL(locked()),m_widgetBFGenerate,SLOT(on_locked())); connect(this,SIGNAL(unlocked()),m_widgetBFGenerate,SLOT(on_unlocked())); connect(this,SIGNAL(updateView()),m_widgetBFView,SLOT(on_viewUpdate())); m_widgetPanelMode->on_checkedRand(); // set checked Random bool formula state for start application }
void Qmonthly::setActions() { connect(selectButton, SIGNAL(clicked()), this, SLOT(load())); connect(generateButton, SIGNAL(clicked()), this, SLOT(generate())); }
void generate(OutputIterator first, OutputIterator last, Function op, command_queue &queue) { vector<T> tmp(std::distance(first, last), queue.get_context()); generate(tmp.begin(), tmp.end(), queue); transform(tmp.begin(), tmp.end(), first, op, queue); }
slatkin_result slatkin_mc(int maxreps, int r_obs[]) { slatkin_result results; double theta_estimate; int i, j, k, n, repno, Ecount, Fcount; int *r_random, *r_random_to_free; double E_obs, F_obs; double *ranvec; seedMT(time(NULL)); /* Find k and n from the observed configuration */ k = 0; n = 0; while (r_obs[k+1]) { k++; n+=r_obs[k]; } /* memory management notes - the following are dynamically allocated and need to be freed: Slatkin allocates these in the ivector, vector, and matrix methods, BUT does not pass back the raw pointer to the allocated region or "head." Instead, he passes back the spot where he wants the calling code to write data (in the case of the vector call especially). So...we have to readjust the pointers *back* in order to free them...wacky, but true. r_random -- what's being returned is head + 1, so free r_random - 1 ranvec -- just free this pointer b -- have to walk K+1 rows, free each of the rows, then free b */ r_random = ivector(0, k+1); r_random_to_free = r_random - 1; r_random[0] = r_random[k+1] = 0; ranvec = vector(1, k-1); // to avoid doing this in each replicate /* fill b matrix */ //double **b = matrix(1, k, 1, n); double **b = create2DDoubleArray(k+1, n+1); for (j=1; j<=n; j++) b[1][j] = 1.0 / j; for (i=2; i<=k; i++) { b[i][i] = 1.0; for (j=i; j<n; j++) b[i][j+1] = (i * b[i-1][j] + j * b[i][j]) / (j + 1.0); } F_obs = F(k, n, r_obs); E_obs = ewens_stat(r_obs); /*printf("\nn = %d, k = %d, theta = %g, F = %g, maxrep = %d\n", n, k, theta_est(k, n), F_obs, maxrep);*/ Ecount = 0; Fcount = 0; for (repno=1; repno<=maxreps; repno++) { generate(k, n, r_random, ranvec, b); if (ewens_stat(r_random) <= E_obs) Ecount++; if (F(k, n, r_random) <= F_obs) Fcount++; } theta_estimate = theta_est(k, n); results.probability = (double) Ecount / (double) maxreps; results.theta_estimate = theta_estimate; /* free the dynamically allocated memory - the matrix b is still problematic */ free(ranvec); free(r_random_to_free); /* the allocations occur in the matrix() function, starting on line 207 The matrix first allocates a number of rows (k) as pointers to doubles. then it allocates all the columns (n) as pointers to doubles. So to unwind this, we need to walk the matrix and free each row of doubles, and then we can free the original list of double* pointers to the rows themselves. right? */ for(i=0; i < k+1; i++) { free(b[i]); } free(b); return results; }
void generate_ADD(quad *q) { generate(add_v, q); }
void AstBegin::dump(ostream& str) { this->AstNode::dump(str); if (unnamed()) str<<" [UNNAMED]"; if (generate()) str<<" [GEN]"; if (genforp()) str<<" [GENFOR]"; }
void generate_MUL(quad *q) { generate(mul_v, q); }
void CloudsVisualSystemMemory::selfKeyPressed(ofKeyEventArgs & args){ generate(); }
void generate_MOD(quad *q) { generate(mod_v, q); }
void CloudsVisualSystemMemory::selfBegin() { ofAddListener(GetCloudsAudioEvents()->diageticAudioRequested, this, &CloudsVisualSystemMemory::audioRequested); generate(); }
void generate_TABLESETELEM(quad *q) { generate(tablesetelem_v, q); }
void CloudsVisualSystemMemory::guiRenderEvent(ofxUIEventArgs &e) { generate(); }
result_type operator()(Engine& eng) { return generate(eng, _min, _max, _range); }
bool Texture::load(std::string strFn) { setId(strFn); //Create texture // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.width, img.height, 0, img.format, GL_UNSIGNED_BYTE, img.data); #ifdef ARCH_PSP const char *filename = strFn.c_str(); int filenameLength=strlen(filename); if( strncmp((filename+filenameLength-3), "TGA", 3)==0 || strncmp((filename+filenameLength-3), "tga", 3)==0) { Logger::log("[Texture:%s] Loading....",strFn.c_str()); if( !psp_texture.LoadTGA((char *)strFn.c_str()) ) { Logger::log(LOG_ERROR,"failed!\n"); //sceKernelExitGame(); return false; } else { Logger::log("ok."); return true; } psp_texture.Swizzle(); Logger::log("\n"); } #else bool isJpgTexture = false; if( strncmp((strFn.c_str()+strFn.length()-3), "JPG", 3)==0 || strncmp((strFn.c_str()+strFn.length()-3), "jpg", 3)==0) isJpgTexture = true; bool imgLoaded = false; #ifdef ARCH_DC const char *filename = strFn.c_str(); int filenameLength=strlen(filename); if( strncmp((filename+filenameLength-3), "PCX", 3)==0 || strncmp((filename+filenameLength-3), "pcx", 3)==0) { Logger::log("Loading PCX using dreamcast loader"); generate(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_FILTER, GL_FILTER_BILINEAR); loadtxr(filename, &glTexId); return true; } else if( strncmp((filename+filenameLength-3), "PVR", 3)==0 || strncmp((filename+filenameLength-3), "pvr", 3)==0) { Logger::log("Loading PVR using dreamcast loader\n"); generate(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_FILTER, GL_FILTER_BILINEAR); loadpvr(filename, &glTexId); return true; } #endif imgLoaded = img.Load((char *)strFn.c_str()); if (imgLoaded) { generate(); glEnable(GL_TEXTURE_2D); #ifdef OPENGL_ES glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); #endif #ifdef ARCH_DC glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); #endif #if !defined(ARCH_DC) && !defined(OPENGL_ES) && !defined(ARCH_PSP) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); #endif #ifndef ARCH_DC if(isJpgTexture) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); #endif format = img.format; alpha = (format==GL_RGBA)?true:false; glTexImage2D(GL_TEXTURE_2D, 0, img.format, img.width, img.height, 0, img.format, GL_UNSIGNED_BYTE, img.data); #ifndef ARCH_DC if(isJpgTexture) glPixelStorei(GL_UNPACK_ALIGNMENT, 4); #endif return true; } else { return false; } #endif // char c = toupper(strFn[strFn.length()-3]); // // if (c == 'T') // { // load(strFn,FORMAT_TGA); // } // else // if (c == 'P') // { // load(strFn,FORMAT_PNG); // } }