int main(int argc, char *argv[]) { if(argc == 1) { /*Print usage TODO*/ } else if (argc == 2) { init_interface(argv[1], 1, got_packet); } else { init_interface("any", 0, got_packet); } printf("Hello World\n"); return 0; }
void client(char *name, int port) { struct sockaddr_in sockin; int sock; fd_set readfds; fd_set writefds; char buf[4096]; t_curse curse; init_sockin(&sockin, &sock, name, port); init_interface(&curse); while (strcmp(buf, "/part") != 0) { if (strncmp(buf, "/server", 7) == 0) cmd(buf, sock); reset_loop(sock, &readfds); memset(buf, 0, 4096); if (select(sock + 1, &readfds, &writefds, NULL, NULL) != -1) { if (FD_ISSET(sock, &readfds)) send_msg(sock, curse, buf); if (FD_ISSET(0, &readfds)) recup_msg(sock, curse, buf); } } endwin(); close(sock); }
/** * \brief Create the QTouch task. * * \param stack_depth_words Task stack size in 32 bits word. * \param task_priority Task priority. */ void create_qtouch_task(uint16_t stack_depth_words, unsigned portBASE_TYPE task_priority) { enum status_code ret; /** Initialize communication interface */ init_interface(); /** Reset QT device */ qt_hardware_reset(); /** Check communication is ready and able to read Chip ID */ ret = qt_get_comm_ready(); if (ret != STATUS_OK) { while (1) { /** Infinite loop here */ } } /** Read setup block */ qt_read_setup_block(&setup_block); /** Modify setup block parameters for specific example */ demo_set_qt_param(&setup_block); /** Write setup block */ qt_write_setup_block(&setup_block); /** Create the task as described above. */ xTaskCreate(qtouch_task, (const signed char *const) "QTouch", stack_depth_words, NULL, task_priority, NULL); }
int init_interf(void) { aloc_options(); init_options(); init_interface(); endwin(); return 0; }
int hardsid_available(void) { if (init_interface() < 0) { return 0; } return GetHardSIDCount(); }
/** * Start the interface and main client loop */ int interface(struct config* config){ CONFIG = config; init_interface(); fd_set master; fd_set readset; FD_ZERO(&readset); FD_ZERO(&master); FD_SET(config->self.socket, &master); FD_SET(STDIN, &master); int max_sock = config->self.socket; struct timeval tv; while(EXIT == 0){ readset = master; tv.tv_sec = 0; tv.tv_usec = 100; select(max_sock+1, &readset, NULL, NULL, &tv); if(tv.tv_sec == 0 && tv.tv_usec == 0){ if(handle_user() != 0){ perror("BAD THINGS HAPPENED!"); EXIT = 1; } continue; } for(int i = 0; i < max_sock+1; ++i){ if (FD_ISSET(i, &readset)){ if(i == config->self.socket){ if(handle_server(config->self.socket) < 0){ close_interface(); perror("Connection closed to server"); return -1; } }else if(i == STDIN){ handle_user(); } } } refresh(); } return 0; }
/** * @brief Main function logic * * Parse command line options and start running threads * * @note There are no params actually... if you supply one * param, I will assume we are running offline mode with * a pcap file. Otherwise the args will be passed to ngrep * without any type of validation. * */ int main(int argc, char* argv[]) { int ret; //! ngrep thread attributes pthread_attr_t attr; //! ngrep running thread pthread_t exec_t; // Initialize configuration options init_options(); // Parse arguments.. I mean.. if (argc < 2) { // No arguments! usage(argv[0]); return 1; } else if (argc == 2) { // Show offline mode in ui set_option_value("running.mode", "Offline"); set_option_value("running.file", argv[1]); // Assume Offline mode with pcap file if (load_from_file(argv[1]) != 0) { fprintf(stderr, "Error loading data from pcap file %s\n", argv[1]); return 1; } } else { // Show online mode in ui set_option_value("running.mode", "Online"); // Assume online mode, launch ngrep in a thread pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (pthread_create(&exec_t, &attr, (void *) online_capture, argv)) { fprintf(stderr, "Unable to create Exec Thread!\n"); return 1; } pthread_attr_destroy(&attr); } // Initialize interface // This is a blocking call. Interface have user action loops. init_interface(); // Leaving! return ret; }
int main() { // capture any reset reason G_reset_source = MCUSR; // clear the status register by writing ones // (odd, I know, but that is how it is done) MCUSR = 0x1F; // Display on the LCD that serial connection is needed print("Waiting for"); lcd_goto_xy(0, 1); print(" serial conn..."); // This init will block if no serial connection present // so user sees message on LCD to make a connection init_interface(); // Display the user interface over the serial usb // connection serial_check(); print_reset_reason(); print_usb("Welcome to lab 3!\r\n", 19); print_usage(); print_prompt(); // clear "Waiting for connection" message from the LCD clear(); // turn on interrupts sei(); init_motor(); init_encoder(); // set controller for 1000 Hz init_controller_w_rate(50); while (1) { serial_check(); check_for_new_bytes_received(); } return 0; }
int hardsid_open(void) { int res; int chipno; res = init_interface(); if (dll != NULL && has_usb_hardsid) { for (chipno = 0; chipno < 4; chipno++) { HardSID_Lock((BYTE)chipno); } lastaccess_clk = 0; lastaccess_ms = 0; lastaccess_chipno = -1; chipused = -1; ftimer = SetTimer(NULL, ftimer, 1, (TIMERPROC) ftimerproc); } return res; }
/* suites initialization and clean fuctions */ int init_basis(void) { init_interface(); endwin(); return 0; }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif #ifdef ENABLE_LOGGING setupDebug(); #endif int seed = time(NULL); bool verifyexit = false; // set locale to system default setlocale(LC_ALL, ""); #ifdef LOCALIZE bindtextdomain("cataclysm-dda", "lang/mo"); bind_textdomain_codeset("cataclysm-dda", "UTF-8"); textdomain("cataclysm-dda"); #endif //args: world seeding only. argc--; argv++; while (argc) { if(std::string(argv[0]) == "--seed") { argc--; argv++; if(argc) { seed = djb2_hash((unsigned char *)argv[0]); argc--; argv++; } } else if(std::string(argv[0]) == "--jsonverify") { argc--; verifyexit = true; } else { // ignore unknown args. argc--; } argv++; } // ncurses stuff initOptions(); load_options(); // For getting size options initscr(); // Initialize ncurses init_interface(); noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers init_colors(); // See color.cpp // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive std::srand(seed); bool quit_game = false; g = new game; g->init_data(); if(g->game_error()) { exit_handler(-999); } if ( verifyexit ) { item_controller->check_itype_definitions(); item_controller->check_items_of_groups_exist(); MonsterGenerator::generator().check_monster_definitions(); MonsterGroupManager::check_group_definitions(); check_recipe_definitions(); exit_handler(0); } g->init_ui(); if(g->game_error()) { exit_handler(-999); } curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif do { if(!g->opening_screen()) { quit_game = true; } while (!quit_game && !g->do_turn()) ; if (g->game_quit() || g->game_error()) { quit_game = true; } } while (!quit_game); exit_handler(-999); return 0; }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif int seed = time(NULL); bool verifyexit = false; bool check_all_mods = false; // Set default file paths #ifdef PREFIX #define Q(STR) #STR #define QUOTE(STR) Q(STR) PATH_INFO::init_base_path(std::string(QUOTE(PREFIX))); #else PATH_INFO::init_base_path(""); #endif #if (defined USE_HOME_DIR || defined USE_XDG_DIR) PATH_INFO::init_user_dir(); #else PATH_INFO::init_user_dir("./"); #endif PATH_INFO::set_standard_filenames(); MAP_SHARING::setDefaults(); { const char *section_default = nullptr; const char *section_map_sharing = "Map sharing"; const char *section_user_directory = "User directories"; const arg_handler first_pass_arguments[] = { { "--seed", "<string of letters and or numbers>", "Sets the random number generator's seed value", section_default, [&seed](int num_args, const char **params) -> int { if (num_args < 1) return -1; const unsigned char *hash_input = (const unsigned char *) params[0]; seed = djb2_hash(hash_input); return 1; } }, { "--jsonverify", nullptr, "Checks the cdda json files", section_default, [&verifyexit](int, const char **) -> int { verifyexit = true; return 0; } }, { "--check-mods", nullptr, "Checks the json files belonging to cdda mods", section_default, [&check_all_mods](int, const char **) -> int { check_all_mods = true; return 0; } }, { "--basepath", "<path>", "Base path for all game data subdirectories", section_default, [](int num_args, const char **params) { if (num_args < 1) return -1; PATH_INFO::init_base_path(params[0]); PATH_INFO::set_standard_filenames(); return 1; } }, { "--shared", nullptr, "Activates the map-sharing mode", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setSharing(true); MAP_SHARING::setCompetitive(true); MAP_SHARING::setWorldmenu(false); return 0; } }, { "--username", "<name>", "Instructs map-sharing code to use this name for your character.", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::setUsername(params[0]); return 1; } }, { "--addadmin", "<username>", "Instructs map-sharing code to use this name for your character and give you " "access to the cheat functions.", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::addAdmin(params[0]); return 1; } }, { "--adddebugger", "<username>", "Informs map-sharing code that you're running inside a debugger", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::addDebugger(params[0]); return 1; } }, { "--competitive", nullptr, "Instructs map-sharing code to disable access to the in-game cheat functions", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setCompetitive(true); return 0; } }, { "--userdir", "<path>", "Base path for user-overrides to files from the ./data directory and named below", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::init_user_dir(params[0]); PATH_INFO::set_standard_filenames(); return 1; } } }; // The following arguments are dependent on one or more of the previous flags and are run // in a second pass. const arg_handler second_pass_arguments[] = { { "--worldmenu", nullptr, "Enables the world menu in the map-sharing code", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setWorldmenu(true); return true; } }, { "--datadir", "<directory name>", "Sub directory from which game data is loaded", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("datadir", params[0]); PATH_INFO::update_datadir(); return 1; } }, { "--savedir", "<directory name>", "Subdirectory for game saves", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("savedir", params[0]); return 1; } }, { "--configdir", "<directory name>", "Subdirectory for game configuration", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("config_dir", params[0]); PATH_INFO::update_config_dir(); return 1; } }, { "--memorialdir", "<directory name>", "Subdirectory for memorials", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("memorialdir", params[0]); return 1; } }, { "--optionfile", "<filename>", "Name of the options file within the configdir", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("options", params[0]); return 1; } }, { "--keymapfile", "<filename>", "Name of the keymap file within the configdir", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("keymap", params[0]); return 1; } }, { "--autopickupfile", "<filename>", "Name of the autopickup options file within the configdir", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("autopickup", params[0]); return 1; } }, { "--motdfile", "<filename>", "Name of the message of the day file within the motd directory", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("motd", params[0]); return 1; } }, }; // Process CLI arguments. const size_t num_first_pass_arguments = sizeof(first_pass_arguments) / sizeof(first_pass_arguments[0]); const size_t num_second_pass_arguments = sizeof(second_pass_arguments) / sizeof(second_pass_arguments[0]); int saved_argc = --argc; // skip program name const char **saved_argv = (const char **)++argv; while (argc) { if(!strcmp(argv[0], "--help")) { printHelpMessage(first_pass_arguments, num_first_pass_arguments, second_pass_arguments, num_second_pass_arguments); return 0; } else { bool arg_handled = false; for (size_t i = 0; i < num_first_pass_arguments; ++i) { auto &arg_handler = first_pass_arguments[i]; if (!strcmp(argv[0], arg_handler.flag)) { argc--; argv++; int args_consumed = arg_handler.handler(argc, (const char **)argv); if (args_consumed < 0) { printf("Failed parsing parameter '%s'\n", *(argv - 1)); exit(1); } argc -= args_consumed; argv += args_consumed; arg_handled = true; break; } } // Skip other options. if (!arg_handled) { --argc; ++argv; } } } while (saved_argc) { bool arg_handled = false; for (size_t i = 0; i < num_second_pass_arguments; ++i) { auto &arg_handler = second_pass_arguments[i]; if (!strcmp(saved_argv[0], arg_handler.flag)) { --saved_argc; ++saved_argv; int args_consumed = arg_handler.handler(saved_argc, saved_argv); if (args_consumed < 0) { printf("Failed parsing parameter '%s'\n", *(argv - 1)); exit(1); } saved_argc -= args_consumed; saved_argv += args_consumed; arg_handled = true; break; } } // Ingore unknown options. if (!arg_handled) { --saved_argc; ++saved_argv; } } } if (!assure_dir_exist(FILENAMES["user_dir"].c_str())) { printf("Can't open or create %s. Check permissions.\n", FILENAMES["user_dir"].c_str()); exit(1); } setupDebug(); if (setlocale(LC_ALL, "") == NULL) { DebugLog(D_WARNING, D_MAIN) << "Error while setlocale(LC_ALL, '')."; } // Options strings loaded with system locale get_options().init(); get_options().load(); set_language(true); if (initscr() == NULL) { // Initialize ncurses DebugLog( D_ERROR, DC_ALL ) << "initscr failed!"; return 1; } init_interface(); noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers #if !(defined TILES || defined _WIN32 || defined WINDOWS) // For tiles or windows, this is handled already in initscr(). init_colors(); #endif // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive std::srand(seed); g = new game; // First load and initialize everything that does not // depend on the mods. try { g->load_static_data(); if (verifyexit) { if(g->game_error()) { exit_handler(-999); } exit_handler(0); } if (check_all_mods) { // Here we load all the mods and check their // consistency (both is done in check_all_mod_data). g->init_ui(); popup_nowait("checking all mods"); g->check_all_mod_data(); if(g->game_error()) { exit_handler(-999); } // At this stage, the mods (and core game data) // are find and we could start playing, but this // is only for verifying that stage, so we exit. exit_handler(0); } } catch( const std::exception &err ) { debugmsg( "%s", err.what() ); exit_handler(-999); } // Now we do the actual game. g->init_ui(); if(g->game_error()) { exit_handler(-999); } curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif bool quit_game = false; do { if(!g->opening_screen()) { quit_game = true; } while (!quit_game && !g->do_turn()) ; if (g->game_quit() || g->game_error()) { quit_game = true; } } while (!quit_game); exit_handler(-999); return 0; }
/* * The main function checks command line, forks if asked, * launches the subprogram, waits for its death and then * waits until user closes the GUI. */ int main(int argc, char **argv) { args arguments; app_elems interface; int tmp; int child_pipe[2]; char c; memset(&interface, 0, sizeof(app_elems)); memset(&arguments, 0, sizeof(args)); /* Treat command line */ gtk_init(&argc, &argv); if (!(parse_cmdline(argc, argv, &arguments))) return EXIT_FAILURE; /* Fork to background (if asked) */ if (arguments.various & fFLAG) { tmp = fork(); switch (tmp) { case -1: perror("fork"); return EXIT_FAILURE; case 0: if (setsid() == -1) perror("setsid"); /* Child will execute the rest of the code */ break; default: return EXIT_SUCCESS; } } /* Set the signal handler for SIGCHLD */ /* We can't use classic signal handling method (sigaction) here, because calling gtk_main_quit() wouldn't be safe */ g_child_watch_add(-1, cb_child_is_dead, &interface); /* Sub-program will output through this pipe */ if (pipe(child_pipe) == -1) { perror("pipe"); return EXIT_FAILURE; } /* Launch sub-program */ tmp = fork(); switch (tmp) { case -1: perror("fork"); close(child_pipe[0]); close(child_pipe[1]); return EXIT_FAILURE; case 0: /* Child */ close(child_pipe[0]); /* Redirect stdout & stderr to our pipe */ if ((dup2(child_pipe[1], 1) == -1) || (dup2(child_pipe[1], 2) == -1)) { perror("dup2"); return 42; } close(child_pipe[1]); /* Execute the given program */ if (execvp(*(arguments.program), arguments.program) == -1) { perror("execv"); return 42; } return EXIT_SUCCESS; default: /* Parent */ close(child_pipe[1]); /* Create GTK interface */ init_interface(&interface, &arguments, child_pipe[0]); interface.pid_child = tmp; if (arguments.various & sFLAG) gtk_widget_show_all(GTK_WIDGET(interface.window)); /* GTK 'infinite' event loop */ if (!interface.childisdead) gtk_main(); /* Analyze child death */ if (WIFEXITED(interface.childdeath) && WEXITSTATUS(interface.childdeath) == 42) { /* Sub-program didn't start */ fprintf(stderr, _("Program couldn't be launched ...\n")); while (read(child_pipe[0], &c, 1) == 1) { fprintf(stderr, "%c", c); } close(child_pipe[0]); return EXIT_FAILURE; } else { /* Sub-program did start and then died */ if (!gtk_widget_get_visible(GTK_WIDGET(interface.window))) { gtk_widget_show_all(GTK_WIDGET(interface.window)); } GtkWidget *messagefin = gtk_message_dialog_new(GTK_WINDOW(interface.window), GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Sub-program ended !")); gtk_dialog_run(GTK_DIALOG(messagefin)); gtk_widget_destroy(messagefin); gtk_widget_set_sensitive(interface.killbutton, FALSE); gtk_button_set_label(GTK_BUTTON(interface.quitbutton), _("_Quit")); gtk_main(); } close(child_pipe[0]); return EXIT_SUCCESS; } }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif int seed = time(NULL); bool verifyexit = false; bool check_all_mods = false; // Set default file paths #ifdef PREFIX #define Q(STR) #STR #define QUOTE(STR) Q(STR) init_base_path(std::string(QUOTE(PREFIX))); #else PATH_INFO::init_base_path(""); #endif #ifdef USE_HOME_DIR PATH_INFO::init_user_dir(); #else PATH_INFO::init_user_dir("./"); #endif PATH_INFO::set_standart_filenames(); MAP_SHARING::setDefaults(); // Process CLI arguments int saved_argc = --argc; // skip program name char **saved_argv = ++argv; while (argc) { if(std::string(argv[0]) == "--seed") { argc--; argv++; if(argc) { seed = djb2_hash((unsigned char *)argv[0]); argc--; argv++; } } else if(std::string(argv[0]) == "--jsonverify") { argc--; argv++; verifyexit = true; } else if(std::string(argv[0]) == "--check-mods") { argc--; argv++; check_all_mods = true; } else if(std::string(argv[0]) == "--basepath") { argc--; argv++; if(argc) { PATH_INFO::init_base_path(std::string(argv[0])); PATH_INFO::set_standart_filenames(); argc--; argv++; } } else if(std::string(argv[0]) == "--userdir") { argc--; argv++; if (argc) { PATH_INFO::init_user_dir( argv[0] ); PATH_INFO::set_standart_filenames(); argc--; argv++; } } else if(std::string(argv[0]) == "--username") { argc--; argv++; if (argc) { MAP_SHARING::setUsername(std::string(argv[0])); argc--; argv++; } } else if(std::string(argv[0]) == "--addadmin") { argc--; argv++; if (argc) { MAP_SHARING::addAdmin(std::string(argv[0])); argc--; argv++; } } else if(std::string(argv[0]) == "--adddebugger") { argc--; argv++; if (argc) { MAP_SHARING::addDebugger(std::string(argv[0])); argc--; argv++; } } else if(std::string(argv[0]) == "--shared") { argc--; argv++; MAP_SHARING::setSharing(true); MAP_SHARING::setCompetitive(true); MAP_SHARING::setWorldmenu(false); } else if(std::string(argv[0]) == "--competitive") { argc--; argv++; MAP_SHARING::setCompetitive(true); } else { // Skipping other options. argc--; argv++; } } while (saved_argc) { if(std::string(saved_argv[0]) == "--worldmenu") { saved_argc--; saved_argv++; MAP_SHARING::setWorldmenu(true); } else if(std::string(saved_argv[0]) == "--datadir") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("datadir", std::string(saved_argv[0])); PATH_INFO::update_datadir(); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--savedir") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("savedir", std::string(saved_argv[0])); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--configdir") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("config_dir", std::string(saved_argv[0])); PATH_INFO::update_config_dir(); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--optionfile") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("options", std::string(saved_argv[0])); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--keymapfile") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("keymap", std::string(saved_argv[0])); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--autopickupfile") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("autopickup", std::string(saved_argv[0])); saved_argc--; saved_argv++; } } else if(std::string(saved_argv[0]) == "--motdfile") { saved_argc--; saved_argv++; if(saved_argc) { PATH_INFO::update_pathname("motd", std::string(saved_argv[0])); saved_argc--; saved_argv++; } } else { // ignore unknown args. saved_argc--; saved_argv++; } } // setup debug loggind #ifdef ENABLE_LOGGING setupDebug(); #endif // set locale to system default setlocale(LC_ALL, ""); #ifdef LOCALIZE const char *locale_dir; #ifdef __linux__ if (!FILENAMES["base_path"].empty()) { locale_dir = std::string(FILENAMES["base_path"] + "share/locale").c_str(); } else { locale_dir = "lang/mo"; } #else locale_dir = "lang/mo"; #endif // __linux__ bindtextdomain("cataclysm-dda", locale_dir); bind_textdomain_codeset("cataclysm-dda", "UTF-8"); textdomain("cataclysm-dda"); #endif // LOCALIZE // ncurses stuff initOptions(); load_options(); // For getting size options #ifdef LOCALIZE setlocale(LC_ALL, OPTIONS["USE_LANG"].getValue().c_str()); #endif // LOCALIZE if (initscr() == NULL) { // Initialize ncurses DebugLog() << "initscr failed!\n"; return 1; } init_interface(); noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers #if !(defined TILES || defined _WIN32 || defined WINDOWS) // For tiles or windows, this is handled already in initscr(). init_colors(); #endif // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive std::srand(seed); g = new game; // First load and initialize everything that does not // depend on the mods. try { if (!assure_dir_exist(FILENAMES["user_dir"].c_str())) { debugmsg("Can't open or create %s. Check permissions.", FILENAMES["user_dir"].c_str()); exit_handler(-999); } g->load_static_data(); if (verifyexit) { if(g->game_error()) { exit_handler(-999); } exit_handler(0); } if (check_all_mods) { // Here we load all the mods and check their // consistency (both is done in check_all_mod_data). g->init_ui(); popup_nowait("checking all mods"); g->check_all_mod_data(); if(g->game_error()) { exit_handler(-999); } // At this stage, the mods (and core game data) // are find and we could start playing, but this // is only for verifying that stage, so we exit. exit_handler(0); } } catch(std::string &error_message) { if(!error_message.empty()) { debugmsg("%s", error_message.c_str()); } exit_handler(-999); } // Now we do the actuall game g->init_ui(); if(g->game_error()) { exit_handler(-999); } curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif bool quit_game = false; do { if(!g->opening_screen()) { quit_game = true; } while (!quit_game && !g->do_turn()) ; if (g->game_quit() || g->game_error()) { quit_game = true; } } while (!quit_game); exit_handler(-999); return 0; }
/* Run client and the server if needed. */ static void start_moc (const struct parameters *params, lists_t_strs *args) { int server_sock; if (params->foreground) { set_me_server (); server_init (params->debug, params->foreground); server_loop (); return; } server_sock = server_connect (); if (server_sock != -1 && params->only_server) fatal ("Server is already running!"); if (server_sock == -1) { int i = 0; int notify_pipe[2]; ssize_t rc; printf ("Running the server...\n"); /* To notify the client that the server socket is ready */ if (pipe(notify_pipe)) fatal ("pipe() failed: %s", xstrerror (errno)); switch (fork()) { case 0: /* child - start server */ set_me_server (); server_init (params->debug, params->foreground); rc = write (notify_pipe[1], &i, sizeof(i)); if (rc < 0) fatal ("write() to notify pipe failed: %s", xstrerror (errno)); close (notify_pipe[0]); close (notify_pipe[1]); server_loop (); options_free (); decoder_cleanup (); io_cleanup (); files_cleanup (); rcc_cleanup (); common_cleanup (); exit (EXIT_SUCCESS); case -1: fatal ("fork() failed: %s", xstrerror (errno)); default: close (notify_pipe[1]); if (read(notify_pipe[0], &i, sizeof(i)) != sizeof(i)) fatal ("Server exited!"); close (notify_pipe[0]); server_sock = server_connect (); if (server_sock == -1) { perror ("server_connect()"); fatal ("Can't connect to the server!"); } } } if (params->only_server) send_int (server_sock, CMD_DISCONNECT); else { xsignal (SIGPIPE, SIG_IGN); if (!ping_server (server_sock)) fatal ("Can't connect to the server!"); init_interface (server_sock, params->debug, args); interface_loop (); interface_end (); } close (server_sock); }
int main(int argc, char *argv[]) { #ifndef _WIN32 if (geteuid() == 0) { fprintf(stderr, "Running IRC services is root is not recommended."); return 1; } setup_corefile(); #endif memset(&ServicesInfo, 0, sizeof(ServicesInfo)); memset(&ServicesState, 0, sizeof(ServicesState)); ServicesState.configfile = CPATH; ServicesState.logfile = LPATH; ServicesState.pidfile = PPATH; ServicesState.fully_connected = 0; parseargs(&argc, &argv, myopts); if(ServicesState.printversion) { printf("oftc-ircservices: version: %s\n", VERSION); exit(EXIT_SUCCESS); } if(chdir(DPATH)) { perror("chdir"); exit(EXIT_FAILURE); } #ifndef _WIN32 if(!ServicesState.foreground) make_daemon(); else print_startup(getpid()); #endif setup_signals(); memset(&me, 0, sizeof(me)); libio_init(!ServicesState.foreground); init_events(); iorecv_cb = register_callback("iorecv", iorecv_default); connected_cb = register_callback("server connected", server_connected); iosend_cb = register_callback("iosend", iosend_default); OpenSSL_add_all_digests(); init_interface(); check_pidfile(ServicesState.pidfile); init_log(ServicesState.logfile); #ifdef HAVE_RUBY init_ruby(); signal(SIGSEGV, SIG_DFL); #endif init_channel(); init_conf(); init_client(); init_parser(); init_channel_modes(); init_mqueue(); init_tor(); me.from = me.servptr = &me; SetServer(&me); SetMe(&me); dlinkAdd(&me, &me.node, &global_client_list); read_services_conf(TRUE); init_db(); init_uid(); #ifdef HAVE_PYTHON init_python(); #endif init_kill(); write_pidfile(ServicesState.pidfile); ilog(L_NOTICE, "Services Ready"); db_load_driver(); #ifdef USE_SHARED_MODULES if(chdir(MODPATH)) { ilog(L_ERROR, "Could not load core modules from %s: %s", MODPATH, strerror(errno)); exit(EXIT_FAILURE); } /* Go back to DPATH after checking to see if we can chdir to MODPATH */ chdir(DPATH); #else load_all_modules(1); #endif boot_modules(1); connect_server(); for(;;) { while (eventNextTime() <= CurrentTime) eventRun(); execute_callback(do_event_cb); if(events_loop() == -1) { ilog(L_CRIT, "libevent returned error %d", errno); services_die("Libevent returned some sort of error", NO); break; } comm_select(); send_queued_all(); if(dorehash) { ilog(L_INFO, "Got SIGHUP, reloading configuration"); read_services_conf(NO); dorehash = 0; } } return 0; }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif int seed = time(NULL); bool verifyexit = false; bool check_mods = false; std::string dump; dump_mode dmode = dump_mode::TSV; std::vector<std::string> opts; std::string world; /** if set try to load first save in this world on startup */ // Set default file paths #ifdef PREFIX #define Q(STR) #STR #define QUOTE(STR) Q(STR) PATH_INFO::init_base_path(std::string(QUOTE(PREFIX))); #else PATH_INFO::init_base_path(""); #endif #if (defined USE_HOME_DIR || defined USE_XDG_DIR) PATH_INFO::init_user_dir(); #else PATH_INFO::init_user_dir("./"); #endif PATH_INFO::set_standard_filenames(); MAP_SHARING::setDefaults(); { const char *section_default = nullptr; const char *section_map_sharing = "Map sharing"; const char *section_user_directory = "User directories"; const std::array<arg_handler, 12> first_pass_arguments = {{ { "--seed", "<string of letters and or numbers>", "Sets the random number generator's seed value", section_default, [&seed](int num_args, const char **params) -> int { if (num_args < 1) return -1; const unsigned char *hash_input = (const unsigned char *) params[0]; seed = djb2_hash(hash_input); return 1; } }, { "--jsonverify", nullptr, "Checks the cdda json files", section_default, [&verifyexit](int, const char **) -> int { verifyexit = true; return 0; } }, { "--check-mods", "[mods...]", "Checks the json files belonging to cdda mods", section_default, [&check_mods,&opts]( int n, const char *params[] ) -> int { check_mods = true; test_mode = true; for( int i = 0; i < n; ++i ) { opts.emplace_back( params[ i ] ); } return 0; } }, { "--dump-stats", "<what> [mode = TSV] [opts...]", "Dumps item stats", section_default, [&dump,&dmode,&opts](int n, const char *params[]) -> int { if( n < 1 ) { return -1; } test_mode = true; dump = params[ 0 ]; for( int i = 2; i < n; ++i ) { opts.emplace_back( params[ i ] ); } if( n >= 2 ) { if( !strcmp( params[ 1 ], "TSV" ) ) { dmode = dump_mode::TSV; return 0; } else if( !strcmp( params[ 1 ], "HTML" ) ) { dmode = dump_mode::HTML; return 0; } else { return -1; } } return 0; } }, { "--world", "<name>", "Load world", section_default, [&world](int n, const char *params[]) -> int { if( n < 1 ) { return -1; } world = params[0]; return 1; } }, { "--basepath", "<path>", "Base path for all game data subdirectories", section_default, [](int num_args, const char **params) { if (num_args < 1) return -1; PATH_INFO::init_base_path(params[0]); PATH_INFO::set_standard_filenames(); return 1; } }, { "--shared", nullptr, "Activates the map-sharing mode", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setSharing(true); MAP_SHARING::setCompetitive(true); MAP_SHARING::setWorldmenu(false); return 0; } }, { "--username", "<name>", "Instructs map-sharing code to use this name for your character.", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::setUsername(params[0]); return 1; } }, { "--addadmin", "<username>", "Instructs map-sharing code to use this name for your character and give you " "access to the cheat functions.", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::addAdmin(params[0]); return 1; } }, { "--adddebugger", "<username>", "Informs map-sharing code that you're running inside a debugger", section_map_sharing, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; MAP_SHARING::addDebugger(params[0]); return 1; } }, { "--competitive", nullptr, "Instructs map-sharing code to disable access to the in-game cheat functions", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setCompetitive(true); return 0; } }, { "--userdir", "<path>", "Base path for user-overrides to files from the ./data directory and named below", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::init_user_dir(params[0]); PATH_INFO::set_standard_filenames(); return 1; } } }}; // The following arguments are dependent on one or more of the previous flags and are run // in a second pass. const std::array<arg_handler, 9> second_pass_arguments = {{ { "--worldmenu", nullptr, "Enables the world menu in the map-sharing code", section_map_sharing, [](int, const char **) -> int { MAP_SHARING::setWorldmenu(true); return true; } }, { "--datadir", "<directory name>", "Sub directory from which game data is loaded", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("datadir", params[0]); PATH_INFO::update_datadir(); return 1; } }, { "--savedir", "<directory name>", "Subdirectory for game saves", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("savedir", params[0]); return 1; } }, { "--configdir", "<directory name>", "Subdirectory for game configuration", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("config_dir", params[0]); PATH_INFO::update_config_dir(); return 1; } }, { "--memorialdir", "<directory name>", "Subdirectory for memorials", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("memorialdir", params[0]); return 1; } }, { "--optionfile", "<filename>", "Name of the options file within the configdir", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("options", params[0]); return 1; } }, { "--keymapfile", "<filename>", "Name of the keymap file within the configdir", section_user_directory, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("keymap", params[0]); return 1; } }, { "--autopickupfile", "<filename>", "Name of the autopickup options file within the configdir", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("autopickup", params[0]); return 1; } }, { "--motdfile", "<filename>", "Name of the message of the day file within the motd directory", nullptr, [](int num_args, const char **params) -> int { if (num_args < 1) return -1; PATH_INFO::update_pathname("motd", params[0]); return 1; } }, }}; // Process CLI arguments. const size_t num_first_pass_arguments = sizeof(first_pass_arguments) / sizeof(first_pass_arguments[0]); const size_t num_second_pass_arguments = sizeof(second_pass_arguments) / sizeof(second_pass_arguments[0]); int saved_argc = --argc; // skip program name const char **saved_argv = (const char **)++argv; while (argc) { if(!strcmp(argv[0], "--help")) { printHelpMessage(first_pass_arguments.data(), num_first_pass_arguments, second_pass_arguments.data(), num_second_pass_arguments); return 0; } else { bool arg_handled = false; for (size_t i = 0; i < num_first_pass_arguments; ++i) { auto &arg_handler = first_pass_arguments[i]; if (!strcmp(argv[0], arg_handler.flag)) { argc--; argv++; int args_consumed = arg_handler.handler(argc, (const char **)argv); if (args_consumed < 0) { printf("Failed parsing parameter '%s'\n", *(argv - 1)); exit(1); } argc -= args_consumed; argv += args_consumed; arg_handled = true; break; } } // Skip other options. if (!arg_handled) { --argc; ++argv; } } } while (saved_argc) { bool arg_handled = false; for (size_t i = 0; i < num_second_pass_arguments; ++i) { auto &arg_handler = second_pass_arguments[i]; if (!strcmp(saved_argv[0], arg_handler.flag)) { --saved_argc; ++saved_argv; int args_consumed = arg_handler.handler(saved_argc, saved_argv); if (args_consumed < 0) { printf("Failed parsing parameter '%s'\n", *(argv - 1)); exit(1); } saved_argc -= args_consumed; saved_argv += args_consumed; arg_handled = true; break; } } // Ingore unknown options. if (!arg_handled) { --saved_argc; ++saved_argv; } } } if (!assure_dir_exist(FILENAMES["user_dir"].c_str())) { printf("Can't open or create %s. Check permissions.\n", FILENAMES["user_dir"].c_str()); exit(1); } setupDebug(); if (setlocale(LC_ALL, "") == NULL) { DebugLog(D_WARNING, D_MAIN) << "Error while setlocale(LC_ALL, '')."; } else { try { std::locale::global( std::locale( "" ) ); } catch( const std::exception& ) { // if user default locale retrieval isn't implemented by system try{ // default to basic C locale std::locale::global( std::locale::classic() ); } catch( const std::exception &err ) { debugmsg( "%s", err.what() ); exit_handler(-999); } } } get_options().init(); get_options().load(); set_language(); // in test mode don't initialize curses to avoid escape sequences being inserted into output stream if( !test_mode ) { if( initscr() == nullptr ) { // Initialize ncurses DebugLog( D_ERROR, DC_ALL ) << "initscr failed!"; return 1; } init_interface(); noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers } #if !(defined TILES || defined _WIN32 || defined WINDOWS) // For tiles or windows, this is handled already in initscr(). init_colors(); #endif // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive srand(seed); g = new game; // First load and initialize everything that does not // depend on the mods. try { g->load_static_data(); if (verifyexit) { exit_handler(0); } if( !dump.empty() ) { init_colors(); exit( g->dump_stats( dump, dmode, opts ) ? 0 : 1 ); } if( check_mods ) { init_colors(); loading_ui ui( false ); exit( g->check_mod_data( opts, ui ) && !test_dirty ? 0 : 1 ); } } catch( const std::exception &err ) { debugmsg( "%s", err.what() ); exit_handler(-999); } // Now we do the actual game. g->init_ui(); curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif while( true ) { if( !world.empty() ) { if( !g->load( world ) ) { break; } world.clear(); // ensure quit returns to opening screen } else { main_menu menu; if( !menu.opening_screen() ) { break; } } while( !g->do_turn() ); }; exit_handler(-999); return 0; }
int xbd_scan(struct device *self, struct xbd_attach_args *mainbus_xbda, cfprint_t print) { struct xbdreq *xr; struct xbd_attach_args *xbda; xen_disk_t *xd; int i; init_interface(); if (xen_start_info.flags & SIF_PRIVILEGED) setup_sysctl(); #if NXBD > 0 xbd_major = devsw_name2blk("xbd", NULL, 0); #endif #if NWD > 0 xbd_wd_major = devsw_name2blk("wd", NULL, 0); /* XXX Also handle the cdev majors since stuff like * read_sector calls strategy on the cdev. This only works if * all the majors we care about are different. */ xbd_wd_cdev_major = major(devsw_blk2chr(makedev(xbd_wd_major, 0))); #endif #if NSD > 0 xbd_sd_major = devsw_name2blk("sd", NULL, 0); xbd_sd_cdev_major = major(devsw_blk2chr(makedev(xbd_sd_major, 0))); #endif #if NCD > 0 xbd_cd_major = devsw_name2blk("cd", NULL, 0); xbd_cd_cdev_major = major(devsw_blk2chr(makedev(xbd_cd_major, 0))); #endif MALLOC(xr, struct xbdreq *, BLK_RING_SIZE * sizeof(struct xbdreq), M_DEVBUF, M_WAITOK | M_ZERO); #ifdef DEBUG xbd_allxr = xr; #endif /* XXX Xen1.2: We cannot use BLK_RING_SIZE many slots, since * Xen 1.2 keeps indexes masked in the ring and the case where * we queue all slots at once is handled wrong. */ for (i = 0; i < BLK_RING_SIZE - 1; i++) PUT_XBDREQ(&xr[i]); MALLOC(vbd_info, xen_disk_t *, MAX_VBDS * sizeof(xen_disk_t), M_DEVBUF, M_WAITOK); memset(vbd_info, 0, MAX_VBDS * sizeof(xen_disk_t)); nr_vbds = get_vbd_info(vbd_info); if (nr_vbds <= 0) goto out; for (i = 0; i < nr_vbds; i++) { xd = &vbd_info[i]; xbda = get_xbda(xd); if (xbda) { xbda->xa_xd = xd; config_found(self, xbda, print); } } enable_update_events(self); return 0; out: FREE(vbd_info, M_DEVBUF); vbd_info = NULL; FREE(xr, M_DEVBUF); #ifdef DEBUG xbd_allxr = NULL; #endif SLIST_INIT(&xbdreqs); return 0; }
int infInit() { init_interface(); return 0; }
bool CabDiag::tick(Packet* packet) { // Initialize State if (!init) { init = true; press_start_to_exit = true; reset(); switch (state) { case STATE_INTERFACE: init_interface(); break; case STATE_OUTPUT: init_output(); break; case STATE_INPUT: init_input(); break; case STATE_CRT: init_crt(); break; case STATE_MOTORT: init_motor_test(); press_start_to_exit = false; // Not skippable break; } } if (counter == 60) ohud.blit_text_new(7, 23, "PRESS START BUTTON TO EXIT", 0x84); if (press_start_to_exit && counter >= 60 && input.is_pressed(Input::START)) { done = true; } // Tick State switch (state) { case STATE_INTERFACE: tick_interface(packet); break; case STATE_OUTPUT: tick_output(); break; case STATE_INPUT: tick_input(packet); break; case STATE_CRT: break; case STATE_MOTORT: press_start_to_exit = outrun.outputs->diag_motor(packet->ai1, packet->mci, 0); break; } osprites.sprite_copy(); osprites.update_sprites(); otiles.write_tilemap_hw(); oroad.tick(); if (press_start_to_exit) counter++; return done; }
int main(int argc, char *argv[]) { int opt = 10, pid = 0; char config[1024] = {0}; int log_level = 0; FILE *pidfp; memset(&mproxy, 0, sizeof(mcast_proxy)); mproxy.print_level = LOG_PRI_ERROR; mproxy.syslog_level = LOG_PRI_ERROR; while((opt = getopt(argc, argv, "c:d:vp:h")) > 0) { switch (opt) { case 'c': IMP_LOG_DEBUG("config file is %s\n", optarg); strcpy(config, optarg); break; case 'p': IMP_LOG_DEBUG("pid file is %s\n", optarg); strcpy(pid_file, optarg); break; case 'd': /*to do log*/ log_level = atoi(optarg); if(log_level < 0) { IMP_LOG_DEBUG("log level must be greater than 0\n"); exit(1); } if(log_level > LOG_PRI_LOWEST) log_level = LOG_PRI_DEBUG; mproxy.print_level = log_level; IMP_LOG_DEBUG("logLevel = %d\n", log_level); break; case 'v': printf("version: %s\n", IMP_VERSION); exit(1); case 'h': show_usage(); default: show_usage(); } } if(config[0] == 0) { show_usage(); } /* dump current PID */ pid = getpid(); if ((pidfp = fopen(pid_file, "w")) != NULL) { fprintf(pidfp, "%d\n", pid); fclose(pidfp); } atexit(free_resource); signal(SIGTERM, sig_term_handler); signal(SIGINT, sig_term_handler); signal(SIGUSR1, sig_usr1_handler); imp_interface_init(); imp_init_timer(); imp_membership_db_init(); if (load_config(config) == STATUS_NOK || init_interface(&mproxy) == STATUS_NOK || init_mproxy4(&mproxy) == STATUS_NOK || init_mproxy6(&mproxy) == STATUS_NOK) { IMP_LOG_ERROR("exiting.........\n"); free_resource(); exit(1); } add_all_vif(); init_timer(&mproxy); while(1) { struct timeval* tm; fd_set fdset; int max = 0; int resval = 0; FD_ZERO(&fdset); if(mproxy.igmp_socket > 0) FD_SET(mproxy.igmp_socket, &fdset); #ifdef ENABLE_IMP_MLD if(mproxy.mld_socket > 0) FD_SET(mproxy.mld_socket, &fdset); max = mproxy.igmp_socket > mproxy.mld_socket ? mproxy.igmp_socket:mproxy.mld_socket; #else max = mproxy.igmp_socket; #endif tm = imp_check_timer(); resval = select(max + 1, &fdset, NULL, NULL, tm); if(resval == -1) { perror(__FUNCTION__); }else if(resval) IMP_LOG_DEBUG("Data arrive\n"); else IMP_LOG_DEBUG("timeout\n"); if(mproxy.igmp_socket > 0 && FD_ISSET(mproxy.igmp_socket, &fdset)) { mcast_recv_igmp(mproxy.igmp_socket, mproxy.igmp_version); } #ifdef ENABLE_IMP_MLD if (mproxy.mld_socket > 0 && FD_ISSET(mproxy.mld_socket, &fdset)) { mcast_recv_mld(mproxy.mld_socket, mproxy.mld_version); } #endif } free_resource(); del_all_vif(); k_stop4_mproxy(mproxy.igmp_socket); k_stop6_mproxy(mproxy.mld_socket); }
int main(int argc, char* argv[]) { int sockfd, fdmax, i, port; char *host; struct hostent *hp; struct sockaddr_in server_addr; fd_set master; fd_set read_fds; if (argc==4) { host = argv[1]; port = atoi(argv[2]); if(strlen(argv[3]) > NAME_SIZE){ fprintf(stderr, "User name too long"); exit(1); } else{ strcpy(username, argv[3]); printf("%s\n", username); } } else { fprintf(stderr, "usage: ./client <host> <port> <username>\n"); exit(1); } /* translate host name into peer’s IP address */ hp = gethostbyname(host); if (!hp) { fprintf(stderr, "unknown host: %s\n", host); exit(1); } if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("Socket"); exit(1); } server_addr.sin_family = AF_INET; server_addr.sin_port = htons(port); server_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); memset(server_addr.sin_zero, '\0', sizeof server_addr.sin_zero); if(connect(sockfd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) { perror("connect"); exit(1); } printf("%s\n", username); if(send(sockfd, username,sizeof(username), 0) < 0){ perror("name send"); exit(1); } FD_ZERO(&master); FD_ZERO(&read_fds); FD_SET(0, &master); FD_SET(sockfd, &master); fdmax = sockfd; init_interface(); while(1){ read_fds = master; if(select(fdmax+1, &read_fds, NULL, NULL, NULL) == -1){ perror("select"); exit(4); } for(i=0; i <= fdmax; i++ ) if(FD_ISSET(i, &read_fds)) send_recv(i, sockfd); } out_printf("client-quited\n"); close(sockfd); return 0; }