void stp_xml_preinit(void) { static int xml_is_preinitialized = 0; if (!xml_is_preinitialized) { stpi_xml_registry = stp_list_create(); stp_list_set_freefunc(stpi_xml_registry, xml_registry_freefunc); stp_list_set_namefunc(stpi_xml_registry, xml_registry_namefunc); stpi_xml_preloads = stp_list_create(); stp_list_set_freefunc(stpi_xml_preloads, xml_preload_freefunc); stp_list_set_namefunc(stpi_xml_preloads, xml_preload_namefunc); } }
stp_list_t * stp_list_copy(const stp_list_t *list) { stp_list_t *ret; stp_node_copyfunc copyfunc = stp_list_get_copyfunc(list); stp_list_item_t *item = list->start; check_list(list); ret = stp_list_create(); stp_list_set_copyfunc(ret, stp_list_get_copyfunc(list)); /* If we use default (shallow) copy, we can't free the elements of it */ if (stp_list_get_copyfunc(list)) stp_list_set_freefunc(ret, stp_list_get_freefunc(list)); stp_list_set_namefunc(ret, stp_list_get_namefunc(list)); stp_list_set_long_namefunc(ret, stp_list_get_long_namefunc(list)); stp_list_set_sortfunc(ret, stp_list_get_sortfunc(list)); while (item) { void *data = item->data; if (copyfunc) stp_list_item_create (ret, NULL, (*copyfunc)(data)); else stp_list_item_create(ret, NULL, data); item = stp_list_item_next(item); } return ret; }
void stp_xml_parse_file_named(const char *name) { stp_list_t *dir_list; /* List of directories to scan */ stp_list_t *file_list; /* List of XML files */ stp_list_item_t *item; /* Pointer to current list item */ if (!(dir_list = stp_list_create())) return; stp_list_set_freefunc(dir_list, stp_list_node_free_data); if (getenv("STP_DATA_PATH")) stp_path_split(dir_list, getenv("STP_DATA_PATH")); else stp_path_split(dir_list, PKGXMLDATADIR); file_list = stp_path_search(dir_list, name); stp_list_destroy(dir_list); item = stp_list_get_start(file_list); while (item) { stp_deprintf(STP_DBG_XML, "stp_xml_parse_file_named: source file: %s\n", (const char *) stp_list_item_get_data(item)); stp_xml_parse_file((const char *) stp_list_item_get_data(item)); item = stp_list_item_next(item); } stp_list_destroy(file_list); }
stp_string_list_t * stp_string_list_create(void) { stp_list_t *ret = stp_list_create(); stp_list_set_freefunc(ret, free_list_element); stp_list_set_namefunc(ret, namefunc); stp_list_set_copyfunc(ret, copyfunc); stp_list_set_long_namefunc(ret, long_namefunc); return (stp_string_list_t *) ret; }
/* * Load all available modules. Return nonzero on failure. */ int stp_module_load(void) { /* initialise libltdl */ #ifdef USE_LTDL static int ltdl_is_initialised = 0; /* Is libltdl initialised? */ #endif static int module_list_is_initialised = 0; /* Is the module list initialised? */ #if defined(USE_LTDL) || defined(USE_DLOPEN) stp_list_t *dir_list; /* List of directories to scan */ stp_list_t *file_list; /* List of modules to open */ stp_list_item_t *file; /* Pointer to current module */ #endif #ifdef USE_LTDL if (!ltdl_is_initialised) { if (lt_dlinit()) { stp_erprintf("Error initialising libltdl: %s\n", DLERROR()); return 1; } ltdl_is_initialised = 1; } /* set default search paths */ lt_dladdsearchdir(PKGMODULEDIR); #endif /* initialise module_list */ if (!module_list_is_initialised) { if (!(module_list = stp_list_create())) return 1; stp_list_set_freefunc(module_list, module_list_freefunc); module_list_is_initialised = 1; } /* search for available modules */ #if defined (USE_LTDL) || defined (USE_DLOPEN) if (!(dir_list = stp_list_create())) return 1; stp_list_set_freefunc(dir_list, stp_list_node_free_data); if (getenv("STP_MODULE_PATH")) { stp_path_split(dir_list, getenv("STP_MODULE_PATH")); } else { #ifdef USE_LTDL stp_path_split(dir_list, getenv("LTDL_LIBRARY_PATH")); stp_path_split(dir_list, lt_dlgetsearchpath()); #else stp_path_split(dir_list, PKGMODULEDIR); #endif } #ifdef USE_LTDL file_list = stp_path_search(dir_list, ".la"); #else file_list = stp_path_search(dir_list, ".so"); #endif stp_list_destroy(dir_list); /* load modules */ file = stp_list_get_start(file_list); while (file) { stp_module_open((const char *) stp_list_item_get_data(file)); file = stp_list_item_next(file); } stp_list_destroy(file_list); #else /* use a static module list */ { int i=0; while (static_modules[i]) { stp_module_register(static_modules[i]); i++; } } #endif return 0; }