@@ -285,7 +285,7 @@ static int ini_callback(const char *sect void load_options() { use_default_options(); - ini_load("SDLPoP.ini", ini_callback); + ini_load(PKGSRC_DATA_PATH "SDLPoP.ini", ini_callback); if (!options.use_fixes_and_enhancements) disable_fixes_and_enhancements(); }
void load_options() { use_default_options(); ini_load("SDLPoP.ini", global_ini_callback); // global configuration // load mod-specific INI configuration if (use_custom_levelset) { char filename[256]; snprintf(filename, sizeof(filename), "mods/%s/%s", levelset_name, "mod.ini"); ini_load(filename, mod_ini_callback); } if (!options.use_fixes_and_enhancements) disable_fixes_and_enhancements(); }
int config_init() { setting->ini = ini_load(setting->config_path); if (NULL == setting->ini) { fatal("Load config failure!"); } }
INI_CONTAINER* ini_start(char* filepath) { INI_CONTAINER* container = NULL; ini_init(&container, filepath); if (container != NULL) ini_load(container); return container; }
/*! load_initial_plugin will be called when this plug in being loaded. * Please notice that a global parament "map_instances" is introduced, for multi-instance situation * in windows OCX usage. A Brave new instance of "qtvplugin_geomarker" will be created for each different viewer_interface. * * @param strSLibPath the absolute path of this dll. * @param ptrviewer the pointer to main view. * @return return the instance pointer to the instance belong to ptrviewer */ layer_interface * qtvplugin_geomarker::load_initial_plugin(QString strSLibPath,viewer_interface * ptrviewer) { //!In this instance, we will see how to create a new instance for each ptrviewer qtvplugin_geomarker * instance = 0; //!1.Check whether there is already a instance for ptrviewer( viewer_interface) mutex_instances.lock(); //!1.1 situation 1: map_instances is empty, which means no instance exists. We just save this pointer to map_instances if (map_instances.empty()==true) { map_instances[ptrviewer] = this; instance = this; } /*! 1.2 situation 2: map_instances dose not contain ptrviewer, which is the normal situation when a second ocx ctrl is initializing. * we just allocate a new qtvplugin_geomarker, and save key-value in map_instances. */ else if (map_instances.contains(ptrviewer)==false) { instance = new qtvplugin_geomarker; map_instances[ptrviewer] = instance; } //! 1.3 situation 3: a ABNORMAL situation. load_initial_plugin is called again. else instance = map_instances[ptrviewer]; mutex_instances.unlock(); //2. if the instance is just this object, we do real init code. if (instance==this) { QFileInfo info(strSLibPath); m_SLLibPath = strSLibPath; m_SLLibName = info.completeBaseName(); m_pVi = ptrviewer; mutex_instances.lock(); m_nInstance = ++count_instances[m_SLLibName]; mutex_instances.unlock(); loadTranslations(); ini_load(); style_load(); initialBindPluginFuntions(); } //3. elseif, we call the instance's load_initial_plugin method instead else { layer_interface * ret = instance->load_initial_plugin(strSLibPath,ptrviewer); assert(ret==instance); return ret; } qDebug()<<QFont::substitutions(); return instance; }
void Settings::load(const void* _data, uint32_t _len) { if (NULL != m_ini) { ini_destroy(INI_T(m_ini) ); } if (NULL == _data) { m_ini = ini_create(m_allocator); } else { m_ini = ini_load( (const char*)_data, _len, m_allocator); } }
/* * API * * loads the project's configuration from the INI file specified by `prefix`. * the INI file is `prefix`.ini. * * if some required parameters is missing, or if its value is illegal, a message * is printed and the functions returns INI_STATUS_ERROR. otherwise, the function * returns INI_STATUS_OK. * * the config argument will be populated with the values of the parameters */ int config_load(config_t * config, const char * prefix) { int res = INI_STATUS_ERROR; const char * str_value; char inifilename[MAX_INPUT_BUFFER]; inifile_t ini; config->seed_table = NULL; strncpy(inifilename, prefix, sizeof(inifilename) - 5); strcat(inifilename, ".ini"); if (ini_load(&ini, inifilename) != INI_STATUS_OK) { /* error message printed by ini_load */ return INI_STATUS_ERROR; } strncpy(config->prefix, prefix, sizeof(config->prefix)); INI_GET_STR("rule", config->rule_pattern); INI_GET_STR("lexicon_name", config->lexicon_file); INI_GET_STR("hash_name", config->hash_name); INI_GET_STR("main_rand_seed", config->random_seed); INI_GET_NUM("num_of_R", config->chain_length); INI_GET_NUM("multi_query", config->num_of_query_results); INI_GET_NUM("bucket_size", config->bucket_size); INI_GET_NUM("hash_size", config->num_of_buckets); if (strcasecmp(config->hash_name, "MD5") == 0) { config->hash_func = MD5BasicHash; config->digest_size = MD5_OUTPUT_LENGTH_IN_BYTES; } else if (strcasecmp(config->hash_name, "SHA1") == 0) { config->hash_func = SHA1BasicHash; config->digest_size = SHA1_OUTPUT_LENGTH_IN_BYTES; } else { fprintf(stderr, "INI: hash_name must be 'MD5' or 'SHA1'"); goto cleanup; } res = INI_STATUS_OK; cleanup: ini_finalize(&ini); return res; }
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { // This shouldn't be done on DllMain if (!initialized) { initialized = TRUE; ini_load(); ini_save(); if (!load_xinput_dll(hinstDLL)) return FALSE; } return TRUE; }
static void goldlim_ini_load(void) { char *value; ini_t *ini = ini_load(INI_NAME); if (!ini) { LOG("No "INI_NAME" found."); return; } value = ini_get_setting(ini, "goldlim", "InventoryMultiplier"); if (value) gold_inv_mul = strtol(value, NULL, 0); value = ini_get_setting(ini, "goldlim", "StashMultiplier"); if (value) gold_stash_mul = strtol(value, NULL, 0); ini_free(ini); }
static void loader_ini_load(void) { ini_t *ini = ini_load(INI_NAME); modules = 0; if (!ini) return; while (ini_seek_section(ini, "loader")) { while (ini_seek_setting(ini, NULL)) { char *value = ini_value(ini); module[modules] = LoadLibrary(value); if (module[modules] != NULL) { LOG("Loaded %s at %p", value, modules[module]); ++modules; } else { LOG("Failed to loaded %s", value); } } } ini_free(ini); }
void load_options() { use_default_options(); ini_load("SDLPoP.ini", ini_callback); if (!options.use_fixes_and_enhancements) disable_fixes_and_enhancements(); }
static int init ( void ) { traceLastFunc( "init()" ); if ( g_hOrigDll == NULL ) { if ( GetModuleFileName(g_hDllModule, g_szWorkingDirectory, sizeof(g_szWorkingDirectory) - 32) != 0 ) { if ( strrchr(g_szWorkingDirectory, '\\') != NULL ) *strrchr( g_szWorkingDirectory, '\\' ) = 0; else strcpy( g_szWorkingDirectory, "." ); } else { strcpy( g_szWorkingDirectory, "." ); } // Hello World Log( "Initializing exe24 mod" ); Log( "Compiled: %s CL:%d", COMPILE_DT, COMPILE_VERSION ); // log windows version for people that forget to report it WindowsInfo.osPlatform = (int) * (DWORD *)GTAvar_osPlatform; WindowsInfo.osVer = (int) * (DWORD *)GTAvar_osVer; WindowsInfo.winVer = (int) * (DWORD *)GTAvar_winVer; WindowsInfo.winMajor = (int) * (DWORD *)GTAvar_winMajor; if ( WindowsInfo.osPlatform == 2 ) Log( "OS: Windows Version %d.%d.%d", WindowsInfo.winMajor, WindowsInfo.winVer, WindowsInfo.osVer ); else Log( "OS: Not Windows (%d.%d.%d)", WindowsInfo.winMajor, WindowsInfo.winVer, WindowsInfo.osVer ); #pragma warning( disable : 4127 ) if ( sizeof(struct vehicle_info) != 2584 ) { Log( "sizeof(struct vehicle_info) == %d, aborting.", sizeof(struct vehicle_info) ); return 0; } if ( sizeof(struct actor_info) != 1988 ) { Log( "sizeof(struct actor_info) == %d, aborting.", sizeof(struct actor_info) ); return 0; } #pragma warning( default : 4127 ) ini_load(); if ( !set.i_have_edited_the_ini_file ) { MessageBox( 0, "Error when starting exe24.info mod.","Error", 0 ); return 0; } // get SAMP and set g_dwSAMP_Addr getSamp(); // get actual d3d9.dll and proxy original D3D9Device char filename[MAX_PATH]; if (fileExists(".\\d3d9_exe24+.dll")) { strlcat(filename, ".\\d3d9_exe24+.dll", sizeof(filename)); } else { GetSystemDirectory(filename, (UINT)(MAX_PATH - strlen("\\d3d9.dll") - 1)); strlcat(filename, "\\d3d9.dll", sizeof(filename)); } g_hOrigDll = LoadLibrary( filename ); if ( g_hOrigDll == NULL ) { Log( "Failed to load %s", filename ); return 0; } orig_Direct3DCreate9 = ( D3DC9 ) GetProcAddress( g_hOrigDll, "Direct3DCreate9" ); if ( orig_Direct3DCreate9 == NULL ) { Log( "%s does not export Direct3DCreate9!?", filename ); FreeLibrary( g_hOrigDll ); return 0; } } return 1; }
ExcCode options_config_load(const char *filename) { TRY(ini_load(filename, sections)); shortcuts[shortcuts_count].handler = NULL; return 0; }
static void merc_ini_load(void) { char *value; int i; ini_t *ini = ini_load(INI_NAME); if (!ini) { LOG("No "INI_NAME" found."); return; } while (ini_seek_section(ini, NULL)) { int i; char *end; char *section = ini_section(ini); if (strncasecmp(section, "merc", 4) != 0) continue; i = strtoul(§ion[4], &end, 10) - 1; if (!section[4] || *end) continue; if (i < 0 || i >= MERCOPT_MAX) continue; while (ini_seek_setting(ini, NULL)) { char *key = ini_key(ini); char *value = ini_value(ini); if (strcasecmp(key, "class") == 0) { mercopt[i].merc_class = strtoul(value, NULL, 0); } else if (strcasecmp(key, "allow_class") == 0) { int j; int klass[7]; int klasses = merc_parse_array(value, klass, 7); mercopt[i].allow_class = 0; for (j = 0; j < klasses; ++j) mercopt[i].allow_class |= 1 << klass[j]; } else if (strcasecmp(key, "allow_2h") == 0) { mercopt[i].allow_2h = !!strtoul(value, NULL, 0); } else if (strcasecmp(key, "dual") == 0) { mercopt[i].dual_types = merc_parse_array(value, mercopt[i].dual_type, MERCOPT_TYPE_MAX); } else if (strcasecmp(key, "except") == 0) { mercopt[i].except_types = merc_parse_array(value, mercopt[i].except_type, MERCOPT_TYPE_MAX); } else if (strcasecmp(key, "allow") == 0) { mercopt[i].allow_types = merc_parse_array(value, mercopt[i].allow_type, MERCOPT_TYPE_MAX); } else if (strcasecmp(key, "deny") == 0) { mercopt[i].deny_types = merc_parse_array(value, mercopt[i].deny_type, MERCOPT_TYPE_MAX); } /* else, ignore ( option for new version? :-D ) */ } } value = ini_get_setting(ini, "mercmod", "loadmpq"); if (value) { merc_load_image_mpq = !!strtoul(value, NULL, 0); } for (i = 0; i < INVREC_MAX; ++i) { char setting[32]; snprintf(setting, sizeof(setting), "inv%d", i + 1); value = ini_get_setting(ini, "mercmod", setting); if (value) { int j, r; int arr[1 + 6*INVENTORY_REC_ITEM_MAX]; int count = merc_parse_array(value, arr, 1 + 6*INVENTORY_REC_ITEM_MAX); if (count <= 0) continue; invrec_idx[i] = arr[0]; for (j = 1, r = 0; j <= (count-6); j += 6) { invrec[i][r].left = arr[j]; invrec[i][r].right = arr[j+1]; invrec[i][r].top = arr[j+2]; invrec[i][r].bottom = arr[j+3]; invrec[i][r].w = arr[j+4]; invrec[i][r].h = arr[j+5]; } } } ini_free(ini); }
int main(int argc, char *argv[]) { int ros_argc; char **ros_argv; std::string node_name(NODE_NAME_DEFAULT); int option; int ival; double dval; int ws_port = WS_PORT_DEFAULT; int emove_port = EMOVE_PORT_DEFAULT; double period = 1; int ws_server_id; int ws_connection_id; ulapi_task_struct *ws_client_read_task; ws_client_read_task_args *ws_client_read_args; ulapi_task_struct *ws_client_write_task; ws_client_write_task_args *ws_client_write_args; int emove_server_id; ulapi_task_struct emove_server_task; emove_server_task_args emove_server_args; enum {INBUF_LEN = 1024}; char inbuf[INBUF_LEN]; opterr = 0; while (true) { option = getopt(argc, argv, ":i:n:p:t:Whd"); if (option == -1) break; switch (option) { case 'i': inifile_name = std::string(optarg); break; case 'n': // first check for valid name if (optarg[0] == '-') { fprintf(stderr, "invalid node name: %s\n", optarg); return 1; } node_name = std::string(optarg); break; case 'w': ival = atoi(optarg); ws_port = ival; break; case 'e': ival = atoi(optarg); emove_port = ival; break; case 't': dval = atof(optarg); if (dval < FLT_EPSILON) { fprintf(stderr, "bad value for period: %s\n", optarg); return 1; } period = dval; break; // FIXME -- ipad case 'W': ws_all = true; break; case 'h': print_help(); break; case 'd': debug = true; break; case ':': fprintf(stderr, "missing value for -%c\n", optopt); return 1; break; default: fprintf (stderr, "unrecognized option -%c\n", optopt); return 1; break; } // switch (option) } // while (true) for getopt if (ULAPI_OK != ulapi_init()) { fprintf(stderr, "can't init ulapi\n"); return 1; } if (! inifile_name.empty()) { if (0 != ini_load(inifile_name, &ws_port, &emove_port)) { fprintf(stderr, "error reading ini file %s\n", inifile_name.c_str()); return 1; } } ulapi_mutex_init(&ws_stat_mutex, 1); ulapi_mutex_init(&emove_stat_mutex, 1); // pass everything after a '--' separator to ROS ros_argc = argc - optind; ros_argv = &argv[optind]; ros::init(ros_argc, ros_argv, node_name); ros::NodeHandle nh; ros::Subscriber wssub; ros::Subscriber emovesub; wssub = nh.subscribe(KITTING_WS_STAT_TOPIC, TOPIC_QUEUE_LEN, ws_stat_callback); emovesub = nh.subscribe(KITTING_EMOVE_STAT_TOPIC, TOPIC_QUEUE_LEN, emove_stat_callback); /* Run two processes, one that serves up the Workstation-level commands and status, and the other that serves up the Emove status. This main thread will handle the Workstation level. */ ws_server_id = ulapi_socket_get_server_id(ws_port); if (ws_server_id < 0) { fprintf(stderr, "can't serve WS port %d\n", ws_port); return 1; } emove_server_id = ulapi_socket_get_server_id(emove_port); if (emove_server_id < 0) { fprintf(stderr, "can't serve Emove port %d\n", emove_port); return 1; } ulapi_task_init(&emove_server_task); emove_server_args.task = &emove_server_task; emove_server_args.id = emove_server_id; emove_server_args.period_nsecs = (int) (period * 1.0e9); ulapi_task_start(&emove_server_task, reinterpret_cast<ulapi_task_code>(emove_server_task_code), reinterpret_cast<void *>(&emove_server_args), ulapi_prio_highest(), 0); bool done = false; while (! done) { if (debug) printf("waiting for a WS HMI connection on %d...\n", ws_server_id); ws_connection_id = ulapi_socket_get_connection_id(ws_server_id); if (ws_connection_id < 0) { fprintf(stderr, "can't get a WS HMI connection\n"); break; } if (debug) printf("got a WS HMI connection on id %d\n", ws_connection_id); // spawn connection tasks for reading and writing ws_client_read_task = reinterpret_cast<ulapi_task_struct *>(malloc(sizeof(*ws_client_read_task))); ws_client_read_args = reinterpret_cast<ws_client_read_task_args *>(malloc(sizeof(*ws_client_read_args))); ulapi_task_init(ws_client_read_task); ws_client_read_args->task = ws_client_read_task; ws_client_read_args->id = ws_connection_id; ulapi_task_start(ws_client_read_task, reinterpret_cast<ulapi_task_code>(ws_client_read_task_code), reinterpret_cast<void *>(ws_client_read_args), ulapi_prio_highest(), 0); ws_client_write_task = reinterpret_cast<ulapi_task_struct *>(malloc(sizeof(*ws_client_write_task))); ws_client_write_args = reinterpret_cast<ws_client_write_task_args *>(malloc(sizeof(*ws_client_write_args))); ulapi_task_init(ws_client_write_task); ws_client_write_args->task = ws_client_write_task; ws_client_write_args->id = ws_connection_id; ws_client_write_args->period_nsecs = (int) (period * 1.0e9); ulapi_task_start(ws_client_write_task, reinterpret_cast<ulapi_task_code>(ws_client_write_task_code), reinterpret_cast<void *>(ws_client_write_args), ulapi_prio_highest(), 0); } // while (true) ulapi_socket_close(ws_server_id); if (debug) printf("server on %d done\n", ws_server_id); return 0; }
static bool loadZum1(std::string const& dataIn) { // Remove the header data const std::string data = dataIn.substr(5); createDefaultEmpty(); currentDoc().width_ = 0; currentDoc().height_ = 0; ini_t * ini = ini_load(data.c_str(), nullptr); { // Load columns section const int columnsSection = ini_find_section(ini, "columns", 0); if (columnsSection != INI_NOT_FOUND) { const int columnsCount = ini_property_count(ini, columnsSection); for (int i = 0; i < columnsCount; ++i) { const int col = Index::strToColumn(std::string(ini_property_name(ini, columnsSection, i))); const int width = std::atoi(ini_property_value(ini, columnsSection, i)); currentDoc().columnWidth_[col] = width; } } } { // Load data section const int dataSection = ini_find_section(ini, "data", 0); if (dataSection == INI_NOT_FOUND) { logError("Could not locate the data section in the document"); ini_destroy(ini); return false; } const int dataCount = ini_property_count(ini, dataSection); for (int i = 0; i < dataCount; ++i) { const Index idx = Index::fromStr(std::string(ini_property_name(ini, dataSection, i))); const std::string value = ini_property_value(ini, dataSection, i); setText(idx, value); } } { // Load format section const int formatSection = ini_find_section(ini, "format", 0); if (formatSection != INI_NOT_FOUND) { const int formatCount = ini_property_count(ini, formatSection); for (int i = 0; i < formatCount; ++i) { const Index idx = Index::fromStr(std::string(ini_property_name(ini, formatSection, i))); const std::string value = ini_property_value(ini, formatSection, i); getCell(idx).format = parseFormat(value); } } } ini_destroy(ini); evaluateDocument(); return true; }
static int init ( void ) { traceLastFunc( "init()" ); if ( g_hOrigDll == NULL ) { if ( GetModuleFileName(g_hDllModule, g_szWorkingDirectory, sizeof(g_szWorkingDirectory) - 32) != 0 ) { if ( strrchr(g_szWorkingDirectory, '\\') != NULL ) *strrchr( g_szWorkingDirectory, '\\' ) = 0; else strcpy( g_szWorkingDirectory, "." ); } else { strcpy( g_szWorkingDirectory, "." ); } // Hello World Log( "Initializing %s", NAME ); Log( "Compiled: %s CL:%d", COMPILE_DT, COMPILE_VERSION ); // log windows version for people that forget to report it WindowsInfo.osPlatform = (int) * (DWORD *)GTAvar_osPlatform; WindowsInfo.osVer = (int) * (DWORD *)GTAvar_osVer; WindowsInfo.winVer = (int) * (DWORD *)GTAvar_winVer; WindowsInfo.winMajor = (int) * (DWORD *)GTAvar_winMajor; if ( WindowsInfo.osPlatform == 2 ) Log( "OS: Windows Version %d.%d.%d", WindowsInfo.winMajor, WindowsInfo.winVer, WindowsInfo.osVer ); else Log( "OS: Not Windows (%d.%d.%d)", WindowsInfo.winMajor, WindowsInfo.winVer, WindowsInfo.osVer ); /* int D3D9UseVersion = (int)*(DWORD*)GTAvar__D3D9UseVersion; Log("D3D9UseVersion: %d", D3D9UseVersion); int DXVersion = (int)*(DWORD*)GTAvar__DXVersion; Log("DXVersion: %d", DXVersion); int windowsVersion = (int)*(DWORD*)GTAvar__windowsVersion; Log("windowsVersion: %d", windowsVersion); int CPUSupportsMMX = (int)*(DWORD*)__rwD3D9CPUSupportsMMX; int CPUSupports3DNow = (int)*(DWORD*)__rwD3D9CPUSupports3DNow; int CPUSupportsSSE = (int)*(DWORD*)__rwD3D9CPUSupportsSSE; int CPUSupportsSSE2 = (int)*(DWORD*)__rwD3D9CPUSupportsSSE2; if (!CPUSupportsMMX) Log("CPU Supports MMX: %d", CPUSupportsMMX); if (!CPUSupports3DNow) Log("CPU Supports 3DNow: %d", CPUSupports3DNow); if (!CPUSupportsSSE) Log("CPU Supports SSE: %d", CPUSupportsSSE); if (!CPUSupportsSSE2) Log("CPU Supports SSE2: %d", CPUSupportsSSE2); */ #pragma warning( disable : 4127 ) if ( sizeof(struct vehicle_info) != 2584 ) { Log( "sizeof(struct vehicle_info) == %d, aborting.", sizeof(struct vehicle_info) ); return 0; } if ( sizeof(struct actor_info) != 1988 ) { Log( "sizeof(struct actor_info) == %d, aborting.", sizeof(struct actor_info) ); return 0; } #pragma warning( default : 4127 ) ini_load(); if ( !set.i_have_edited_the_ini_file ) { MessageBox( 0, "Looks like you've not edited the .ini file like you were told to!\n""\n" "Before you can use mod_sa, you have to set \"i_have_edited_the_ini_file\" to true.\n" "We did this so you would read the INI file to see the configurability of mod_sa.\n", "You're a retard.", 0 ); ShellExecute( 0, "open", "notepad", INI_FILE, g_szWorkingDirectory, SW_SHOW ); return 0; } // get SAMP and set g_dwSAMP_Addr getSamp(); // get actual d3d9.dll and proxy original D3D9Device char filename[MAX_PATH]; GetSystemDirectory( filename, (UINT) (MAX_PATH - strlen("\\d3d9.dll") - 1) ); strlcat( filename, "\\d3d9.dll", sizeof(filename) ); g_hOrigDll = LoadLibrary( filename ); if ( g_hOrigDll == NULL ) { Log( "Failed to load %s", filename ); return 0; } orig_Direct3DCreate9 = ( D3DC9 ) GetProcAddress( g_hOrigDll, "Direct3DCreate9" ); if ( orig_Direct3DCreate9 == NULL ) { Log( "%s does not export Direct3DCreate9!?", filename ); FreeLibrary( g_hOrigDll ); return 0; } } return 1; }
int main(int argc, char **argv) { int ros_argc; char **ros_argv; std::string node_name(NODE_NAME_DEFAULT); int option; int ival; double dval; nist_kitting::ws_stat ws_stat_buf; ws_stat_buf.stat.period = PERIOD_DEFAULT; opterr = 0; while (true) { option = getopt(argc, argv, ":i:n:t:p:f:hd"); if (option == -1) break; switch (option) { case 'i': inifile_name = std::string(optarg); break; case 'n': // first check for valid name if (optarg[0] == '-') { fprintf(stderr, "invalid node name: %s\n", optarg); return 1; } node_name = std::string(optarg); break; case 't': dval = atof(optarg); if (dval < FLT_EPSILON) { fprintf(stderr, "bad value for period: %s\n", optarg); return 1; } ws_stat_buf.stat.period = dval; break; case 'p': planning_app = std::string(optarg); break; case 'f': plan_file = std::string(optarg); break; case 'h': print_help(); break; case 'd': debug = 1; ulapi_set_debug(ULAPI_DEBUG_ALL); break; case ':': fprintf(stderr, "missing value for -%c\n", optopt); return 1; break; default: fprintf (stderr, "unrecognized option -%c\n", optopt); return 1; break; } } if (ULAPI_OK != ulapi_init()) { fprintf(stderr, "can't init ulapi\n"); return 1; } if (inifile_name.empty()) { fprintf(stderr, "no ini file provided\n"); return 1; } if (0 != ini_load(inifile_name, planning_app, plan_file)) { fprintf(stderr, "error reading ini file %s\n", inifile_name.c_str()); return 1; } if (planning_app.empty()) { fprintf(stderr, "no planning application provided\n"); return 1; } if (plan_file.empty()) { fprintf(stderr, "no plan file provided\n"); return 1; } if (debug) { ROS_INFO("Using planning application '%s', plan file '%s'\n", planning_app.c_str(), plan_file.c_str()); } // pass everything after a '--' separator to ROS ros_argc = argc - optind; ros_argv = &argv[optind]; ros::init(ros_argc, ros_argv, node_name); ros::NodeHandle nh; ros::Subscriber ws_cmd_sub; ros::Subscriber emove_stat_sub; ros::Publisher ws_stat_pub; ros::Publisher emove_cmd_pub; ros::Rate loop_rate(1.0 / ws_stat_buf.stat.period); ws_cmd_sub = nh.subscribe(KITTING_WS_CMD_TOPIC, TOPIC_QUEUE_LEN, ws_cmd_callback); emove_stat_sub = nh.subscribe(KITTING_EMOVE_STAT_TOPIC, TOPIC_QUEUE_LEN, emove_stat_callback); ws_stat_pub = nh.advertise<nist_kitting::ws_stat>(KITTING_WS_STAT_TOPIC, TOPIC_QUEUE_LEN); emove_cmd_pub = nh.advertise<nist_kitting::emove_cmd>(KITTING_EMOVE_CMD_TOPIC, TOPIC_QUEUE_LEN); // stuff a NOP command ws_stat_buf.stat.type = ws_cmd_buf.cmd.type = KITTING_NOP; ws_stat_buf.stat.serial_number = ws_cmd_buf.cmd.serial_number = 0; ws_stat_buf.stat.state = RCS_STATE_NEW_COMMAND; ws_stat_buf.stat.status = RCS_STATUS_EXEC; ws_stat_buf.stat.heartbeat = 0; signal(SIGINT, quit); double start, end, last_start = ulapi_time() - ws_stat_buf.stat.period; while (true) { ros::spinOnce(); start = ulapi_time(); ws_stat_buf.stat.cycle = start - last_start; last_start = start; if (ws_stat_buf.stat.serial_number != ws_cmd_buf.cmd.serial_number) { ws_stat_buf.stat.type = ws_cmd_buf.cmd.type; ws_stat_buf.stat.serial_number = ws_cmd_buf.cmd.serial_number; ws_stat_buf.stat.state = RCS_STATE_NEW_COMMAND; ws_stat_buf.stat.status = RCS_STATUS_EXEC; if (NULL != planning_process) { ulapi_process_stop(planning_process); ulapi_process_delete(planning_process); planning_process = NULL; } } switch (ws_cmd_buf.cmd.type) { case KITTING_NOP: do_cmd_kitting_nop(ws_stat_buf); break; case KITTING_INIT: do_cmd_kitting_init(ws_stat_buf, emove_cmd_pub, emove_stat_buf); break; case KITTING_HALT: do_cmd_halt(ws_stat_buf); break; case KITTING_WS_ASSEMBLE_KIT: do_cmd_kitting_ws_assemble_kit(ws_cmd_buf.assemble_kit, ws_stat_buf, emove_cmd_pub, emove_stat_buf); break; default: // unrecognized command -- FIXME break; } ws_stat_buf.stat.heartbeat++; end = ulapi_time(); ws_stat_buf.stat.duration = ulapi_time() - start; ws_stat_pub.publish(ws_stat_buf); loop_rate.sleep(); } return 0; }
int main() { /* $ export MALLOC_TRACE=malloc.log */ mtrace(); ini_t *conf = ini_load("test.ini"); if (conf == NULL) error(1, errno, "ini_load fail"); char *type; ini_read_str(conf, "main", "type", &type, "test"); puts(type); free(type); char value[100] = { 0 }; ini_read_strn(conf, "main", "len", value, sizeof(value), NULL); puts(value); int i; ini_read_int(conf, "int", "int", &i, 0); unsigned ui; ini_read_unsigned(conf, "int", "unsigned", &ui, 0); printf("int: %d, unsigned: %u\n", i, ui); int8_t int8; ini_read_int8(conf, "int", "int8", &int8, 0); uint8_t uint8; ini_read_uint8(conf, "int", "uint8", &uint8, 0); printf("int8: %i, uint8: %u\n", int8, uint8); int16_t int16; ini_read_int16(conf, "int", "int16", &int16, 0); uint16_t uint16; ini_read_uint16(conf, "int", "uint16", &uint16, 0); printf("int16: %i, uint16: %u\n", int16, uint16); int32_t int32; ini_read_int32(conf, "int", "int32", &int32, 0); uint32_t uint32; ini_read_uint32(conf, "int", "uint32", &uint32, 0); printf("int32: %i, uint32: %u\n", int32, uint32); int64_t int64; ini_read_int64(conf, "int", "int64", &int64, 0); uint64_t uint64; ini_read_uint64(conf, "int", "uint64", &uint64, 0); printf("int64: %"PRIi64", uint64: %"PRIu64"\n", int64, uint64); float f; ini_read_float(conf, "float", "float", &f, 0); double d; ini_read_double(conf, "float", "double", &d, 0); printf("float: %f, double: %f\n", f, d); struct sockaddr_in addr; ini_read_ipv4_addr(conf, "addr", "ipv4", &addr, "127.0.0.1:0"); printf("%s:%u\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); char *proc_name = NULL; ini_read_str(conf, "global", "proc_name", &proc_name, "test.ini"); printf("proc_name: %s\n", proc_name); free(proc_name); char *phone_num = NULL; ini_read_str(conf, "damon", "phone num", &phone_num, "123456789"); printf("phone num: %s\n", phone_num); free(phone_num); char *city = NULL; ini_read_str(conf, "global", "$%^#@!", &city, "shen zhen"); puts(city); free(city); char *name = NULL; ini_read_str(conf, NULL, "名字", &name, ""); puts(name); free(name); ini_free(conf); return 0; }
conf_t *conf_init(void) { conf_t *self; ini_t *ini; char *tmp, **splitted; int nsplits; unsigned i; dict_t *vars; self = xmalloc(sizeof(conf_t)); self->post_pkgadd = NULL; self->ask_for_update = 1; self->not_found_policy = ASK; ini = ini_new(CONF_FILE); ini_add(ini, "ilenia"); ini_set_default(ini, "ilenia", "post_pkgadd", xstrdup("")); ini_set_default(ini, "ilenia", "ask_for_update", xstrdup("1")); ini_set_default(ini, "ilenia", "not_found_policy", xstrdup("ASK")); ini_set_default(ini, "ilenia", "repositories_hierarchy", xstrdup("")); ini_set_default(ini, "ilenia", "enable_colors", xstrdup("Yes")); ini_set_default(ini, "ilenia", "verbose", xstrdup("No")); ini_add(ini, "favourite_repositories"); ini_add(ini, "locked_versions"); ini_add(ini, "aliases"); ini_add(ini, "pkgmk_confs"); ini_load(ini); if ((tmp = getenv("POST_PKGADD")) == NULL) tmp = ini_get(ini, "ilenia", "post_pkgadd"); self->post_pkgadd = xstrdup(tmp); if ((tmp = getenv("ASK_FOR_UPDATE")) == NULL) tmp = ini_get(ini, "ilenia", "ask_for_update"); if (!strcasecmp(tmp, "NO")) self->ask_for_update = 0; else self->ask_for_update = 1; if ((tmp = getenv("NOT_FOUND_POLICY")) == NULL) tmp = ini_get(ini, "ilenia", "not_found_policy"); if (!strcasecmp(tmp, "NEVERMIND")) self->not_found_policy = NEVERMIND; else if (!strcasecmp(tmp, "STOP")) self->not_found_policy = STOP; else self->not_found_policy = ASK; tmp = ini_get(ini, "ilenia", "repositories_hierarchy"); if (tmp != NULL) { strreplace(&tmp, "\t", " ", -1); while (strstr(tmp, " ")) strreplace(&tmp, " ", " ", -1); splitted = NULL; nsplits = strsplit(tmp, ' ', &splitted); self->repositories_hierarchy = list_new_from_array((void **)splitted, nsplits); free(splitted); } else self->repositories_hierarchy = list_new(); if ((tmp = getenv("ENABLE_COLORS")) == NULL) tmp = ini_get(ini, "ilenia", "enable_colors"); if (!strcasecmp(tmp, "NO")) self->enable_colors = 0; else self->enable_colors = 1; if ((tmp = getenv("VERBOSE")) == NULL) tmp = ini_get(ini, "ilenia", "verbose"); if (strcasecmp(tmp, "Yes") == 0) self->verbose = 1; else self->verbose = 0; self->favourite_repositories = dict_new(); vars = ini_get_vars(ini, "favourite_repositories"); for (i = 0; vars && i < vars->length; i++) dict_add(self->favourite_repositories, vars->elements[i]->key, xstrdup(vars->elements[i]->value)); self->locked_versions = dict_new(); vars = ini_get_vars(ini, "locked_versions"); for (i = 0; vars && i < vars->length; i++) dict_add(self->locked_versions, vars->elements[i]->key, xstrdup(vars->elements[i]->value)); self->aliases = dict_new(); vars = ini_get_vars(ini, "aliases"); for (i = 0; vars != NULL && i < vars->length; i++) { tmp = vars->elements[i]->value; strreplace(&tmp, "\t", " ", -1); while (strstr(tmp, " ")) strreplace(&tmp, " ", " ", -1); splitted = NULL; nsplits = strsplit(tmp, ' ', &splitted); if (nsplits == 0) continue; dict_add(self->aliases, vars->elements[i]->key, list_new_from_array((void **)splitted, nsplits)); free(splitted); } self->pkgmk_confs = dict_new(); vars = ini_get_vars(ini, "pkgmk_confs"); for (i = 0; vars && i < vars->length; i++) dict_add(self->pkgmk_confs, vars->elements[i]->key, xstrdup(vars->elements[i]->value)); ini_free(ini); return self; }