void displayEditFeed1(int mode, int index, int x, int y) { Time *t; t = &feedTime[index]; temp_text[0] = index + 1 + '0'; temp_text[1] = ':'; temp_text[2] = 0; clearLine(x); Lcd_Out(x, y, title); Lcd_Out(x, y + TITLE_LENGTH, temp_text); Lcd_Out(x, y + TITLE_LENGTH + 3, timeStr(t->hh)); Lcd_Out(x, y + TITLE_LENGTH + 5, column); Lcd_Out(x, y + TITLE_LENGTH + 6, timeStr(t->mn)); }
std::string logPrefix() { std::ostringstream oss; oss << timeStr(); oss << "[" << std::setw(6) << getpid() << "] "; return oss.str(); }
void qrcode_clock::updateTime() { // get time QDateTime time = QDateTime::currentDateTime(); QString timeStr(QString::number(time.toTime_t())); // encode time as QR code QRcode *qrCodeMatrix(QRcode_encodeString8bit(timeStr.toStdString().c_str(), 0, QR_ECLEVEL_H)); if (!qrCodeMatrix) { qDebug() << "kein QrCode erzeugt"; return; } // transfer QR code into picture m_qrImage = new QImage(qrCodeMatrix->width, qrCodeMatrix->width, QImage::Format_Mono); for (int i = 0; i < qrCodeMatrix->width; ++i) { for (int j = 0; j < qrCodeMatrix->width; ++j) { m_qrImage->setPixel(j, i, qrCodeMatrix->data[i * qrCodeMatrix->width + j] & 1); } } QRcode_free(qrCodeMatrix); m_qrImage->setColor(0, qRgb(255,255,255)); m_qrImage->setColor(1, qRgb(0,0,0)); m_qrClock->setPixmap(QPixmap::fromImage(*m_qrImage)); // show human readable time m_humanClock->setText(time.toUTC().toString() + " UTC"); }
void wxGamePanel::UpdateTime() { // 경기 시간 갱신 wxString timeStr(wxT("00:00")); long remainTime = m_periLen - m_elapseTime.Time(); if (remainTime > 0) { timeStr = wxTimeSpan::Milliseconds(remainTime).Format(wxT("%M:%S")); } else { StartBuzzer(); StopTime(); } m_timeCtrl->SetValue(timeStr); // 공격 시간 갱신 wxString shotClockStr(wxT("00")); long remainShotClock = m_shotClock - m_attackTime.Time(); if (remainShotClock > 0) { shotClockStr = wxTimeSpan::Milliseconds(remainShotClock).Format(wxT("%S")); } else { if (m_playing) { StartBuzzer(); // 무한 재귀 호출을 막기 위해서, false를 인자로 전달한다. ResetShotClock(false); } } m_shotClockCtrl->SetValue(shotClockStr); }
void SyslogParser::parseNew(const std::string& msg, RemoteSyslogChannel::Severity severity, RemoteSyslogChannel::Facility fac, std::size_t& pos) { Poco::Message::Priority prio = convert(severity); // rest of the unparsed header is: // VERSION SP TIMESTAMP SP HOSTNAME SP APP-NAME SP PROCID SP MSGID std::string versionStr(parseUntilSpace(msg, pos)); std::string timeStr(parseUntilSpace(msg, pos)); // can be the nilvalue! std::string hostName(parseUntilSpace(msg, pos)); std::string appName(parseUntilSpace(msg, pos)); std::string procId(parseUntilSpace(msg, pos)); std::string msgId(parseUntilSpace(msg, pos)); std::string message(msg.substr(pos)); pos = msg.size(); Poco::DateTime date; int tzd = 0; bool hasDate = Poco::DateTimeParser::tryParse(RemoteSyslogChannel::SYSLOG_TIMEFORMAT, timeStr, date, tzd); Poco::Message logEntry(msgId, message, prio); logEntry["host"] = hostName; logEntry["app"] = appName; if (hasDate) logEntry.setTime(date.timestamp()); int lval(0); Poco::NumberParser::tryParse(procId, lval); logEntry.setPid(lval); _pListener->log(logEntry); }
void displayFeedTimes(int x, int y) { Time *t; int i; t = &feedTime; clearLine(x); Lcd_Out(x, y, title); y += TITLE_LENGTH; for(i = 0; i < 2; i++, t++) { Lcd_Out(x, y, timeStr(t->hh)); Lcd_Out(x, y + 2, column); Lcd_Out(x, y + 3, timeStr(t->mn)); y += 6; } }
QStringList StatisticsWidget::createRowByWorker(const QString &actor, const WorkerInfo &info) { QStringList result; const WorkflowMonitor *m = dashboard->monitor(); CHECK(NULL != m, result); result << wrapLongText(m->actorName(actor)); result << timeStr(info.timeMks); result << QString::number(m->getDataProduced(actor)); return result; }
static bool SAMLCheckTimeAttr(const DOMElement *elem, const char *attrName, bool notBefore) { const XMLCh *timeAttr = elem->getAttribute(MAKE_UNICODE_STRING(attrName)); if ((NULL == timeAttr) || (0 == *timeAttr)) { /* * The presence of all time restrictions in SAML are optional, so if * the attribute is not present, that is fine. */ return true; } SAMLStringWrapper timeStr(timeAttr); GTimeVal attrTime; if (!g_time_val_from_iso8601(timeStr.c_str(), &attrTime)) { Log("%s: Could not parse %s value (%s).\n", __FUNCTION__, attrName, timeStr.c_str()); return false; } GTimeVal now; g_get_current_time(&now); glong diff; /* * Check the difference, doing the math so that a positive * value is bad. Ignore the micros since we're letting clock * skew add a fudge-factor. */ if (notBefore) { // expect time <= now diff = attrTime.tv_sec - now.tv_sec; } else { // expect now <= time diff = now.tv_sec - attrTime.tv_sec; } /* * A negative value is fine, a postive value * greater than the clock skew range is bad. */ if (diff > clockSkewAdjustment) { Warning("%s: FAILED SAML assertion (timeStamp %s, delta %d) %s.\n", __FUNCTION__, timeStr.c_str(), (int) diff, notBefore ? "is not yet valid" : "has expired"); return false; } return true; }
String TimeClass::format(time_t t, const char* format_spec) { if (format_spec==NULL) format_spec = this->format_spec; if (!format_spec || !strcmp(format_spec,TIME_FORMAT_DEFAULT)) { return timeStr(t); } t += time_zone_cache; t += dst_current_cache; tm* calendar_time = localtime(&t); return timeFormatImpl(calendar_time, format_spec, time_zone_cache + dst_current_cache); }
F64 LLWLAnimator::getLocalTime() { char buffer[9]; time_t rawtime; struct tm* timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); strftime(buffer, 9, "%H:%M:%S", timeinfo); std::string timeStr(buffer); F64 tod = ((F64)atoi(timeStr.substr(0,2).c_str())) / 24.f + ((F64)atoi(timeStr.substr(3,2).c_str())) / 1440.f + ((F64)atoi(timeStr.substr(6,2).c_str())) / 86400.f; return tod; }
/*初始化主对话框*/ void initMainDlg(HINSTANCE hInstance) { HWND hMainDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAIN), GetDesktopWindow(), mainDlgProc); //设置对话框的图标 SendMessage(hMainDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(NULL, IDI_APPLICATION)); /*显示时间*/ Char timeBuf[32]; // 时间字符缓冲区 timeStr(timeBuf); SetWindowText(GetDlgItem(hMainDlg, IDC_TIME), timeBuf); //初始化列表控件 initTable(hMainDlg); //显示主对话框 ShowWindow(hMainDlg, SW_SHOW); hCourseDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_COURSE), GetDesktopWindow(), courseDlgProc); hideCourseDlg(); }
void printVerbose(Header *h) { char str[STR_LEN], *temp = (char*)alloca(sizeof(char) * TEMP_LEN); /* permissions */ if (h->typeflag == TF_DIR) str[0] = 'd'; else if (h->typeflag == TF_LNK) str[0] = 'l'; else str[0] = '-'; str[1] = 0; temp = permissionStr(temp, h->mode); strcat(str, temp); strcat(str, " "); /* owner/group */ strcat(str, h->uname); strcat(str, "/"); strcat(str, h->gname); strcat(str, " "); /* TODO: determine correct length */ /* size */ sprintf(temp, "%8lu", (unsigned long int)h->size); strcat(str, temp); strcat(str, " "); /* mtime */ temp = timeStr(temp, &h->mtime); sprintf(temp, "%s", temp); strcat(str, temp); /* printf */ printf("%s ", str); printStandard(h); }
/*! Returns localized string representation of given \a date formatted with Symbian locale date format. If \a short_format is true the format will be a short version. Otherwise it uses a longer version. */ static QString symbianDateToString(const QDate &date, bool short_format) { int month = date.month() - 1; int day = date.day() - 1; int year = date.year(); TDateTime dateTime; dateTime.Set(year, TMonth(month), day, 0, 0, 0, 0); TTime timeStr(dateTime); TBuf<KMaxLongDateFormatSpec*2> buffer; TPtrC dateFormat; if (short_format) { dateFormat.Set(ptrGetShortDateFormatSpec(_s60Locale)); } else { dateFormat.Set(ptrGetLongDateFormatSpec(_s60Locale)); } TRAPD(err, ptrTimeFormatL(timeStr, buffer, dateFormat, *_s60Locale.GetLocale());) if (err == KErrNone)
void SyslogParser::parseBSD(const std::string& msg, RemoteSyslogChannel::Severity severity, RemoteSyslogChannel::Facility fac, std::size_t& pos) { Poco::Message::Priority prio = convert(severity); // rest of the unparsed header is: // "%b %f %H:%M:%S" SP hostname|ipaddress // detect three spaces int spaceCnt = 0; std::size_t start = pos; while (spaceCnt < 3 && pos < msg.size()) { if (msg[pos] == ' ') { spaceCnt++; if (spaceCnt == 1) { // size must be 3 chars for month if (pos - start != 3) { // probably a shortened time value, or the hostname // assume hostName Poco::Message logEntry(msg.substr(start, pos-start), msg.substr(pos+1), prio); _pListener->log(logEntry); return; } } else if (spaceCnt == 2) { // a day value! if (!(std::isdigit(msg[pos-1]) && (std::isdigit(msg[pos-2]) || std::isspace(msg[pos-2])))) { // assume the next field is a hostname spaceCnt = 3; } } if (pos + 1 < msg.size() && msg[pos+1] == ' ') { // we have two spaces when the day value is smaller than 10! ++pos; // skip one } } ++pos; } std::string timeStr(msg.substr(start, pos-start-1)); int tzd(0); Poco::DateTime date; int year = date.year(); // year is not included, use the current one bool hasDate = Poco::DateTimeParser::tryParse(RemoteSyslogChannel::BSD_TIMEFORMAT, timeStr, date, tzd); if (hasDate) { int m = date.month(); int d = date.day(); int h = date.hour(); int min = date.minute(); int sec = date.second(); date = Poco::DateTime(year, m, d, h, min, sec); } // next entry is host SP std::string hostName(parseUntilSpace(msg, pos)); // TAG: at most 32 alphanumeric chars, ANY non alphannumeric indicates start of message content // ignore: treat everything as content std::string message(msg.substr(pos)); pos = msg.size(); Poco::Message logEntry(hostName, message, prio); logEntry.setTime(date.timestamp()); _pListener->log(logEntry); }
void GPRMC::decode() { //$GPRMC,162748,A,5214.0456,N,01103.4540,E,0.0,0.0,250309,0.0,E,A*17CRLF if (m_message.size() > 65) { uint32_t pos = 0; string strGPRMC = m_message.substr(pos, 6); if (strGPRMC != "$GPRMC") { clog << "No $GPRMC message." << endl; return; } //////////////////////////////////////////////////////// pos = pos + 6 + 1; // Consume value + "," stringstream timeStr(m_message.substr(pos, 6)); uint32_t time; timeStr >> time; pos = pos + 6 + 1; // Consume value + "," char type = m_message.at(pos); if (type != 'A') { clog << "No data message." << endl; return; } //////////////////////////////////////////////////////// pos = pos + 1 + 1; // Consume value + "," stringstream latitudeStr(m_message.substr(pos, 2)); pos = pos + 2; // Consume value stringstream latitudeArcMinuteStr(m_message.substr(pos, 7)); double temp; double latitude = 0; latitudeStr >> temp; latitude = temp; latitudeArcMinuteStr >> temp; latitude += (temp / 60); pos = pos + 7 + 1; // Consume value + "," char LAT = m_message.at(pos); m_coordinate.setLatitude(latitude); m_coordinate.setLATITUDE((LAT == 'N') ? WGS84Coordinate::NORTH : WGS84Coordinate::SOUTH); //////////////////////////////////////////////////////// pos = pos + 1 + 1; // Consume value + "," stringstream longitudeStr(m_message.substr(pos, 3)); pos = pos + 3; // Consume value stringstream longitudeArcMinuteStr(m_message.substr(pos, 7)); double longitude = 0; longitudeStr >> temp; longitude = temp; longitudeArcMinuteStr >> temp; longitude += (temp / 60); pos = pos + 7 + 1; // Consume value + "," char LON = m_message.at(pos); m_coordinate.setLongitude(longitude); m_coordinate.setLONGITUDE((LON == 'W') ? WGS84Coordinate::WEST: WGS84Coordinate::EAST); //////////////////////////////////////////////////////// pos = pos + 1 + 1; // Consume value + "," stringstream velocityStr; char c = m_message.at(pos); while (c != ',') { velocityStr << c; pos++; c = m_message.at(pos); } pos = pos + 1; // Consume "," stringstream directionStr; c = m_message.at(pos); while (c != ',') { directionStr << c; pos++; c = m_message.at(pos); } pos = pos + 1; // Consume "," stringstream ddmmStr(m_message.substr(pos, 4)); pos = pos + 4; // Consume value stringstream yyStr(m_message.substr(pos, 2)); uint32_t yy; yyStr >> yy; stringstream dateTimeStr; dateTimeStr << ddmmStr.str() << GPRMC::BASE_YEAR + yy << timeStr.str(); m_timeStamp = TimeStamp(dateTimeStr.str()); pos = pos + 2 + 1; // Consume value + "," stringstream magneticDeviationStr; c = m_message.at(pos); while (c != ',') { magneticDeviationStr << c; pos++; c = m_message.at(pos); } pos = pos + 1; // Consume "," LON = m_message.at(pos); pos = pos + 1 + 1; // Consume value + "," type = m_message.at(pos); pos = pos + 1 + 1; // Consume value + "*" const uint32_t messageEnd = pos; stringstream checksumStr(m_message.substr(pos)); uint32_t checksum; checksumStr >> hex >> checksum; uint32_t XOR = 0; for(uint32_t i = 0; i < messageEnd; i++) { XOR ^= m_message.at(i); } if (XOR != checksum) { clog << "GPRMC corrupt!" << endl; } }
void start() { std::ofstream pidfile(SC_PID); if (!pidfile.good()) { std::cerr << "cannot open PID file " << SC_PID << ": " << strerror(errno) << std::endl; exit(errno); } pidfile << getpid() << std::endl; pidfile.close(); std::ofstream log; log.open(SC_LOG, std::ofstream::app); log << "\n" << logPrefix() << "starting shoutcast daemon" << std::endl; log << logPrefix() << "reading shoutcast configuration files from " << SC_CONFIG << std::endl; log.close(); // Enumerate config files in shoutcast config dir. DIR *dir; struct dirent *ent; dir = opendir (SC_CONFIG); if (dir == NULL) { log.open(SC_LOG, std::ofstream::app); log << logPrefix() << "cannot read scd configuration direcoty " << SC_CONFIG << ": " << strerror(errno) << std::endl; log.close(); exit(errno); } for (; ent = readdir(dir); ent != NULL) { std::string cfgfile = ent->d_name; if (cfgfile == "." || cfgfile == "..") { continue; } std::string cfgpath = SC_CONFIG; cfgpath += "/"; cfgpath += cfgfile; Child c; c.pid = 0; c.config = cfgpath; size_t idx = cfgfile.find("."); c.log = SC_LOGDIR"sc_stream_"; c.log += cfgfile.substr(0, idx); c.log += ".log"; g_children.push_back(c); log.open(SC_LOG, std::ofstream::app); log << logPrefix() << "found shoutcast configuration: " << cfgpath << std::endl; log.close(); } closedir(dir); // Start respawn loop. while (g_running) { // Respawn all children with zero pid. for (Children::iterator i = g_children.begin(); i != g_children.end(); ++i) { if (i->pid == 0) { i->pid = fork(); if (i->pid == 0) { // Open log file and redirect stdout, stderr. FILE *f = fopen(i->log.c_str(), "a"); int r1 = dup2(fileno(f), 1); int r2 = dup2(fileno(f), 2); fclose(f); // Start child process. std::cout << timeStr() << "[" << getpid() << "] started" << std::endl; if (execl(SC_EXEC, SC_EXEC, i->config.c_str(), (char*)0) < 0) { exit(1); } } else { log.open(SC_LOG, std::ofstream::app); log << logPrefix() << "spawned server for config " << i->config << ", server pid is [" << i->pid << "]" << std::endl; log.close(); } } } // Wait for any failed children. int status; pid_t pid = wait(&status); if (!g_running) break; // Mark a failed child to restart. for (Children::iterator i = g_children.begin(); i != g_children.end(); ++i) { if (i->pid == pid) { log.open(SC_LOG, std::ofstream::app); log << logPrefix() << "server with pid [" << pid << "] (" << i->config << ") failed with status " << status << std::endl; log.close(); i->pid = 0; break; } } } log.open(SC_LOG, std::ofstream::app); log << logPrefix() << "terminated" << "\n" << std::endl; log.close(); }
void TUIGame::handleTestSuite(const std::string& cmd) { std::ifstream fr; int lineNo = -1; try { size_t idx = cmd.find_first_of(' '); if (idx == cmd.npos) return; std::string filename(cmd.substr(0, idx)); std::string timeStr(cmd.substr(idx + 1)); int timeLimit; if (!str2Num(timeStr, timeLimit)) { std::cout << "Error parsing number: " << timeStr << std::endl; return; } // std::cout << "file:" << filename << " time:" << timeStr << " (" << timeLimit << ")" << std::endl; fr.open(filename.c_str()); Player& pl = whitePlayer->isHumanPlayer() ? *blackPlayer : *whitePlayer; if (pl.isHumanPlayer()) { std::cout << "No computer player available" << std::endl; return; } ComputerPlayer& cp = static_cast<ComputerPlayer&>(pl); int numRight = 0; int numTotal = 0; std::string line; lineNo = 0; while (getline(fr, line).good()) { lineNo++; if (startsWith(line, "#") || (line.length() == 0)) continue; size_t idx1 = line.find(" bm "); if (idx1 == line.npos) { std::cout << "Parse error, line:" << lineNo << std::endl; return; } std::string fen = line.substr(0, idx1); size_t idx2 = line.find(";", idx1); if (idx2 == line.npos) { std::cout << "Parse error, line:" << lineNo << std::endl; return; } std::string bm = line.substr(idx1+4, idx2 - (idx1+4)); // std::cout << "Line " << std::setw(3) << lineNo << ": fen:" << fen << " bm:" << bm << std::endl; Position testPos = TextIO::readFEN(fen); cp.clearTT(); std::pair<Move, std::string> ret = cp.searchPosition(testPos, timeLimit); Move sm = ret.first; std::string PV = ret.second; Move m(sm); std::vector<std::string> answers; splitString(bm, answers); bool correct = false; for (size_t i = 0; i < answers.size(); i++) { const std::string& a = answers[i]; Move am(TextIO::stringToMove(testPos, a)); if (am.isEmpty()) throw ChessParseError("Invalid move " + a); if (am.equals(m)) { correct = true; break; } } if (correct) numRight++; numTotal++; std::cout << std::setw(3) << lineNo << ' ' << std::setw(6) << TextIO::moveToString(testPos, sm, false) << ' ' << std::setw(6) << sm.score() << ' ' << (correct ? 1 : 0) << ' ' << std::setw(3) << numRight << '/' << std::setw(3) << numTotal << ' ' << bm << " : " << PV << std::endl; } fr.close(); } catch (const std::ifstream::failure& ex) { std::cout << "IO error: " << ex.what() << std::endl; } catch (const ChessParseError& cpe) { std::cout << "Parse error, line " << lineNo << ": " << cpe.what() << std::endl; } }