void InitLoggingInternal(bool toConsole, bool connectExistingSHM) { try { if (!toConsole) { if (connectExistingSHM) { SHMLogger::open("usvfs"); } else { SHMLogger::create("usvfs"); } } // a temporary logger was created in DllMain spdlog::drop("usvfs"); #pragma message("need a customized name for the shm") auto logger = toConsole ? spdlog::create<spdlog::sinks::stdout_sink_mt>("usvfs") : spdlog::create<spdlog::sinks::shm_sink>("usvfs", "usvfs"); logger->set_pattern("%H:%M:%S.%e [%L] %v"); logger = toConsole ? spdlog::create<spdlog::sinks::stdout_sink_mt>("hooks") : spdlog::create<spdlog::sinks::shm_sink>("hooks", "usvfs"); logger->set_pattern("%H:%M:%S.%e <%P:%t> [%L] %v"); } catch (const std::exception&) { // TODO should really report this //OutputDebugStringA((boost::format("init exception: %1%\n") % e.what()).str().c_str()); spdlog::create<spdlog::sinks::null_sink>("usvfs"); spdlog::create<spdlog::sinks::null_sink>("hooks"); } }
int main(void) { char c; uart_init(); print("jtag scanner for atmega328p\ncompatible with diy arduinoob duemilanewb 2.0\nso that it has a chance to make hackaday\n -- lekernel@hsb, /tmp/export tour, june 2009\n\n"); while(1) { print("\n" "s > scan\n" "p > set pattern ["); print(pattern); print("]\n"); c = uart_rcv(); switch(c) { case 's': scan(); break; case 'p': set_pattern(); break; } } return 0; }
LoggerPtr LogRegistry::getOrCreateLogger(const std::string &logger_name) { // If logger already exists, return a copy of it auto spd_logger = spdlog::get(logger_name); if (!spd_logger) { // Bummer, it didn't exist. We'll create one from scratch. try { spd_logger = spdlog::details::registry::instance().create( logger_name, begin(sinks_), end(sinks_)); spd_logger->set_pattern(DEFAULT_PATTERN); /// @todo should this level be different than other levels? spd_logger->set_level(convertToLevelEnum(minLevel_)); spd_logger->flush_on( convertToLevelEnum(DEFAULT_FLUSH_LEVEL)); } catch (const std::exception &e) { generalPurposeLog_->error() << "Caught exception attempting to create logger: " << e.what(); generalPurposeLog_->error() << "Error creating logger. " "Will only log to the " "console."; } catch (...) { generalPurposeLog_->error() << "Error creating logger. " "Will only log to the " "console."; } } return Logger::makeFromExistingImplementation(logger_name, spd_logger); }
/* Compile a regexp and signal a Lisp error if anything goes wrong. */ void compile_pattern (Lisp_Object pattern, struct re_pattern_buffer *bufp, char *translate, int backward) { char *val; Lisp_Object dummy; if (EQ (pattern, last_regexp) && translate == bufp->translate /* 92.4.10 by K.Handa */ /* 93.7.13 by K.Handa */ && NILP (current_buffer->mc_flag) == !bufp->mc_flag && (!bufp->syntax_version || bufp->syntax_version == syntax_table_version) && (!bufp->category_version || bufp->category_version == category_table_version)) return; if (CONSP (pattern)) /* pre-compiled regexp */ { Lisp_Object compiled; val = 0; pattern = XCONS (pattern)->car; if (CONSP (pattern) && (compiled = backward ? XCONS(pattern)->cdr : XCONS(pattern)->car) && XTYPE (compiled) == Lisp_Vector && XVECTOR (compiled)->size == 4) { /* set_pattern will set bufp->allocated to NULL */ set_pattern (compiled, bufp, translate); return; } val = "Invalied pre-compiled regexp"; goto invalid_regexp; } CHECK_STRING (pattern, 0); last_regexp = Qnil; bufp->translate = translate; bufp->syntax_version = bufp->category_version = 0; /* 93.7.13 by K.Handa */ /* 92.7.10 by T.Enami 'bufp->allocated == 0' means bufp->buffer points to pre-compiled pattern in a lisp string, which should not be 'realloc'ed. */ if (bufp->allocated == 0) bufp->buffer = 0; val = re_compile_pattern (XSTRING (pattern)->data, XSTRING (pattern)->size, bufp); if (val) { invalid_regexp: dummy = build_string (val); while (1) Fsignal (Qinvalid_regexp, Fcons (dummy, Qnil)); } last_regexp = pattern; return; }
void Logger::set_logger_console() { unset_logger(); auto logger_ = spdlog::stdout_logger_mt("bmv2"); logger = logger_.get(); set_pattern(); logger_->set_level(to_spd_level(LogLevel::DEBUG)); }
void Logger::set_logger_file(const std::string &filename) { unset_logger(); auto logger_ = spdlog::rotating_logger_mt("bmv2", filename, 1024 * 1024 * 5, 3); logger = logger_.get(); set_pattern(); logger_->set_level(to_spd_level(LogLevel::DEBUG)); }
void Log::init() { logInitialized = true; m_sinks.push_back(std::make_shared<spdlog::sinks::simple_file_sink_st>("logfile", true)); auto combined_logger = std::make_shared<spdlog::logger>("papas_logger", begin(m_sinks), end(m_sinks)); // register it if you need to access it globally spdlog::register_logger(combined_logger); combined_logger->set_pattern("%l: %v"); combined_logger->set_level(spdlog::level::debug); }
int main(int argc, char **argv) { spdlog::set_sync_mode(); auto console = spdlog::stdout_color_mt("console"); console->set_level(spdlog::level::warn); console->set_pattern("[ ] [%Y-%m-%d %H:%M:%S] [%t] [%l] %v"); int result = perform_tests(argc, argv); spdlog::drop_all(); return result; }
int main(int, char* []) { int howmany = 1000000; namespace spd = spdlog; ///Create a file rotating logger with 5mb size max and 3 rotated files auto logger = spdlog::create<spd::sinks::simple_file_sink_st>("file_logger", "logs/spd-bench-st.txt", false); logger->set_pattern("[%Y-%b-%d %T.%e]: %v"); for(int i = 0 ; i < howmany; ++i) logger->info("spdlog message #{} : This is some text for your pleasure", i); return 0; }
void PDebug::init() { // we either create a null sink or we sink to a file logInitialized = true; if (PDebug::s_fname == "") { // no output m_sinks.push_back(std::make_shared<spdlog::sinks::null_sink_st>()); } else { // output to named file //TODO error checking if (PDebug::slevel == spdlog::level::info) std::remove(PDebug::s_fname.c_str()); // delete file m_sinks.push_back(std::make_shared<spdlog::sinks::simple_file_sink_st>(PDebug::s_fname.c_str(), true)); } auto plogger = std::make_shared<spdlog::logger>("pdebug", begin(m_sinks), end(m_sinks)); plogger->set_level(PDebug::slevel); // what level output will be sent to log plogger->set_pattern("%v"); spdlog::register_logger(plogger); }
LoggerPtr Logger::makeWithSink(std::string const &name, spdlog::sink_ptr sink) { if (!sink) { // bad sink! std::cerr << "WARNING: Logger::makeWithSink(\"" << name << "\", sink) called with a null sink! Will result " "in a fallback logger!" << std::endl; return makeFallback(name); } auto spd_logger = std::make_shared<spdlog::logger>(name, sink); spd_logger->set_pattern(DEFAULT_PATTERN); spd_logger->flush_on(convertToLevelEnum(DEFAULT_FLUSH_LEVEL)); return makeLogger(name, spd_logger); }
void netscape_10_1_win32_topmost_patch::init() { /* * This is the call to SetWindowPos that makes the Flash Window topmost. * We don't want to set it to topmost but bring it to the front of the Z-Order instead. */ unsigned char pattern[] = { 0x50, /* push eax */ 0x57, /* push edi */ 0x52, /* push edx */ 0x6A, 0xFF, /* push -1 (this is HWND_TOPMOST) */ 0xFF, 0x75, 0xFC, /* push [ebp+hWnd] */ 0x89, 0x46, 0x30, /* mov [esi+30h], eax */ 0x89, 0x4E, 0x34, /* mov [esi+34h], ecx */ 0xFF, 0x15, 0x5C, 0xD5, 0x42, 0x10, /* call SetWindowPos */ 0x39, 0x5D, 0xFC, /* cmp [ebp+hWnd], ebx */ }; unsigned char pattern_mask[] = { 0xFF, /* push eax */ 0xFF, /* push edi */ 0xFF, /* push edx */ 0xFF, 0xFF, /* push -1 (this is HWND_TOPMOST) */ 0xFF, 0xFF, 0x00, /* push [ebp+hWnd] */ 0xFF, 0xF0, 0x00, /* mov [esi+30h], eax */ 0xFF, 0xF0, 0x00, /* mov [esi+34h], ecx */ 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, /* call SetWindowPos */ 0xFF, 0xFF, 0x00, /* cmp [ebp+hWnd], ebx */ }; set_pattern( utils::buffer(pattern, pattern + sizeof(pattern)), utils::buffer(pattern_mask, pattern_mask + sizeof(pattern_mask)) ); unsigned char patch[] = { PUSH_EBX, NOP }; unsigned char patch_mask[] = { 0xFF, 0xFF }; set_patch( 3, utils::buffer(patch, patch + sizeof(patch)), utils::buffer(patch_mask, patch_mask + sizeof(patch_mask)) ); set_name("Netscape 10.1 Win32 topmost patch"); }
void netscape_win32_patch::init() { /* * This is the test inside the Netscape Flash player plugin that starts * the fullscreen window destruction routine when the player loses focus. */ unsigned char pattern[] = { 0x39, 0x9E, 0x14, 0x04, 0x00, 0x00, /* cmp [esi+addr], ebx */ 0x74, 0x47, /* jz short */ 0x53, /* push ebx */ 0x8D, 0x45, /* mov ecx, esi */ 0xF0, 0x50, 0x8B, 0xCE, 0xE8, 0x0A, 0xC3, 0xFF, 0xFF, }; unsigned char pattern_mask[] = { 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, }; set_pattern( utils::buffer(pattern, pattern + sizeof(pattern)), utils::buffer(pattern_mask, pattern_mask + sizeof(pattern_mask)) ); unsigned char patch[] = { JMP }; unsigned char patch_mask[] = { 0xFF }; set_patch( 6, utils::buffer(patch, patch + sizeof(patch)), utils::buffer(patch_mask, patch_mask + sizeof(patch_mask)) ); set_name("Netscape 10.0 Win32 fullscreen patch"); }
int RGBLED::ioctl(device::file_t *filp, int cmd, unsigned long arg) { int ret = ENOTTY; switch (cmd) { case RGBLED_SET_RGB: /* set the specified color */ _r = ((rgbled_rgbset_t *) arg)->red; _g = ((rgbled_rgbset_t *) arg)->green; _b = ((rgbled_rgbset_t *) arg)->blue; send_led_rgb(); return OK; case RGBLED_SET_COLOR: /* set the specified color name */ set_color((rgbled_color_t)arg); send_led_rgb(); return OK; case RGBLED_SET_MODE: /* set the specified mode */ set_mode((rgbled_mode_t)arg); return OK; case RGBLED_SET_PATTERN: /* set a special pattern */ set_pattern((rgbled_pattern_t *)arg); return OK; default: /* see if the parent class can make any use of it */ #ifdef __PX4_NUTTX ret = CDev::ioctl(filp, cmd, arg); #else ret = VDev::ioctl(filp, cmd, arg); #endif break; } return ret; }
void netscape_win32_topmost_patch::init() { /* * This is the call to SetWindowPos that makes the Flash Window topmost. * We don't want to set it to topmost but bring it to the front of the Z-Order instead. */ unsigned char pattern[] = { 0x52, /* push edx */ 0x50, /* push eax (eax is zero here) */ 0x51, /* push ecx */ 0x6A, 0xFF, /* push -1 (this is HWND_TOPMOST) */ 0x53, /* push ebx */ 0xFF, 0x15, 0x00, 0x00, 0x00, 0x00, /* call SetWindowPos */ 0x3B, 0x9E, 0x28, 0x10, 0x00, 0x00 /* cmp ebx, [esi+1028h] */ }; unsigned char pattern_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF }; set_pattern( utils::buffer(pattern, pattern + sizeof(pattern)), utils::buffer(pattern_mask, pattern_mask + sizeof(pattern_mask)) ); unsigned char patch[] = { PUSH_EAX, NOP }; unsigned char patch_mask[] = { 0xFF, 0xFF }; set_patch( 3, utils::buffer(patch, patch + sizeof(patch)), utils::buffer(patch_mask, patch_mask + sizeof(patch_mask)) ); set_name("Netscape 10.0 Win32 topmost patch"); }
void netscape_10_1_win32_patch::init() { /* * This is the test inside the Netscape Flash player that checks for WM_KILLFOCUS * in fullscreen. */ unsigned char pattern[] = { 0x48, /* dec eax */ 0x74, 0x39, /* jz short loc_10181650 */ 0x83, 0xE8, 0x07, /* sub eax, 7 */ 0x74, 0x11, /* jz short loc_1018162D */ 0x83, 0xE8, 0x05, /* sub eax, 5 */ 0x75, 0x13, /* jnz short loc_10181634 */ }; unsigned char pattern_mask[] = { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, }; set_pattern( utils::buffer(pattern, pattern + sizeof(pattern)), utils::buffer(pattern_mask, pattern_mask + sizeof(pattern_mask)) ); unsigned char patch[] = { NOP, NOP }; unsigned char patch_mask[] = { 0xFF, 0xFF }; set_patch( 1, utils::buffer(patch, patch + sizeof(patch)), utils::buffer(patch_mask, patch_mask + sizeof(patch_mask)) ); set_name("Netscape 10.1 Win32 fullscreen patch"); }
LoggerPtr Logger::makeWithSinks(std::string const &name, spdlog::sinks_init_list sinks) { for (auto &sink : sinks) { if (!sink) { std::cerr << "WARNING: " "Logger::makeWithSinks(\"" << name << "\", sinks) called " "with at least one null sink! Will " "result in a fallback logger!" << std::endl; // got a bad sink /// @todo should we be making a fallback logger here, just /// hoping spdlog will deal with a bad sink pointer without /// issue, or filtering the init list to a non-nullptr /// vector? return makeFallback(name); } } auto spd_logger = std::make_shared<spdlog::logger>(name, sinks); spd_logger->set_pattern(DEFAULT_PATTERN); spd_logger->flush_on(convertToLevelEnum(DEFAULT_FLUSH_LEVEL)); return makeLogger(name, spd_logger); }
int RGBLED::ioctl(struct file *filp, int cmd, unsigned long arg) { int ret = ENOTTY; switch (cmd) { case RGBLED_SET_RGB: /* set the specified color */ _r = ((rgbled_rgbset_t *) arg)->red; _g = ((rgbled_rgbset_t *) arg)->green; _b = ((rgbled_rgbset_t *) arg)->blue; send_led_rgb(); return OK; case RGBLED_SET_COLOR: /* set the specified color name */ set_color((rgbled_color_t)arg); send_led_rgb(); return OK; case RGBLED_SET_MODE: /* set the specified mode */ set_mode((rgbled_mode_t)arg); return OK; case RGBLED_SET_PATTERN: /* set a special pattern */ set_pattern((rgbled_pattern_t *)arg); return OK; default: break; } return ret; }
int main(int argc, char* argv[]) { auto loglevel = spdlog::level::info; tec::InitializeComponents(); tec::InitializeFileFactories(); // TODO write a proper arguments parser // Now only search for -v or -vv to set log level for (int i = 1; i < argc; i++) { if (std::string(argv[i]).compare("-v")) { loglevel = spdlog::level::debug; } else if (std::string(argv[i]).compare("-vv")) { loglevel = spdlog::level::trace; } } // Console and logging initialization tec::Console console; spdlog::set_async_mode(1048576); std::vector<spdlog::sink_ptr> sinks; sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>()); sinks.push_back(std::make_shared<tec::ConsoleSink>(console)); auto log = std::make_shared<spdlog::logger>("console_log", begin(sinks), end(sinks)); log->set_level(loglevel); log->set_pattern("%v"); // [%l] [thread %t] %v"); // Format on stdout spdlog::register_logger(log); log->info("Initializing OpenGL..."); tec::OS os; if (!os.InitializeWindow(1024, 768, "TEC 0.1", 3, 3)) { log->info("Exiting. The context wasn't created properly please update drivers and try again."); exit(1); } console.AddConsoleCommand("exit", "exit : Exit from TEC", [&os] (const char* args) { os.Quit(); }); std::thread* asio_thread = nullptr; std::thread* sync_thread = nullptr; tec::Simulation simulation; tec::GameStateQueue game_state_queue; tec::networking::ServerConnection connection; console.AddConsoleCommand("msg", "msg : Send a message to all clients.", [&connection] (const char* args) { const char* end_arg = args; while (*end_arg != '\0') { end_arg++; } // Args now points were the arguments begins std::string message(args, end_arg - args); connection.SendChatMessage(message); }); console.AddConsoleCommand("connect", "connect ip : Connects to the server at ip", [&connection] (const char* args) { const char* end_arg = args; while (*end_arg != '\0' && *end_arg != ' ') { end_arg++; } // Args now points were the arguments begins std::string ip(args, end_arg - args); connection.Connect(ip); }); log->info(std::string("Loading assets from: ") + tec::FilePath::GetAssetsBasePath()); log->info("Initializing GUI system..."); tec::IMGUISystem gui(os.GetWindow()); log->info("Initializing rendering system..."); tec::RenderSystem rs; rs.SetViewportSize(os.GetWindowWidth(), os.GetWindowHeight()); log->info("Initializing simulation system..."); tec::PhysicsSystem& ps = simulation.GetPhysicsSystem(); tec::VComputerSystem vcs; log->info("Initializing sound system..."); tec::SoundSystem ss; std::int64_t frame_id = 1; log->info("Initializing voxel system..."); tec::VoxelSystem vox_sys; log->info("Initializing script system..."); tec::LuaSystem lua_sys; tec::BuildTestEntities(); tec::ProtoLoad(); tec::FPSController* camera_controller = nullptr; gui.AddWindowDrawFunction("connect_window", [&] () { ImGui::SetNextWindowPosCenter(); ImGui::Begin("Connect to Server", NULL, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse); static int octets[4] = {127, 0, 0, 1}; float width = ImGui::CalcItemWidth(); ImGui::PushID("IP"); ImGui::AlignFirstTextHeightToWidgets(); ImGui::TextUnformatted("IP"); ImGui::SameLine(); for (int i = 0; i < 4; i++) { ImGui::PushItemWidth(width / 4.0f); ImGui::PushID(i); bool invalid_octet = false; if (octets[i] > 255) { octets[i] = 255; invalid_octet = true; ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); } if (octets[i] < 0) { octets[i] = 0; invalid_octet = true; ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 0.0f, 1.0f)); } ImGui::InputInt("##v", &octets[i], 0, 0, ImGuiInputTextFlags_CharsDecimal); if (invalid_octet) { ImGui::PopStyleColor(); } ImGui::SameLine(); ImGui::PopID(); ImGui::PopItemWidth(); } ImGui::PopID(); ImGui::SameLine(); if (ImGui::Button("Connect")) { std::stringstream ip; ip << octets[0] << "." << octets[1] << "." << octets[2] << "." << octets[3]; log->info("Connecting to " + ip.str()); connection.Disconnect(); if (connection.Connect(ip.str())) { std::thread on_connect([&simulation, &connection, &camera_controller, &log] () { unsigned int tries = 0; while (connection.GetClientID() == 0) { tries++; if (tries < 2000) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } else { log->error("Failed to get client ID!"); return; } } log->info("You are connected as client ID " + std::to_string(connection.GetClientID())); camera_controller = new tec::FPSController(connection.GetClientID()); tec::Entity camera(connection.GetClientID()); camera.Add<tec::Velocity>(); simulation.AddController(camera_controller); }); on_connect.detach(); gui.HideWindow("connect_window"); asio_thread = new std::thread([&connection] () { connection.StartRead(); }); sync_thread = new std::thread([&connection] () { connection.StartSync(); }); } else { log->error("Failed to connect to " + ip.str()); } } ImGui::End(); ImGui::SetWindowSize("Connect to Server", ImVec2(0, 0)); }); gui.AddWindowDrawFunction("sample_window", [ ] () { ImGui::ShowTestWindow(); }); gui.AddWindowDrawFunction("active_entity", [ ] () { if (tec::active_entity != 0) { ImGui::SetTooltip("#%" PRI_EID, tec::active_entity); } }); gui.ShowWindow("active_entity"); gui.AddWindowDrawFunction("main_menu", [&os, &connection, &gui] () { if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMenu("Connect")) { bool visible = gui.IsWindowVisible("connect_window"); if (ImGui::MenuItem("Connect to server...", "", visible)) { if (visible) { gui.HideWindow("connect_window"); } else { gui.ShowWindow("connect_window"); } } ImGui::EndMenu(); } ImGui::Text("Ping %" PRI_PING_TIME_T, connection.GetAveragePing()); ImGui::EndMainMenuBar(); } }); gui.ShowWindow("main_menu"); gui.AddWindowDrawFunction("ping_times", [&connection] () { ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0)); ImGui::Begin("ping_times", NULL, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs); static float arr[10]; std::list<tec::networking::ping_time_t> recent_pings = connection.GetRecentPings(); std::size_t i = 0; for (tec::networking::ping_time_t ping : recent_pings) { arr[i++] = static_cast<float>(ping); } ImGui::PlotHistogram("Ping", arr, 10, 0, nullptr, 0.0f, 100.0f); ImGui::SetWindowPos("ping_times", ImVec2(ImGui::GetIO().DisplaySize.x - ImGui::GetWindowSize().x - 10, 20)); ImGui::End(); ImGui::SetWindowSize("ping_times", ImVec2(0, 0)); ImGui::PopStyleColor(); }); gui.ShowWindow("ping_times"); gui.AddWindowDrawFunction("console", [&console] () { console.Draw(); }); gui.ShowWindow("console"); double delta = os.GetDeltaTime(); double mouse_x, mouse_y; std::thread ss_thread([&] () { ss.Update(); }); while (!os.Closing()) { os.OSMessageLoop(); delta = os.GetDeltaTime(); ss.SetDelta(delta); std::async(std::launch::async, [&vox_sys, delta] () { vox_sys.Update(delta); }); game_state_queue.Interpolate(delta); const tec::GameState client_state = simulation.Simulate(delta, game_state_queue.GetInterpolatedState()); if (connection.GetClientID() != 0) { tec::proto::Entity self; self.set_id(connection.GetClientID()); if (client_state.positions.find(connection.GetClientID()) != client_state.positions.end()) { tec::Position pos = client_state.positions.at(connection.GetClientID()); pos.Out(self.add_components()); } if (client_state.orientations.find(connection.GetClientID()) != client_state.orientations.end()) { tec::Orientation ori = client_state.orientations.at(connection.GetClientID()); ori.Out(self.add_components()); } if (client_state.velocities.find(connection.GetClientID()) != client_state.velocities.end()) { tec::Velocity vel = client_state.velocities.at(connection.GetClientID()); vel.Out(self.add_components()); } tec::networking::ServerMessage update_message; update_message.SetStateID(connection.GetLastRecvStateID()); update_message.SetMessageType(tec::networking::ENTITY_UPDATE); update_message.SetBodyLength(self.ByteSize()); self.SerializeToArray(update_message.GetBodyPTR(), update_message.GetBodyLength()); update_message.encode_header(); connection.Send(update_message); } vcs.Update(delta); rs.Update(delta, client_state); lua_sys.Update(delta); os.GetMousePosition(&mouse_x, &mouse_y); tec::active_entity = ps.RayCastMousePick(connection.GetClientID(), mouse_x, mouse_y, static_cast<float>(os.GetWindowWidth()), static_cast<float>(os.GetWindowHeight())); //ps.DebugDraw(); if (camera_controller != nullptr) { if (camera_controller->mouse_look) { os.EnableMouseLock(); } else { os.DisableMouseLock(); } } gui.Update(delta); console.Update(delta); os.SwapBuffers(); frame_id++; std::this_thread::sleep_for(std::chrono::milliseconds(1)); } ss.Stop(); ss_thread.join(); connection.Disconnect(); connection.Stop(); if (asio_thread) { asio_thread->join(); } if (sync_thread) { sync_thread->join(); } if (camera_controller) { delete camera_controller; } return 0; }
/************************************* This program can be used to evaluate a jboost-trained classifier on new data. The code contains a single procedure: double predict(void **attr, double *ret) The first argument attr is an array of pointers corresponding to the attributes specified in the spec file. Thus, if attribute i is text, then attr[i] must be a char array; if attribute i is a number, then *attr[i] must be a double; and if attribute i is finite, then *attr[i] must be an int containing the index of the chosen value. An undefined attribute is indicated by setting attr[i] to NULL. Specifically, these pointers are: index attr.type data.type name ------------------------------------------ 0 number double H 1 number double S 2 number double V The second argument ret is a pointer to an array of k doubles, where k is the number of classes. The scores for each of the k classes will be stored in this array. If ret is NULL, then no scores are stored. In any case, predict returns the score for class 0 (=ret[0]). These scores correspond to the classes as follows: index class name ------------------------ 0 non-hedge 1 hedge This classifier was automatically generated by jboost on Tue Jul 13 15:08:29 PDT 2010. *************************************/ double predict_hedge(void **attr, double *r) { int i, j, h, a; HashTableEntry_t *entry; char *s; static char **words = NULL; static int max_word_list_size = 0; int num_words; static char *buffer = NULL; static int buffer_size = 0; char **pat; Prediction_t p; if (!hash_table) { hash_table = (HashTableEntry_t **) malloc(hash_table_size * sizeof(HashTableEntry_t *)); for (i = 0; i < hash_table_size; i++) hash_table[i] = NULL; for (i = 0; i < num_keys; i++) { h = hash(keys[i]); entry = (HashTableEntry_t *) malloc(sizeof(HashTableEntry_t)); entry->key = keys[i]; entry->id = i; entry->next = hash_table[h]; hash_table[h] = entry; } for (i = 0; i < num_text_attr; i++) tokens[text_attr[i]] = (char *) malloc(num_keys * sizeof(char)); } for (i = 0; i < num_text_attr; i++) { a = text_attr[i]; if (!defined_attr(a)) continue; for (j = 0; j < num_keys; j++) tokens[a][j] = 0; while ((int)strlcpy(buffer, (char*)attr[a], buffer_size) >= buffer_size) { buffer_size = 2 * strlen((char*)attr[a]); buffer = (char *) realloc(buffer, (buffer_size+1) * sizeof(char)); } num_words = 0; for (s = strtok(buffer, WHITE_CHARS); s; s = strtok(NULL, WHITE_CHARS)) { if (num_words >= max_word_list_size) { max_word_list_size = 2 * max_word_list_size + 1; words = (char **) realloc(words, max_word_list_size * sizeof(char *)); } words[num_words++] = s; } for (pat = text_patterns[i]; *pat; pat++) { set_pattern(num_words, words, *pat); while (more_tokens()) { s = next_token(); for (entry = hash_table[hash(s)]; entry; entry = entry->next) if (!strcmp(entry->key, s)) { tokens[a][entry->id] = 1; break; } } } } reset_pred(); add_pred( /* R */ -1.5703415908067735); if (defined_attr(0)) { /* R.0 */ if (double_attr(0) <= 38.5) { add_pred( /* R.0:0 */ -2.3084710148438226); if (defined_attr(2)) { /* R.0:0.0 */ if (double_attr(2) <= 151.5) { add_pred( /* R.0:0.0:0 */ -0.684943728771417); if (defined_attr(0)) { /* R.0:0.0:0.0 */ if (double_attr(0) <= 25.5) { add_pred( /* R.0:0.0:0.0:0 */ -2.152760562250308); } else { add_pred( /* R.0:0.0:0.0:1 */ -0.145127144697649); } } } else { add_pred( /* R.0:0.0:1 */ 0.1622785738132802); if (defined_attr(0)) { /* R.0:0.0:1.0 */ if (double_attr(0) <= 32.5) { add_pred( /* R.0:0.0:1.0:0 */ -0.041186232840863486); if (defined_attr(2)) { /* R.0:0.0:1.0:0.0 */ if (double_attr(2) <= 180.5) { add_pred( /* R.0:0.0:1.0:0.0:0 */ 0.05416385221501532); } else { add_pred( /* R.0:0.0:1.0:0.0:1 */ -0.4506307670737777); if (defined_attr(1)) { /* R.0:0.0:1.0:0.0:1.0 */ if (double_attr(1) <= 66.5) { add_pred( /* R.0:0.0:1.0:0.0:1.0:0 */ -1.754297806456438); } else { add_pred( /* R.0:0.0:1.0:0.0:1.0:1 */ -0.149899694117695); } } } } } else { add_pred( /* R.0:0.0:1.0:1 */ 0.4653850048809295); if (defined_attr(1)) { /* R.0:0.0:1.0:1.0 */ if (double_attr(1) <= 118.5) { add_pred( /* R.0:0.0:1.0:1.0:0 */ 0.6200887149640352); if (defined_attr(1)) { /* R.0:0.0:1.0:1.0:0.0 */ if (double_attr(1) <= 66.5) { add_pred( /* R.0:0.0:1.0:1.0:0.0:0 */ -0.3380329805124019); } else { add_pred( /* R.0:0.0:1.0:1.0:0.0:1 */ 0.6620859936891355); if (defined_attr(0)) { /* R.0:0.0:1.0:1.0:0.0:1.0 */ if (double_attr(0) <= 34.5) { add_pred( /* R.0:0.0:1.0:1.0:0.0:1.0:0 */ -0.14966868400232972); } else { add_pred( /* R.0:0.0:1.0:1.0:0.0:1.0:1 */ 0.8345713682188565); if (defined_attr(2)) { /* R.0:0.0:1.0:1.0:0.0:1.0:1.0 */ if (double_attr(2) <= 165.5) { add_pred( /* R.0:0.0:1.0:1.0:0.0:1.0:1.0:0 */ -0.08277050467145954); } else { add_pred( /* R.0:0.0:1.0:1.0:0.0:1.0:1.0:1 */ 1.724622198256853); } } } } } } } else { add_pred( /* R.0:0.0:1.0:1.0:1 */ -0.08361314787282521); if (defined_attr(2)) { /* R.0:0.0:1.0:1.0:1.0 */ if (double_attr(2) <= 192.5) { add_pred( /* R.0:0.0:1.0:1.0:1.0:0 */ 0.16898278163413977); } else { add_pred( /* R.0:0.0:1.0:1.0:1.0:1 */ -1.2517067174856766); } } } } } } if (defined_attr(0)) { /* R.0:0.0:1.1 */ if (double_attr(0) <= 14.5) { add_pred( /* R.0:0.0:1.1:0 */ -2.0774599935917664); } else { add_pred( /* R.0:0.0:1.1:1 */ 0.04230024662743034); } } } } } else { add_pred( /* R.0:1 */ 0.5865117555937588); if (defined_attr(1)) { /* R.0:1.0 */ if (double_attr(1) <= 68.5) { add_pred( /* R.0:1.0:0 */ -1.944954782019729); if (defined_attr(1)) { /* R.0:1.0:0.0 */ if (double_attr(1) <= 60.5) { add_pred( /* R.0:1.0:0.0:0 */ -0.15788699896499447); } else { add_pred( /* R.0:1.0:0.0:1 */ 0.4593615303922345); if (defined_attr(2)) { /* R.0:1.0:0.0:1.0 */ if (double_attr(2) <= 199.5) { add_pred( /* R.0:1.0:0.0:1.0:0 */ 0.03642568762571531); } else { add_pred( /* R.0:1.0:0.0:1.0:1 */ 1.9415332605829128); } } if (defined_attr(0)) { /* R.0:1.0:0.0:1.1 */ if (double_attr(0) <= 46.5) { add_pred( /* R.0:1.0:0.0:1.1:0 */ -0.059521117324528694); } else { add_pred( /* R.0:1.0:0.0:1.1:1 */ 1.646241566882711); } } } } if (defined_attr(0)) { /* R.0:1.0:0.1 */ if (double_attr(0) <= 42.5) { add_pred( /* R.0:1.0:0.1:0 */ 0.5289184865811988); if (defined_attr(2)) { /* R.0:1.0:0.1:0.0 */ if (double_attr(2) <= 172.0) { add_pred( /* R.0:1.0:0.1:0.0:0 */ -0.20716614421251148); } else { add_pred( /* R.0:1.0:0.1:0.0:1 */ 1.7944868441330777); } } } else { add_pred( /* R.0:1.0:0.1:1 */ -0.15342620765351278); } } } else { add_pred( /* R.0:1.0:1 */ 1.3487299349956285); if (defined_attr(0)) { /* R.0:1.0:1.0 */ if (double_attr(0) <= 44.5) { add_pred( /* R.0:1.0:1.0:0 */ -0.3885232916817575); if (defined_attr(0)) { /* R.0:1.0:1.0:0.0 */ if (double_attr(0) <= 39.5) { add_pred( /* R.0:1.0:1.0:0.0:0 */ -1.0183360263129613); if (defined_attr(1)) { /* R.0:1.0:1.0:0.0:0.0 */ if (double_attr(1) <= 130.5) { add_pred( /* R.0:1.0:1.0:0.0:0.0:0 */ 0.6440075359354377); } else { add_pred( /* R.0:1.0:1.0:0.0:0.0:1 */ -0.9755493420011564); } } } else { add_pred( /* R.0:1.0:1.0:0.0:1 */ -0.15689015540920606); if (defined_attr(1)) { /* R.0:1.0:1.0:0.0:1.0 */ if (double_attr(1) <= 172.5) { add_pred( /* R.0:1.0:1.0:0.0:1.0:0 */ -0.09071514039247376); } else { add_pred( /* R.0:1.0:1.0:0.0:1.0:1 */ 1.6527294836981075); } } } } } else { add_pred( /* R.0:1.0:1.0:1 */ 3.3724279930827445); } } if (defined_attr(0)) { /* R.0:1.0:1.1 */ if (double_attr(0) <= 47.5) { add_pred( /* R.0:1.0:1.1:0 */ -0.10069080466293845); if (defined_attr(1)) { /* R.0:1.0:1.1:0.0 */ if (double_attr(1) <= 75.5) { add_pred( /* R.0:1.0:1.1:0.0:0 */ -0.5824831155640398); if (defined_attr(2)) { /* R.0:1.0:1.1:0.0:0.0 */ if (double_attr(2) <= 199.5) { add_pred( /* R.0:1.0:1.1:0.0:0.0:0 */ -0.4329427773351343); } else { add_pred( /* R.0:1.0:1.1:0.0:0.0:1 */ 1.5874355804408251); } } } else { add_pred( /* R.0:1.0:1.1:0.0:1 */ 0.07069970262166185); if (defined_attr(1)) { /* R.0:1.0:1.1:0.0:1.0 */ if (double_attr(1) <= 131.5) { add_pred( /* R.0:1.0:1.1:0.0:1.0:0 */ 0.4995594730986961); if (defined_attr(2)) { /* R.0:1.0:1.1:0.0:1.0:0.0 */ if (double_attr(2) <= 129.5) { add_pred( /* R.0:1.0:1.1:0.0:1.0:0.0:0 */ -1.9891620801262064); } else { add_pred( /* R.0:1.0:1.1:0.0:1.0:0.0:1 */ 0.5268855571387349); if (defined_attr(2)) { /* R.0:1.0:1.1:0.0:1.0:0.0:1.0 */ if (double_attr(2) <= 176.5) { add_pred( /* R.0:1.0:1.1:0.0:1.0:0.0:1.0:0 */ 0.7557279595043741); if (defined_attr(2)) { /* R.0:1.0:1.1:0.0:1.0:0.0:1.0:0.0 */ if (double_attr(2) <= 147.5) { add_pred( /* R.0:1.0:1.1:0.0:1.0:0.0:1.0:0.0:0 */ 0.211471570243803); } else { add_pred( /* R.0:1.0:1.1:0.0:1.0:0.0:1.0:0.0:1 */ 1.865638252988876); } } } else { add_pred( /* R.0:1.0:1.1:0.0:1.0:0.0:1.0:1 */ -0.40404397845501544); } } } } } else { add_pred( /* R.0:1.0:1.1:0.0:1.0:1 */ -0.15509001581110649); if (defined_attr(1)) { /* R.0:1.0:1.1:0.0:1.0:1.0 */ if (double_attr(1) <= 176.5) { add_pred( /* R.0:1.0:1.1:0.0:1.0:1.0:0 */ -0.1173193141226254); if (defined_attr(0)) { /* R.0:1.0:1.1:0.0:1.0:1.0:0.0 */ if (double_attr(0) <= 40.5) { add_pred( /* R.0:1.0:1.1:0.0:1.0:1.0:0.0:0 */ -0.3809983716248288); } else { add_pred( /* R.0:1.0:1.1:0.0:1.0:1.0:0.0:1 */ 0.179767715726413); } } } else { add_pred( /* R.0:1.0:1.1:0.0:1.0:1.0:1 */ 1.8711643753671245); } } } } } } } else { add_pred( /* R.0:1.0:1.1:1 */ 2.2158590253065507); } } if (defined_attr(1)) { /* R.0:1.0:1.2 */ if (double_attr(1) <= 168.5) { add_pred( /* R.0:1.0:1.2:0 */ -0.12643459296681406); } else { add_pred( /* R.0:1.0:1.2:1 */ 1.683688846252166); if (defined_attr(2)) { /* R.0:1.0:1.2:1.0 */ if (double_attr(2) <= 144.5) { add_pred( /* R.0:1.0:1.2:1.0:0 */ 1.5041581364536265); } else { add_pred( /* R.0:1.0:1.2:1.0:1 */ -0.35121334635822976); } } } } } } } } if (defined_attr(2)) { /* R.1 */ if (double_attr(2) <= 176.5) { add_pred( /* R.1:0 */ -1.040053036460521); if (defined_attr(2)) { /* R.1:0.0 */ if (double_attr(2) <= 159.5) { add_pred( /* R.1:0.0:0 */ -0.5124701129328292); if (defined_attr(0)) { /* R.1:0.0:0.0 */ if (double_attr(0) <= 42.5) { add_pred( /* R.1:0.0:0.0:0 */ -0.7305519660811753); if (defined_attr(1)) { /* R.1:0.0:0.0:0.0 */ if (double_attr(1) <= 113.5) { add_pred( /* R.1:0.0:0.0:0.0:0 */ 0.2699968474197122); if (defined_attr(0)) { /* R.1:0.0:0.0:0.0:0.0 */ if (double_attr(0) <= 22.5) { add_pred( /* R.1:0.0:0.0:0.0:0.0:0 */ -1.678264232567051); } else { add_pred( /* R.1:0.0:0.0:0.0:0.0:1 */ 0.17189817039697008); if (defined_attr(1)) { /* R.1:0.0:0.0:0.0:0.0:1.0 */ if (double_attr(1) <= 66.5) { add_pred( /* R.1:0.0:0.0:0.0:0.0:1.0:0 */ -0.86614427496919); if (defined_attr(0)) { /* R.1:0.0:0.0:0.0:0.0:1.0:0.0 */ if (double_attr(0) <= 32.5) { add_pred( /* R.1:0.0:0.0:0.0:0.0:1.0:0.0:0 */ 0.3818265122689831); } else { add_pred( /* R.1:0.0:0.0:0.0:0.0:1.0:0.0:1 */ -1.4081571924827916); } } } else { add_pred( /* R.1:0.0:0.0:0.0:0.0:1.0:1 */ 0.16942954110554106); if (defined_attr(0)) { /* R.1:0.0:0.0:0.0:0.0:1.0:1.0 */ if (double_attr(0) <= 25.5) { add_pred( /* R.1:0.0:0.0:0.0:0.0:1.0:1.0:0 */ -0.3983438230659967); } else { add_pred( /* R.1:0.0:0.0:0.0:0.0:1.0:1.0:1 */ 0.30615347757419353); if (defined_attr(1)) { /* R.1:0.0:0.0:0.0:0.0:1.0:1.0:1.0 */ if (double_attr(1) <= 85.5) { add_pred( /* R.1:0.0:0.0:0.0:0.0:1.0:1.0:1.0:0 */ 0.0076791814589392505); } else { add_pred( /* R.1:0.0:0.0:0.0:0.0:1.0:1.0:1.0:1 */ 0.543328724671646); if (defined_attr(2)) { /* R.1:0.0:0.0:0.0:0.0:1.0:1.0:1.0:1.0 */ if (double_attr(2) <= 129.5) { add_pred( /* R.1:0.0:0.0:0.0:0.0:1.0:1.0:1.0:1.0:0 */ -1.0860218657165563); } else { add_pred( /* R.1:0.0:0.0:0.0:0.0:1.0:1.0:1.0:1.0:1 */ 0.4090273199682347); } } } } } } } } } } } else { add_pred( /* R.1:0.0:0.0:0.0:1 */ -0.3148436971769342); if (defined_attr(0)) { /* R.1:0.0:0.0:0.0:1.0 */ if (double_attr(0) <= 36.5) { add_pred( /* R.1:0.0:0.0:0.0:1.0:0 */ -1.2549844173525702); if (defined_attr(2)) { /* R.1:0.0:0.0:0.0:1.0:0.0 */ if (double_attr(2) <= 147.5) { add_pred( /* R.1:0.0:0.0:0.0:1.0:0.0:0 */ 0.16040740748325924); } else { add_pred( /* R.1:0.0:0.0:0.0:1.0:0.0:1 */ -1.67597996198092); } } } else { add_pred( /* R.1:0.0:0.0:0.0:1.0:1 */ 0.18146753524900283); } } } } } else { add_pred( /* R.1:0.0:0.0:1 */ 0.33979256653282547); if (defined_attr(1)) { /* R.1:0.0:0.0:1.0 */ if (double_attr(1) <= 85.5) { add_pred( /* R.1:0.0:0.0:1.0:0 */ -1.3873673060743354); } else { add_pred( /* R.1:0.0:0.0:1.0:1 */ 1.9815616932116344); } } } } if (defined_attr(2)) { /* R.1:0.0:0.1 */ if (double_attr(2) <= 156.5) { add_pred( /* R.1:0.0:0.1:0 */ -0.022491077963445762); if (defined_attr(0)) { /* R.1:0.0:0.1:0.0 */ if (double_attr(0) <= 27.5) { add_pred( /* R.1:0.0:0.1:0.0:0 */ -0.4420010997405122); } else { add_pred( /* R.1:0.0:0.1:0.0:1 */ 0.08315664104910361); } } } else { add_pred( /* R.1:0.0:0.1:1 */ 0.7332461472729285); } } } else { add_pred( /* R.1:0.0:1 */ 0.8639652909665309); if (defined_attr(0)) { /* R.1:0.0:1.0 */ if (double_attr(0) <= 17.5) { add_pred( /* R.1:0.0:1.0:0 */ -2.7740041174015078); } else { add_pred( /* R.1:0.0:1.0:1 */ 0.5142782849088333); if (defined_attr(2)) { /* R.1:0.0:1.0:1.0 */ if (double_attr(2) <= 172.5) { add_pred( /* R.1:0.0:1.0:1.0:0 */ -0.07445047510288035); } else { add_pred( /* R.1:0.0:1.0:1.0:1 */ 0.2584637871781386); if (defined_attr(0)) { /* R.1:0.0:1.0:1.0:1.0 */ if (double_attr(0) <= 20.5) { add_pred( /* R.1:0.0:1.0:1.0:1.0:0 */ 0.8433102013190467); } else { add_pred( /* R.1:0.0:1.0:1.0:1.0:1 */ 0.07244848447026009); } } } } } } } } if (defined_attr(2)) { /* R.1:0.1 */ if (double_attr(2) <= 164.5) { add_pred( /* R.1:0.1:0 */ -0.30761154583601386); if (defined_attr(0)) { /* R.1:0.1:0.0 */ if (double_attr(0) <= 21.5) { add_pred( /* R.1:0.1:0.0:0 */ -2.497733978950459); } else { add_pred( /* R.1:0.1:0.0:1 */ 0.03075786835793493); } } } else { add_pred( /* R.1:0.1:1 */ 0.5018782446749349); if (defined_attr(1)) { /* R.1:0.1:1.0 */ if (double_attr(1) <= 80.5) { add_pred( /* R.1:0.1:1.0:0 */ -0.08051828521892859); } else { add_pred( /* R.1:0.1:1.0:1 */ 0.3433415314266024); if (defined_attr(2)) { /* R.1:0.1:1.0:1.0 */ if (double_attr(2) <= 167.5) { add_pred( /* R.1:0.1:1.0:1.0:0 */ -0.31430958233547046); } else { add_pred( /* R.1:0.1:1.0:1.0:1 */ 0.23224382427285292); } } } } } } if (defined_attr(1)) { /* R.1:0.2 */ if (double_attr(1) <= 57.5) { add_pred( /* R.1:0.2:0 */ -1.1971298972635522); if (defined_attr(2)) { /* R.1:0.2:0.0 */ if (double_attr(2) <= 161.5) { add_pred( /* R.1:0.2:0.0:0 */ -2.2401358180330604); } else { add_pred( /* R.1:0.2:0.0:1 */ -0.0845333173302181); } } } else { add_pred( /* R.1:0.2:1 */ 0.13737463393850743); } } } else { add_pred( /* R.1:1 */ 1.3181092195632418); if (defined_attr(1)) { /* R.1:1.0 */ if (double_attr(1) <= 30.5) { add_pred( /* R.1:1.0:0 */ -2.5148989017986128); } else { add_pred( /* R.1:1.0:1 */ -0.20409486442827884); if (defined_attr(2)) { /* R.1:1.0:1.0 */ if (double_attr(2) <= 238.5) { add_pred( /* R.1:1.0:1.0:0 */ -0.1858564752004232); if (defined_attr(1)) { /* R.1:1.0:1.0:0.0 */ if (double_attr(1) <= 146.5) { add_pred( /* R.1:1.0:1.0:0.0:0 */ -0.10821366338987466); } else { add_pred( /* R.1:1.0:1.0:0.0:1 */ 0.3037512034560033); if (defined_attr(0)) { /* R.1:1.0:1.0:0.0:1.0 */ if (double_attr(0) <= 41.5) { add_pred( /* R.1:1.0:1.0:0.0:1.0:0 */ -0.047481557682593864); if (defined_attr(2)) { /* R.1:1.0:1.0:0.0:1.0:0.0 */ if (double_attr(2) <= 189.5) { add_pred( /* R.1:1.0:1.0:0.0:1.0:0.0:0 */ 0.4035584528476263); } else { add_pred( /* R.1:1.0:1.0:0.0:1.0:0.0:1 */ -0.6064700805580778); } } } else { add_pred( /* R.1:1.0:1.0:0.0:1.0:1 */ 2.0252941965158313); } } } } } else { add_pred( /* R.1:1.0:1.0:1 */ 2.2747118243108764); } } if (defined_attr(2)) { /* R.1:1.0:1.1 */ if (double_attr(2) <= 249.5) { add_pred( /* R.1:1.0:1.1:0 */ -0.038975390796047615); } else { add_pred( /* R.1:1.0:1.1:1 */ 1.5528355798277673); } } } } } } if (defined_attr(0)) { /* R.2 */ if (double_attr(0) <= 20.5) { add_pred( /* R.2:0 */ -2.610375235184446); } else { add_pred( /* R.2:1 */ -0.2710961215672253); if (defined_attr(2)) { /* R.2:1.0 */ if (double_attr(2) <= 145.5) { add_pred( /* R.2:1.0:0 */ -1.6486691863044591); if (defined_attr(2)) { /* R.2:1.0:0.0 */ if (double_attr(2) <= 140.5) { add_pred( /* R.2:1.0:0.0:0 */ -0.3279373004971422); if (defined_attr(1)) { /* R.2:1.0:0.0:0.0 */ if (double_attr(1) <= 93.5) { add_pred( /* R.2:1.0:0.0:0.0:0 */ -0.9606284812372308); if (defined_attr(2)) { /* R.2:1.0:0.0:0.0:0.0 */ if (double_attr(2) <= 137.5) { add_pred( /* R.2:1.0:0.0:0.0:0.0:0 */ -1.763951131982535); } else { add_pred( /* R.2:1.0:0.0:0.0:0.0:1 */ -0.03726976801059363); } } } else { add_pred( /* R.2:1.0:0.0:0.0:1 */ 0.14395268381709128); } } } else { add_pred( /* R.2:1.0:0.0:1 */ 0.5249514942841438); } } if (defined_attr(1)) { /* R.2:1.0:0.1 */ if (double_attr(1) <= 125.5) { add_pred( /* R.2:1.0:0.1:0 */ 0.3291356091991712); } else { add_pred( /* R.2:1.0:0.1:1 */ -0.2950615190768818); } } } else { add_pred( /* R.2:1.0:1 */ 0.37915004757403853); if (defined_attr(1)) { /* R.2:1.0:1.0 */ if (double_attr(1) <= 46.5) { add_pred( /* R.2:1.0:1.0:0 */ -2.0454621835394784); if (defined_attr(1)) { /* R.2:1.0:1.0:0.0 */ if (double_attr(1) <= 30.5) { add_pred( /* R.2:1.0:1.0:0.0:0 */ -1.3192679722183982); } else { add_pred( /* R.2:1.0:1.0:0.0:1 */ 0.48294605488070363); } } } else { add_pred( /* R.2:1.0:1.0:1 */ 0.5061666509601495); if (defined_attr(1)) { /* R.2:1.0:1.0:1.0 */ if (double_attr(1) <= 124.5) { add_pred( /* R.2:1.0:1.0:1.0:0 */ 0.490348630000452); if (defined_attr(1)) { /* R.2:1.0:1.0:1.0:0.0 */ if (double_attr(1) <= 77.5) { add_pred( /* R.2:1.0:1.0:1.0:0.0:0 */ -0.25321685647558695); if (defined_attr(2)) { /* R.2:1.0:1.0:1.0:0.0:0.0 */ if (double_attr(2) <= 224.5) { add_pred( /* R.2:1.0:1.0:1.0:0.0:0.0:0 */ -0.15151260938623637); } else { add_pred( /* R.2:1.0:1.0:1.0:0.0:0.0:1 */ 2.845621733771073); } } if (defined_attr(0)) { /* R.2:1.0:1.0:1.0:0.0:0.1 */ if (double_attr(0) <= 31.5) { add_pred( /* R.2:1.0:1.0:1.0:0.0:0.1:0 */ -0.5093195262565716); if (defined_attr(2)) { /* R.2:1.0:1.0:1.0:0.0:0.1:0.0 */ if (double_attr(2) <= 189.5) { add_pred( /* R.2:1.0:1.0:1.0:0.0:0.1:0.0:0 */ -0.1419952873717447); } else { add_pred( /* R.2:1.0:1.0:1.0:0.0:0.1:0.0:1 */ -2.1412495690489246); } } if (defined_attr(1)) { /* R.2:1.0:1.0:1.0:0.0:0.1:0.1 */ if (double_attr(1) <= 74.5) { add_pred( /* R.2:1.0:1.0:1.0:0.0:0.1:0.1:0 */ -0.07406036194900878); } else { add_pred( /* R.2:1.0:1.0:1.0:0.0:0.1:0.1:1 */ 0.4135929245369406); } } } else { add_pred( /* R.2:1.0:1.0:1.0:0.0:0.1:1 */ 0.3392695017326207); if (defined_attr(0)) { /* R.2:1.0:1.0:1.0:0.0:0.1:1.0 */ if (double_attr(0) <= 38.5) { add_pred( /* R.2:1.0:1.0:1.0:0.0:0.1:1.0:0 */ 1.0031446705235072); } else { add_pred( /* R.2:1.0:1.0:1.0:0.0:0.1:1.0:1 */ -0.23825439015685795); } } } } } else { add_pred( /* R.2:1.0:1.0:1.0:0.0:1 */ 0.7481038558495774); if (defined_attr(0)) { /* R.2:1.0:1.0:1.0:0.0:1.0 */ if (double_attr(0) <= 33.5) { add_pred( /* R.2:1.0:1.0:1.0:0.0:1.0:0 */ -0.17577526394793988); if (defined_attr(1)) { /* R.2:1.0:1.0:1.0:0.0:1.0:0.0 */ if (double_attr(1) <= 111.5) { add_pred( /* R.2:1.0:1.0:1.0:0.0:1.0:0.0:0 */ 0.23911466099189893); } else { add_pred( /* R.2:1.0:1.0:1.0:0.0:1.0:0.0:1 */ -1.578696913063582); } } } else { add_pred( /* R.2:1.0:1.0:1.0:0.0:1.0:1 */ 1.6628647899159104); if (defined_attr(1)) { /* R.2:1.0:1.0:1.0:0.0:1.0:1.0 */ if (double_attr(1) <= 115.5) { add_pred( /* R.2:1.0:1.0:1.0:0.0:1.0:1.0:0 */ 1.25144328347683); } else { add_pred( /* R.2:1.0:1.0:1.0:0.0:1.0:1.0:1 */ -0.5865273124258277); } } } } } } if (defined_attr(0)) { /* R.2:1.0:1.0:1.0:0.1 */ if (double_attr(0) <= 22.5) { add_pred( /* R.2:1.0:1.0:1.0:0.1:0 */ -0.6843733016020083); } else { add_pred( /* R.2:1.0:1.0:1.0:0.1:1 */ 0.29624089553326993); } } if (defined_attr(2)) { /* R.2:1.0:1.0:1.0:0.2 */ if (double_attr(2) <= 149.5) { add_pred( /* R.2:1.0:1.0:1.0:0.2:0 */ -0.5911350821057278); if (defined_attr(1)) { /* R.2:1.0:1.0:1.0:0.2:0.0 */ if (double_attr(1) <= 117.5) { add_pred( /* R.2:1.0:1.0:1.0:0.2:0.0:0 */ -0.6108223989598811); } else { add_pred( /* R.2:1.0:1.0:1.0:0.2:0.0:1 */ 0.5362523744830769); } } } else { add_pred( /* R.2:1.0:1.0:1.0:0.2:1 */ -0.026421606992493827); } } } else { add_pred( /* R.2:1.0:1.0:1.0:1 */ -0.43640692611804505); if (defined_attr(0)) { /* R.2:1.0:1.0:1.0:1.0 */ if (double_attr(0) <= 43.5) { add_pred( /* R.2:1.0:1.0:1.0:1.0:0 */ -0.4956532793240687); } else { add_pred( /* R.2:1.0:1.0:1.0:1.0:1 */ 2.835703956763267); } } if (defined_attr(0)) { /* R.2:1.0:1.0:1.0:1.1 */ if (double_attr(0) <= 42.5) { add_pred( /* R.2:1.0:1.0:1.0:1.1:0 */ -0.12323362238916509); if (defined_attr(0)) { /* R.2:1.0:1.0:1.0:1.1:0.0 */ if (double_attr(0) <= 33.5) { add_pred( /* R.2:1.0:1.0:1.0:1.1:0.0:0 */ -1.4966855552519744); } else { add_pred( /* R.2:1.0:1.0:1.0:1.1:0.0:1 */ -0.027351295325299976); } } } else { add_pred( /* R.2:1.0:1.0:1.0:1.1:1 */ 1.1483248182182038); } } } } } } } } } } if (defined_attr(0)) { /* R.3 */ if (double_attr(0) <= 28.5) { add_pred( /* R.3:0 */ -0.6163783938814559); if (defined_attr(2)) { /* R.3:0.0 */ if (double_attr(2) <= 182.5) { add_pred( /* R.3:0.0:0 */ -0.2528365530634249); if (defined_attr(0)) { /* R.3:0.0:0.0 */ if (double_attr(0) <= 23.5) { add_pred( /* R.3:0.0:0.0:0 */ -0.27494430137190895); if (defined_attr(1)) { /* R.3:0.0:0.0:0.0 */ if (double_attr(1) <= 62.5) { add_pred( /* R.3:0.0:0.0:0.0:0 */ -1.630577120954592); } else { add_pred( /* R.3:0.0:0.0:0.0:1 */ -0.13231656787855123); } } } else { add_pred( /* R.3:0.0:0.0:1 */ 0.2808067495727751); if (defined_attr(1)) { /* R.3:0.0:0.0:1.0 */ if (double_attr(1) <= 81.5) { add_pred( /* R.3:0.0:0.0:1.0:0 */ -0.13859100533933028); } else { add_pred( /* R.3:0.0:0.0:1.0:1 */ 0.678522861659102); if (defined_attr(0)) { /* R.3:0.0:0.0:1.0:1.0 */ if (double_attr(0) <= 26.5) { add_pred( /* R.3:0.0:0.0:1.0:1.0:0 */ 0.13843447014463545); } else { add_pred( /* R.3:0.0:0.0:1.0:1.0:1 */ 0.9686570177482606); } } } } if (defined_attr(2)) { /* R.3:0.0:0.0:1.1 */ if (double_attr(2) <= 146.5) { add_pred( /* R.3:0.0:0.0:1.1:0 */ -1.5993486150951208); } else { add_pred( /* R.3:0.0:0.0:1.1:1 */ 0.030060253414887064); } } } } if (defined_attr(1)) { /* R.3:0.0:0.1 */ if (double_attr(1) <= 88.5) { add_pred( /* R.3:0.0:0.1:0 */ -0.06789359723070867); } else { add_pred( /* R.3:0.0:0.1:1 */ 0.26859934730275725); if (defined_attr(0)) { /* R.3:0.0:0.1:1.0 */ if (double_attr(0) <= 18.5) { add_pred( /* R.3:0.0:0.1:1.0:0 */ -0.8622713211564897); } else { add_pred( /* R.3:0.0:0.1:1.0:1 */ 0.19370923863529962); if (defined_attr(2)) { /* R.3:0.0:0.1:1.0:1.0 */ if (double_attr(2) <= 176.5) { add_pred( /* R.3:0.0:0.1:1.0:1.0:0 */ 4.6304165261783263E-4); } else { add_pred( /* R.3:0.0:0.1:1.0:1.0:1 */ 1.554734216111625); } } } } } } } else { add_pred( /* R.3:0.0:1 */ -1.6034195912365583); } } } else { add_pred( /* R.3:1 */ 0.3691242897246513); if (defined_attr(0)) { /* R.3:1.0 */ if (double_attr(0) <= 84.5) { add_pred( /* R.3:1.0:0 */ 0.14589718578227953); if (defined_attr(0)) { /* R.3:1.0:0.0 */ if (double_attr(0) <= 52.5) { add_pred( /* R.3:1.0:0.0:0 */ -0.010443579789724959); } else { add_pred( /* R.3:1.0:0.0:1 */ 1.3674815451556133); if (defined_attr(1)) { /* R.3:1.0:0.0:1.0 */ if (double_attr(1) <= 30.5) { add_pred( /* R.3:1.0:0.0:1.0:0 */ -1.459891127193395); } else { add_pred( /* R.3:1.0:0.0:1.0:1 */ 1.4633702623974139); } } } } } else { add_pred( /* R.3:1.0:1 */ -3.384828121964291); } } } } return finalize_pred(); }
std::weak_ptr<spdlog::logger> CLog::GetLogger( log_type _type) { std::weak_ptr<spdlog::logger> logger; try { switch (_type) { case log_type::NETWORK: logger = spdlog::get("net"); break; case log_type::DATABASE: logger = spdlog::get("db"); break; case log_type::GENERAL: default: logger = spdlog::get("server"); break; } if (logger.expired()) { std::ostringstream format; format << "[%H:%M:%S.%e.%f %z] [%L]"; if (level_ <= spdlog::level::debug) format << " [thread %t]"; format << " [%n]" << " %v "; size_t q_size = 1048576; spdlog::set_async_mode(q_size, spdlog::async_overflow_policy::discard_log_msg, nullptr, std::chrono::seconds(30)); std::string path, name; switch (_type) { case log_type::NETWORK: { path = "logs/network"; name = "net"; break; } case log_type::DATABASE: { path = "logs/database"; name = "db"; break; } case log_type::GENERAL: default: { path = "logs/server"; name = "server"; break; } } std::vector<spdlog::sink_ptr> net_sink; #ifdef _WIN32 auto console_sink = std::make_shared<spdlog::sinks::wincolor_stdout_sink_mt>(); net_sink.push_back(console_sink); #else auto console_sink = std::make_shared<spdlog::sinks::ansicolor_sink>(spdlog::sinks::stdout_sink_mt::instance()); //auto daily_sink = std::make_shared<spdlog::sinks::daily_file_sink_mt>( //path.c_str(), "txt", 23, 59); #ifdef SPDLOG_ENABLE_SYSLOG auto syslog_sink = std::make_shared<spdlog::sinks::syslog_sink>(name.c_str()); net_sink.push_back(syslog_sink); #endif net_sink.push_back(console_sink); //net_sink.push_back(daily_sink); #endif auto net_logger = std::make_shared<spdlog::logger>( name.c_str(), begin(net_sink), end(net_sink)); net_logger->set_level(level_); net_logger->set_pattern(format.str()); spdlog::register_logger(net_logger); return net_logger; } } catch (const spdlog::spdlog_ex& ex) { std::cout << "Log failed: " << ex.what() << std::endl; } return logger; }
main(void) { configure(2,2,2,3,1,1); set_pattern(pattern); neu = 1; ziel_id = -1; scanwinkel = 0; aufloes = 44; while(1) { ziel_id = scan(scanwinkel,aufloes,&ziel_entfernung); if (ziel_id == -1) { aufloes = 44; neu = 1; do { if (ziel_id == -1) scanwinkel+=90; ziel_id = scan(scanwinkel,aufloes,&ziel_entfernung); } while (ziel_id == -1); } while ( (aufloes>1) && (neu)) { aufloes = aufloes / 2; scanwinkel = scanwinkel - (aufloes / 2); if (scanwinkel < 0) scanwinkel += 360; ziel_id = scan(scanwinkel,aufloes,&ziel_entfernung); if (ziel_id == -1) scanwinkel += (aufloes*2); } neu = 0; runde = ticks(); if ( runde > (geschossen+49) ) { shoot(scanwinkel,ziel_entfernung); geschossen = ticks(); } else { if (ziel_entfernung > 100) { ladung = battery(); ladung = ladung / 100; switch (ladung) { case 1 : case 2 : case 3 : movement(0,scanwinkel); break; case 4 : case 5 : movement(30,scanwinkel); break; default: movement(50,scanwinkel); } } else movement(0,scanwinkel); } } /* of while(1) */ } /* main() */
void do_test (bool intl, // international? charT which, // which overload to exercise const char *cname, // the name of the charT type const char *tname, // the name of the floating point type int lineno, // line number LongDouble val, // the expected extracted value const char *str, // the sequence to extract from int consumed = -1, // expected number extractions int flags = 0, // initial ios flags int err_expect = -1, // expected final state int frac_digits = 0, // fractional digits const char *fmat = 0, // money_base::pattern const char *cursym = 0, // currency symbol const char *grouping = "") // grouping string { if (!rw_enabled (lineno)) { rw_note (0, __FILE__, __LINE__, "test on line %d disabled", lineno); return; } if (!fmat) { // if fmat isn't set, use the default pattern static const std::money_base::pattern pat = { { std::money_base::symbol, std::money_base::sign, std::money_base::none, std::money_base::value } }; fmat = pat.field; } else fmat = set_pattern (fmat).field; // local format? (the opposite of interantional) const bool locl = !intl; // take care to initialize Punct static data before installing // the facet in case locale or the base facet calls the overridden // virtuals early to cache the results PunctData<charT>::format_ [intl][1].field [0] = fmat [0]; PunctData<charT>::format_ [intl][1].field [1] = fmat [1]; PunctData<charT>::format_ [intl][1].field [2] = fmat [2]; PunctData<charT>::format_ [intl][1].field [3] = fmat [3]; PunctData<charT>::format_ [locl][1].field [0] = fmat [3]; PunctData<charT>::format_ [locl][1].field [1] = fmat [2]; PunctData<charT>::format_ [locl][1].field [2] = fmat [1]; PunctData<charT>::format_ [locl][1].field [3] = fmat [0]; // zero out positive format (not used by money_get) PunctData<charT>::format_ [intl][0] = std::money_base::pattern (); PunctData<charT>::format_ [locl][0] = std::money_base::pattern (); // expand (widen) currency symbol PunctData<charT>::curr_symbol_ [intl] = rw_expand ((charT*)0, cursym); PunctData<charT>::curr_symbol_ [locl] = 0; PunctData<charT>::grouping_ [intl] = grouping; PunctData<charT>::grouping_ [locl] = 0; PunctData<charT>::frac_digits_ [intl] = frac_digits; PunctData<charT>::frac_digits_ [locl] = frac_digits + 1; Ios<charT> io; MoneyGet<charT> mg; // create distinct punctuation facets for each iteration to make sure // any data cached in between successive calls to the facet's public // member functions are flushed if (intl) { const std::moneypunct<charT, true> *pf = new Punct<charT, true>(0); io.imbue (std::locale (io.getloc (), pf)); } else { const std::moneypunct<charT, false> *pf = new Punct<charT, false>(0); io.imbue (std::locale (io.getloc (), pf)); } io.flags (std::ios_base::fmtflags (flags)); // expand (widen) input sequence const charT* const next = rw_expand ((charT*)0, str); std::ios_base::iostate err = std::ios_base::goodbit; const charT *last; if (0 == which) { // exercise get (..., long double) last = next + std::char_traits<charT>::length (next); LongDouble x = 0; last = mg.get (next, last, intl, io, err, x); if (-1 == err_expect) err_expect = err; const int success = !(-1 != consumed && last - next != consumed || err != err_expect); rw_assert (success, __FILE__, lineno, "money_get<%s>::get (%{*Ac}, ..., %b, ..., %s&), " "ate %d, expected %d, frac_digits = %d, " "flags = %{If}, grouping = %#s, pattern = %{LM}, " "state = %{Is}, expected %{Is}", cname, int (sizeof *next), next, intl, tname, last - next, consumed, frac_digits, flags, grouping, fmat, err, err_expect); rw_assert (2 > rw_ldblcmp (x, val), __FILE__, lineno, "money_get<%s>::get (%{*Ac}, ..., %b, ..., %s&), " "got %Lg, expected %Lg, frac_digits = %d, " "flags = %{If}s, grouping = %#s, pattern = %{LM}, " "state = %{Is}, expected %{Is}", cname, int (sizeof *next), next, intl, tname, x, val, frac_digits, flags, grouping, fmat, err, err_expect); } else { // exercise get (..., string_type) static const charT initial[] = { '*', '*', '*', '\0' }; typename std::money_get<charT, const charT*>::string_type bs (initial); last = next + std::char_traits<charT>::length (next); last = mg.get (next, last, intl, io, err, bs); int success = !(-1 != consumed && last - next != consumed || err != err_expect); rw_assert (success, __FILE__, lineno, "money_get<%s>::get (%{*Ac}, ..., %b, ..., " "basic_string<%s>&), ate %d, expected %d, " "frac_digits = %d, flags = %{If}, grouping = %#s" ", format = %{LM}, state = %{Is}, expected %{Is}", cname, int (sizeof *next), next, intl, cname, last - next, consumed, frac_digits, flags, grouping, fmat, err, err_expect); if (success) { char narrow_buf [4096]; rw_narrow (narrow_buf, bs.c_str ()); LongDouble x = 0; // prevent gcc warning: ANSI C does not support // the `L' length modifier const char fmt[] = "%" _RWSTD_LDBL_PRINTF_PREFIX "g"; int n = std::sscanf (narrow_buf, fmt, &x); success = !( err_expect & std::ios::failbit && !*grouping && (1 == n || bs != initial) || !(err_expect & std::ios::failbit) && 1 < rw_ldblcmp (x, val)); rw_assert (success, __FILE__, lineno, "money_get<%s>::get (%{*Ac}, ..., %b, ..., " "basic_string<%s>&), got %s, expected %Lg, " "frac_digits = %d, flags = %{If}, grouping = %#s," " pattern = %{LM}, iostate = %{Is}, expected %{Is}", cname, int (sizeof *next), next, intl, cname, bs.c_str (), val, frac_digits, flags, grouping, fmat, err, err_expect); } } delete[] PunctData<charT>::curr_symbol_ [intl]; delete[] next; }
double predict(void **attr, double *r) { int i, j, h, a; HashTableEntry_t *entry; char *s; static char **words = NULL; static int max_word_list_size = 0; int num_words; static char *buffer = NULL; static int buffer_size = 0; char **pat; Prediction_t p; if (!hash_table) { hash_table = (HashTableEntry_t **) malloc(hash_table_size * sizeof(HashTableEntry_t *)); for (i = 0; i < hash_table_size; i++) hash_table[i] = NULL; for (i = 0; i < num_keys; i++) { h = hash(keys[i]); entry = (HashTableEntry_t *) malloc(sizeof(HashTableEntry_t)); entry->key = keys[i]; entry->id = i; entry->next = hash_table[h]; hash_table[h] = entry; } for (i = 0; i < num_text_attr; i++) tokens[text_attr[i]] = (char *) malloc(num_keys * sizeof(char)); } for (i = 0; i < num_text_attr; i++) { a = text_attr[i]; if (!defined_attr(a)) continue; for (j = 0; j < num_keys; j++) tokens[a][j] = 0; while (strlcpy(buffer, attr[a], buffer_size) >= buffer_size) { buffer_size = 2 * strlen(attr[a]); buffer = (char *) realloc(buffer, (buffer_size+1) * sizeof(char)); } num_words = 0; for (s = strtok(buffer, WHITE_CHARS); s; s = strtok(NULL, WHITE_CHARS)) { if (num_words >= max_word_list_size) { max_word_list_size = 2 * max_word_list_size + 1; words = (char **) realloc(words, max_word_list_size * sizeof(char *)); } words[num_words++] = s; } for (pat = text_patterns[i]; *pat; pat++) { set_pattern(num_words, words, *pat); while (more_tokens()) { s = next_token(); for (entry = hash_table[hash(s)]; entry; entry = entry->next) if (!strcmp(entry->key, s)) { tokens[a][entry->id] = 1; break; } } } } reset_pred(); add_pred( /* R */ -12.749460048194328); if (defined_attr(0)) { /* R.0 */ if (double_attr(0) <= 177.0) { add_pred( /* R.0:0 */ -2.004376634962274); } else { add_pred( /* R.0:1 */ -2.3567817736620276); } } if (defined_attr(29)) { /* R.1 */ if (double_attr(29) <= 3048.5) { add_pred( /* R.1:0 */ -1.338593393492093); } else { add_pred( /* R.1:1 */ -0.6200385657309491); } } if (defined_attr(1)) { /* R.2 */ if (double_attr(1) <= -393.5) { add_pred( /* R.2:0 */ -0.8486933874746179); } else { add_pred( /* R.2:1 */ -1.2644752669813994); } } if (defined_attr(48)) { /* R.3 */ if (double_attr(48) <= 403.0) { add_pred( /* R.3:0 */ -1.376837492407414); } else { add_pred( /* R.3:1 */ -0.41640583184316987); } } return finalize_pred(); }
void PDebug::consoleinit() { // for debugging goes to screen instead logInitialized = true; auto console = spdlog::stdout_logger_mt("pdebug", false); console->set_level(spdlog::level::info); console->set_pattern("PB: %v"); }
static inline int process_article(const struct fileheader *f,int n,const struct boardheader *b){ static const struct flock lck_set={.l_type=F_RDLCK,.l_whence=SEEK_SET,.l_start=0,.l_len=0,.l_pid=0}; static const struct flock lck_clr={.l_type=F_UNLCK,.l_whence=SEEK_SET,.l_start=0,.l_len=0,.l_pid=0}; static struct stat st; static struct tm *p; static char name[BOUND]; static int fd,i,j,k,l; static time_t timestamp; static const char *S,*M,*N; static void *vp; do{ if((timestamp=get_posttime(f))<from||timestamp>to) break; if(ISSET(PARAM_P)&&strcmp(f->owner,post)) break; setbfile(name,b->filename,f->filename); if(stat(name,&st)==-1||!S_ISREG(st.st_mode)||st.st_size<size) break; if((fd=open(name,O_RDONLY #ifdef O_NOATIME |O_NOATIME #endif /* O_NOATIME */ ,0644))==-1) break; if(fcntl(fd,F_SETLKW,&lck_set)==-1){ close(fd); break; } vp=mmap(NULL,st.st_size,PROT_READ,MAP_PRIVATE,fd,0); fcntl(fd,F_SETLKW,&lck_clr); close(fd); if((S=(const char*)vp)==MAP_FAILED) break; for(p=NULL,j=0,i=0;S[i]&&i<st.st_size;i++){ #define EQUAL(cp,cs) (((cp)==(cs))||(ISSET(PARAM_I)&&((cp)==toupper(cs)))) while(j>0&&!EQUAL(P[j],S[i])) j=L[j-1]; if(EQUAL(P[j],S[i])) j++; if(!P[j]){ M=&S[l=((i-j)+1)]; if(!ISSET(PARAM_N)){ for(k=0,N=M;!(N<S);N--) if((*N)&0x80) k++; if(!(k&0x01)) continue; } if(!p&&!(p=localtime(×tamp))) continue; count++; fprintf(out,"%6d %-20.20s %4d %4s %04d%02d%02d%02d%02d%02d %-17.17s %6d %-13.13s %s\n", n,b->filename,current,mode,(p->tm_year+1900),(p->tm_mon+1),(p->tm_mday), (p->tm_hour),(p->tm_min),(p->tm_sec),f->filename,l,f->owner,f->title); if(ISSET(PARAM_S)) break; j=L[j-1]; } #undef EQUAL } munmap(vp,st.st_size); number++; } while(0); return 0; } static inline int process_board(const struct boardheader *b,int n,void *v){ static char name[BOUND]; do{ if(ISSET(PARAM_A)) break; if(ISSET(PARAM_U)){ if(!check_read_perm(user,b)) return -1; break; } if(ISSET(PARAM_B)) break; if(!public_board(b)) return -2; } while(0); current=n; if(!ISSET(PARAM_Q)) fprintf(stdout,"正在处理版面 %-29.29s ... ",b->filename); if(!ISSET(PARAM_E)){ mode="版面"; setbdir(DIR_MODE_NORMAL,name,b->filename); APPLY_RECORD(name,process_article,sizeof(struct fileheader),b,0,true); } if(ISSET(PARAM_D)){ mode="回收"; setbdir(DIR_MODE_DELETED,name,b->filename); APPLY_RECORD(name,process_article,sizeof(struct fileheader),b,0,true); } if(ISSET(PARAM_J)){ mode="自删"; setbdir(DIR_MODE_JUNK,name,b->filename); APPLY_RECORD(name,process_article,sizeof(struct fileheader),b,0,true); } if(!ISSET(PARAM_Q)) fprintf(stdout,"%s\n","处理完成!"); return 0; } int main(int argc,char **argv){ #define EXIT(msg) do{fprintf(stderr,"%s\n",(msg));if(out)fclose(out);exit(__LINE__);}while(0) const struct boardheader *board; char name[BOUND],path[BOUND]; const char *desc; int ret; double cost; if(!getcwd(path,BOUND)) EXIT("获取当前工作目录时发生错误"); if(chdir(BBSHOME)==-1) EXIT("切换工作目录时发生错误..."); if((mark=time(NULL))==(time_t)(-1)) EXIT("获取时间时发生错误..."); resolve_ucache(); resolve_boards(); to=mark; opterr=0; while((ret=getopt(argc,argv,"r:f:t:ab:u:p:djesnio:qh"))!=-1){ switch(ret){ #define CHECK_CONFLICT(param) do{if(ISSET(param))EXIT("给定的选项间存在冲突...");}while(0) #define CHECK_DEPENDENCE(param) do{if(!ISSET(param))EXIT("给定的选项间缺少依赖...");}while(0) #define CHECK_DUP(param) do{if(ISSET(param))EXIT("给定的选项中存在重复...");}while(0) #define SET(param) do{CHECK_DUP(param);flag|=(param);}while(0) case 'r': CHECK_CONFLICT(PARAM_F|PARAM_T); SET(PARAM_R); do{ struct tm t,*p; int n; if(!isdigit(optarg[0])) EXIT("选项 -r 的参数无法解析..."); n=atoi(optarg); if(!(p=localtime(&mark))) EXIT("解析时间时发生错误..."); memcpy(&t,p,sizeof(struct tm)); t.tm_hour=0; t.tm_min=0; t.tm_sec=0; if((from=mktime(&t))==(time_t)(-1)) EXIT("设定时间时发生错误..."); } while(0); break; #define PARSE2(p) ((((p)[0]*10)+((p)[1]*1))-('0'*11)) #define PARSE4(p) ((PARSE2(p)*100)+(PARSE2(&(p)[2])*1)) case 'f': CHECK_CONFLICT(PARAM_R); SET(PARAM_F); do{ struct tm t; int i; for(i=0;optarg[i];i++) if(!isdigit(optarg[i])) break; if(i!=14) EXIT("选项 -f 的参数无法解析..."); memset(&t,0,sizeof(struct tm)); t.tm_year=(PARSE4(optarg)-1900); t.tm_mon=(PARSE2(&optarg[4])-1); t.tm_mday=PARSE2(&optarg[6]); t.tm_hour=PARSE2(&optarg[8]); t.tm_min=PARSE2(&optarg[10]); t.tm_sec=PARSE2(&optarg[12]); if((from=mktime(&t))==(time_t)(-1)) EXIT("设定时间时发生错误..."); } while(0); break; case 't': CHECK_CONFLICT(PARAM_R); SET(PARAM_T); do{ struct tm t; int i; for(i=0;optarg[i];i++) if(!isdigit(optarg[i])) break; if(i!=14) EXIT("选项 -t 的参数无法解析..."); memset(&t,0,sizeof(struct tm)); t.tm_year=(PARSE4(optarg)-1900); t.tm_mon=(PARSE2(&optarg[4])-1); t.tm_mday=PARSE2(&optarg[6]); t.tm_hour=PARSE2(&optarg[8]); t.tm_min=PARSE2(&optarg[10]); t.tm_sec=PARSE2(&optarg[12]); if((from=mktime(&t))==(time_t)(-1)) EXIT("设定时间时发生错误..."); } while(0); break; #undef PARSE2 #undef PARSE4 case 'a': CHECK_CONFLICT(PARAM_B|PARAM_U); SET(PARAM_A); break; case 'b': CHECK_CONFLICT(PARAM_A|PARAM_U); SET(PARAM_B); if(!(current=getbid(optarg,&board))) EXIT("选项 -b 所指定的版面无法获取..."); break; case 'u': CHECK_CONFLICT(PARAM_A|PARAM_B); SET(PARAM_U); do{ struct userec *u; if(!getuser(optarg,&u)) EXIT("选项 -u 所指定的用户无法获取..."); user=u; } while(0); break; case 'p': SET(PARAM_P); snprintf(post,OWNER_LEN,"%s",optarg); break; case 'd': SET(PARAM_D); break; case 'j': SET(PARAM_J); break; case 'e': CHECK_DEPENDENCE(PARAM_D|PARAM_J); SET(PARAM_E); break; case 's': SET(PARAM_S); break; case 'n': SET(PARAM_N); break; case 'i': SET(PARAM_I); break; case 'o': SET(PARAM_O); if(optarg[0]!='/') snprintf(name,BOUND,"%s/%s",path,optarg); else snprintf(name,BOUND,"%s",optarg); break; case 'q': SET(PARAM_Q); break; case 'h': usage(); return 0; default: usage(); EXIT("不可识别的选项..."); break; #undef CHECK_CONFLICT #undef CHECK_DEPENDENCE #undef CHECK_DUP #undef SET } } if(from>to){ usage(); EXIT("当前时间设定不合法..."); } if(!ISSET(PARAM_Q)&&setvbuf(stdout,NULL,_IONBF,BUFSIZ)) EXIT("调整文件缓冲时发生错误..."); if((argc-optind)!=1){ usage(); EXIT("不可识别的参数..."); } set_pattern(argv[optind]); set_link(argv[optind]); if(!size) EXIT("模式串不能为空串..."); if(!ISSET(PARAM_O)) snprintf(name,BOUND,"%s/res_%lu.us",path,mark); if(!(out=fopen(name,"w"))) EXIT("打开文件时发生错误..."); fprintf(out,"%6s %-20.20s %4s %4s %-14.14s %-17.17s %6s %-13.13s %s\n", "文章号","版面名称"," BID","位置","发表时间","文件名","偏移量","作者","标题"); if(!(P[0]&0x80)) flag|=PARAM_N; if(ISSET(PARAM_B)) process_board(board,current,NULL); else APPLY_BIDS(process_board,NULL); fclose(out); cost=difftime(time(NULL),mark); if(cost>86400){ cost/=86400; desc="天"; } else if(cost>3600){ cost/=3600; desc="小时"; } else if(cost>60){ cost/=60; desc="分钟"; } else desc="秒"; fprintf(stdout,"\n操作已完成! 共处理 %d 篇文章, 获得 %d 处匹配, 耗时 %.2lf %s!\n", number,count,cost,desc); return 0; #undef EXIT }
/* main update function called at 50Hz */ void ExternalLED::update(void) { // reduce update rate from 50hz to 10hz _counter++; if (_counter < 5) { return; } _counter = 0; // internal counter used to control step of armed and gps led _counter2++; if (_counter2 >= 10) { _counter2 = 0; } // initialising if (AP_Notify::flags.initialising) { // blink arming and gps leds at 5hz switch(_counter2) { case 0: case 2: case 4: case 6: case 8: armed_led(true); gps_led(false); break; case 1: case 3: case 5: case 7: case 9: armed_led(false); gps_led(true); break; } return; } // arming led control if (AP_Notify::flags.armed) { armed_led(true); }else{ // blink arming led at 2hz switch(_counter2) { case 0: case 1: case 2: case 5: case 6: case 7: armed_led(false); break; case 3: case 4: case 8: case 9: armed_led(true); break; } } // GPS led control switch (AP_Notify::flags.gps_status) { case 0: // no GPS attached gps_led(false); break; case 1: case 2: // GPS attached but no lock, blink at 4Hz switch(_counter2) { // Pattern: 3(off), 2(on), 3(off), 2(on), repeat case 0: case 1: case 2: case 5: case 6: case 7: gps_led(false); break; case 3: case 4: case 8: case 9: gps_led(true); break; } break; case 3: // solid blue on gps lock gps_led(true); break; } // motor led control // if we are displaying a pattern complete it if (_pattern != NONE) { _pattern_counter++; switch(_pattern) { case NONE: // do nothing break; case FAST_FLASH: switch(_pattern_counter) { case 1: case 3: case 5: case 7: case 9: motor_led1(true); motor_led2(true); break; case 2: case 4: case 6: case 8: motor_led1(false); motor_led2(false); break; case 10: motor_led1(false); motor_led2(false); set_pattern(NONE); break; } break; case OSCILLATE: switch(_pattern_counter) { case 1: motor_led1(true); motor_led2(false); break; case 4: motor_led1(false); motor_led2(true); break; case 6: set_pattern(NONE); break; } break; } }else{ if (AP_Notify::flags.failsafe_battery || AP_Notify::flags.failsafe_radio) { // radio or battery failsafe indicated by fast flashing set_pattern(FAST_FLASH); } else { // otherwise do whatever the armed led is doing motor_led1(_flags.armedled_on); motor_led2(_flags.armedled_on); } } }
RegExFilter::RegExFilter(const char* pattern, const CaseSensivity case_sensivity) : impl(new Impl()) { set_pattern(pattern, case_sensivity); }
/* XXX MDL20161018 should only be invoked after all instances of EventHandlers are * destroyed. This is the expected case and the user should not have to * do anything special */ void onExit() { /* For SynchroTraceSim thread scheduling * and CPI calculations */ std::string pthread_metadata(EventHandlers::output_directory + "/sigil.pthread.out"); std::string stats_metadata(EventHandlers::output_directory + "/sigil.stats.out"); std::ofstream pthread_file(pthread_metadata, std::ios::trunc | std::ios::out); std::ofstream stats_file(stats_metadata, std::ios::trunc | std::ios::out); if (pthread_file.fail() == true) { SigiLog::fatal("Failed to open: " + pthread_metadata); } else if (stats_file.fail() == true) { SigiLog::fatal("Failed to open: " + stats_metadata); } spdlog::set_sync_mode(); auto pthread_sink = std::make_shared<spdlog::sinks::ostream_sink_st>(pthread_file); auto stats_sink = std::make_shared<spdlog::sinks::ostream_sink_st>(stats_file); auto pthread_logger = spdlog::create(pthread_metadata, {pthread_sink}); auto stats_logger = spdlog::create(stats_metadata, {stats_sink}); pthread_logger->set_pattern("%v"); stats_logger->set_pattern("%v"); /*********************************************************************/ SigiLog::info("Flushing thread metadata to: " + pthread_metadata); /* The order the threads were seen SHOULD match to * the order of thread_t values of the pthread_create * calls. For example, with the valgrind frontend, * the --fair-sched=yes option should make sure each * thread is switched to in the order they were created */ assert(thread_spawns.size() == thread_creates.size()); int create_idx = 1; //skip the first idx, which is the initial thread for (auto &pair : thread_spawns) { /* SynchroTraceSim only supports threads * that were spawned from the original thread */ if (pair.first == 1) { pthread_logger->info("##" + std::to_string(pair.second) + "," + std::to_string(thread_creates[create_idx])); } ++create_idx; //Skip past thread spawns that happened in other threads } /* TODO Confirm with KS and SN how barriers are processed */ /* Iterate through each unique barrier_t address and * aggregate all the associated, participating threads */ for (auto &pair : barrier_participants) { std::ostringstream ss; ss << "**" << pair.first; for (auto &tid : pair.second) { ss << "," << tid; } pthread_logger->info(ss.str()); } pthread_logger->flush(); /*********************************************************************/ /*********************************************************************/ SigiLog::info("Flushing statistics to: " + stats_metadata); StatCounter total_instr_count{0}; for (auto &p : PerThreadStats::per_thread_counts) { stats_logger->info("Thread Stats: " + std::to_string(p.first)); stats_logger->info("\tIOPS : " + std::to_string(std::get<PerThreadStats::Type::IOP>(p.second))); stats_logger->info("\tFLOPS : " + std::to_string(std::get<PerThreadStats::Type::FLOP>(p.second))); stats_logger->info("\tReads : " + std::to_string(std::get<PerThreadStats::Type::Read>(p.second))); stats_logger->info("\tWrites: " + std::to_string(std::get<PerThreadStats::Type::Write>(p.second))); total_instr_count += std::get<PerThreadStats::Type::Instr>(p.second); } stats_logger->info("Total instructions: " + std::to_string(total_instr_count)); stats_logger->flush(); /*********************************************************************/ }
int rapMapMap(int argc, char* argv[]) { std::cerr << "RapMap Mapper\n"; std::string versionString = rapmap::version; TCLAP::CmdLine cmd( "RapMap Mapper", ' ', versionString); cmd.getProgramName() = "rapmap"; TCLAP::ValueArg<std::string> index("i", "index", "The location of the pseudoindex", true, "", "path"); TCLAP::ValueArg<std::string> read1("1", "leftMates", "The location of the left paired-end reads", false, "", "path"); TCLAP::ValueArg<std::string> read2("2", "rightMates", "The location of the right paired-end reads", false, "", "path"); TCLAP::ValueArg<std::string> unmatedReads("r", "unmatedReads", "The location of single-end reads", false, "", "path"); TCLAP::ValueArg<uint32_t> numThreads("t", "numThreads", "Number of threads to use", false, 1, "positive integer"); TCLAP::ValueArg<uint32_t> maxNumHits("m", "maxNumHits", "Reads mapping to more than this many loci are discarded", false, 200, "positive integer"); TCLAP::ValueArg<std::string> outname("o", "output", "The output file (default: stdout)", false, "", "path"); TCLAP::SwitchArg endCollectorSwitch("e", "endCollector", "Use the simpler (and faster) \"end\" collector as opposed to the more sophisticated \"skipping\" collector", false); TCLAP::SwitchArg noout("n", "noOutput", "Don't write out any alignments (for speed testing purposes)", false); cmd.add(index); cmd.add(noout); cmd.add(read1); cmd.add(read2); cmd.add(unmatedReads); cmd.add(outname); cmd.add(numThreads); cmd.add(maxNumHits); cmd.add(endCollectorSwitch); auto consoleSink = std::make_shared<spdlog::sinks::stderr_sink_mt>(); auto consoleLog = spdlog::create("stderrLog", {consoleSink}); try { cmd.parse(argc, argv); bool pairedEnd = (read1.isSet() or read2.isSet()); if (pairedEnd and (read1.isSet() != read2.isSet())) { consoleLog->error("You must set both the -1 and -2 arguments to align " "paired end reads!"); std::exit(1); } if (pairedEnd and unmatedReads.isSet()) { consoleLog->error("You cannot specify both paired-end and unmated " "reads in the input!"); std::exit(1); } if (!pairedEnd and !unmatedReads.isSet()) { consoleLog->error("You must specify input; either both paired-end " "or unmated reads!"); std::exit(1); } std::string indexPrefix(index.getValue()); if (indexPrefix.back() != '/') { indexPrefix += "/"; } if (!rapmap::fs::DirExists(indexPrefix.c_str())) { consoleLog->error("It looks like the index you provided [{}] " "doesn't exist", indexPrefix); std::exit(1); } IndexHeader h; std::ifstream indexStream(indexPrefix + "header.json"); { cereal::JSONInputArchive ar(indexStream); ar(h); } indexStream.close(); if (h.indexType() != IndexType::PSEUDO) { consoleLog->error("The index {} does not appear to be of the " "appropriate type (pseudo)", indexPrefix); std::exit(1); } RapMapIndex rmi; rmi.load(indexPrefix); std::cerr << "\n\n\n\n"; // from: http://stackoverflow.com/questions/366955/obtain-a-stdostream-either-from-stdcout-or-stdofstreamfile // set either a file or cout as the output stream std::streambuf* outBuf; std::ofstream outFile; bool haveOutputFile{false}; if (outname.getValue() == "") { outBuf = std::cout.rdbuf(); } else { outFile.open(outname.getValue()); outBuf = outFile.rdbuf(); haveOutputFile = true; } // Now set the output stream to the buffer, which is // either std::cout, or a file. std::ostream outStream(outBuf); // Must be a power of 2 size_t queueSize{268435456}; spdlog::set_async_mode(queueSize); auto outputSink = std::make_shared<spdlog::sinks::ostream_sink_mt>(outStream); auto outLog = std::make_shared<spdlog::logger>("outLog", outputSink); outLog->set_pattern("%v"); uint32_t nthread = numThreads.getValue(); std::unique_ptr<paired_parser> pairParserPtr{nullptr}; std::unique_ptr<single_parser> singleParserPtr{nullptr}; if (!noout.getValue()) { rapmap::utils::writeSAMHeader(rmi, outLog); } SpinLockT iomutex; { ScopedTimer timer; HitCounters hctrs; consoleLog->info("mapping reads . . . \n\n\n"); if (pairedEnd) { std::vector<std::thread> threads; std::vector<std::string> read1Vec = rapmap::utils::tokenize(read1.getValue(), ','); std::vector<std::string> read2Vec = rapmap::utils::tokenize(read2.getValue(), ','); if (read1Vec.size() != read2Vec.size()) { consoleLog->error("The number of provided files for " "-1 and -2 must be the same!"); std::exit(1); } size_t numFiles = read1Vec.size() + read2Vec.size(); char** pairFileList = new char*[numFiles]; for (size_t i = 0; i < read1Vec.size(); ++i) { pairFileList[2*i] = const_cast<char*>(read1Vec[i].c_str()); pairFileList[2*i+1] = const_cast<char*>(read2Vec[i].c_str()); } size_t maxReadGroup{1000}; // Number of reads in each "job" size_t concurrentFile{2}; // Number of files to read simultaneously pairParserPtr.reset(new paired_parser(4 * nthread, maxReadGroup, concurrentFile, pairFileList, pairFileList+numFiles)); /** Create the threads depending on the collector type **/ if (endCollectorSwitch.getValue()) { EndCollector endCollector(&rmi); for (size_t i = 0; i < nthread; ++i) { threads.emplace_back(processReadsPair<EndCollector, SpinLockT>, pairParserPtr.get(), std::ref(rmi), std::ref(endCollector), &iomutex, outLog, std::ref(hctrs), maxNumHits.getValue(), noout.getValue()); } } else { SkippingCollector skippingCollector(&rmi); for (size_t i = 0; i < nthread; ++i) { threads.emplace_back(processReadsPair<SkippingCollector, SpinLockT>, pairParserPtr.get(), std::ref(rmi), std::ref(skippingCollector), &iomutex, outLog, std::ref(hctrs), maxNumHits.getValue(), noout.getValue()); } } for (auto& t : threads) { t.join(); } delete [] pairFileList; } else { std::vector<std::thread> threads; std::vector<std::string> unmatedReadVec = rapmap::utils::tokenize(unmatedReads.getValue(), ','); size_t maxReadGroup{1000}; // Number of reads in each "job" size_t concurrentFile{1}; stream_manager streams( unmatedReadVec.begin(), unmatedReadVec.end(), concurrentFile); singleParserPtr.reset(new single_parser(4 * nthread, maxReadGroup, concurrentFile, streams)); /** Create the threads depending on the collector type **/ if (endCollectorSwitch.getValue()) { EndCollector endCollector(&rmi); for (size_t i = 0; i < nthread; ++i) { threads.emplace_back(processReadsSingle<EndCollector, SpinLockT>, singleParserPtr.get(), std::ref(rmi), std::ref(endCollector), &iomutex, outLog, std::ref(hctrs), maxNumHits.getValue(), noout.getValue()); } } else { SkippingCollector skippingCollector(&rmi); for (size_t i = 0; i < nthread; ++i) { threads.emplace_back(processReadsSingle<SkippingCollector, SpinLockT>, singleParserPtr.get(), std::ref(rmi), std::ref(skippingCollector), &iomutex, outLog, std::ref(hctrs), maxNumHits.getValue(), noout.getValue()); } } for (auto& t : threads) { t.join(); } } consoleLog->info("Done mapping reads."); consoleLog->info("In total saw {} reads.", hctrs.numReads); consoleLog->info("Final # hits per read = {}", hctrs.totHits / static_cast<float>(hctrs.numReads)); consoleLog->info("Discarded {} reads because they had > {} alignments", hctrs.tooManyHits, maxNumHits.getValue()); consoleLog->info("flushing output"); outLog->flush(); } if (haveOutputFile) { outFile.close(); } return 0; } catch (TCLAP::ArgException& e) { consoleLog->error("Exception [{}] when parsing argument {}", e.error(), e.argId()); return 1; } }