int start() { unsigned short character = 0x00; int ipc_status; message msg; int irq_set_kb = kb_subscribe_int(); int irq_set_timer = timer_subscribe_int(); int irq_set_mouse = mouse_subscribe_int(); int r; unsigned char packet[3]; unsigned short counter = 0; space_invaders_font = font_init("spaceinvader_font_transparent.bmp"); srand(1); options_load(); mouse_init(); init_state(); highscore_load(); vg_init(VBE_VIDEO_MODE); while (1) { //TODO change condition /* Get a request message. */ if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG & irq_set_kb) { /* keyboard interrupt */ character = kb_int_handler(); if (character != KB_2BYTE_SCODE) kb_event_handler(character); } if (msg.NOTIFY_ARG & irq_set_mouse){ /* mouse interrupt */ mouse_int_handler(counter, packet); if(packet[0] != MOUSE_ACK && (packet[0] & BIT(3))) counter++; if(counter == 3){ counter = 0; mouse_event_handler(packet); } } if (msg.NOTIFY_ARG & irq_set_timer){ /* timer interrupt */ timer_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } return 0; }
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hInstNULL, LPSTR lpszCmdLine, int nCmdShow) { setlocale(LC_ALL, "Russian"); CrcGenerateTable(); options_load(); dialog_main(hInstance, NULL); return 0; }
int main(int argc, char* argv[]) { struct ir_remote* remotes; char path[128]; const loglevel_t level = options_get_app_loglevel("irsimreceive"); lirc_log_get_clientlog("irsimreceive", path, sizeof(path)); lirc_log_set_file(path); lirc_log_open("irsimreceive", 1, level); options_load(argc, argv, NULL, parse_options); setup(argv[optind + 1]); remotes = read_lircd_conf(argv[optind]); return simreceive(remotes); }
int main(int argc, const char * const *argv) { apr_pool_t *pool; server_options_t options; const char *log_conf_path; apt_dir_layout_t *dir_layout = NULL; /* APR global initialization */ if(apr_initialize() != APR_SUCCESS) { apr_terminate(); return 0; } /* create APR pool */ pool = apt_pool_create(); if(!pool) { apr_terminate(); return 0; } /* load options */ if(options_load(&options,argc,argv,pool) != TRUE) { apr_pool_destroy(pool); apr_terminate(); return 0; } if(options.dir_layout_conf) { /* create and load directories layout from the configuration file */ dir_layout = apt_dir_layout_create(pool); if(dir_layout) apt_dir_layout_load(dir_layout,options.dir_layout_conf,pool); } else { /* create default directories layout */ dir_layout = apt_default_dir_layout_create(options.root_dir_path,pool); } if(!dir_layout) { printf("Failed to Create Directories Layout\n"); apr_pool_destroy(pool); apr_terminate(); return 0; } /* get path to logger configuration file */ log_conf_path = apt_confdir_filepath_get(dir_layout,"logger.xml",pool); /* create and load singleton logger */ apt_log_instance_load(log_conf_path,pool); if(options.log_priority) { /* override the log priority, if specified in command line */ apt_log_priority_set(atoi(options.log_priority)); } if(options.log_output) { /* override the log output mode, if specified in command line */ apt_log_output_mode_set(atoi(options.log_output)); } if(apt_log_output_mode_check(APT_LOG_OUTPUT_FILE) == TRUE) { /* open the log file */ const char *log_dir_path = apt_dir_layout_path_get(dir_layout,APT_LAYOUT_LOG_DIR); apt_log_file_open(log_dir_path,"unimrcpserver",MAX_LOG_FILE_SIZE,MAX_LOG_FILE_COUNT,TRUE,pool); } if(options.foreground == TRUE) { /* run command line */ uni_cmdline_run(dir_layout,pool); } #ifdef WIN32 else { /* run as windows service */ uni_service_run(options.svcname,dir_layout,pool); } #else else {
void startClient() { char *logfile = "/sdcard/client.out"; FILE *fp; if((fp=freopen("/sdcard/freeciv_out_client.log", "w" ,stdout))==NULL) { printf("Cannot open file.\n"); exit(1); } if((fp=freopen("/sdcard/freeciv_err_client.log", "w" ,stderr))==NULL) { printf("Cannot open file.\n"); exit(1); } setenv ("HOME", "/sdcard/FreeCiv", 0); setenv ("USER", "Sparky", 0); LOGI("Hello JNI"); log_init(logfile, LOG_DEBUG , NULL); int i, loglevel; int ui_options = 0; bool ui_separator = FALSE; char *option=NULL; bool user_tileset = FALSE; i_am_client(); /* Tell to libfreeciv that we are client */ /* Ensure that all AIs are initialized to unused state */ ai_type_iterate(ai) { init_ai(ai); } ai_type_iterate_end; init_our_capability(); (void)user_username(default_user_name, MAX_LEN_NAME); if (!is_valid_username(default_user_name)) { char buf[sizeof(default_user_name)]; my_snprintf(buf, sizeof(buf), "_%s", default_user_name); if (is_valid_username(buf)) { sz_strlcpy(default_user_name, buf); } else { my_snprintf(default_user_name, sizeof(default_user_name), "player%d", myrand(10000)); } } game.all_connections = conn_list_new(); game.est_connections = conn_list_new(); ui_init(); fc_init_network(); init_our_capability(); chatline_common_init(); init_player_dlg_common(); init_themes(); options_init(); strcpy(default_sound_plugin_name,"none"); server_port = 9999; sz_strlcpy(server_host, "localhost"); options_load(); mysrand(time(NULL)); helpdata_init(); boot_help_texts(NULL); LOGI("Reading tilespec"); tilespec_try_read("amplio2", TRUE); LOGI("Done reading tilespec"); overview_size_changed(); audio_real_init("stdsounds", "none"); //audio_play_music("music_start", NULL); auto_connect = TRUE; init_mapcanvas_and_overview(); /* run gui-specific client */ ui_main(0, NULL); /* termination */ client_exit(); return; }
/* MAIN entry point */ int main(int argc, char *argv[]) { int i, n, ret = 0; int config_loop; int verbosity; int detach; kstr *err_msg; struct kdsignal_info sigs[] = { {SIGALRM, kd_SIGALRM_handler }, {SIGINT, kd_SIGINT_handler }, {SIGTERM, kd_SIGTERM_handler }, {SIGCHLD, kd_SIGCHLD_handler }, {SIGUSR1, kd_SIGUSR1_handler }, {SIGHUP, kd_SIGHUP_handler } }; int ignored_sigs[] = {SIGPIPE, 0}; apr_pool_t *server_pool; printf("Teambox Sign-On Server daemon\n"); printf("Copyright (C) 2006-2012 Opersys inc.\n\n"); ktools_initialize(); kmem_set_handler(NULL, NULL, NULL, NULL, kd_abort_handler, NULL); /* Configuration and option setup. 1 - Load the internal defaults. They have the least priority. 2 - Load the configuration file. 3 - Load the command line options, overriding 2 and 1. */ /* Initializes APR. */ apr_initialize(); apr_pool_create(&main_pool, NULL); /* Configuration. */ do { log_open(main_pool); log_set_all_level("syslog", 0); if (options_load(main_pool, opts_tbl, opts_tbl_cnt, CONFIG_PATH "/tbxsosd.conf", kd_options_error_handler, 0) < 0) { kstr str; kstr_init(&str); format_current_error_for_user(&str); fprintf(stderr, "config read error: %s.\n", str.data); kstr_clean(&str); break; } kd_init_logging(); /* Command line stuff. */ if (kd_options_parse(argc, argv) < 0) { ret = -1; break; } /* Load options for local use. No need to check the return value since the values should have been set earlier when parsing the command line. */ detach = options_get_bool("server.detach"); verbosity = options_get_uint32("server.log_verbosity"); log_set_verbosity(verbosity); /* Proceed to static initialization of modules. */ if (kdssl_static_init(main_pool) < 0) { kd_dump_error(); err_msg = kerror_str_n(0); CRITICAL(_log_server_, "SSL initialization failed: %s.", err_msg->data); kstr_destroy(err_msg); ret = -1; break; } if (kdclient_static_init(main_pool) < 0) { kd_dump_error(); err_msg = kerror_str_n(0); ERROR(_log_server_, "Basic initialization failed: %s", err_msg->data); kstr_destroy(err_msg); ret = -1; break; } if (kdkey_static_init() < 0) { kd_dump_error(); err_msg = kerror_str_n(0); ERROR(_log_server_, "Basic initialization failed: %s", err_msg->data); kstr_destroy(err_msg); ret = -1; break; } /* Spawn the master process. */ if (detach && kd_spawn(main_pool) == 0) break; kdsignal_handled(sizeof(sigs) / sizeof(struct kdsignal_info), sigs); kdsignal_ignored(ignored_sigs); apr_pool_create(&server_pool, main_pool); /* Block all signals we say we are handling since it's the job of the server object to handle them. */ kdsignal_block_all_handled(); /* Create the new server object. */ if ((server = kdserver_new(server_pool)) == NULL) { kd_dump_error(); err_msg = kerror_str_n(0); CRITICAL(_log_server_, "Error initializing the server: %s", err_msg->data); kstr_destroy(err_msg); ret = -1; break; } /* At this point, the expected behavior in signal handling can resume. */ kdsignal_unblock_all_handled(); for (i = 0; i < server->ssl_sock_count; i++) INFO(_log_server_, "Listening for SSL on %s:%ld.", inet_ntoa(server->ssl_sock_addr[i]->sin_addr), ntohs(server->ssl_sock_addr[i]->sin_port)); for (i = 0; i < server->n_sock_count; i++) INFO(_log_server_, "Listening on %s:%ld.", inet_ntoa(server->n_sock_addr[i]->sin_addr), ntohs(server->n_sock_addr[i]->sin_port)); /* Loop in the server. This will block until the server quits. */ config_loop = 1; while (config_loop && !ret) { n = kdserver_main(server, main_pool); if (n < 0) { err_msg = kerror_str_n(0); CRITICAL(_log_server_, "Server error: %s", err_msg->data); kstr_destroy(err_msg); ret = - 1; break; } /* Reloading configuration was demanded. */ else if (n == 0 && server->sig_flag & FLAG_REHASH) { INFO(_log_server_, "Reloading configuration."); /* Get rid of this block. */ kdsignal_block_all_handled(); apr_pool_destroy(server_pool); server = NULL; kdsignal_unblock_all_handled(); if (options_reload(main_pool, CONFIG_PATH "/tbxsosd.conf") < 0) { kd_dump_error(); CRITICAL(_log_server_, "config read error"); ret = -1; } if (kdclient_static_init(main_pool) < 0) { kd_dump_error(); err_msg = kerror_str_n(0); CRITICAL(_log_server_, "Basic initialization failed: %s", err_msg->data); kstr_destroy(err_msg); ret = -1; } apr_pool_create(&server_pool, main_pool); /* Block all signals we say we are handling since it's the job of the server object to handle them. */ kdsignal_block_all_handled(); /* Create the new server object. */ if ((server = kdserver_new(server_pool)) == NULL) { kd_dump_error(); err_msg = kerror_str_n(0); CRITICAL(_log_server_, "Error initializing the server: %s", err_msg->data); kstr_destroy(err_msg); ret = -1; break; } /* At this point, the expected behavior in signal handling can resume. */ kdsignal_unblock_all_handled(); } /* Clean quit. */ else if (n == 0) { INFO(_log_server_, "Server terminating."); config_loop = 0; } } } while (0); kdkey_static_clean(); apr_pool_destroy(main_pool); apr_terminate(); ktools_finalize(); return ret; }