const String& DateField::MIN_DATE_STRING() { static String _MIN_DATE_STRING; if (_MIN_DATE_STRING.empty()) { _MIN_DATE_STRING = timeToString(0); } return _MIN_DATE_STRING; }
std::string MessageTimer::getProgressMessage(double progress, bool bIncludeElapsed, bool bIncludeRemaining) const { const double miliSecs = elapsed(); std::string result; if (bIncludeElapsed) { if (!result.empty()) result += " "; result += "Elapsed: " + timeToString(miliSecs); } if (bIncludeRemaining && progress > 0.0) { if (!result.empty()) result += " "; result += "Remaining: " + timeToString(miliSecs * (1.0-progress)/progress); } return result; }
char* getElapsedTime(Config* config, int status) { if (!config->mpd_status) { return strdup(""); } unsigned time = mpd_status_get_elapsed_time(config->mpd_status); return timeToString(config, time); }
void GameUi::update(float seconds) { clockLabel->SetText(timeToString(gameClock.getElapsedTime())); if (messageTimeout != Time::Zero && messageTimer.getElapsedTime() >= messageTimeout) { messageLabel->SetText(""); messageTimeout = Time::Zero; } if (stillSelected && selectionTimer.getElapsedTime() >= sf::seconds(4)) { unselectTile(selectedPoint); } }
void MainWindow::openMovie(const QString &fileName) { QString title = QFileInfo(fileName).fileName(); title = title.left(title.indexOf('.')); setWindowTitle(tr("%1 - %2").arg("Subtitles Editor").arg(title)); m_fileNameLabel->setText(title); m_timeLabel->setText(QString("00:00.0 / %1").arg(timeToString(m_mediaObject->totalTime()))); m_mediaObject->setCurrentSource(Phonon::MediaSource(fileName)); m_ui->actionPlayPause->setEnabled(true); }
void viewTransaction(Transaction* tx) { textArea text; if(tx->credit) { text.title = (char*)"Credit information"; } else { text.title = (char*)"Debit information"; } text.allowLeft = 1; textElement elem[15]; text.elements = elem; text.numelements = 0; //we will use this as element cursor elem[text.numelements].text = (char*)"Description:"; elem[text.numelements].color=COLOR_LIGHTGRAY; elem[text.numelements].spaceAtEnd=1; text.numelements++; elem[text.numelements].text = tx->description; text.numelements++; elem[text.numelements].text = (char*)"Date & time:"; elem[text.numelements].newLine = 1; elem[text.numelements].spaceAtEnd=1; elem[text.numelements].color=COLOR_LIGHTGRAY; text.numelements++; char date[50]; dateToString(date, tx->date.year, tx->date.month, tx->date.day); strcat(date, (char*)" "); // timeToString concatenates timeToString(date, tx->time.hour, tx->time.minute, tx->time.second); elem[text.numelements].text = date; text.numelements++; char amount[20]; currencyToString(amount, &tx->amount); elem[text.numelements].text = (char*)"Amount:"; elem[text.numelements].newLine = 1; elem[text.numelements].spaceAtEnd=1; elem[text.numelements].color=COLOR_LIGHTGRAY; text.numelements++; elem[text.numelements].text = amount; text.numelements++; doTextArea(&text); }
static void drawChallenges(void) { int i; Challenge *c; char *challengeStatus; SDL_Color color; int y = 215; drawText(SCREEN_WIDTH / 2, y, 24, TA_CENTER, colors.white, game.currentMission->description); if (battle.status == MS_START && game.currentMission->challengeData.timeLimit) { y+= 50; drawText(SCREEN_WIDTH / 2, y, 20, TA_CENTER, colors.white, TIME_LIMIT_TEXT, timeToString(game.currentMission->challengeData.timeLimit, 0)); } y += 25; for (i = 0 ; i < MAX_CHALLENGES ; i++) { c = game.currentMission->challengeData.challenges[i]; if (c) { y += 50; color = colors.white; challengeStatus = _("Incomplete"); if (c->passed) { color = colors.green; challengeStatus = _("Complete"); } else if (battle.status == MS_COMPLETE ||battle.status == MS_FAILED) { color = colors.red; challengeStatus = _("Failed"); } drawText(SCREEN_WIDTH / 2 - 50, y, 22, TA_RIGHT, colors.white, "%s", getChallengeDescription(c)); drawText(SCREEN_WIDTH / 2 + 50, y, 22, TA_LEFT, color, challengeStatus); } } }
QString ResultList::getItemString(ResultList::ColumnType type, QVariant* item) const { const QString resultTypeTexts[6] = { tr("OK"), tr("OT"), tr("MP"), tr("DNF"), tr("DISQ"), tr("DNS") }; switch (type) { case ColumnRank: if (item->isValid() && item->toInt() > 0) return item->toString(); else return "-"; case ColumnCategory: return reinterpret_cast<AbstractCategory*>(item->value<void*>())->name; case ColumnRunner: { Runner* runner = reinterpret_cast<Runner*>(item->value<void*>()); if (runner) return runner->getShortDesc(); else return ""; } case ColumnClub: { Club* club = reinterpret_cast<Club*>(item->value<void*>()); if (club) return club->getName(); else if (item->type() == QVariant::String) return item->toString(); else return tr("- no club -"); } case ColumnPoints: case ColumnPointInfo: return item->isValid() ? pointsToString(item->toInt(), decimal_places, decimal_factor) : "-"; case ColumnTime: return item->isValid() ? timeToString(item->toInt()) : ""; case ColumnResult: return resultTypeTexts[item->toInt()]; default: return item->toString(); } }
void load_events() { // initialize random number generator; it has to be done only once (after reset) srand(current_time()); events_count = eeprom_read_byte(&events_count_ee); // initialize - for testing purposes /* if (events_count == 0) { send_string("add_default\r\n"); add_default_events(); } */ if (events_count == 0) { send_line("No events => MANUAL_MODE"); event_mode = MANUAL_MODE; return; } // load events into ram eeprom_read_block(&events, &events_ee, sizeof(struct Event) * EVENTS_SIZE); // prepare prepare_actual_events(); // print events print_events(); // check current state of pins // if the device is power off, and later power on - it doesn't know what should be current state of pins int32_t time = current_time(); send_string(" start time: "); char formatted_date[30]; timeToString(time, formatted_date); send_string(formatted_date); send_enter(); current_state(); }
void FingerprinterProgressBar::reset() { ui.fingerprintProgressBar->setMaximum( 0 ); ui.fingerprintProgressBar->setValue( 0 ); ui.fingerprintProgressBar->reset(); pokeProgressBar(); m_timeElapsed = m_timeRemaining = m_timeOfFingerprintStart = m_etaCounter = 0; m_totalTracks = m_tracksFingerprinted = m_tracksSkipped = m_tracksWithErrors = 0; m_average = 0; m_running = m_paused = false; ui.infoLabel->setText( tr( "Idle" ) ); ui.trackLabel->setText( "" ); ui.timeLabel->setText( timeToString( 0 ) ); ui.etaLabel->setText( tr( "N/A" ) ); ui.averageLabel->setText( tr( "N/A" ) ); }
void showLength(void){ uint8_t curTime = EEReadByte(5+history.showLength); char lengthStr[4], timeStr[9]; itoa(history.showLength+1, lengthStr, 10); timeToString(curTime, timeStr); u8g_FirstPage(&u8g); u8g_SetDefaultForegroundColor(&u8g); do { u8g_DrawFrame(&u8g, 0, 0, 128, 64); u8g_DrawLine(&u8g, 64, 0, 64, 64); u8g_DrawStr(&u8g, (64 - u8g_GetStrWidth(&u8g, "Length"))/2, 5, "Length"); u8g_DrawStr(&u8g, (64 - u8g_GetStrWidth(&u8g, lengthStr))/2, 5+20, lengthStr); u8g_DrawStr(&u8g, 64+(64 - u8g_GetStrWidth(&u8g, "Time"))/2, 5, "Time"); u8g_DrawStr(&u8g, 64+(64 - u8g_GetStrWidth(&u8g, timeStr))/2, 5+20, timeStr); } while (u8g_NextPage(&u8g)); }
gboolean FullscreenVideoControllerGtk::updateHudProgressBar() { float mediaDuration(m_player->duration()); float mediaPosition(m_player->currentTime()); if (!m_seekLock) { gdouble value = 0.0; if (mediaPosition && mediaDuration) value = (mediaPosition * 100.0) / mediaDuration; GtkAdjustment* adjustment = gtk_range_get_adjustment(GTK_RANGE(m_timeHScale)); gtk_adjustment_set_value(adjustment, value); } gtk_range_set_fill_level(GTK_RANGE(m_timeHScale), (m_player->maxTimeLoaded() / mediaDuration)* 100); gchar* label = g_strdup_printf("%s / %s", timeToString(mediaPosition).utf8().data(), timeToString(mediaDuration).utf8().data()); gtk_label_set_text(GTK_LABEL(m_timeLabel), label); g_free(label); return TRUE; }
String CtrlrLog::formatMessage(const CtrlrLogMessage &m, const bool includeLevel, const bool includeTimestamp) { String ret; if (includeLevel) ret << levelToString (m.level); if (includeTimestamp) ret << timeToString (m.time); ret << ": "; if (m.message.endsWith("\n")) { ret << m.message.substring(1); } else { ret << m.message; } return (ret); }
void FingerprinterProgressBar::stop( bool finished ) { setRunning( false ); m_timer.stop(); if ( m_stopped ) { m_stopped = false; // If we had asked it to stop, just close the dialog onOkClicked(); ui.stopButton->setEnabled( true ); } else { ui.infoLabel->setText( tr( "Done. Thanks!" ) ); ui.trackLabel->setText( "" ); ui.etaLabel->setText( timeToString( 0 ) ); ui.okButton->setVisible( true ); ui.stopButton->setVisible( false ); } }
void MainWindow::stateChanged(Phonon::State state) { switch (state) { case Phonon::ErrorState: if (m_mediaObject->errorType() == Phonon::FatalError) { QMessageBox::warning(this, tr("Fatal Error"), m_mediaObject->errorString()); } else { QMessageBox::warning(this, tr("Error"), m_mediaObject->errorString()); } m_ui->actionPlayPause->setEnabled(false); case Phonon::StoppedState: m_ui->actionPlayPause->setText(tr("Play")); m_ui->actionPlayPause->setIcon(QIcon::fromTheme("media-playback-play", style()->standardIcon(QStyle::SP_MediaPlay))); m_ui->actionStop->setEnabled(false); m_timeLabel->setText(QString("00:00.0 / %1").arg(timeToString(m_mediaObject->totalTime()))); break; case Phonon::PlayingState: m_ui->actionPlayPause->setText(tr("Pause")); m_ui->actionPlayPause->setEnabled(true); m_ui->actionPlayPause->setIcon(QIcon::fromTheme("media-playback-pause", style()->standardIcon(QStyle::SP_MediaPause))); m_ui->actionStop->setEnabled(true); break; case Phonon::PausedState: m_ui->actionPlayPause->setText(tr("Play")); m_ui->actionPlayPause->setEnabled(true); m_ui->actionPlayPause->setIcon(QIcon::fromTheme("media-playback-play", style()->standardIcon(QStyle::SP_MediaPlay))); m_ui->actionStop->setEnabled(true); break; default: break; } }
void currentTimeToString(char *buffer, int format) { timeToString(buffer, getCurrentHour(), getCurrentMinute(), getCurrentSecond(), format, getSetting(SETTING_CLOCK_SECONDS)); }
QString AudioPlaybackBlock::getPositionString() { const double position = m_player.getPosition(); const double length = m_player.getLength(); const double positionSec = length * position; return timeToString(positionSec); }
QString AudioPlaybackBlock::getLengthString() const { const double length = m_player.getLength(); return timeToString(length); }
void TimeBehavior::onUpdate(Menu& menu, MenuItem& item) { item.value = frames ? timeToStringFrames(v) : timeToString(v); item.hasValue = true; }
void InvestigationScene::setupScene() { std::vector<Point> positions; positions.push_back(pointMake(32, 48)); positions.push_back(pointMake(34, 48)); positions.push_back(pointMake(36, 48)); positions.push_back(pointMake(38, 48)); positions.push_back(pointMake(40, 49)); positions.push_back(pointMake(40, 51)); positions.push_back(pointMake(40, 53)); positions.push_back(pointMake(30, 49)); positions.push_back(pointMake(30, 51)); positions.push_back(pointMake(32, 52)); const char *fontFile = "res/AveriaSerif-Regular.ttf"; font = al_load_font(fontFile, 18, 0); if (!font) { Director::getInstance()->abortWithMessage("%s not found or failed to load\n", fontFile); } fontBig = al_load_font(fontFile, 26, 0); if (!fontBig) { Director::getInstance()->abortWithMessage("%s not found or failed to load\n", fontFile); } searchSound = al_load_sample("res/search.wav"); if (!searchSound) { Director::getInstance()->abortWithMessage("%s not found or failed to load\n", "res/search.wav"); } clickSound = al_load_sample("res/click.wav"); if (!clickSound) { Director::getInstance()->abortWithMessage("%s not found or failed to load\n", "res/click.wav"); } std::vector<TilemapLayer *> layers = TilemapLayer::parseTMXFile("res/mansion.tmx"); std::vector<TilemapLayer *>::iterator it; TilemapLayer *firstLayer = layers[0]; camera = new Camera(800, 600, firstLayer->getBoundsSize().width, firstLayer->getBoundsSize().height); for (it = layers.begin(); it < layers.end(); ++it) { TilemapLayer *layer = (TilemapLayer *) *it; layer->setCamera(camera); addToDisplayList(layer); if (layer->isCollision()) { collision = layer; } } playerSprite = new Spritesheet("res/professor_walk_cycle_no_hat.png", 64, 64); playerSprite->setTag(PLAYER_SPRITE_TAG); playerSprite->setCamera(camera); playerSprite->setPosition(pointMake(35 * 32, 50 * 32)); playerSprite->setAnchorPoint(pointMake(0.5, 0.9)); playerSprite->setAutoZOrder(true); addToDisplayList(playerSprite); mysterySeed = 0; do { mysteryTime = 0; mysterySeed = time(0); mystery = new Mystery("res/mansion.xml", mysterySeed, collision->getData(), collision->getSize().width, collision->getSize().height); while (!mystery->ended && mysteryTime < MAX_MYSTERY_DURATION) { mystery->step(); mysteryTime++; } if (!mystery->ended) { delete mystery; mystery = NULL; } } while (mystery == NULL); printf("Case seed: %d Total duration: %ld %s\n", mysterySeed, mysteryTime, timeToString(mysteryTime, true).c_str()); std::vector<Character *> characters = mystery->getCharacters(); std::vector<Character *>::iterator itChars; int i = 0; for (itChars = characters.begin(); itChars < characters.end(); ++itChars) { Character *character = (Character *) *itChars; int frame = i * 2; if (!character->dead) { int idx = rand() % positions.size(); Point pos = positions[idx]; character->position = pos; positions.erase(positions.begin() + idx); } else { frame++; } Spritesheet *sprite = new Spritesheet("res/characters.png", 64, 64); sprite->setTag(character->tag); sprite->setCamera(camera); sprite->setAnchorPoint(pointMake(0.5, 0.9)); sprite->setAutoZOrder(true); sprite->setFrame(frame); Rect tileRect = collision->getTileRect(character->position.x, character->position.y); sprite->setPosition(rectMidPoint(tileRect)); addToDisplayList(sprite); i++; } std::vector<POI *>::iterator itWeapons; i = 0; for (itWeapons = mystery->weapons.begin(); itWeapons < mystery->weapons.end(); ++itWeapons) { POI *weapon = (POI *) *itWeapons; Spritesheet *sprite = new Spritesheet("res/weapons.png", 32, 32); sprite->setTag(i + 20); sprite->setFrame(i); sprite->setCamera(camera); sprite->setAnchorPoint(pointMake(0.5, 0.5)); sprite->setZOrder(400); Rect tileRect = collision->getTileRect(weapon->position.x, weapon->position.y); sprite->setPosition(rectMidPoint(tileRect)); addToDisplayList(sprite); i++; } actionButton = new Button("action", font, BTN_TXT_COLOR, "res/btn_action.png", "res/btn_action_pressed.png"); actionButton->setZOrder(500); actionButton->setAnchorPoint(pointMake(0.5, 1)); actionButton->setPosition(pointMake(400, 400)); actionButton->setCamera(camera); actionButton->setHandler(this); addToDisplayList(actionButton); Spritesheet *bkgRoomLabel = new Spritesheet("res/bkg_room_name.png"); bkgRoomLabel->setAnchorPoint(pointMake(0.5, 0.5)); bkgRoomLabel->setPosition(pointMake(400, 40)); bkgRoomLabel->setZOrder(501); addToDisplayList(bkgRoomLabel); currentRoomLabel = new Label("room", font, al_map_rgb(0, 0, 0)); currentRoomLabel->setAnchorPoint(pointMake(0.5, 0.5)); currentRoomLabel->setPosition(bkgRoomLabel->getPosition()); currentRoomLabel->setZOrder(502); addToDisplayList(currentRoomLabel); Spritesheet *bkgWeaponLabel = new Spritesheet("res/bkg_room_name.png"); bkgWeaponLabel->setAnchorPoint(pointMake(0.5, 0.5)); bkgWeaponLabel->setPosition(pointMake(720, 40)); bkgWeaponLabel->setZOrder(501); addToDisplayList(bkgWeaponLabel); crimeWeaponLabel = new Label("No weapon", font, al_map_rgb(0, 0, 0)); crimeWeaponLabel->setAnchorPoint(pointMake(0.5, 0.5)); crimeWeaponLabel->setPosition(bkgWeaponLabel->getPosition()); crimeWeaponLabel->setZOrder(502); addToDisplayList(crimeWeaponLabel); Spritesheet *bkgAccusationLabel = new Spritesheet("res/bkg_room_name.png"); bkgAccusationLabel->setAnchorPoint(pointMake(0.5, 0.5)); bkgAccusationLabel->setPosition(pointMake(80, 40)); bkgAccusationLabel->setZOrder(501); addToDisplayList(bkgAccusationLabel); char buf[100]; sprintf(buf, "%d accusations left", MAX_ACCUSATIONS); accusationsLabel = new Label(buf, font, al_map_rgb(0, 0, 0), 120); accusationsLabel->setAnchorPoint(pointMake(0.5, 0.5)); accusationsLabel->setPosition(bkgAccusationLabel->getPosition()); accusationsLabel->setZOrder(502); addToDisplayList(accusationsLabel); bkgQuestion = new Spritesheet("res/bkg_question.png"); bkgQuestion->setAnchorPoint(pointMake(0.5, 0.5)); bkgQuestion->setPosition(pointMake(400, 300)); bkgQuestion->setZOrder(503); bkgQuestion->setVisible(false); addToDisplayList(bkgQuestion); questionLabel = new Label("question", font, al_map_rgb(0, 0, 0), 350); questionLabel->setAnchorPoint(pointMake(0.5, 0.5)); questionLabel->setPosition(pointMake(400, 120)); questionLabel->setZOrder(504); questionLabel->setVisible(false); addToDisplayList(questionLabel); whenLabel = new Label("00:00 and 00:15", fontBig, al_map_rgb(0, 0, 0)); whenLabel->setAnchorPoint(pointMake(0.5, 0.5)); whenLabel->setPosition(pointMake(400, 300)); whenLabel->setZOrder(504); whenLabel->setVisible(false); addToDisplayList(whenLabel); askQuestionButton = new Button("Ask", font, BTN_TXT_COLOR, "res/btn_med.png", "res/btn_med_pressed.png"); askQuestionButton->setZOrder(504); askQuestionButton->setAnchorPoint(pointMake(0.5, 0.5)); askQuestionButton->setPosition(pointMake(480, 490)); askQuestionButton->setHandler(this); askQuestionButton->setVisible(false); askQuestionButton->setEnabled(false); addToDisplayList(askQuestionButton); cancelQuestionButton = new Button("Cancel", font, BTN_TXT_COLOR, "res/btn_med.png", "res/btn_med_pressed.png"); cancelQuestionButton->setZOrder(504); cancelQuestionButton->setAnchorPoint(pointMake(0.5, 0.5)); cancelQuestionButton->setPosition(pointMake(300, 490)); cancelQuestionButton->setHandler(this); cancelQuestionButton->setVisible(false); cancelQuestionButton->setEnabled(false); addToDisplayList(cancelQuestionButton); bkgSpeech = new Spritesheet("res/speech.png"); bkgSpeech->setAnchorPoint(pointMake(0.35, 1)); bkgSpeech->setCamera(camera); bkgSpeech->setZOrder(503); bkgSpeech->setVisible(false); addToDisplayList(bkgSpeech); speechLabel = new Label("speech", font, al_map_rgb(0, 0, 0), 280); speechLabel->setAnchorPoint(pointMake(0.5, 0.5)); speechLabel->setCamera(camera); speechLabel->setZOrder(504); speechLabel->setVisible(false); addToDisplayList(speechLabel); speechCountLabel = new Label("1/1", font, al_map_rgb(0, 0, 0)); speechCountLabel->setAnchorPoint(pointMake(1, 0.5)); speechCountLabel->setCamera(camera); speechCountLabel->setZOrder(504); speechCountLabel->setVisible(false); addToDisplayList(speechCountLabel); speechButton = new Button(bkgSpeech->getFrameSize()); speechButton->setAnchorPoint(bkgSpeech->getAnchorPoint()); speechButton->setCamera(camera); speechButton->setZOrder(504); speechButton->setEnabled(false); speechButton->setHandler(this); addToDisplayList(speechButton); camera->setCenter(playerSprite->getPosition()); activeCharacter = NULL; activePOI = NULL; currentRoom = NULL; crimeWeapon = NULL; accusationsLeft = MAX_ACCUSATIONS; questionsAsked = 0; moving = pointMake(0, 0); moveDir = 0; curFrame = 0; endScene = false; debug = false; currentFilter.timeStart = 0; currentFilter.timeEnd = QUESTION_INTERVAL; std::string msg; msg.append(mystery->victim->name); msg.append("'s body was found around "); msg.append(timeToString(mystery->corpseFoundTime + START_TIME, false)); msg.append(" in the "); msg.append(mystery->corpseFoundRoom->name); msg.append("."); ModalDialog *dialog = new ModalDialog(msg.c_str(), font, "OK", NULL); dialog->setHandler(this); dialog->showInScene(this, 1000); music = al_load_audio_stream("res/mystery.ogg", 4, 2048); al_set_audio_stream_playmode(music, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(music, al_get_default_mixer()); inDialogue = false; inputLocked = true; investigationStartTime = time(0); }
static void updateChallengeMissionData(void) { STRNCPY(timeLimit, timeToString(game.currentMission->challengeData.timeLimit, 0), MAX_DESCRIPTION_LENGTH); sprintf(restrictions, "%s", listRestrictions()); }
int main(int argc, char **argv) { // socket int sock; pid_t pid; char message[BUFSIZE]; char stamp[BUFSIZE]; int str_len, recv_len, recv_num; struct sockaddr_in serv_addr; // time.h struct tm *t; time_t timer; if(argc != 3) { printf("Usage: %s <IP> <port>\n", argv[0]); exit(1); } sock = socket(PF_INET, SOCK_STREAM, 0); memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = inet_addr(argv[1]); serv_addr.sin_port = htons(atoi(argv[2])); if(connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) == -1) { error_handling((char*)"connect() error!"); } pid = fork(); if(pid == 0) { while(1) { fputs("전송할 메시지를 입력 하세요.(q to quit): """, stdout); fgets(message, BUFSIZE, stdin); timer = time(NULL); // get a current time t = localtime(&timer); // struct if(!strcmp(message, "q\n")) { shutdown(sock, SHUT_WR); close(sock); exit(0); } // cat strings strcat(stamp, timeToString(t)); strcat(stamp, message); write(sock, stamp, strlen(stamp)); // send [timestamp]: message memset(stamp,NULL,BUFSIZE); } } else { while(1) { int str_len = read(sock, message, BUFSIZE); if(str_len == 0) { exit(0); } message[str_len] = 0; printf("서버로부터 전송된 메시지: %s\n", message); } } close(sock); return 0; }
TCHAR* DateField::timeToString(const int64_t time) { TCHAR* buf = _CL_NEWARRAY(TCHAR,DATEFIELD_DATE_LEN + 1); timeToString(time,buf); return buf; }
int main(int argc, char **argv) { double dt = 0; long nvtk = 0; char outnum[240]; long time_output = 0; long flops = 0; // double output_time = 0.0; double next_output_time = 0; double start_time = 0, end_time = 0; double start_iter = 0, end_iter = 0; double elaps = 0; double avgMcps = 0; long nAvgMcps = 0; #ifdef MPI MPI_Init(&argc, &argv); DeviceSet(); #endif if (H.mype == 1) fprintf(stdout, "Hydro starts.\n"); process_args(argc, argv, &H); hydro_init(&H, &Hv); // PRINTUOLD(H, &Hv); cuAllocOnDevice(H); // Allocate work space for 1D sweeps allocate_work_space(H, &Hw, &Hvw); // vtkfile(nvtk, H, &Hv); if (H.dtoutput > 0) { // outputs are in physical time not in time steps time_output = 1; next_output_time = next_output_time + H.dtoutput; } if (H.dtoutput > 0 || H.noutput > 0) vtkfile(++nvtk, H, &Hv); if (H.mype == 0) fprintf(stdout, "Hydro starts main loop.\n"); cuPutUoldOnDevice(H, &Hv); start_time = cclock(); // fprintf(stdout, "%lg %lg %d %d \n", H.t, H.tend, H.nstep, H.nstepmax); while ((H.t < H.tend) && (H.nstep < H.nstepmax)) { double iter_time = 0; flopsAri = flopsSqr = flopsMin = flopsTra = 0; start_iter = cclock(); outnum[0] = 0; flops = 0; if ((H.nstep % 2) == 0) { cuComputeDeltat(&dt, H, &Hw, &Hv, &Hvw); // fprintf(stdout, "dt=%lg\n", dt); if (H.nstep == 0) { dt = dt / 2.0; } if (H.nproc > 1) { #ifdef MPI double dtmin; int uno = 1; MPI_Allreduce(&dt, &dtmin, uno, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD); dt = dtmin; #endif } } if ((H.nstep % 2) == 0) { cuHydroGodunov(1, dt, H, &Hv, &Hw, &Hvw); } else { cuHydroGodunov(2, dt, H, &Hv, &Hw, &Hvw); } end_iter = cclock(); iter_time = (double) (end_iter - start_iter); H.nstep++; H.t += dt; { double iter_time = (double) (end_iter - start_iter); #ifdef MPI long flopsAri_t, flopsSqr_t, flopsMin_t, flopsTra_t; MPI_Allreduce(&flopsAri, &flopsAri_t, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); MPI_Allreduce(&flopsSqr, &flopsSqr_t, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); MPI_Allreduce(&flopsMin, &flopsMin_t, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); MPI_Allreduce(&flopsTra, &flopsTra_t, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD); // if (H.mype == 1) // printf("%ld %ld %ld %ld %ld %ld %ld %ld \n", flopsAri, flopsSqr, flopsMin, flopsTra, flopsAri_t, flopsSqr_t, flopsMin_t, flopsTra_t); flops = flopsAri_t * FLOPSARI + flopsSqr_t * FLOPSSQR + flopsMin_t * FLOPSMIN + flopsTra_t * FLOPSTRA; #else flops = flopsAri * FLOPSARI + flopsSqr * FLOPSSQR + flopsMin * FLOPSMIN + flopsTra * FLOPSTRA; #endif nbFLOPS++; if (flops > 0) { if (iter_time > 1.e-9) { double mflops = (double) flops / (double) 1.e+6 / iter_time; MflopsSUM += mflops; sprintf(outnum, "%s {%.2f Mflops %ld Ops} (%.3fs)", outnum, mflops, flops, iter_time); } } else { sprintf(outnum, "%s (%.3fs)", outnum, iter_time); } } if (iter_time > 1.e-9) { double mcps = ((double) H.globnx * (double) H.globny) / iter_time / 1e6l; if (H.nstep > 5) { sprintf(outnum, "%s (%.1lf MC/s)", outnum, mcps); nAvgMcps++; avgMcps += mcps; } } if (time_output == 0 && H.noutput > 0) { if ((H.nstep % H.noutput) == 0) { cuGetUoldFromDevice(H, &Hv); vtkfile(++nvtk, H, &Hv); sprintf(outnum, "%s [%04ld]", outnum, nvtk); } } else { if (time_output == 1 && H.t >= next_output_time) { cuGetUoldFromDevice(H, &Hv); vtkfile(++nvtk, H, &Hv); next_output_time = next_output_time + H.dtoutput; sprintf(outnum, "%s [%04ld]", outnum, nvtk); } } if (H.mype == 0) { fprintf(stdout, "--> step=%-4ld %12.5e, %10.5e %s\n", H.nstep, H.t, dt, outnum); fflush(stdout); } } end_time = cclock(); hydro_finish(H, &Hv); cuFreeOnDevice(); // Deallocate work space deallocate_work_space(H, &Hw, &Hvw); elaps = (double) (end_time - start_time); timeToString(outnum, elaps); if (H.mype == 0) fprintf(stdout, "Hydro ends in %ss (%.3lf) <%.2lf MFlops>.\n", outnum, elaps, (float) (MflopsSUM / nbFLOPS)); if (H.mype == 0) { avgMcps /= nAvgMcps; fprintf(stdout, "Average MC/s: %.1lf\n", avgMcps); } #ifdef MPI MPI_Finalize(); #endif return 0; }
//------------------------------------------------------------------------------ void Scan_registry_user_local(sqlite3 *db, unsigned int session_id) { if (registry_users_extract(db,session_id))return; //load all users informations HMODULE hDLL; typedef DWORD (WINAPI *NETAPIBUFFERFREE)(LPVOID Buffer); NETAPIBUFFERFREE NetApiBufferFree; typedef DWORD (WINAPI *NETUSERENUM)(LPCWSTR servername, DWORD level, DWORD filter, LPBYTE* bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries, LPDWORD resume_handle); NETUSERENUM NetUserEnum; typedef DWORD (WINAPI *NETUSERGETINFO)( LPCWSTR servername, LPCWSTR username, DWORD level, LPBYTE* bufptr); NETUSERGETINFO NetUserGetInfo; typedef DWORD (WINAPI *NETUSERGETLOCALGROUPS)( LPCWSTR servername, LPCWSTR username, DWORD level, DWORD flags, LPBYTE* bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries); NETUSERGETLOCALGROUPS NetUserGetLocalGroups; typedef struct _USER_INFO_0 { LPWSTR usri0_name; }*LPUSER_INFO_0; typedef struct _USER_INFO_2 { LPWSTR usri2_name; LPWSTR usri2_password; DWORD usri2_password_age; DWORD usri2_priv; LPWSTR usri2_home_dir; LPWSTR usri2_comment; DWORD usri2_flags; LPWSTR usri2_script_path; DWORD usri2_auth_flags; LPWSTR usri2_full_name; LPWSTR usri2_usr_comment; LPWSTR usri2_parms; LPWSTR usri2_workstations; DWORD usri2_last_logon; DWORD usri2_last_logoff; DWORD usri2_acct_expires; DWORD usri2_max_storage; DWORD usri2_units_per_week; PBYTE usri2_logon_hours; DWORD usri2_bad_pw_count; DWORD usri2_num_logons; LPWSTR usri2_logon_server; DWORD usri2_country_code; DWORD usri2_code_page; } USER_INFO_2, *PUSER_INFO_2, *LPUSER_INFO_2; typedef struct _GROUP_USERS_INFO_0 { LPWSTR grui0_name; } GROUP_USERS_INFO_0, *PGROUP_USERS_INFO_0, *LPGROUP_USERS_INFO_0; //load function if ((hDLL = LoadLibrary( "NETAPI32.dll"))!=NULL) { NetApiBufferFree = (NETAPIBUFFERFREE) GetProcAddress(hDLL,"NetApiBufferFree"); NetUserEnum = (NETUSERENUM) GetProcAddress(hDLL,"NetUserEnum"); NetUserGetInfo = (NETUSERGETINFO) GetProcAddress(hDLL,"NetUserGetInfo"); NetUserGetLocalGroups = (NETUSERGETLOCALGROUPS) GetProcAddress(hDLL,"NetUserGetLocalGroups"); if (NetApiBufferFree && NetUserEnum && NetUserGetInfo && NetUserGetLocalGroups) { //enumerate all accounts DWORD nStatus, i, nb, total; LPUSER_INFO_0 pBuf, Buffer; USER_INFO_2 * pBuf_info; char name[MAX_PATH],RID[MAX_PATH],SID[MAX_PATH],group[MAX_PATH],type[MAX_PATH], description[MAX_PATH],last_logon[DATE_SIZE_MAX],last_password_change[DATE_SIZE_MAX]; DWORD nb_connexion,state_id; LPGROUP_USERS_INFO_0 LBuffer,pTmpBuf; DWORD dwEntriesRead, dwTotalEntries, j, s; do { nStatus = NetUserEnum(0,0,2,(LPBYTE*)&pBuf,-1,&nb,&total,0); if (((nStatus == 0) || (nStatus == 234)) && (Buffer = pBuf) != 0) { for (i = 0; i < nb; i++) { if (Buffer->usri0_name!=0) { //init name[0] = 0; RID[0] = 0; SID[0] = 0; group[0] = 0; description[0] = 0; last_logon[0] = 0; last_password_change[0] = 0; nb_connexion = 0; state_id = 0; type[0] = 0; if (NetUserGetInfo(0,Buffer->usri0_name,2,(LPBYTE *)&pBuf_info) == 0) { //name snprintf(name,MAX_PATH,"%S",Buffer->usri0_name); //get account infos ^^ SID + RID GetSIDFromUser(name, RID, SID, MAX_PATH); //group if (NetUserGetLocalGroups(0,Buffer->usri0_name,0,1,(LPBYTE*)&LBuffer,-1,&dwEntriesRead,&dwTotalEntries) == 0) { if ((pTmpBuf = LBuffer) != 0) { for (j = 0; j < dwEntriesRead; j++) { if(pTmpBuf != 0) { s = strlen(group); if (s>=MAX_PATH)break; snprintf(group+s,MAX_PATH-s,"%S,",pTmpBuf->grui0_name); } pTmpBuf++; } } } //description snprintf(description,MAX_PATH,"(%S) %S %S",pBuf_info->usri2_full_name,pBuf_info->usri2_usr_comment,pBuf_info->usri2_comment); //state if (pBuf_info->usri2_flags&0x2)state_id = 300;//Disable else state_id = 301;//Enable if (pBuf_info->usri2_flags&0x10)state_id+=2;//Lock //last_logon if (pBuf_info->usri2_last_logon != 0) { timeToString(pBuf_info->usri2_last_logon, last_logon, DATE_SIZE_MAX); } //last_password_change if (pBuf_info->usri2_password_age != 0) { snprintf(last_password_change,DATE_SIZE_MAX,"%lu %02lu:%02lu:%02lu", pBuf_info->usri2_password_age/86400, pBuf_info->usri2_password_age%86400/3600, pBuf_info->usri2_password_age%86400%3600/60, pBuf_info->usri2_password_age%86400%3600%60); } //nb_connexion nb_connexion = pBuf_info->usri2_num_logons; //type switch(pBuf_info->usri2_priv) { case 0:snprintf(type,MAX_PATH,"%lu : %s",pBuf_info->usri2_priv,cps[TXT_MSG_GUEST].c);break; case 1:snprintf(type,MAX_PATH,"%lu : %s",pBuf_info->usri2_priv,cps[TXT_MSG_USER].c);break; case 2:snprintf(type,MAX_PATH,"%lu : %s",pBuf_info->usri2_priv,cps[TXT_MSG_ADMIN].c);break; default:snprintf(type,MAX_PATH,"0x%02X : %s",(unsigned int)(pBuf_info->usri2_priv & 0xff),cps[TXT_MSG_UNK].c);break; } addRegistryUsertoDB("NETAPI32",name, RID, SID, group, description, last_logon, last_password_change, nb_connexion, type, state_id, session_id, db); } Buffer++; }else break; } } }while (nStatus == ERROR_MORE_DATA && start_scan); } FreeLibrary(hDLL); } }
void print_event(uint8_t event_number) { struct Event event = events[event_number]; // print pin switch (event.pin) { case PWM0_PD6: send_string(" PWM0_PD6 "); break; case PWM1_PD5: send_string(" PWM1_PD5 "); break; case PWM2_PB1: send_string(" PWM2_PB1 "); break; case PWM3_PD3: send_string(" PWM3_PD3 "); break; case EXP0_PC2: send_string(" EXP0_PC2 "); break; case EXP1_PD4: send_string(" EXP1_PD4 "); break; case EXP2_PD7: send_string(" EXP2_PD7 "); break; case EXP3_PB0: send_string(" EXP3_PB0 "); break; default: send_string(" unknown pin "); break; } if (event.type == EXP) send_string("EXP "); else if (event.type == PWM) send_string("PWM "); else if (event.type == CLOUDS) send_string("CLOUDS "); // event_time char formatted_date[30]; timeToString(event.time, formatted_date); send_string(formatted_date); send_string(" "); if (event.type == EXP) { if (event.pin_state == 1) { // simple event send_string("HIGH "); } else if (event.pin_state == 0) { send_string("LOW "); } } else if (event.type == PWM) { send_int(event.pin_state); send_string("% "); if ((event.inc != 0) & (event.duration != 0)) { send_int(event.inc); send_string("%/"); send_int(event.duration / 60); send_string("[m] "); } } else if (event.type == CLOUDS) { send_int(event.pin_state); send_string("% "); send_int(event.inc); send_string("%/"); send_int(event.temp_duration); send_string("[s] "); } send_enter(); }
main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "USAGE: printLog <fname>\n"); exit(1); } int fd; if ((fd = open(argv[1], O_RDONLY)) < 0) { fprintf(stderr, "Can't open '%s'\n", argv[1]); exit(1); } struct stat stat; fstat(fd, &stat); int len = stat.st_size; char *buf = malloc(len); char *data = buf; char *end = data + len; read(fd, buf, len); while (data < end) { switch ( ((LogHdr *)data)->type ) { case LOG_FILE_VERSION: { LogFileVersion *l = (LogFileVersion *)data; char *recipes = (char *)(l + 1); char *path = recipes + l->recipelen; printf("\n%06ld #%d FILE '%s', %s, len %ld, recipelen %ld, VERSION %d:\n", data - buf, l->hdr.id, path, timeToString(l->mtime), l->flen, l->recipelen, l->hdr.version); while (recipes < path) { printf("\t\t%s\n", recipes); recipes += A_HASH_SIZE; } } break; case LOG_UNLINK: case LOG_MKDIR: case LOG_RMDIR: case LOG_CHMOD: { LogOther *l = (LogOther *)data; char *path = (char *)(l + 1); char *translate[LOG_MACHINE + 1]; translate[LOG_UNLINK] = "UNLINK"; translate[LOG_MKDIR] = "MKDIR"; translate[LOG_RMDIR] = "RMDIR"; translate[LOG_CHMOD] = "CHMOD"; printf("\n%06ld #%d %s '%s' mode/flags 0%o\n", data - buf, l->hdr.id, translate[l->hdr.type], path, l->flags); } break; default: printf("BAD RECORD\n"); exit(1); } data += ((LogHdr *)data)->len; } }
int main(int argc, char**argv) { if (argc < 4) { write(2, "You must supply an IP address, a port, and a secret key!\r\n", 25); return -1; } #ifdef Debug printf("Argv[1]: %s\r\nArgv[2]: %s\r\nArgv[3]: %s\r\n", argv[1], argv[2], argv[3]); #endif int port = numberFromString(argv[2]); if (port < 49152 || port > 65535) { write(2, "The port must be between 49152 and 65535!\r\n", 43); return -1; } #ifdef Debug printf("Port: %d\r\n", port); #endif // Malloc space for our secret key secret = mallocAndCheck(sizeof(char)*strlen(argv[3])); strcpy(secret, argv[3]); #ifdef Debug printf("Secret: %s\r\n", secret); #endif char *buffer = mallocAndCheck(sizeof(char)*1024); int x; for(x = 0; x < 1024; x++) { buffer[x] = '\0'; } int msglen = 1024; addrlen = (socklen_t)sizeof(struct sockaddr_storage); udpSocket = socket(AF_INET, SOCK_DGRAM, 0); if(udpSocket <= 0) { write(2, "Unable to bind socket!\r\n", 24); return -1; } registeredaddr = mallocAndCheck(addrlen); ((struct sockaddr_in *)registeredaddr)->sin_family = AF_INET; ((struct sockaddr_in *)registeredaddr)->sin_port = htons(port); // Parse the arg given to us for the IP if(inet_pton(AF_INET, argv[1], &((struct sockaddr_in *)registeredaddr)->sin_addr) <= 0) { write(2, "Failed to parse IP Address!\r\n", 29); return -1; } int reminders = 1; int registered = 0; int lastReminder = 0; setClientAlarmHandler(); // While we have reminders to receive while(reminders) { for(x = 0; x < 1024; x++) { buffer[x] = '\0'; } // If we've not registered, send a registration packet if(!registered) { registration(0); } // Busy wait for a packet while(recvfrom(udpSocket, buffer, msglen, 0, registeredaddr, &addrlen) <= 0) { // If we've not received a registration ACK // and we don't have an alarm set to send it // again, we'll set a timer if(!alarmSet) setClientAlarm(); } #ifdef Debug printf("\r\nReceived: %s\r\n", buffer); #endif // Exit packet will tell us when we're done if(strcmp(buffer, "Exit\r\n\r\n") == 0) { write(2, "All Reminders Received!\r\n", 25); reminders = 0; } // Our registration was dropped! else if (strcmp(buffer, "DropRegistration\r\n\r\n") == 0) { write(2, "Registration Dropped!\r\n", 23); registered = 0; } // Our registration was accepted! else if (strcmp(buffer, "Registered\r\n\r\n") == 0) { write(2, "Registered!\r\n", 13); registered = 1; alarm(0); } // Default case else { int number = numberFromString(buffer); #ifdef Debug printf("Received: %d, Last: %d\r\n", number, lastReminder); #endif // If we've received a reminder that is more than just the increment // of the last one, send the resend packet if(number - lastReminder > 1) { // WE LOST A PACKET! char* resend = mallocAndCheck(sizeof(char)*8 + sizeof(int)); memset(resend, 0, sizeof(char)*8 + sizeof(int)); strcpy(resend, "Resend\t"); strcat(resend, timeToString(lastReminder+1)); mySendTo(udpSocket, resend, strlen(resend), 0, registeredaddr, addrlen); } // Otherwise, cancel our registration alarm if we've had one // and update our last received reminder. // Display the reminder packet; else { alarm(0); alarmSet = 0; lastReminder = number; write(2, buffer, strlen(buffer)); write(2, "\r\n", 2); } } } return 0; }
void LLFloaterEnvSettings::syncMenu() { LLSliderCtrl* sldr; sldr = getChild<LLSliderCtrl>("EnvTimeSlider"); // sync the clock F32 val = (F32)LLWLParamManager::instance()->mAnimator.getDayTime(); std::string timeStr = timeToString(val); LLTextBox* textBox; textBox = getChild<LLTextBox>("EnvTimeText"); textBox->setValue(timeStr); // sync time slider which starts at 6 AM val -= 0.25; if(val < 0) { val++; } sldr->setValue(val); // sync cloud coverage bool err; childSetValue("EnvCloudSlider", LLWLParamManager::instance()->mCurParams.getFloat("cloud_shadow", err)); LLWaterParamManager * param_mgr = LLWaterParamManager::instance(); // sync water params LLColor4 col = param_mgr->getFogColor(); LLColorSwatchCtrl* colCtrl = getChild<LLColorSwatchCtrl>("EnvWaterColor"); col.mV[3] = 1.0f; colCtrl->set(col); childSetValue("EnvWaterFogSlider", param_mgr->mFogDensity.mExp); param_mgr->setDensitySliderValue(param_mgr->mFogDensity.mExp); // turn off Use Estate Time button if it's already being used if(LLWLParamManager::instance()->mAnimator.mUseLindenTime) { childDisable("EnvUseEstateTimeButton"); } else { childEnable("EnvUseEstateTimeButton"); } if(!gPipeline.canUseVertexShaders()) { childDisable("EnvWaterColor"); childDisable("EnvWaterColorText"); //childDisable("EnvAdvancedWaterButton"); } else { childEnable("EnvWaterColor"); childEnable("EnvWaterColorText"); //childEnable("EnvAdvancedWaterButton"); } // only allow access to these if they are using windlight if(!gPipeline.canUseWindLightShaders()) { childDisable("EnvCloudSlider"); childDisable("EnvCloudText"); //childDisable("EnvAdvancedSkyButton"); } else { childEnable("EnvCloudSlider"); childEnable("EnvCloudText"); //childEnable("EnvAdvancedSkyButton"); } }
void timeToLabel(QLabel *label, const Core::Time &t, const char *fmt, bool addTimeZone) { if ( SCScheme.dateTime.useLocalTime ) label->setToolTip((t.toString(fmt) + " UTC").c_str()); label->setText(timeToString(t, fmt, addTimeZone)); }