void MyPrintout::LayoutColumns() { m_pageRect = GetLogicalPageMarginsRect(*g_pageSetupData); // A full column m_columnWidth = m_pageRect.width - (m_gridRect.width - GRID_PADDING) - COLUMN_PADDING; // Unscale the DC for measuring. wxDC * dc = GetDC(); SaveUserScale(); // Measure the width of the largest clue number const int max_clue_number = std::max(m_puz->m_across.back().Number(), m_puz->m_down .back().Number()); dc->SetFont(m_numberFont); if (max_clue_number >= 100) dc->GetTextExtent(FormatNumber(999), &m_numberWidth, NULL); else dc->GetTextExtent(FormatNumber(99), &m_numberWidth, NULL); RestoreUserScale(); // The portion of the column that is taken up by clue text. m_clueWidth = m_columnWidth - (m_numberWidth + NUMBER_PADDING); }
void CmdThread::debuggerInfo(InfoVec &info) { Add(info, "Host", Process::GetHostName()); Add(info, "Binary", Process::GetAppName()); Add(info, "Version", HHVM_VERSION); Add(info, "Process ID", FormatNumber("%lld", Process::GetProcessId())); Add(info, "Thread ID", FormatNumber("0x%llx", (int64_t)Process::GetThreadId())); }
// Print a performance counter in a specific format void PrintPerfCounter(const char * counterDesc, const char * counterUnit, double counter, double elapsedTime, int size) { char printBuf[256]; double avgCounter = counter / elapsedTime; double rankAvgCounter = avgCounter / size; printf("%s: %s (total), ", counterDesc, FormatNumber(avgCounter, counterUnit, printBuf)); printf("%s (per process)\n", FormatNumber(rankAvgCounter, counterUnit, printBuf)); }
void FormatPoint(char* txt, const Point& p) { char x[16]; char y[16]; char z[16]; FormatNumber(x, p.x); FormatNumber(y, p.y); FormatNumber(z, p.z); sprintf(txt, "(%s, %s, %s)", x, y, z); }
void iDlg_CreatInfo::DoCompose(const iRect& clRect) { iRect rc(clRect); // title gTextComposer.TextOut(dlgfc_hdr, gApp.Surface(),rc.point(),gTextMgr[m_cGroup.Type()*3+TRID_CREATURE_PEASANT_F2], iRect(rc.x,rc.y,rc.w,15),AlignCenter); rc.y+=15; // icon BlitIcon(gApp.Surface(),PDGG_MINIMON+m_cGroup.Type(),iRect(rc.x,rc.y,rc.w,45)); rc.y+=45; // Perks if (CREAT_DESC[m_cGroup.Type()].perks != CPERK_NONE) rc.y+=15; // props iRect trc(rc.x,rc.y,90,12); iTextComposer::FontConfig fc(iTextComposer::FS_SMALL, RGB16(192,192,255)); gTextComposer.TextOut(fc, gApp.Surface(),trc.point(),iStringT(gTextMgr[TRID_SKILL_ATTACK])+_T(" :"),trc,AlignTopRight); trc.y+=10; gTextComposer.TextOut(fc, gApp.Surface(),trc.point(),iStringT(gTextMgr[TRID_SKILL_DEFENCE])+_T(" :"),trc,AlignTopRight); trc.y+=10; gTextComposer.TextOut(fc, gApp.Surface(),trc.point(),iStringT(gTextMgr[TRID_SKILL_SHOTS])+_T(" :"),trc,AlignTopRight); trc.y+=10; gTextComposer.TextOut(fc, gApp.Surface(),trc.point(),iStringT(gTextMgr[TRID_SKILL_DAMAGE])+_T(" :"),trc,AlignTopRight); trc.y+=10; gTextComposer.TextOut(fc, gApp.Surface(),trc.point(),iStringT(gTextMgr[TRID_SKILL_HEALTH])+_T(" :"),trc,AlignTopRight); trc.y+=10; gTextComposer.TextOut(fc, gApp.Surface(),trc.point(),iStringT(gTextMgr[TRID_SKILL_SPEED])+_T(" :"),trc,AlignTopRight); trc.y+=10; gTextComposer.TextOut(fc, gApp.Surface(),trc.point(),iStringT(gTextMgr[TRID_SKILL_MORALE])+_T(" :"),trc,AlignTopRight); trc.y+=10; gTextComposer.TextOut(fc, gApp.Surface(),trc.point(),iStringT(gTextMgr[TRID_SKILL_LUCK])+_T(" :"),trc,AlignTopRight); trc.y+=10; trc = iRect(rc.x+95,rc.y,rc.w-105,12); iTextComposer::FontConfig tfc(iTextComposer::FS_SMALL, RGB16(255,220,192)); iStringT tout; tout.Setf(_T("%d (%d)"),CREAT_DESC[m_cGroup.Type()].attack, CREAT_DESC[m_cGroup.Type()].attack+m_furtSkills.Value(FSK_ATTACK)); gTextComposer.TextOut(tfc, gApp.Surface(),trc.point(),tout,trc,AlignTopLeft); trc.y+=10; tout.Setf(_T("%d (%d)"),CREAT_DESC[m_cGroup.Type()].defence, CREAT_DESC[m_cGroup.Type()].defence+m_furtSkills.Value(FSK_DEFENCE)); gTextComposer.TextOut(tfc, gApp.Surface(),trc.point(),tout,trc,AlignTopLeft); trc.y+=10; if (CREAT_DESC[m_cGroup.Type()].shots) tout.Setf(_T("%d"),CREAT_DESC[m_cGroup.Type()].shots); else tout.Setf(_T("-")); gTextComposer.TextOut(tfc, gApp.Surface(),trc.point(),tout,trc,AlignTopLeft); trc.y+=10; tout.Setf(_T("%d - %d"),CREAT_DESC[m_cGroup.Type()].damage_min,CREAT_DESC[m_cGroup.Type()].damage_max); gTextComposer.TextOut(tfc, gApp.Surface(),trc.point(),tout,trc,AlignTopLeft); trc.y+=10; tout.Setf(_T("%d (%d)"),CREAT_DESC[m_cGroup.Type()].hits, CREAT_DESC[m_cGroup.Type()].hits+m_furtSkills.Value(FSK_HITS)); gTextComposer.TextOut(tfc, gApp.Surface(),trc.point(),tout,trc,AlignTopLeft); trc.y+=10; tout.Setf(_T("%d (%d)"),CREAT_DESC[m_cGroup.Type()].speed, CREAT_DESC[m_cGroup.Type()].speed+m_furtSkills.Value(FSK_SPEED)); gTextComposer.TextOut(tfc, gApp.Surface(),trc.point(),tout,trc,AlignTopLeft); trc.y+=10; sint32 morale = (CREAT_DESC[m_cGroup.Type()].perks&CPERK_UNDEAD)?0:(m_furtSkills.Value(FSK_MORALE)+m_moraleMod); gTextComposer.TextOut(tfc, gApp.Surface(),trc.point(),FormatNumber(morale,true),trc,AlignTopLeft); trc.y+=10; gTextComposer.TextOut(tfc, gApp.Surface(),trc.point(),FormatNumber(m_furtSkills.Value(FSK_LUCK),true),trc,AlignTopLeft); trc.y+=10; }
/** ** Draw reverse number with font at x,y clipped. ** ** @param x X screen position ** @param y Y screen position ** @param font Font number ** @param number Number to be displayed. ** ** @return The length of the printed text. */ int VideoDrawReverseNumberClip(int x, int y, CFont *font, int number) { char buf[sizeof(int) * 10 + 2]; FormatNumber(number, buf); return VideoDrawReverseTextClip(x, y, font, buf); }
/** ** Draw number with font at x,y unclipped. ** ** @param x X screen position ** @param y Y screen position ** @param font Font number ** @param number Number to be displayed. ** ** @return The length of the printed text. */ int VideoDrawNumber(int x, int y, CFont *font, int number) { char buf[sizeof(int) * 10 + 2]; FormatNumber(number, buf); return VideoDrawText(x, y, font, buf); }
void MyPrintout::DrawClue(const XPuzzle::Clue & clue, int * x, int * y) { // Draw clue text // Adjust x to account for the clue number width before drawing the clue // text. Return x to its previous position afterwards so that the clue // number ends up in the right place. wxDC * dc = GetDC(); *x += m_numberWidth + NUMBER_PADDING; dc->SetFont(m_clueFont); int height; DrawTextLine(WrapText(clue.Text(), m_clueWidth), x, y, NULL, &height); *x -= m_numberWidth + NUMBER_PADDING; if (m_isDrawing) { // Draw clue number dc->SetFont(m_numberFont); dc->DrawLabel(FormatNumber(clue.Number()), wxRect(*x, *y - height, m_numberWidth, dc->GetCharHeight()), wxALIGN_RIGHT); } }
void BCountry::FormatNumber(char* string, size_t maxSize, int32 value) { BString fullString; FormatNumber(&fullString, value); strncpy(string, fullString.String(), maxSize); }
static idSWFScriptVar FormatColumn( const columnDef_t * columnDef, int64 score ) { switch( columnDef->displayType ) { case STATS_COLUMN_DISPLAY_TIME_MILLISECONDS: return idSWFScriptVar( FormatTime( score ) ); case STATS_COLUMN_DISPLAY_CASH: return idSWFScriptVar( FormatCash( score ) ); default: return idSWFScriptVar( FormatNumber( score ) ); } }
wxString CSizeFormatBase::FormatUnit(COptionsBase* pOptions, const wxLongLong& size, CSizeFormatBase::_unit unit, int base /*=1024*/) { _format format = _format(pOptions->GetOptionVal(OPTION_SIZE_FORMAT)); if (base == 1000) format = si1000; else if (format != si1024) format = iec; return wxString::Format(_T("%s %s"), FormatNumber(pOptions, size), GetUnit(pOptions, unit, format)); }
void mysqlExtension::debuggerInfo(InfoVec &info) { auto count = MySQL::NumCachedConnections(); Add(info, "Persistent", FormatNumber("%" PRId64, count)); AddServerStats(info, "sql.conn" ); AddServerStats(info, "sql.reconn_new" ); AddServerStats(info, "sql.reconn_ok" ); AddServerStats(info, "sql.reconn_old" ); AddServerStats(info, "sql.query" ); }
std::wstring CSizeFormatBase::FormatUnit(COptionsBase* pOptions, int64_t size, CSizeFormatBase::_unit unit, int base) { _format format = _format(pOptions->GetOptionVal(OPTION_SIZE_FORMAT)); if (base == 1000) { format = si1000; } else if (format != si1024) { format = iec; } return FormatNumber(pOptions, size) + L" " + GetUnit(pOptions, unit, format); }
void Conference::OnJoin() { CListCtrl *list= (CListCtrl*)GetDlgItem(IDC_CONFLIST); POSITION pos = list->GetFirstSelectedItemPosition(); if (pos) { int i = list->GetNextSelectedItem(pos); //Call *pCall = (Call *) list->GetItemData(i); CString number = L"105"+list->GetItemText(i,0); microsipDlg->messagesDlg->AddTab(FormatNumber(number), L"Conference", TRUE, NULL, TRUE && accountSettings.singleMode); microsipDlg->messagesDlg->Call(0); } EndDialog(1); }
void FltDlg::UpdateObjective() { if (!objective_list || mission_type < 0 || !ship) return; Sim* sim = Sim::GetSim(); char txt[32]; for (int item = 0; item < objective_list->NumItems(); item++) { const char* obj_name = objective_list->GetItemText(item); Element* elem = sim->FindElement(obj_name); // if element has expired, remove it from the objective list if (!elem || !elem->IsActive() || elem->IsFinished()) { objective_list->RemoveItem(item); item--; } // otherwise, the element is still active, so update range/region else { Ship* s = elem->GetShip(1); double r = 0; bool con = false; if (s) { Point s_loc = s->Location() + s->GetRegion()->Location(); Point h_loc = ship->Location() + ship->GetRegion()->Location(); r = (s_loc - h_loc).length(); con = ship->FindContact(s) != 0; if (con) { FormatNumber(txt, r); } else { strcpy_s(txt, Game::GetText("FltDlg.Unknown").data()); r = 2e9; } } objective_list->SetItemText(item, 1, s->GetRegion()->Name()); objective_list->SetItemText(item, 2, txt); objective_list->SetItemData(item, 2, (DWORD) r); } } }
/** ** Returns the pixel width of text. ** ** @param text Text to calculate the width of. ** ** @return The width in pixels of the text. */ int CFont::Width(const int number) const { int width = 0; #if 0 bool isformat = false; #endif int utf8; size_t pos = 0; std::string text = FormatNumber(number); const int len = text.length(); DynamicLoad(); while (GetUTF8(text.c_str(), len, pos, utf8)) { width += this->CharWidth[utf8 - 32] + 1; } return width; }
/** ** Returns the pixel width of text. ** ** @param text Text to calculate the width of. ** ** @return The width in pixels of the text. */ int CFont::Width(const int number) const { int width = 0; #if 0 bool isformat = false; #endif int utf8; size_t pos = 0; char text[ sizeof(int) * 10 + 2]; const int len = FormatNumber(number, text); DynamicLoad(); while (GetUTF8(text, len, pos, utf8)) { #if 0 if (utf8 == '~') { //if (pos >= text.size()) { // bad formatted string if (pos >= size) { // bad formatted string break; } if (text[pos] == '<' || text[pos] == '>') { isformat = false; ++pos; continue; } if (text[pos] == '!') { ++pos; continue; } if (text[pos] != '~') { // ~~ -> ~ isformat = !isformat; continue; } } if (!isformat) { width += this->CharWidth[utf8 - 32] + 1; } #else width += this->CharWidth[utf8 - 32] + 1; #endif } return width; }
void DecimalFormatRenderer::RenderAll(std::ostream &reply, Context &ctx, const ROAnything &config) { StartTrace(DecimalFormatRenderer.RenderAll); TraceAny(config, "config"); String sString, sScale, sDecSeparator, sMaxLength; if (!ReadConfig( ctx, config, sString, sScale, sDecSeparator )) { return; } if (sString.Length()) { if (!FormatNumber( sString, sScale, sDecSeparator )) { return; } } Trace("string to return [" << sString << "]"); reply << sString; }
static void DumpFlowWorkerIP(FILE *fp, int ipv, uint64_t total) { char totalstr[256]; enum ProfileFlowWorkerId fwi; for (fwi = 0; fwi < PROFILE_FLOWWORKER_SIZE; fwi++) { struct ProfileProtoRecords *r = &packet_profile_flowworker_data[fwi]; for (int p = 0; p < 257; p++) { SCProfilePacketData *pd = ipv == 4 ? &r->records4[p] : &r->records6[p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-20s IPv%d %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n", ProfileFlowWorkerIdToString(fwi), ipv, p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } } }
void MsnPkgDlg::DrawNavPlan() { if (mission) { if (pkg_index < 0 || pkg_index >= mission->GetElements().size()) pkg_index = 0; MissionElement* element = mission->GetElements()[pkg_index]; if (nav_list && element) { nav_list->ClearItems(); Point loc = element->Location(); int i = 0; ListIter<Instruction> navpt = element->NavList(); while (++navpt) { char txt[256]; sprintf_s(txt, "%d", i + 1); nav_list->AddItem(txt); nav_list->SetItemText(i, 1, Instruction::ActionName(navpt->Action())); nav_list->SetItemText(i, 2, navpt->RegionName()); double dist = Point(loc - navpt->Location()).length(); FormatNumber(txt, dist); nav_list->SetItemText(i, 3, txt); sprintf_s(txt, "%d", navpt->Speed()); nav_list->SetItemText(i, 4, txt); loc = navpt->Location(); i++; } } } }
void IDebuggable::AddServerStats(InfoVec &out, const char *name, const char *statsName /* = NULL */) { if (statsName == NULL) statsName = name; Add(out, name, FormatNumber("%lld", ServerStats::Get(statsName))); }
void SCProfilingDumpPacketStats(void) { int i; FILE *fp; char totalstr[256]; uint64_t total; if (profiling_packets_enabled == 0) return; if (profiling_packets_output_to_file == 1) { fp = fopen(profiling_packets_file_name, profiling_packets_file_mode); if (fp == NULL) { SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", profiling_packets_file_name, strerror(errno)); return; } } else { fp = stdout; } fprintf(fp, "\n\nPacket profile dump:\n"); fprintf(fp, "\n%-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s\n", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot", "%%"); fprintf(fp, "%-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s\n", "------", "-----", "----------", "------------", "------------", "-----------", "-----------", "---"); total = 0; for (i = 0; i < 257; i++) { SCProfilePacketData *pd = &packet_profile_data4[i]; total += pd->tot; pd = &packet_profile_data6[i]; total += pd->tot; } for (i = 0; i < 257; i++) { SCProfilePacketData *pd = &packet_profile_data4[i]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, " IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %6.2f\n", i, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } for (i = 0; i < 257; i++) { SCProfilePacketData *pd = &packet_profile_data6[i]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, " IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %6.2f\n", i, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } fprintf(fp, "Note: Protocol 256 tracks pseudo/tunnel packets.\n"); fprintf(fp, "\nPer Thread module stats:\n"); fprintf(fp, "\n%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s", "Thread Module", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot", "%%"); #ifdef PROFILE_LOCKING fprintf(fp, " %-10s %-10s %-12s %-12s %-10s %-10s %-12s %-12s\n", "locks", "ticks", "cont.", "cont.avg", "slocks", "sticks", "scont.", "scont.avg"); #else fprintf(fp, "\n"); #endif fprintf(fp, "%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s", "------------------------", "------", "-----", "----------", "------------", "------------", "-----------", "-----------", "---"); #ifdef PROFILE_LOCKING fprintf(fp, " %-10s %-10s %-12s %-12s %-10s %-10s %-12s %-12s\n", "--------", "--------", "----------", "-----------", "--------", "--------", "------------", "-----------"); #else fprintf(fp, "\n"); #endif int m; total = 0; for (m = 0; m < TMM_SIZE; m++) { if (tmm_modules[m].flags & TM_FLAG_LOGAPI_TM) continue; int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p]; total += pd->tot; pd = &packet_profile_tmm_data6[m][p]; total += pd->tot; } } for (m = 0; m < TMM_SIZE; m++) { if (tmm_modules[m].flags & TM_FLAG_LOGAPI_TM) continue; int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-24s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %6.2f", TmModuleTmmIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); #ifdef PROFILE_LOCKING fprintf(fp, " %10.2f %12"PRIu64" %12"PRIu64" %10.2f %10.2f %12"PRIu64" %12"PRIu64" %10.2f\n", (float)pd->lock/pd->cnt, (uint64_t)pd->ticks/pd->cnt, pd->contention, (float)pd->contention/pd->cnt, (float)pd->slock/pd->cnt, (uint64_t)pd->sticks/pd->cnt, pd->scontention, (float)pd->scontention/pd->cnt); #else fprintf(fp, "\n"); #endif } } for (m = 0; m < TMM_SIZE; m++) { if (tmm_modules[m].flags & TM_FLAG_LOGAPI_TM) continue; int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_tmm_data6[m][p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-24s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %6.2f\n", TmModuleTmmIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } } DumpFlowWorker(fp); fprintf(fp, "\nPer App layer parser stats:\n"); fprintf(fp, "\n%-20s %-6s %-5s %-12s %-12s %-12s %-12s\n", "App Layer", "IP ver", "Proto", "cnt", "min", "max", "avg"); fprintf(fp, "%-20s %-6s %-5s %-12s %-12s %-12s %-12s\n", "--------------------", "------", "-----", "----------", "------------", "------------", "-----------"); total = 0; for (m = 0; m < ALPROTO_MAX; m++) { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_app_data4[m][p]; total += pd->tot; pd = &packet_profile_app_data6[m][p]; total += pd->tot; } } for (m = 0; m < ALPROTO_MAX; m++) { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_app_data4[m][p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-20s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n", AppProtoToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } } for (m = 0; m < ALPROTO_MAX; m++) { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_app_data6[m][p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-20s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n", AppProtoToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } } /* proto detect output */ { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_app_pd_data4[p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); fprintf(fp, "%-20s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s\n", "Proto detect", p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr); } for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_app_pd_data6[p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); fprintf(fp, "%-20s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s\n", "Proto detect", p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr); } } total = 0; for (m = 0; m < PROF_DETECT_SIZE; m++) { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_detect_data4[m][p]; total += pd->tot; pd = &packet_profile_detect_data6[m][p]; total += pd->tot; } } fprintf(fp, "\n%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s", "Log Thread Module", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot", "%%"); #ifdef PROFILE_LOCKING fprintf(fp, " %-10s %-10s %-12s %-12s %-10s %-10s %-12s %-12s\n", "locks", "ticks", "cont.", "cont.avg", "slocks", "sticks", "scont.", "scont.avg"); #else fprintf(fp, "\n"); #endif fprintf(fp, "%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s", "------------------------", "------", "-----", "----------", "------------", "------------", "-----------", "-----------", "---"); #ifdef PROFILE_LOCKING fprintf(fp, " %-10s %-10s %-12s %-12s %-10s %-10s %-12s %-12s\n", "--------", "--------", "----------", "-----------", "--------", "--------", "------------", "-----------"); #else fprintf(fp, "\n"); #endif total = 0; for (m = 0; m < TMM_SIZE; m++) { if (!(tmm_modules[m].flags & TM_FLAG_LOGAPI_TM)) continue; int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p]; total += pd->tot; pd = &packet_profile_tmm_data6[m][p]; total += pd->tot; } } for (m = 0; m < TMM_SIZE; m++) { if (!(tmm_modules[m].flags & TM_FLAG_LOGAPI_TM)) continue; int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-24s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %6.2f", TmModuleTmmIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); #ifdef PROFILE_LOCKING fprintf(fp, " %10.2f %12"PRIu64" %12"PRIu64" %10.2f %10.2f %12"PRIu64" %12"PRIu64" %10.2f\n", (float)pd->lock/pd->cnt, (uint64_t)pd->ticks/pd->cnt, pd->contention, (float)pd->contention/pd->cnt, (float)pd->slock/pd->cnt, (uint64_t)pd->sticks/pd->cnt, pd->scontention, (float)pd->scontention/pd->cnt); #else fprintf(fp, "\n"); #endif } } for (m = 0; m < TMM_SIZE; m++) { if (!(tmm_modules[m].flags & TM_FLAG_LOGAPI_TM)) continue; int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_tmm_data6[m][p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-24s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %6.2f\n", TmModuleTmmIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } } fprintf(fp, "\nLogger/output stats:\n"); total = 0; for (m = 0; m < LOGGER_SIZE; m++) { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_log_data4[m][p]; total += pd->tot; pd = &packet_profile_log_data6[m][p]; total += pd->tot; } } fprintf(fp, "\n%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s\n", "Logger", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot"); fprintf(fp, "%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s\n", "------------------------", "------", "-----", "----------", "------------", "------------", "-----------", "-----------"); for (m = 0; m < LOGGER_SIZE; m++) { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_log_data4[m][p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-24s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n", PacketProfileLoggertIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } } for (m = 0; m < LOGGER_SIZE; m++) { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_log_data6[m][p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-24s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n", PacketProfileLoggertIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } } fprintf(fp, "\nGeneral detection engine stats:\n"); total = 0; for (m = 0; m < PROF_DETECT_SIZE; m++) { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_detect_data4[m][p]; total += pd->tot; pd = &packet_profile_detect_data6[m][p]; total += pd->tot; } } fprintf(fp, "\n%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s\n", "Detection phase", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot"); fprintf(fp, "%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s\n", "------------------------", "------", "-----", "----------", "------------", "------------", "-----------", "-----------"); for (m = 0; m < PROF_DETECT_SIZE; m++) { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_detect_data4[m][p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-24s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n", PacketProfileDetectIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } } for (m = 0; m < PROF_DETECT_SIZE; m++) { int p; for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_detect_data6[m][p]; if (pd->cnt == 0) { continue; } FormatNumber(pd->tot, totalstr, sizeof(totalstr)); double percent = (long double)pd->tot / (long double)total * 100; fprintf(fp, "%-24s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n", PacketProfileDetectIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); } } fclose(fp); }
void TStatisticsDialog::SetupWindow () { TDialog::SetupWindow(); ::CenterWindow(this); SendDlgItemMsg(IDC_TH_NUM, WM_SETTEXT, 0, (LPARAM)FormatNumber(NumThings)); SendDlgItemMsg(IDC_VE_NUM, WM_SETTEXT, 0, (LPARAM)FormatNumber(NumVertexes)); SendDlgItemMsg(IDC_LD_NUM, WM_SETTEXT, 0, (LPARAM)FormatNumber(NumLineDefs)); SendDlgItemMsg(IDC_SD_NUM, WM_SETTEXT, 0, (LPARAM)FormatNumber(NumSideDefs)); SendDlgItemMsg(IDC_SE_NUM, WM_SETTEXT, 0, (LPARAM)FormatNumber(NumSectors)); SendDlgItemMsg(IDC_TH_SIZE, WM_SETTEXT, 0, (LPARAM)FormatNumber(((ULONG)NumThings * sizeof(Thing) + 512L) / 1024L)); SendDlgItemMsg(IDC_VE_SIZE, WM_SETTEXT, 0, (LPARAM)FormatNumber(((ULONG)NumVertexes * sizeof(Vertex) + 512L) / 1024L)); SendDlgItemMsg(IDC_LD_SIZE, WM_SETTEXT, 0, (LPARAM)FormatNumber(((ULONG)NumLineDefs * sizeof(LineDef) + 512L) / 1024L)); SendDlgItemMsg(IDC_SD_SIZE, WM_SETTEXT, 0, (LPARAM)FormatNumber(((ULONG)NumSideDefs * sizeof(SideDef) + 512L) / 1024L)); SendDlgItemMsg(IDC_SE_SIZE, WM_SETTEXT, 0, (LPARAM)FormatNumber(((ULONG)NumSectors * sizeof(Sector) + 512L) / 1024L)); SendDlgItemMsg(IDC_TH_BYTES, WM_SETTEXT, 0, (LPARAM)FormatNumber((ULONG)NumThings * sizeof(Thing))); SendDlgItemMsg(IDC_VE_BYTES, WM_SETTEXT, 0, (LPARAM)FormatNumber((ULONG)NumVertexes * sizeof(Vertex))); SendDlgItemMsg(IDC_LD_BYTES, WM_SETTEXT, 0, (LPARAM)FormatNumber((ULONG)NumLineDefs * sizeof(LineDef))); SendDlgItemMsg(IDC_SD_BYTES, WM_SETTEXT, 0, (LPARAM)FormatNumber((ULONG)NumSideDefs * sizeof(SideDef))); SendDlgItemMsg(IDC_SE_BYTES, WM_SETTEXT, 0, (LPARAM)FormatNumber((ULONG)NumSectors * sizeof(Sector))); }
string &InsertCommas(unsigned __int64 li,string &strDest) { strDest.Format(L"%I64u", li); return FormatNumber(strDest,strDest); }
void MsnPkgDlg::DrawThreats() { for (int i = 0; i < 5; i++) if (threat[i]) threat[i]->SetText(""); if (!mission) return; MissionElement* player = mission->GetPlayer(); if (!player) return; Text rgn0 = player->Region(); Text rgn1; int iff = player->GetIFF(); ListIter<Instruction> nav = player->NavList(); while (++nav) { if (rgn0 != nav->RegionName()) rgn1 = nav->RegionName(); } if (threat[0]) { Point base_loc = mission->GetElements()[0]->Location(); int i = 0; ListIter<MissionElement> iter = mission->GetElements(); while (++iter) { MissionElement* elem = iter.value(); if (elem->GetIFF() == 0 || elem->GetIFF() == iff || elem->IntelLevel() <= Intel::SECRET) continue; if (elem->IsSquadron()) continue; if (elem->IsGroundUnit()) { if (!elem->GetDesign() || elem->GetDesign()->type != Ship::SAM) continue; if (elem->Region() != rgn0 && elem->Region() != rgn1) continue; } int mission_role = elem->MissionRole(); if (mission_role == Mission::STRIKE || mission_role == Mission::INTEL || mission_role >= Mission::TRANSPORT) continue; char rng[32]; char role[32]; char txt[256]; if (mission_role == Mission::SWEEP || mission_role == Mission::INTERCEPT || mission_role == Mission::FLEET || mission_role == Mission::BOMBARDMENT) strcpy_s(role, Game::GetText("MsnDlg.ATTACK").data()); else strcpy_s(role, Game::GetText("MsnDlg.PATROL").data()); double dist = Point(base_loc - elem->Location()).length(); FormatNumber(rng, dist); sprintf_s(txt, "%s - %d %s - %s", role, elem->Count(), elem->GetDesign()->abrv, rng); if (threat[i]) threat[i]->SetText(txt); i++; if (i >= 5) break; } } }
string & WINAPI FileSizeToStr(string &strDestStr, unsigned __int64 Size, int Width, int ViewFlags) { string strStr; unsigned __int64 Divider; int IndexDiv, IndexB; // подготовительные мероприятия if (!UnitStr[0][0][0]) { PrepareUnitStr(); } int Commas=(ViewFlags & COLUMN_COMMAS); int FloatSize=(ViewFlags & COLUMN_FLOATSIZE); int Economic=(ViewFlags & COLUMN_ECONOMIC); int UseMinSizeIndex=(ViewFlags & COLUMN_MINSIZEINDEX); int MinSizeIndex=(ViewFlags & COLUMN_MINSIZEINDEX_MASK)+1; int ShowBytesIndex=(ViewFlags & COLUMN_SHOWBYTESINDEX); if (ViewFlags & COLUMN_THOUSAND) { Divider=1000; IndexDiv=0; } else { Divider=1024; IndexDiv=1; } unsigned __int64 Sz = Size, Divider2 = Divider/2, Divider64 = Divider, OldSize; if (FloatSize) { unsigned __int64 Divider64F = 1, Divider64F_mul = 1000, Divider64F2 = 1, Divider64F2_mul = Divider; //выравнивание идёт по 1000 но само деление происходит на Divider //например 999 bytes покажутся как 999 а вот 1000 bytes уже покажутся как 0.97 K for (IndexB=0; IndexB<UNIT_COUNT-1; IndexB++) { if (Sz < Divider64F*Divider64F_mul) break; Divider64F = Divider64F*Divider64F_mul; Divider64F2 = Divider64F2*Divider64F2_mul; } if (!IndexB) strStr.Format(L"%d", (DWORD)Sz); else { Sz = (OldSize=Sz) / Divider64F2; OldSize = (OldSize % Divider64F2) / (Divider64F2 / Divider64F2_mul); DWORD Decimal = (DWORD)(0.5+(double)(DWORD)OldSize/(double)Divider*100.0); if (Decimal >= 100) { Decimal -= 100; Sz++; } strStr.Format(L"%d.%02d", (DWORD)Sz,Decimal); FormatNumber(strStr,strStr,2); } if (IndexB>0 || ShowBytesIndex) { Width-=(Economic?1:2); if (Width<0) Width=0; if (Economic) strDestStr.Format(L"%*.*s%1.1s",Width,Width,strStr.CPtr(),UnitStr[IndexB][IndexDiv]); else strDestStr.Format(L"%*.*s %1.1s",Width,Width,strStr.CPtr(),UnitStr[IndexB][IndexDiv]); } else strDestStr.Format(L"%*.*s",Width,Width,strStr.CPtr()); return strDestStr; } if (Commas) InsertCommas(Sz,strStr); else strStr.Format(L"%I64u", Sz); if ((!UseMinSizeIndex && strStr.GetLength()<=static_cast<size_t>(Width)) || Width<5) { if (ShowBytesIndex) { Width-=(Economic?1:2); if (Width<0) Width=0; if (Economic) strDestStr.Format(L"%*.*s%1.1s",Width,Width,strStr.CPtr(),UnitStr[0][IndexDiv]); else strDestStr.Format(L"%*.*s %1.1s",Width,Width,strStr.CPtr(),UnitStr[0][IndexDiv]); } else strDestStr.Format(L"%*.*s",Width,Width,strStr.CPtr()); } else { Width-=(Economic?1:2); IndexB=0; do { //Sz=(Sz+Divider2)/Divider64; Sz = (OldSize=Sz) / Divider64; if ((OldSize % Divider64) > Divider2) ++Sz; IndexB++; if (Commas) InsertCommas(Sz,strStr); else strStr.Format(L"%I64u",Sz); } while ((UseMinSizeIndex && IndexB<MinSizeIndex) || strStr.GetLength() > static_cast<size_t>(Width)); if (Economic) strDestStr.Format(L"%*.*s%1.1s",Width,Width,strStr.CPtr(),UnitStr[IndexB][IndexDiv]); else strDestStr.Format(L"%*.*s %1.1s",Width,Width,strStr.CPtr(),UnitStr[IndexB][IndexDiv]); } return strDestStr; }
int CLabel::Draw(int x, int y, int number) const { std::string str = FormatNumber(number); return DoDrawText<false>(x, y, str.c_str(), str.length(), normal); }
//--------------------------------------------------------------------------- void __fastcall TSynchronizeChecklistDialog::StatusBarDrawPanel( TStatusBar * StatusBar, TStatusPanel * Panel, const TRect & Rect) { bool Possible; TSynchronizeChecklist::TAction Action = TSynchronizeChecklist::TAction(Panel->Index); switch (Action) { case TSynchronizeChecklist::saNone: Possible = true; break; case TSynchronizeChecklist::saUploadNew: Possible = ((FMode == smRemote) || (FMode == smBoth)) && FLAGCLEAR(FParams, spTimestamp); break; case TSynchronizeChecklist::saDownloadNew: Possible = ((FMode == smLocal) || (FMode == smBoth)) && FLAGCLEAR(FParams, spTimestamp); break; case TSynchronizeChecklist::saUploadUpdate: Possible = ((FMode == smRemote) || (FMode == smBoth)) && (FLAGCLEAR(FParams, spNotByTime) || FLAGSET(FParams, spBySize)); break; case TSynchronizeChecklist::saDownloadUpdate: Possible = ((FMode == smLocal) || (FMode == smBoth)) && (FLAGCLEAR(FParams, spNotByTime) || FLAGSET(FParams, spBySize)); break; case TSynchronizeChecklist::saDeleteRemote: Possible = (FMode == smRemote) && FLAGCLEAR(FParams, spTimestamp); break; case TSynchronizeChecklist::saDeleteLocal: Possible = (FMode == smLocal) && FLAGCLEAR(FParams, spTimestamp); break; default: assert(false); Possible = false; break; } int ImageIndex = Panel->Index; UnicodeString PanelText; if (Possible) { PanelText = FORMAT(LoadStrPart(SYNCHRONIZE_SELECTED_ACTIONS, 1), (FormatNumber(FChecked[Panel->Index]), FormatNumber(FTotals[Panel->Index]))); } else { PanelText = LoadStrPart(SYNCHRONIZE_SELECTED_ACTIONS, 2); } int TextHeight = StatusBar->Canvas->TextHeight(PanelText); int X = Rect.Left + ActionImages->Width + 4; int Y = (Rect.Top + Rect.Bottom - TextHeight) / 2; StatusBar->Canvas->TextRect(Rect, X, Y, PanelText); X = Rect.Left + 1; Y = ((Rect.Top + Rect.Bottom - ActionImages->Height) / 2); ActionImages->Draw(StatusBar->Canvas, X, Y, ImageIndex, Possible); }
std::wstring CSizeFormatBase::Format(COptionsBase* pOptions, int64_t size, bool add_bytes_suffix, CSizeFormatBase::_format format, bool thousands_separator, int num_decimal_places) { assert(format != formats_count); assert(size >= 0); if (size < 0) { size = 0; } if (format == bytes) { std::wstring result = FormatNumber(pOptions, size, &thousands_separator); if (!add_bytes_suffix) { return result; } else { return fz::sprintf(fztranslate("%s byte", "%s bytes", size), result); } } std::wstring places; int divider; if (format == si1000) { divider = 1000; } else { divider = 1024; } // Exponent (2^(10p) or 10^(3p) depending on option int p = 0; int64_t r = size; int remainder = 0; bool clipped = false; while (r > divider && p < 6) { int64_t const rr = r / divider; if (remainder != 0) { clipped = true; } remainder = static_cast<int>(r - rr * divider); r = rr; ++p; } if (!num_decimal_places) { if (remainder != 0 || clipped) { ++r; } } else if (p) { // Don't add decimal places on exact bytes if (format != si1000) { // Binary, need to convert 1024 into range from 1-1000 if (clipped) { ++remainder; clipped = false; } remainder = (int)ceil((double)remainder * 1000 / 1024); } int max; switch (num_decimal_places) { default: num_decimal_places = 1; // Fall-through case 1: max = 9; divider = 100; break; case 2: max = 99; divider = 10; break; case 3: max = 999; break; } if (num_decimal_places != 3) { if (remainder % divider) { clipped = true; } remainder /= divider; } if (clipped) { remainder++; } if (remainder > max) { r++; remainder = 0; } wchar_t fmt[] = L"%00d"; fmt[2] = '0' + num_decimal_places; places = fz::sprintf(fmt, remainder); } std::wstring result = ToString(r, 0, 0); if (!places.empty()) { std::wstring const& sep = GetRadixSeparator(); result += sep; result += places; } result += ' '; static wchar_t byte_unit = 0; if (!byte_unit) { std::wstring t = _("B <Unit symbol for bytes. Only translate first letter>"); // @translator: Only translate first letter. byte_unit = t[0]; } if (!p) { return result + byte_unit; } result += prefix[p]; if (format == iec) { result += 'i'; } result += byte_unit; return result; }
int CLabel::DrawReverseClip(int x, int y, int number) const { std::string str = FormatNumber(number); return DoDrawText<true>(x, y, str.c_str(), str.length(), reverse); }