std::string pretty(Move m, Piece movedPieceType) { if (is_drop(m)) return (pretty(move_to(m)) + pretty2(movedPieceType) + (pretty_jp ? "打" : "*")); else return pretty(move_to(m)) + pretty2(movedPieceType) + (is_promote(m) ? (pretty_jp ? "成" : "+") : "") + "["+ pretty(move_from(m))+"]"; }
void database_fixture::print_call_orders()const { cout << std::fixed; cout.precision(5); cout << std::setw(10) << std::left << "NAME" << " "; cout << std::setw(10) << std::right << "TYPE" << " "; cout << std::setw(16) << std::right << "DEBT" << " "; cout << std::setw(16) << std::right << "COLLAT" << " "; cout << std::setw(16) << std::right << "CALL PRICE(D/C)" << " "; cout << std::setw(16) << std::right << "~CALL PRICE(C/D)" << " "; cout << std::setw(16) << std::right << "SWAN(D/C)" << " "; cout << std::setw(16) << std::right << "SWAN(C/D)" << "\n"; cout << string(70, '='); for( const call_order_object& o : db.get_index_type<call_order_index>().indices() ) { std::cout << "\n"; cout << std::setw( 10 ) << std::left << o.borrower(db).name << " "; cout << std::setw( 16 ) << std::right << pretty( o.get_debt() ) << " "; cout << std::setw( 16 ) << std::right << pretty( o.get_collateral() ) << " "; cout << std::setw( 16 ) << std::right << o.call_price.to_real() << " "; cout << std::setw( 16 ) << std::right << (~o.call_price).to_real() << " "; cout << std::setw( 16 ) << std::right << (o.get_debt()/o.get_collateral()).to_real() << " "; cout << std::setw( 16 ) << std::right << (~(o.get_debt()/o.get_collateral())).to_real() << " "; } std::cout << "\n"; }
void graphlab ( double dmin , // Minimum data value double dmax , // and maximum int nticks , // Approximate (!) number of ticks to use double *gmin , // Minimum value actually plotted double *gmax , // (And max) for a 'nice' plot range double *dif , // Increment between ticks int *ntot , // Total digits for labels (includes dec pt & sign) int *nfrac // Number of fractional digits to show ) { double range, big ; range = pretty ( dmax - dmin , 0 ) ; *dif = pretty ( range / (nticks-1) , 1 ) ; *gmax = ceil ( dmax / *dif ) * *dif ; *gmin = floor ( dmin / *dif ) * *dif ; *nfrac = -floor ( log10 (*dif) ) ; if (*nfrac < 0) *nfrac = 0 ; *ntot = *nfrac + 2 ; /* Leading digit + decimal point */ if (*gmin < 0.) ++*ntot ; /* Minus sign */ big = abs (*gmin) ; if (big < abs (*gmax) ) big = abs (*gmax) ; if (big >= 10.) *ntot += floor ( log10 ( big ) ) ; /* Extra digits */ }
void dump() const { QTextStream outs(stderr, QIODevice::WriteOnly); QList<Line> lines; foreach (const char *func, counters.keys()) { const Counters &fCount = counters[func]; for (int i = 0, ei = fCount.size(); i != ei; ++i) { quint64 count = fCount[i]; if (!count) continue; Line line; line.func = func; unmangle(i, line.tag1, line.tag2); line.count = count; lines.append(line); } } qSort(lines.begin(), lines.end(), Line::less); outs << lines.size() << " counters:" << endl; foreach (const Line &line, lines) outs << qSetFieldWidth(10) << line.count << qSetFieldWidth(0) << " | " << line.func << " | " << pretty(line.tag1) << " | " << pretty(line.tag2) << endl; }
std::string pretty(Move m) { if (is_drop(m)) return (pretty(move_to(m)) + pretty2(Piece(move_from(m))) + (pretty_jp ? "打" : "*")); else return pretty(move_from(m)) + pretty(move_to(m)) + (is_promote(m) ? (pretty_jp ? "成" : "+") : ""); }
void database_fixture::print_limit_order( const limit_order_object& cur )const { std::cout << std::setw(10) << cur.seller(db).name << " "; std::cout << std::setw(10) << "LIMIT" << " "; std::cout << std::setw(16) << pretty( cur.amount_for_sale() ) << " "; std::cout << std::setw(16) << pretty( cur.amount_to_receive() ) << " "; std::cout << std::setw(16) << cur.sell_price.to_real() << " "; }
void pretty(rbtree* root) { if (root == NULL) return; pretty(root->left); int h=height(root); int i; for(i=1;i<h;i++) printf("\t"); if(root->color==RED) printf("[%d, R] \n", root->T); else printf("[%d, B] \n", root->T); pretty(root->right); }
std::string pretty(const message::transaction& tx) { std::ostringstream ss; ss << "Transaction:\n" << "\tversion = " << tx.version << "\n" << "\tlocktime = " << tx.locktime << "\n" << "Inputs:\n"; for (message::transaction_input input: tx.inputs) ss << pretty(input); ss << "Outputs:\n"; for (message::transaction_output output: tx.outputs) ss << pretty(output); ss << "\n"; return ss.str(); }
void msig::operator()(Env& env, JTx& jt) const { auto const mySigners = signers; jt.signer = [mySigners, &env](Env&, JTx& jt) { jt[sfSigningPubKey.getJsonName()] = ""; boost::optional<STObject> st; try { st = parse(jt.jv); } catch(parse_error const&) { env.test.log << pretty(jt.jv) << std::endl; Rethrow(); } auto& js = jt[sfSigners.getJsonName()]; js.resize(mySigners.size()); for(std::size_t i = 0; i < mySigners.size(); ++i) { auto const& e = mySigners[i]; auto& jo = js[i][sfSigner.getJsonName()]; jo[jss::Account] = e.acct.human(); jo[jss::SigningPubKey] = strHex(e.sig.pk().slice()); Serializer ss {buildMultiSigningData (*st, e.acct.id())}; auto const sig = ripple::sign ( *publicKeyType(e.sig.pk().slice()), e.sig.sk(), ss.slice()); jo[sfTxnSignature.getJsonName()] = strHex(Slice{ sig.data(), sig.size() }); } }; }
void prettify(const char *in, char *out, int no_brackets) { const char *p; char c; while (*in != '\0') { c = *in++; p = pretty(c); if (p == NULL) { *out++ = c; } else { if (! no_brackets) { *out++ = '['; } else if (no_brackets == 1) { if (strcmp(p, "approx") == 0) { p = "~"; } else if (strcmp(p, "cmplx") == 0) { p = "c"; } } while (*p != '\0') { *out++ = *p++; } if (! no_brackets ) { *out++ = ']'; } } } *out = '\0'; }
void irept::remove_ref(dt *old_data) { if(old_data==NULL) return; assert(old_data->ref_count!=0); #ifdef IREP_DEBUG std::cout << "R: " << old_data << " " << old_data->ref_count << std::endl; #endif old_data->ref_count--; if(old_data->ref_count==0) { #ifdef IREP_DEBUG std::cout << "D: " << pretty() << std::endl; std::cout << "DELETING " << old_data->data << " " << old_data << std::endl; old_data->clear(); std::cout << "DEALLOCATING " << old_data << "\n"; #endif delete old_data; #ifdef IREP_DEBUG std::cout << "DONE\n"; #endif } }
int main() { auto a = relations::node::make("a"); auto b = relations::node::make("b"); auto c = relations::node::make("c"); auto d = relations::node::make("d"); auto e = relations::node::make("e"); auto f = relations::node::make("f"); auto g = relations::node::make("g"); auto h = relations::node::make("h"); auto i = relations::node::make("i"); a->add_enemy(b); b->add_enemy(c); b->add_enemy(d); c->add_enemy(b); c->add_enemy(d); c->add_enemy(e); e->add_enemy(f); f->add_enemy(g); f->add_enemy(h); h->add_enemy(i); auto friends = a->list_friends(); pretty(friends.begin(), friends.end(), 4, 10); return 0; }
void irept::dump(void) const { std::cout << pretty(0) << std::endl; return; }
void irept::remove_ref(dt *old_data) { if(old_data==&empty_d) return; #if 0 nonrecursive_destructor(old_data); #else assert(old_data->ref_count!=0); #ifdef IREP_DEBUG std::cout << "R: " << old_data << " " << old_data->ref_count << std::endl; #endif old_data->ref_count--; if(old_data->ref_count==0) { #ifdef IREP_DEBUG std::cout << "D: " << pretty() << std::endl; std::cout << "DELETING " << old_data->data << " " << old_data << std::endl; old_data->clear(); std::cout << "DEALLOCATING " << old_data << "\n"; #endif // may cause recursive call delete old_data; #ifdef IREP_DEBUG std::cout << "DONE\n"; #endif } #endif }
main (argc, argv) { AP_ptr ap_fp; int getach(); mmdf_init ("PARSE"); logptr -> ll_level = LLOGFTR; if (argc == 2) debug++; for (;;) { printf ("Parse: "); ap_fp = ap_fullparse (getach); if (ap_fp == (AP_ptr) NOTOK) { printf ("\nNOTOK: on %s\n", namtab[ap_llex]); } else if (ap_fp == (AP_ptr) DONE) { printf ("\nNOTOK: on %s\n", namtab[ap_llex]); } else if (ap_fp == OK) { printf ("\nOK?: on %s\n", namtab[ap_llex]); } else { printf ("\n\nAccept\n"); pretty (ap_fp); printf ("\n"); while (ap_sqdelete (ap_fp, (AP_ptr)0) != 0); ap_free (ap_fp); /* delete full string */ ap_fp = (AP_ptr) 0; continue; } break; } exit (0); }
int sign(int a[10],int j, int degree){ /* function to decide whether term needs a + or - before it */ for (int j=0;j<=degree;j++){ /*for loop to count up the polynomial with the power decreasing */ int result =0; int k=j; while(k>=0){ /*While loop to go through loop and sum the previous terms so decide if the term needs a + or minus before it */ result= a[k-1]+result; k--; } if(result!=0){ /*If the sum is not 0, original printing takes place, assuming coefficient is not 0, by calling the pretty function */ if(a[j]!=0){ pretty(a,j,degree);} } else { /* If sum is 0, then printing will take place with no + or -, assuming coefficient is not 0, by calling pretty2 function */ if(a[j]!=0){ pretty2(a,j,degree); } } } return 0; /* Returns 0 to the main function*/ }
std::ostream& operator<<(std::ostream& os, HandKind hk) { for (Piece pc = PAWN; pc < PIECE_HAND_NB; ++pc) if (hand_exists(hk, pc)) std::cout << pretty(pc); return os; }
void msig::operator()(Env const& env, JTx& jt) const { // VFALCO Inefficient pre-C++14 auto accounts = accounts_; std::sort(accounts.begin(), accounts.end(), [](Account const& lhs, Account const& rhs) { return lhs.id() < rhs.id(); }); jt.signer = [accounts, &env](Env&, JTx& jt) { jt["SigningPubKey"] = ""; boost::optional<STObject> st; try { st = parse(jt.jv); } catch(parse_error const&) { env.test.log << pretty(jt.jv); throw; } auto const signFor = parseBase58<AccountID>( jt.jv[jss::Account].asString()); if (! signFor) { env.test.log << "invalid AccountID: '" << jt.jv[jss::Account].asString() << "'"; throw parse_error("msig: bad Account"); } auto& jv = jt["MultiSigners"][0u]["SigningFor"]; jv[jss::Account] = jt[jss::Account]; auto& js = jv["SigningAccounts"]; js.resize(accounts.size()); for(std::size_t i = 0; i < accounts.size(); ++i) { auto const& e = accounts[i]; auto& jo = js[i]["SigningAccount"]; jo[jss::Account] = e.human(); jo[jss::SigningPubKey] = strHex(e.pk().slice()); Serializer ss; ss.add32 (HashPrefix::txMultiSign); st->addWithoutSigningFields(ss); ss.add160(*signFor); ss.add160(e.id()); auto const sig = ripple::sign( *publicKeyType(e.pk().slice()), e.sk(), ss.slice()); jo["MultiSignature"] = strHex(Slice{ sig.data(), sig.size() }); } }; }
// Associate the term t with the name n in the current scope. Expr* declare(Name* n, Expr* e) { Scope* s = current_scope(); if (s->count(n) != 0) { error(e->loc) << format("name '{}' already bound in this scope", pretty(n)); return nullptr; } s->insert({n, e}); return e; }
context(int id, const thread_binding &b) : m_id(id) , m_bind(b) , m_pfq(group_policy::undefined, opt::caplen, opt::slots) , m_read() , m_batch() , m_set() , m_flow() , m_filename() , m_file(nullptr) { if (m_bind.gid == -1) m_bind.gid = id; if (!opt::dumpfile.empty()) { auto fs = pfq::split(opt::dumpfile, "."); m_filename = fs.at(0) + ".pfq." + std::to_string(id) + (fs.size() > 1 ? ("." + fs.at(1)) : ".pcap"); } m_pfq.join_group(m_bind.gid, group_policy::shared); for(auto &d : m_bind.dev) { if (d.queue.empty()) { m_pfq.bind_group(m_bind.gid, d.name.c_str(), -1); std::cout << "+ bind to " << d.name << "@" << -1 << std::endl; } else for(auto q : d.queue) { std::cout << "+ bind to " << d.name << "@" << q << std::endl; m_pfq.bind_group(m_bind.gid, d.name.c_str(), q); } } if (opt::use_comp) { std::cout << "computation: " << pretty (opt::comp) << std::endl; m_pfq.set_group_computation(m_bind.gid, opt::comp); } if (!opt::function.empty() && (m_id == 0)) { std::cout << "function: " << opt::function << std::endl; m_pfq.set_group_computation(m_bind.gid, opt::function); } m_pfq.timestamping_enable(false); m_pfq.enable(); }
void msig2_t::operator()(Env const& env, JTx& jt) const { // VFALCO Inefficient pre-C++14 auto const sigs = sigs_; jt.signer = [sigs, &env](Env&, JTx& jt) { jt["SigningPubKey"] = ""; boost::optional<STObject> st; try { st = parse(jt.jv); } catch(parse_error const&) { env.test.log << pretty(jt.jv); throw; } auto& ja = jt["MultiSigners"]; ja.resize(sigs.size()); for (auto i = std::make_pair(0, sigs.begin()); i.first < sigs.size(); ++i.first, ++i.second) { auto const& sign_for = i.second->first; auto const& list = i.second->second; auto& ji = ja[i.first]["SigningFor"]; ji[jss::Account] = sign_for.human(); auto& js = ji["SigningAccounts"]; js.resize(list.size()); for (auto j = std::make_pair(0, list.begin()); j.first < list.size(); ++j.first, ++j.second) { auto& jj = js[j.first]["SigningAccount"]; jj[jss::Account] = j.second->human(); jj[jss::SigningPubKey] = strHex( j.second->pk().slice()); Serializer ss; ss.add32 (HashPrefix::txMultiSign); st->addWithoutSigningFields(ss); ss.add160(sign_for.id()); ss.add160(j.second->id()); auto const sig = ripple::sign( *publicKeyType(j.second->pk().slice()), j.second->sk(), ss.slice()); jj["MultiSignature"] = strHex(Slice{ sig.data(), sig.size() }); } } }; }
// BonaPieceの内容を表示する。手駒ならH,盤上の駒なら升目。例) HP3 (3枚目の手駒の歩) std::ostream& operator<<(std::ostream& os, BonaPiece bp) { if (bp < fe_hand_end) { for (auto c : COLOR) for (Piece pc = PAWN; pc < KING; ++pc) { // この駒種の上限(e.g. 歩 = 18) int kind_num = kpp_hand_index[c][pc].fw - kpp_hand_index[c][pc].fb; int start = kpp_hand_index[c][pc].fb; if (start <= bp && bp < start+kind_num * 2) { bool is_black = bp < start + kind_num; if (!is_black) bp = (BonaPiece)(bp - kind_num); #ifdef PRETTY_JP os << "手" << (is_black ? "先" : "後") << pretty(pc) << int(bp - start + 1); // ex.手先歩3 #else os << "H" << (is_black ? "B" : "W") << pc << int(bp - kpp_hand_index[c][pc].fb + 1); // ex.HBP3 #endif break; } } } else { for (auto pc : Piece()) if (kpp_board_index[pc].fb <= bp && bp < kpp_board_index[pc].fb + SQ_NB) { #ifdef PRETTY_JP os << Square(bp - kpp_board_index[pc].fb) << pretty(pc); // ex.32P #else os << Square(bp - kpp_board_index[pc].fb) << pc; // ex.32P #endif break; } } return os; }
std::ostream& operator<<(std::ostream& os, Hand hand) { for (Piece pr = PAWN; pr < PIECE_HAND_NB; ++pr) { int c = hand_count(hand, pr); // 0枚ではないなら出力。 if (c != 0) { // 1枚なら枚数は出力しない。2枚以上なら枚数を最初に出力 // PRETTY_JPが指定されているときは、枚数は後ろに表示。 const std::string cs = (c != 1) ? std::to_string(c) : ""; std::cout << (pretty_jp ? "" : cs) << pretty(pr) << (pretty_jp ? cs : ""); } } return os; }
static void dump_code(unsigned int pc, unsigned int max, int annotate) { int dbl = 0, sngl = 0; printf("ADDR OPCODE MNEMONIC%s\n\n", annotate?"\t\tComment":""); do { char instr[16]; const opcode op = getprog(pc); const char *p = prt(op, instr); int i; if (isDBL(op)) { dbl++; printf("%04x: %04x %04x ", pc, op & 0xffff, (op >> 16)&0xffff); } else { sngl++; printf("%04x: %04x ", pc, op); } //printf("%04x: %04x ", pc, op); if (op == RARG(RARG_ALPHA, ' ')) strcpy(instr+2, "[space]"); while (*p != '\0') { char c = *p++; const char *q = pretty(c); if (q == NULL) putchar(c); else if (strcmp("narrow-space", q) == 0 && *p == c) { printf(" "); p++; } else printf("[%s]", q); } if (annotate) { extern const unsigned short int xrom_targets[]; for (i=0; i<num_xrom_entry_points; i++) if (addrXROM(xrom_entry_points[i].address) == pc) printf("\t\t\tXLBL %s", xrom_entry_points[i].name); for (i=0; i<num_xrom_labels; i++) if (xrom_labels[i].op == op) printf("\t\t\t%s", xrom_labels[i].name); if (RARG_CMD(op) == RARG_SKIP || RARG_CMD(op) == RARG_BSF) printf("\t\t-> %04x", pc + (op & 0xff) + 1); else if (RARG_CMD(op) == RARG_BACK || RARG_CMD(op) == RARG_BSB) printf("\t\t-> %04x", pc - (op & 0xff)); else if (RARG_CMD(op) == RARG_XEQ || RARG_CMD(op) == RARG_GTO) printf("\t\t\t-> %04x", addrXROM(0) + xrom_targets[op & RARG_MASK]); } putchar('\n'); pc = do_inc(pc, 0); } while (! PcWrapped);
int main() { std::string str; std::cout << "give me some templated type:\n"; // lines std::string line; bool empty = false; while (!empty) { getline(std::cin, line); str += line; empty |= line.empty(); } std::cout << "\n#####STARTING#####\n"; std::cout << pretty(str) << std::endl; std::cout << "\n#####FINISHED#####\n"; return 0; }
void prettify(const char *in, char *out) { const char *p; char c; while (*in != '\0') { c = *in++; p = pretty(c); if (p == NULL) *out++ = c; else { *out++ = '['; while (*p != '\0') *out++ = *p++; *out++ = ']'; } } *out = '\0'; }
void object::test<3>() { ensure("SRS UTM handle is NULL", NULL != srs_utm_); ensure("SRS LL handle is NULL", NULL != srs_ll_); err_ = OSRSetUTM(srs_utm_, 11, TRUE); ensure_equals("Can't set UTM zone", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_utm_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_ll_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); ct_ = OCTNewCoordinateTransformation(srs_ll_, srs_utm_); ensure("PROJ.4 missing, transforms not available", NULL != ct_); const char* wkt = "POINT(-117.5 32.0)"; OGRGeometryH geom = NULL; err_ = OGR_G_CreateFromWkt((char**) &wkt, NULL, &geom); ensure_equals("Can't import geometry from WKT", OGRERR_NONE, err_); ensure("Can't create geometry", NULL != geom); err_ = OGR_G_Transform(geom, ct_); ensure_equals("OGR_G_Transform() failed", err_, OGRERR_NONE); OGRSpatialReferenceH srs = NULL; srs = OGR_G_GetSpatialReference(geom); char* wktSrs = NULL; err_ = OSRExportToPrettyWkt(srs, &wktSrs, FALSE); ensure("Exported SRS to WKT is NULL", NULL != wktSrs); std::string pretty(wktSrs); ensure_equals("SRS output is incorrect", pretty.substr(0, 6), std::string("PROJCS")); OGRFree(wktSrs); OGR_G_DestroyGeometry(geom); }
static int dumpop(const opcode c, int pt) { char tracebuf[25]; const char *s, *m; if (c == RARG(RARG_ALPHA, 0)) return 0; xset(tracebuf, '\0', sizeof(tracebuf)); s = prt(c, tracebuf); if (strcmp(s, "???") != 0) { char t[100], *q = t; int l = 35; if (c == RARG(RARG_ALPHA, ' ')) strcpy(tracebuf+2, "[space]"); q += sprintf(t, "%04x ", (unsigned int)c); while (*s != '\0') { const unsigned char z = 0xff & *s++; m = pretty(z); if (m == NULL) { *q++ = z; l--; } else { l -= slen(m) + 2; q += sprintf(q, "[%s]", m); } } *q++ = '\0'; if (pt) { printf("%s", t); rarg_values(c, l); putchar('\n'); } return 1; } return 0; }
static void dump_menu(const char *name, const char *prefix, const enum catalogues cata) { int i; char cmd[16]; const char *p; const char *buf; const char *m; const int oldcata = State2.catalogue; int n; State2.catalogue = cata; n = current_catalogue_max(); printf("%s catalogue:\n", name); for (i=0; i<n; i++) { int l = 35 - slen(prefix); const opcode cati = current_catalogue(i); buf = catcmd(cati, cmd); if (cati == RARG(RARG_ALPHA, ' ')) strcpy(cmd+2, "[space]"); printf("\t%d\t%s", i+1, prefix); for (p=buf; *p != '\0'; p++) { const unsigned char c = 0xff & *p; m = pretty(c); if (m == NULL) { printf("%c", c); l--; } else { printf("[%s]", m); l -= slen(m) + 2; } } rarg_values(cati, l); printf("\n"); } printf("\n"); State2.catalogue = oldcata; }
void FilePrefsDriver::set(const Preferences& p) { _current = p.copy(); StringMap<Json> sound; sound["volume"] = Json::number(p.volume); sound["speech"] = Json::boolean(p.speech_on); sound["idle music"] = Json::boolean(p.play_idle_music); sound["game music"] = Json::boolean(p.play_music_in_game); StringMap<Json> keys; for (auto i : range<size_t>(KEY_COUNT)) { keys[kKeyNames[i]] = Json::number(p.keys[i]); } StringMap<Json> all; all["sound"] = Json::object(sound); all["keys"] = Json::object(keys); String path(format("{0}/config.json", dirs().root)); ScopedFd fd(open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644)); String pretty(pretty_print(Json::object(all))); write(fd, utf8::encode(pretty)); }