boolean_t get_current_profile(int fd, int *profile) { size_t i; uchar_t smallbuf[8]; size_t buflen; uchar_t *bufp; int ret = B_FALSE; /* * first determine amount of memory needed to hold all profiles. * The first four bytes of smallbuf concatenated tell us the * number of bytes of memory we need but do not take themselves * into account. Therefore, add four to allocate that number * of bytes. */ if (get_configuration(fd, 0, 8, &smallbuf[0])) { buflen = GET32(smallbuf) + 4; bufp = (uchar_t *)malloc(buflen); /* now get all profiles */ if (get_configuration(fd, 0, buflen, bufp)) { *profile = GET16(&bufp[6]); ret = B_TRUE; } free(bufp); } return (ret); }
static int lua_likwid_getConfiguration(lua_State* L) { int ret = 0; if (config_isInitialized == 0) { ret = init_configuration(); if (ret == 0) { config_isInitialized = 1; configfile = get_configuration(); } else { lua_newtable(L); lua_pushstring(L, "configFile"); lua_pushnil(L); lua_settable(L,-3); lua_pushstring(L, "topologyFile"); lua_pushnil(L); lua_settable(L,-3); lua_pushstring(L, "daemonPath"); lua_pushnil(L); lua_settable(L,-3); lua_pushstring(L, "daemonMode"); lua_pushinteger(L, -1); lua_settable(L,-3); lua_pushstring(L, "maxNumThreads"); lua_pushinteger(L, MAX_NUM_THREADS); lua_settable(L,-3); lua_pushstring(L, "maxNumNodes"); lua_pushinteger(L, MAX_NUM_NODES); lua_settable(L,-3); return 1; } } if ((config_isInitialized) && (configfile == NULL)) { configfile = get_configuration(); } lua_newtable(L); lua_pushstring(L, "configFile"); lua_pushstring(L, configfile->configFileName); lua_settable(L,-3); lua_pushstring(L, "topologyFile"); lua_pushstring(L, configfile->topologyCfgFileName); lua_settable(L,-3); lua_pushstring(L, "daemonPath"); lua_pushstring(L, configfile->daemonPath); lua_settable(L,-3); lua_pushstring(L, "daemonMode"); lua_pushinteger(L, (int)configfile->daemonMode); lua_settable(L,-3); lua_pushstring(L, "maxNumThreads"); lua_pushinteger(L, configfile->maxNumThreads); lua_settable(L,-3); lua_pushstring(L, "maxNumNodes"); lua_pushinteger(L, configfile->maxNumNodes); lua_settable(L,-3); return 1; }
void invocation(const ComType com, const uint8_t *data) { switch(((StandardMessage*)data)->header.fid) { case FID_SET_CONFIGURATION: { set_configuration(com, (SetConfiguration*)data); return; } case FID_GET_CONFIGURATION: { get_configuration(com, (GetConfiguration*)data); return; } case FID_SET_CALIBRATION: { set_calibration(com, (SetCalibration*)data); return; } case FID_GET_CALIBRATION: { get_calibration(com, (GetCalibration*)data); return; } default: { simple_invocation(com, data); break; } } if(((StandardMessage*)data)->header.fid > FID_LAST) { BA->com_return_error(data, sizeof(MessageHeader), MESSAGE_ERROR_CODE_NOT_SUPPORTED, com); } }
bool structured_data_reader::raw_read( unsigned int entry_id, std::vector<unsigned char>& all_elems) { all_elems.resize(get_configuration().get_neuron_count() * sizeof(float)); return read(entry_id, (float *)(&all_elems[0])); }
SyncFileActionMetadataResults SyncMetadataManager::all_pending_actions() const { SharedRealm realm = Realm::get_shared_realm(get_configuration()); TableRef table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_fileActionMetadata); Results results(realm, table->where()); return SyncFileActionMetadataResults(std::move(results), std::move(realm), m_file_action_schema); }
/********** MAIN PROGRAM ************************************************ * * Control background light of a WS-2300 weather station * and writes the data to a log file. * * Just run the program without parameters for usage. * * It takes two parameters. The first is the log filename with path * The second is the config file name with path * If this parameter is omitted the program will look at the default paths * See the open2300.conf-dist file for info * ***********************************************************************/ int main(int argc, char *argv[]) { WEATHERSTATION ws2300; struct config_type config; if (argc < 2 || argc > 3) { print_usage(); } get_configuration(&config, argv[2]); ws2300 = open_weatherstation(config.serial_device_name); /* Get on or off */ if (strcmp(argv[1],"on") == 0) { light(ws2300,1); } else if (strcmp(argv[1],"off") == 0) { light(ws2300,0); } else { print_usage(); } close_weatherstation(ws2300); return (0); }
const char* get_system_property_audio_encodings() { const javacall_media_configuration *cfg = get_configuration(); if (cfg != NULL) { return cfg->audioEncoding; } return NULL; }
const char* get_system_property_video_snapshot_encodings() { const javacall_media_configuration *cfg = get_configuration(); if (cfg != NULL) { return cfg->videoSnapshotEncoding; } return NULL; }
//----------------------------------------------------------------- // usb_process_request: //----------------------------------------------------------------- static void usb_process_request(struct device_request *request, unsigned char type, unsigned char req, unsigned char *data) { if ( type == USB_STANDARD_REQUEST ) { // Standard requests switch (req) { case REQ_GET_STATUS: get_status(request); break; case REQ_CLEAR_FEATURE: clear_feature(request); break; case REQ_SET_FEATURE: set_feature(request); break; case REQ_SET_ADDRESS: set_address(request); break; case REQ_GET_DESCRIPTOR: get_descriptor(request); break; case REQ_GET_CONFIGURATION: get_configuration(request); break; case REQ_SET_CONFIGURATION: set_configuration(request); break; case REQ_GET_INTERFACE: get_interface(request); break; case REQ_SET_INTERFACE: set_interface(request); break; default: log_printf(USBLOG_ERR, "USB: Unknown standard request %x\n", req); usbhw_control_endpoint_stall(); break; } } else if ( type == USB_VENDOR_REQUEST ) { log_printf(USBLOG_ERR, "Vendor: Unknown command\n"); // None supported usbhw_control_endpoint_stall(); } else if ( type == USB_CLASS_REQUEST && _class_request) { _class_request(req, request->wValue, request->wIndex, data, request->wLength); } else usbhw_control_endpoint_stall(); }
SyncUserMetadataResults SyncMetadataManager::get_users(bool marked) const { // Open the Realm. SharedRealm realm = Realm::get_shared_realm(get_configuration()); TableRef table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_userMetadata); Query query = table->where().equal(m_user_schema.idx_marked_for_removal, marked); Results results(realm, std::move(query)); return SyncUserMetadataResults(std::move(results), std::move(realm), m_user_schema); }
void facade::init(std::vector<std::string> args) { base::app::app::init(args); /////////////////////////////////////////////////// base::event::event* new_event=NULL; /////////////////////////////////////////////////// connect_event_handler("event.base.app.shutdown", boost::bind(&base::app::app::handle_shutdown, this, _1)); /////////////////////////////////////////////////// std::string config_file("config/bj.client.dev.ini"); try { boost::property_tree::ini_parser::read_ini(config_file, *get_configuration("default")); } catch(const std::exception& e) { std::cerr<<"[facade::init] Exception: "<<e.what()<<"."<<std::endl; std::cout<<"usage: "<<args[0]<<" [host_ip] [host_port]"<<std::endl; /////////////////////////////////////////// new_event=base::event::Factory::get("event.base.app.shutdown"); new_event->set_debug_info(_DEBUG_INFO_()); post_event(new_event); /////////////////////////////////////////// return; } //std::cout<<base::formatting::to_string(_options)<<std::endl; merge_configuration_options("default"); //std::cout<<base::ptree::str(*get_configuration("default"))<<std::endl; /////////////////////////////////////////////////// // connect_event_handler("event.base.deadlinetimer.timeout", boost::bind(&facade::handle_timeout, this, _1)); /////////////////////////////////////////////////// _xml=new xml(this); _cli=new cli(this); _cli->init(); _server_settings=new server_settings(); /////////////////////////////////////////////////// _session=new session(this); _session->init(); std::string host_ip=get_configuration("default")->get<std::string>("server.ip"); int port=get_configuration("default")->get<int>("common.tcp_port"); boost::asio::ip::tcp::endpoint* endpoint= new boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(host_ip), port); _session->connect(endpoint); /////////////////////////////////////////////////// _player=new player(this); _player->set_name(get_configuration("default")->get<std::string>("player.name")); _player->set_nick(get_configuration("default")->get<std::string>("player.nick")); _player->set_pass(get_configuration("default")->get<std::string>("player.pass")); _player->set_skin_id(get_configuration("default")->get<int>("player.skin_id")); /////////////////////////////////////////////////// _player_controller=new player_controller(this); _player_controller->set_player(_player); _player_controller->init(); /////////////////////////////////////////////////// get_thread_group()->add_thread(new boost::thread(boost::bind(&cli::poll_std_cin, _cli))); }
const char* get_system_property_supports_video_capture() { const javacall_media_configuration *cfg = get_configuration(); if (cfg != NULL) { if (NULL != cfg->videoEncoding) { return "true"; } else { return "false"; } } return ""; }
const char* get_system_property_supports_recording() { const javacall_media_configuration *cfg = get_configuration(); if (cfg != NULL) { if (JAVACALL_TRUE == cfg->supportRecording) { return "true"; } else { return "false"; } } return ""; }
void activate_refresh (GtkMenuItem *menu, gpointer data) { struct program_options options; if (menu == NULL && data == NULL) { /* Bogus condition to use parameters */ ; } /* remove_menu_items();*/ get_configuration(&options); if (options.menu_items != NULL) { add_menu_items(options.menu_items); } }
std::string& Configuration::get_configuration( const std::string& section, const std::string& key ) { KeyValueMap& key_value_map = get_configuration( section ); KeyValueMap::iterator find_it = key_value_map.find( key ); if ( find_it != key_value_map.end() ) { return find_it->second; } static std::string empty_string; return empty_string; }
void walk_profiles(int fd, int (*f)(void *, int, boolean_t), void *arg) { size_t i; uint16_t profile, current_profile; uchar_t smallbuf[8]; size_t buflen; uchar_t *bufp; int ret; /* * first determine amount of memory needed to hold all profiles. * The first four bytes of smallbuf concatenated tell us the * number of bytes of memory we need but do not take themselves * into account. Therefore, add four to allocate that number * of bytes. */ if (get_configuration(fd, 0, 8, &smallbuf[0])) { buflen = GET32(smallbuf) + 4; bufp = (uchar_t *)malloc(buflen); /* now get all profiles */ if (get_configuration(fd, 0, buflen, bufp)) { current_profile = GET16(&bufp[6]); for (i = 8 + 4; i < buflen; i += 4) { profile = GET16(&bufp[i]); ret = f(arg, profile, (profile == current_profile)); if (ret == CDUTIL_WALK_STOP) { break; } } } free(bufp); } }
/********** MAIN PROGRAM ************************************************ * * This program reads the max wind data from a WS2300 * and writes the data to a log file. * * Log file format: * Timestamp Date Time Gust * * Just run the program without parameters for usage. * * It takes two parameters. The first is the log filename with path * The second is the config file name with path * If this parameter is omitted the program will look at the default paths * See the open2300.conf-dist file for info * ***********************************************************************/ int main(int argc, char *argv[]) { WEATHERSTATION ws2300; FILE *fileptr; struct config_type config; double tempfloat_max; struct timestamp time_max; get_configuration(&config, argv[2]); ws2300 = open_weatherstation(config.serial_device_name); /* Get log filename. */ if (argc < 2 || argc > 3) { print_usage(); } fileptr = fopen(argv[1], "a+"); if (fileptr == NULL) { printf("Cannot open file %s\n",argv[1]); exit(-1); } /* READ MAX WIND */ //Get Windspeed max wind_minmax(ws2300, config.wind_speed_conv_factor, NULL, &tempfloat_max, NULL, &time_max); fprintf(fileptr, "%02d/%02d/%04d %02d:%02d", time_max.month, time_max.day, time_max.year, time_max.hour, time_max.minute); fprintf(fileptr, " %.1f\n", tempfloat_max); /* RESET MAX WIND */ wind_reset(ws2300, RESET_MAX); close_weatherstation(ws2300); fclose(fileptr); exit(0); }
int main(void) { extern unsigned long _binary_builtin_lar_start; struct LAR *lar; print_banner(); lar = openlar((void *)&_binary_builtin_lar_start); if (lar == NULL) { printf("[CHOOSER]: Unable to scan the attached LAR file\n"); return -1; } get_configuration(lar); if (bayoucfg.n_entries == 0) { printf("[CHOOSER]: No payloads were found in the LAR\n"); return -1; } /* * If timeout == 0xFF, then show the menu immediately. * If timeout is zero, then find and run the default item immediately. * If there is no default item, then show the menu. * If timeout is anything else, then show a message and wait for a * keystroke. If there is no keystroke in time then run the default. * If there is no default then show the menu. */ if (bayoucfg.timeout != 0xFF) { struct payload *d = payload_get_default(); if (d != NULL) { if (bayoucfg.timeout == 0) run_payload(d); else run_payload_timeout(d, bayoucfg.timeout); } } menu(); return 0; }
int test_hpmmode() { Configuration_t config; config = get_configuration(); int def = config->daemonMode; HPMmode(ACCESSMODE_DIRECT); if (config->daemonMode != ACCESSMODE_DIRECT) goto fail; HPMmode(ACCESSMODE_DAEMON); if (config->daemonMode != ACCESSMODE_DAEMON) goto fail; HPMmode(def); HPMmode(ACCESSMODE_DAEMON+1); if (config->daemonMode != def) goto fail; return 1; fail: return 0; }
int test_initconfig() { int ret; ret = init_configuration(); if (ret != 0) goto fail; Configuration_t config = get_configuration(); if (config == NULL) goto fail; if ((config->daemonMode != ACCESSMODE_DIRECT) && (config->daemonMode != ACCESSMODE_DAEMON)) goto fail; if ((config->daemonMode == ACCESSMODE_DAEMON) && (config->daemonPath == NULL)) goto fail; destroy_configuration(); return 1; fail: destroy_configuration(); return 0; }
/* * Retrieve list of supported cd-rw media types (feature 0x37) */ int get_supported_cdrw_media_types(SCSI *usalp) { Uchar cbuf[16]; int ret; fillbytes(cbuf, sizeof (cbuf), '\0'); usalp->silent++; ret = get_configuration(usalp, (char *)cbuf, sizeof (cbuf), 0x37, 2); usalp->silent--; if (ret < 0) return (-1); if (cbuf[3] < 12) /* Couldn't retrieve feature 0x37 */ return (-1); return (int)(cbuf[13]); }
void * xsenThread (void * p) { debug("[xsenThread] p : %p\n", p); XsensThreadData * data = (XsensThreadData *)p; const char * ins_device = (const char *)get_configuration(data->configurations, "ins.device"); debug("ins_device : %s\n", ins_device); XsensProcessorData processorData; processorData.fp = data->fp; debug("## processorData.fp : %p\n", processorData.fp); readXsensData(ins_device, xsensDataProcessor, &processorData); pthread_exit(NULL); }
const char* get_system_property_streamable_contents() { const javacall_media_configuration *cfg = get_configuration(); javacall_media_caps* mediaCaps = NULL; char *p=streamable_content_property; int types_len; if (cfg != NULL && streamable_content_property_filled == JAVACALL_FALSE) { mediaCaps = cfg->mediaCaps; while (mediaCaps != NULL && mediaCaps->mediaFormat != NULL) { /* verify if support streaming from memory */ if (mediaCaps->streamingProtocols & JAVACALL_MEDIA_MEMORY_PROTOCOL) { /* add content Types to property string */ types_len = strlen(mediaCaps->contentTypes); if (((int)(p-streamable_content_property)+types_len+1) >= MAX_STREAMABLE_CONTENT_PROPERTY_LEN) { /* delete duplicates and try again */ mmapi_string_delete_duplicates(streamable_content_property); p = streamable_content_property + strlen(streamable_content_property); if (((int)(p-streamable_content_property)+types_len+1) >= MAX_STREAMABLE_CONTENT_PROPERTY_LEN) { mediaCaps++; continue; } } memcpy(p, mediaCaps->contentTypes, types_len); p += types_len; *p++ = ' '; } mediaCaps++; } if (p != streamable_content_property) { p--; *p = '\0'; /* replace last space with zero */ /* delete duplicates */ mmapi_string_delete_duplicates(streamable_content_property); } streamable_content_property_filled = JAVACALL_TRUE; } return streamable_content_property; }
int main(int argc, char *argv[]) { GameState *state = allocate_game_state(); get_configuration(state->config); initilize(state); DEBUG("tile size is %li\n", sizeof(Tile)); char msg1[] = "Welcome to Kookoolegit! You are in an infinitely long " "non-orientable space. Good luck!"; add_message(msg1); render_messages(&state->config->message_window); calculate_visible_tiles(state->map, state->map->at_location); state->status_message = get_player_status(); state->need_to_redraw = 1; INFO("entering main loop\n"); while (state->is_running) { /* This blocks, waiting for the next user input */ INFO("******************************\n"); DEBUG("Getting command\n"); enum CommandCode cmd; cmd = get_command(); process_command(state, cmd); DEBUG("state is %d\n", state->state); DEBUG("Redraw flag is %d\n", state->need_to_redraw); if (state->need_to_redraw == 1) { clear(); render_messages(&state->config->message_window); render_map_window(state->map, state->map_graphics_state, &state->config->map_window); render_look_message(state->status_message, &state->config->status_window); state->need_to_redraw = 0; flip(); } } cleanup(state); return 0; }
static unsigned int handle_standard_requests() { switch(usb_setup_buffer.bmRequestType) { case 0x80: /* standard device IN requests */ switch(usb_setup_buffer.bRequest) { case GET_DESCRIPTOR: switch (HIGH_BYTE(usb_setup_buffer.wValue)) { case DEVICE: get_device_descriptor(); break; case CONFIGURATION: get_configuration_descriptor(); break; case STRING: get_string_descriptor(); break; default: /* Unknown descriptor */ return 0; } break; case GET_CONFIGURATION: get_configuration(); break; case GET_STATUS: get_device_status(); break; case GET_INTERFACE: get_interface(); break; default: return 0; } break; case 0x81: /* standard interface IN requests */ switch(usb_setup_buffer.bRequest) { case GET_STATUS: get_interface_status(); break; #ifdef HID_ENABLED case GET_DESCRIPTOR: switch (USB_setup_buffer.wValue.byte.high) { case REPORT: get_report_descriptor(); break; } break; #endif default: return 0; } break; case 0x82: /* standard endpoint IN requests */ switch(usb_setup_buffer.bRequest) { case GET_STATUS: get_endpoint_status(); break; default: return 0; } break; case 0x00: /* standard device OUT requests */ switch(usb_setup_buffer.bRequest) { case SET_ADDRESS: PRINTF("Address: %d\r\n", LOW_BYTE(usb_setup_buffer.wValue)); usb_flags |= USB_FLAG_ADDRESS_PENDING; /* The actual setting of the address is done when the status packet is sent. */ usb_send_ctrl_status(); break; #if SETABLE_STRING_DESCRIPTORS > 0 case SET_DESCRIPTOR: if (usb_setup_buffer.wValue.byte.high == STRING) { set_string_descriptor(); } else { return 0; } break; #endif case SET_CONFIGURATION: if (set_configuration()) { #if 0 config_msg.data.config = LOW_BYTE(usb_setup_buffer.wValue); notify_user(&config_msg); #endif } break; default: return 0; } break; case 0x01: /* standard interface OUT requests */ switch(usb_setup_buffer.bRequest) { case SET_INTERFACE: /* Change interface here if we support more than one */ usb_send_ctrl_status(); break; default: return 0; } break; case 0x02: /* standard endpoint OUT requests */ switch(usb_setup_buffer.bRequest) { case SET_FEATURE: case CLEAR_FEATURE: if (usb_setup_buffer.wValue == ENDPOINT_HALT_FEATURE) { usb_arch_halt_endpoint(usb_setup_buffer.wIndex, usb_setup_buffer.bRequest== SET_FEATURE); usb_send_ctrl_status(); } else { usb_error_stall(); } break; default: return 0; } break; #ifdef HID_ENABLED case 0xa1: /* class specific interface IN request*/ switch(USB_setup_buffer.bRequest) { case GET_HID_REPORT: PRINTF("Get report\r\n"); send_ctrl_response((code u_int8_t*)&zero_byte, sizeof(zero_byte)); break; case GET_HID_IDLE: PRINTF("Get idle\r\n"); send_ctrl_response((code u_int8_t*)&zero_byte, sizeof(zero_byte)); break; default: return 0; } break; case 0x21: /* class specific interface OUT request*/ switch(USB_setup_buffer.bRequest) { case SET_HID_IDLE: PRINTF("Set idle\r\n"); send_ctrl_status(); break; default: return 0; } break; #endif default: return 0; } return 1; }
void info(void) { uchar_t *toc, *p, *conf; int ret, toc_size; uint_t bsize; size_t cap = 0; char *msg; struct track_info *ti; msg = gettext("Cannot read Table of contents\n"); get_media_type(target->d_fd); (void) printf(gettext("\nDevice : %.8s %.16s\n"), &target->d_inq[8], &target->d_inq[16]); (void) printf(gettext("Firmware : Rev. %.4s (%.12s)\n"), &target->d_inq[32], &target->d_inq[36]); if (check_device(target, CHECK_DEVICE_NOT_READY)) { (void) check_device(target, CHECK_NO_MEDIA | EXIT_IF_CHECK_FAILED); (void) check_device(target, CHECK_DEVICE_NOT_READY | EXIT_IF_CHECK_FAILED); } if (verbose != 0) { /* * Determine the media type by reading the active profile * from the profile list. */ (void) printf(gettext("Media Type : ")); conf = (uchar_t *)my_zalloc(MMC_FTR_HDR_LEN); if (get_configuration(target->d_fd, MMC_FTR_PRFL_LIST, MMC_FTR_HDR_LEN, conf)) print_profile_name(read_scsi16(&conf[6]), 0, 1); else (void) printf(gettext("UNKNOWN\n")); free(conf); /* * Get the start address of the last possible lead out. */ cap = get_last_possible_lba(target); /* * The start address of the last possible leadout will only * be zero if the disc is full or this drive does not support * this method of determining capacity. */ if (cap == 0) cap = read_format_capacity(target->d_fd, &bsize); /* * Since both methods of determining the capacity of the * media count the correct number of blocks, just multiply * the capacity by the block size. */ cap *= target->d_blksize; if (device_type == CD_RW) { (void) printf(gettext("Media Capacity : %.2f MB "), ((double)cap/ONE_MB_BASE2)); } else { /* * For DVD's make sure we print out "Formatted Media * Capacity". Don't do this for CD-RWs as only * DVDs are formatted. */ (void) printf(gettext("Formatted Media Capacity : " "%.2f GB "), ((double)cap/ONE_GB_BASE10)); } cap /= target->d_blksize; (void) printf(gettext("(%u blocks)\n"), (uint_t)cap); } if (!check_device(target, CHECK_MEDIA_IS_NOT_BLANK)) { (void) printf(gettext("Media is blank\n")); exit(0); } /* Find out the number of entries in the toc */ toc = (uchar_t *)my_zalloc(12); if (!read_toc(target->d_fd, 0, 1, 4, toc)) { err_msg(msg); } else { toc_size = 256*toc[0] + toc[1] + 2; free(toc); /* allocate enough space for each track entry */ toc = (uchar_t *)my_zalloc(toc_size); if (!read_toc(target->d_fd, 0, 1, toc_size, toc)) { err_msg(msg); exit(1); } (void) printf("\n"); /* l10n_NOTE : Preserve column numbers of '|' character */ (void) printf(gettext("Track No. |Type |Start address\n")); (void) printf("----------+--------+-------------\n"); /* look at each track and display it's type. */ for (p = &toc[4]; p < (toc + toc_size); p += 8) { if (p[2] != 0xAA) (void) printf(" %-3d |", p[2]); else (void) printf("Leadout |"); (void) printf("%s |", (p[1] & 4) ? gettext("Data ") : gettext("Audio")); (void) printf("%u\n", read_scsi32(&p[4])); } } (void) printf("\n"); ret = read_toc(target->d_fd, 1, 0, 12, toc); if ((ret == 0) || (toc[1] != 0x0a)) /* For ATAPI drives or old Toshiba drives */ ret = read_toc_as_per_8020(target->d_fd, 1, 0, 12, toc); if (ret && (toc[1] == 0x0a)) { (void) printf(gettext("Last session start address: %u\n"), read_scsi32(&toc[8])); } free(toc); ti = (struct track_info *)my_zalloc(sizeof (struct track_info)); if (build_track_info(target, -1, ti) && (ti->ti_flags & TI_NWA_VALID)) { (void) printf(gettext("Next writable address: %u\n"), ti->ti_nwa); } free(ti); exit(0); }
/********** MAIN PROGRAM ************************************************ * * Control background light of a WS-2300 weather station * and writes the data to a log file. * * Just run the program without parameters for usage. * * It takes two parameters. The first is the log filename with path * The second is the config file name with path * If this parameter is omitted the program will look at the default paths * See the open2300.conf-dist file for info * ***********************************************************************/ int main(int argc, char *argv[]) { WEATHERSTATION ws2300; struct config_type config; if (argc < 2 || argc > 3) { print_usage(); } get_configuration(&config, argv[2]); ws2300 = open_weatherstation(config.serial_device_name); /* Get on or off */ if (strcmp(argv[1],"timax") == 0 || strcmp(argv[1],"dailymax") == 0) { temperature_indoor_reset(ws2300, RESET_MAX); } if (strcmp(argv[1],"timin") == 0 || strcmp(argv[1],"dailymin") == 0) { temperature_indoor_reset(ws2300, RESET_MIN); } if (strcmp(argv[1],"tiboth") == 0) { temperature_indoor_reset(ws2300, RESET_MIN + RESET_MAX); } if (strcmp(argv[1],"tomax") == 0 || strcmp(argv[1],"dailymax") == 0) { temperature_outdoor_reset(ws2300, RESET_MAX); } if (strcmp(argv[1],"tomin") == 0 || strcmp(argv[1],"dailymin") == 0) { temperature_outdoor_reset(ws2300, RESET_MIN); } if (strcmp(argv[1],"toboth") == 0) { temperature_outdoor_reset(ws2300, RESET_MIN + RESET_MAX); } if (strcmp(argv[1],"dpmax") == 0 || strcmp(argv[1],"dailymax") == 0) { dewpoint_reset(ws2300, RESET_MAX); } if (strcmp(argv[1],"dpmin") == 0 || strcmp(argv[1],"dailymin") == 0) { dewpoint_reset(ws2300, RESET_MIN); } if (strcmp(argv[1],"dpboth") == 0) { dewpoint_reset(ws2300, RESET_MIN + RESET_MAX); } if (strcmp(argv[1],"wcmax") == 0 || strcmp(argv[1],"dailymax") == 0) { windchill_reset(ws2300, RESET_MAX); } if (strcmp(argv[1],"wcmin") == 0 || strcmp(argv[1],"dailymin") == 0) { windchill_reset(ws2300, RESET_MIN); } if (strcmp(argv[1],"wcboth") == 0) { windchill_reset(ws2300, RESET_MIN + RESET_MAX); } if (strcmp(argv[1],"wmax") == 0) { wind_reset(ws2300, RESET_MAX); } if (strcmp(argv[1],"wmin") == 0) { wind_reset(ws2300, RESET_MIN); } if (strcmp(argv[1],"wboth") == 0) { wind_reset(ws2300, RESET_MIN + RESET_MAX); } if (strcmp(argv[1],"himax") == 0 || strcmp(argv[1],"dailymax") == 0) { humidity_indoor_reset(ws2300, RESET_MAX); } if (strcmp(argv[1],"himin") == 0 || strcmp(argv[1],"dailymin") == 0) { humidity_indoor_reset(ws2300, RESET_MIN); } if (strcmp(argv[1],"hiboth") == 0) { humidity_indoor_reset(ws2300, RESET_MIN + RESET_MAX); } if (strcmp(argv[1],"homax") == 0 || strcmp(argv[1],"dailymax") == 0) { humidity_outdoor_reset(ws2300, RESET_MAX); } if (strcmp(argv[1],"homin") == 0 || strcmp(argv[1],"dailymin") == 0) { humidity_outdoor_reset(ws2300, RESET_MIN); } if (strcmp(argv[1],"hoboth") == 0) { humidity_outdoor_reset(ws2300, RESET_MIN + RESET_MAX); } if (strcmp(argv[1],"pmax") == 0) { pressure_reset(ws2300, RESET_MAX); } if (strcmp(argv[1],"pmin") == 0) { pressure_reset(ws2300, RESET_MIN); } if (strcmp(argv[1],"pboth") == 0) { pressure_reset(ws2300, RESET_MIN + RESET_MAX); } if (strcmp(argv[1],"r1max") == 0) { rain_1h_max_reset(ws2300); } if (strcmp(argv[1],"r24max") == 0) { rain_24h_max_reset(ws2300); } if (strcmp(argv[1],"r1") == 0) { rain_1h_reset(ws2300); } if (strcmp(argv[1],"r24") == 0) { rain_24h_reset(ws2300); } if (strcmp(argv[1],"rtotal") == 0) { rain_total_reset(ws2300); } close_weatherstation(ws2300); return (0); }
void convert_image() { resource_configuration resconf; resource_map rmap; unit_configuration_map uconfmap; advance_map amap; city_improv_map cimap; government_map govmap; std::vector<civilization*> civs; get_configuration(ruleset_name, &civs, &uconfmap, &amap, &cimap, &resconf, &govmap, &rmap); SDL_Surface* surf = IMG_Load(infile); if(!surf) { throw std::runtime_error("Could not load image"); } int w = surf->w; int h = surf->h; printf("Map size: %dx%d\n", w, h); printf("Bytes per pixel: %d\n", surf->format->BytesPerPixel); int sea = resconf.get_sea_tile(); std::vector<colormap> colormapping; colormapping = loadColorMapping(resconf); int count[num_terrain_types]; memset(count, 0x00, sizeof(count)); map m(w, h, resconf, rmap); m.set_x_wrap(wrap_x); for(int j = 0; j < h; j++) { for(int i = 0; i < w; i++) { color c = sdl_get_pixel(surf, i, j); int mindiff = INT_MAX; int type = -1; for(const auto& cm : colormapping) { int diff = abs(c.r - cm.col.r) + abs(c.g - cm.col.g) + abs(c.b - cm.col.b); if(diff < mindiff) { type = cm.type; mindiff = diff; } } m.set_data(i, j, type); count[type]++; } } // turn coasts to sea for(int j = 0; j < h; j++) { for(int i = 0; i < w; i++) { if(!m.resconf.is_water_tile(m.get_data(i, j))) { for(int k = -1; k <= 1; k++) { for(int l = -1; l <= 1; l++) { int neighbour = m.get_data(i + k, j + l); if(m.resconf.is_ocean_tile(neighbour)) { m.set_data(i + k, j + l, sea); } } } } } } // add random resources m.add_random_resources(); save_map(outfile, ruleset_name, m); int total_land = 0; int total_tiles = w * h; for(int i = 0; i < num_terrain_types; i++) { if(!resconf.is_water_tile(i)) { total_land += count[i]; } } printf("%-20s: %3d %%\n", "Land", 100 * total_land / total_tiles); for(int i = 0; i < num_terrain_types; i++) { if(count[i] && !resconf.is_water_tile(i)) { printf("%-20s: %3d %%\n", resconf.resource_name[i].c_str(), 100 * count[i] / total_land); } } }
/** Application main. Initializes internationalization, libosso, app and appview. Calls user interface creation functions and gtk_main. Follows the component initialization order of osso-filemanager main. @param argc Number of command line arguments @param argv Command line arguments @return 0 if successful; otherwise error code */ int main(int argc, char *argv[]) { gboolean result; g_thread_init(NULL); dbus_g_thread_init(); gdk_threads_init(); mainThread = g_thread_self(); /* Allocate application data structures */ app_data = g_new0(AppData, 1); if (app_data == NULL) { OSSO_LOG_CRIT("Failed memory allocation: AppData"); exit(1); } /* there was no low memory ind from HW yet. */ app_data->low_memory = FALSE; app_data->app_ui_data = g_new0(AppUIData, 1); if (app_data->app_ui_data == NULL) { OSSO_LOG_CRIT("Failed memory allocation: AppUIData"); // free_app_data(); exit(1); } /* Add reference back to parent structure (AppData) */ app_data->app_ui_data->app_data = app_data; /* init comapp_system */ init_comapp_system(app_data); /* Initialize GnomeVFS */ result = gnome_vfs_init(); if (!result) { OSSO_LOG_CRIT("Failed initializing GnomeVFS"); return OSSO_ERROR; } /* Initialize GConf and read application configuration */ if (!init_settings(app_data)) { OSSO_LOG_CRIT("Failed initializing GConf"); return OSSO_ERROR; } if (!get_configuration(argc, argv, app_data)) { OSSO_LOG_CRIT("Failed reading configuration"); return OSSO_ERROR; } #ifdef ENABLE_NLS /* Initialize localization */ /* Gettext does not seem to work properly without the following function * call */ setlocale(LC_ALL, ""); bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif /* ENABLE_NLS */ /* Initialize GTK */ //gtk_init(&argc, &argv); /* Initialize GTK+ and Hildon */ hildon_gtk_init(&argc, &argv); /* Create application UI */ ui_create_main_window(app_data); /* Initialize engine */ pdf_viewer_init(app_data->app_ui_data); app_data->app_ui_data->password_dialog = NULL; app_data->app_ui_data->replace_dialog = NULL; //hildon_gtk_window_take_screenshot(GTK_WINDOW(app_data->app_ui_data->app_view), TRUE); g_signal_connect(G_OBJECT(app_data->app_ui_data->app_view), "map-event", G_CALLBACK(game_get_screenshot), NULL); //prasanna GDK_THR_ENTER; gtk_main(); GDK_THR_LEAVE; if( !just_exit ) { g_debug( "Save configuration..." ); save_configuration(app_data); g_debug( "Deinit engine..." ); pdf_viewer_deinit(); g_debug( "Deinit compapp systems..." ); deinit_comapp_system(app_data); g_debug( "Deinit settings..." ); deinit_settings(); g_debug( "Deinit mime..." ); free_mime_filters(); free_application_mime_types(); g_debug( "Deinit gnomevfs..." ); if (gnome_vfs_initialized()) { gnome_vfs_shutdown(); } } /* Exit successfully, regardless of any errors */ g_debug( "Exit success" ); exit(EXIT_SUCCESS); }
void run_editor() { SDL_Surface* screen = SDL_SetVideoMode(1024, 768, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); if (!screen) { fprintf(stderr, "Unable to set %dx%d video: %s\n", 1024, 768, SDL_GetError()); return; } SDL_WM_SetCaption("Kingdoms Map Editor", NULL); TTF_Font* font = TTF_OpenFont(get_graphics_path("DejaVuSans.ttf").c_str(), 12); if(!font) { fprintf(stderr, "Could not open font: %s\n", TTF_GetError()); return; } const int map_x = 80; const int map_y = 60; const int road_moves = 3; const unsigned int food_eaten_per_citizen = 2; const int num_turns = 300; const int anarchy_period = 1; resource_configuration resconf; resource_map rmap; unit_configuration_map uconfmap; advance_map amap; city_improv_map cimap; government_map govmap; std::vector<civilization*> civs; get_configuration(ruleset_name, &civs, &uconfmap, &amap, &cimap, &resconf, &govmap, &rmap); map m(map_x, map_y, resconf, rmap); pompelmous r(uconfmap, amap, cimap, govmap, &m, road_moves, food_eaten_per_citizen, anarchy_period, num_turns); for(unsigned int i = 0; i < civs.size(); i++) { civs[i]->set_map(&m); civs[i]->set_government(&govmap.begin()->second); r.add_civilization(civs[i]); } gui_resource_files grr; fetch_gui_resource_files(ruleset_name, &grr); editorgui v(screen, r.get_map(), r, grr, *font, ruleset_name); bool running = true; while(running) { v.display(); SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if(v.handle_input(event)) { running = false; } break; case SDL_QUIT: running = false; default: break; } } if(v.is_quitting()) running = false; SDL_Delay(20); } for(unsigned int i = 0; i < civs.size(); i++) { delete civs[i]; } TTF_CloseFont(font); }