static int _find_interface_class(int iclass) { Eina_List *devs; char *name; devs = ecore_file_ls("/sys/bus/usb/devices"); EINA_LIST_FREE(devs, name) { char buf[PATH_MAX]; FILE *f; snprintf(buf, sizeof(buf), "%s/%s/%s", "/sys/bus/usb/devices", name, "bInterfaceClass"); f = fopen(buf, "r"); if (f) { if (fgets(buf, sizeof(buf), f)) { int id = -1; sscanf(buf, "%x", &id); if (iclass == id) { EINA_LIST_FREE(devs, name) free(name); fclose(f); return 1; } } fclose(f); } free(name); }
std::vector< std::string > const FileManager::findFilesOfType( std::string const& _ext , std::string const& _path ) { std::vector< std::string > files; Eina_List* listed( ecore_file_ls( _path.c_str() ) ); if( nullptr != listed ) { Eina_List* unused( nullptr ); void* data( nullptr ); EINA_LIST_FOREACH( listed , unused , data ) { std::string file( _path + "/" + static_cast< char* >( data ) ); if( 1 == ecore_file_is_dir( file.c_str() ) ) { auto sub_files( findFilesOfType( _ext , file ) ); files.insert( files.end() , sub_files.begin() , sub_files.end() ); } else { if( file.rfind( _ext ) == ( file.size() - 3 ) ) files.push_back( file ); } }
/** * @param dir The path to scan for themes * @return Return an Eina_List* of Exchange_Theme_Data* * @brief Get the list of all the themes in the given directory */ EAPI Eina_List* exchange_local_theme_list_get(const char *dir) { Exchange_Object *td = NULL; Eina_List *files; Eina_List *themes = NULL; char *filename; DBG("%s\n", dir); if (!dir || !ecore_file_is_dir(dir)) { ERR("Local dir not valid '%s'\n", dir); return NULL; } files = ecore_file_ls(dir); EINA_LIST_FREE(files, filename) { char path[4096]; char *ext; ext = strrchr(filename, '.'); if (!ext || strcmp(ext, ".edj")) { free(filename); continue; } snprintf(path, sizeof(path), "%s/%s", dir, filename); td = exchange_local_theme_all_data_get(path); themes = eina_list_append(themes, td); free(filename); }
Ecore_File_Monitor * ecore_file_monitor_backend_add(const char *path, void (*func) (void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path), void *data) { Ecore_File_Monitor *em; size_t len; if (!path) return NULL; if (!func) return NULL; em = calloc(1, sizeof(Ecore_File_Monitor_Poll)); if (!em) return NULL; if (!_timer) _timer = ecore_timer_add(_interval, _ecore_file_monitor_poll_handler, NULL); else ecore_timer_interval_set(_timer, ECORE_FILE_INTERVAL_MIN); em->path = strdup(path); len = strlen(em->path); if (em->path[len - 1] == '/' && strcmp(em->path, "/")) em->path[len - 1] = 0; em->func = func; em->data = data; ECORE_FILE_MONITOR_POLL(em)->mtime = ecore_file_mod_time(em->path); _monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em))); if (ecore_file_exists(em->path)) { if (ecore_file_is_dir(em->path)) { /* Check for subdirs */ Eina_List *files; char *file; files = ecore_file_ls(em->path); EINA_LIST_FREE(files, file) { Ecore_File *f; char buf[PATH_MAX]; f = calloc(1, sizeof(Ecore_File)); if (!f) { free(file); continue; } snprintf(buf, sizeof(buf), "%s/%s", em->path, file); f->name = file; f->mtime = ecore_file_mod_time(buf); f->is_dir = ecore_file_is_dir(buf); em->files = (Ecore_File *) eina_inlist_append(EINA_INLIST_GET(em->files), EINA_INLIST_GET(f)); } }
static void _load_keys(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h) { Evas_Object *tbl, *btn; Eina_List *files = NULL, *kbs = NULL; size_t len; char buff[PATH_MAX], *file, *path; static int c = 0, r = 0; if (!obj) return; tbl = elm_table_add(obj); elm_win_resize_object_add(obj, tbl); evas_object_size_hint_weight_set(tbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_show(tbl); len = snprintf(buff, sizeof(buff), "/usr/lib/enlightenment/modules/illume-keyboard/keyboards"); files = ecore_file_ls(buff); buff[len] = '/'; len++; EINA_LIST_FREE(files, file) { char *p; p = strrchr(file, '.'); if ((p) && (!strcmp(p, ".kbd"))) { if (eina_strlcpy(buff + len, file, sizeof(buff) - len) >= sizeof(buff) - len) continue; kbs = eina_list_append(kbs, eina_stringshare_add(buff)); } free(file); }
void get_theme_list() { char * path; path = malloc(sizeof(char) * PATH_MAX); snprintf(path, PATH_MAX, "%s/.e/e/themes", getenv("HOME")); Ecore_List *list; list = ecore_file_ls(path); ecore_list_first_goto(list); char * data; themes = NULL; while ((data = (char *)ecore_list_next(list))) if (strstr(data, ".edj") != NULL) { char * file = (char *) strdup(data); Etheme_Object * o; o = etheme_new(file); themes = eina_list_append(themes, o); free(file); } ecore_list_destroy(list); free(path); }
E_API void * e_modapi_init(E_Module *m) { Eina_List *files; char buf[PATH_MAX]; char *file; wiz_module = m; e_wizard_init(); e_config->scale.use_dpi = 0; e_config->scale.use_custom = 1; e_config->scale.factor = 1.2; e_scale_update(); snprintf(buf, sizeof(buf), "%s/%s", e_module_dir_get(m), MODULE_ARCH); files = ecore_file_ls(buf); files = eina_list_sort(files, 0, (Eina_Compare_Cb)_cb_sort_files); EINA_LIST_FREE(files, file) { if ((!strncmp(file, "page_", 5)) && (eina_str_has_extension(file, ".so"))) { void *handle; snprintf(buf, sizeof(buf), "%s/%s/%s", e_module_dir_get(m), MODULE_ARCH, file); handle = dlopen(buf, RTLD_NOW | RTLD_GLOBAL); if (handle) e_wizard_page_add(handle, dlsym(handle, "wizard_page_init"), dlsym(handle, "wizard_page_shutdown"), dlsym(handle, "wizard_page_show"), dlsym(handle, "wizard_page_hide"), dlsym(handle, "wizard_page_apply")); else { // if its an executable... // XXX // else... printf("%s\n", dlerror()); } } free(file); } e_wizard_go(); return m; }
/** * @return Return a list of strings with filename (remember to free the list * when you don't need anymore) * @brief List all the files and directory currently inside the trash. */ EAPI Eina_List* efreet_trash_ls(void) { char *infofile; char buf[PATH_MAX]; Eina_List *files, *l; // NOTE THIS FUNCTION NOW IS NOT COMPLETE AS I DON'T NEED IT // TODO read the name from the infofile instead of the filename snprintf(buf, sizeof(buf), "%s/files", efreet_trash_dir_get(NULL)); files = ecore_file_ls(buf); EINA_LIST_FOREACH(files, l, infofile) printf("FILE: %s\n", infofile); return files; }
static void check_menu_dir(const char *dir) { char buf[PATH_MAX], *file; Eina_List *files; snprintf(buf, sizeof(buf), "%s/menus", dir); files = ecore_file_ls(buf); EINA_LIST_FREE(files, file) { if (e_util_glob_match(file, "*.menu")) { snprintf(buf, sizeof(buf), "%s/menus/%s", dir, file); menus = eina_list_append(menus, strdup(buf)); } free(file); } }
static Eina_List * load_layouts_from_path(Eina_List *layout_list, const char *path1, const char *path2) { char *f, *p; char *file = malloc(MaxBuffer); Eina_List *l, *ls; asprintf(&p, "%s/%s", path1, path2); ls = ecore_file_ls(p); EINA_LIST_FOREACH(ls, l, f) { char *s = strrchr(f, '.'); if (!s || strcmp(s, ".ini")) continue; *s = '\0'; snprintf(file, MaxBuffer, "%s/%s", path2, f); free(f); keys_t *keys = keys_alloc(file); if (!keys) continue; vk_layout_t *layout = malloc(sizeof(vk_layout_t)); const char *str; str = keys_lookup(keys, "default", "name"); layout->name = strdup(str); str = keys_lookup(keys, "default", "sname"); layout->sname = strdup(str); layout->keys = keys; layout_list = eina_list_append(layout_list, layout); }
EAPI void * e_modapi_init(E_Module *m) { Eina_List *files; char buf[PATH_MAX]; char *file; default_e_theme = NULL; conf_module = m; e_wizard_init(); snprintf(buf, sizeof(buf), "%s/%s", e_module_dir_get(m), MODULE_ARCH); files = ecore_file_ls(buf); files = eina_list_sort(files, 0, (Eina_Compare_Cb)_cb_sort_files); EINA_LIST_FREE(files, file) { if (!strncmp(file, "page_", 5)) { void *handle; snprintf(buf, sizeof(buf), "%s/%s/%s", e_module_dir_get(m), MODULE_ARCH, file); handle = dlopen(buf, RTLD_NOW | RTLD_GLOBAL); if (handle) { e_wizard_page_add(handle, dlsym(handle, "wizard_page_init"), dlsym(handle, "wizard_page_shutdown"), dlsym(handle, "wizard_page_show"), dlsym(handle, "wizard_page_hide"), dlsym(handle, "wizard_page_apply")); } else printf("%s\n", dlerror()); } free(file); } e_wizard_go(); return m; }
static void _walle_wall_populate(Walle *walle, const char *directory, const char *theme) { Evas_Object *o; Evas_Coord ow, oh, w, h; Eina_List *files = NULL; char *file = NULL; char filename[4096]; if (!ecore_file_is_dir(directory) && ecore_file_dir_is_empty(directory)) return; files = ecore_file_ls(directory); if (!files) return; EINA_LIST_FREE(files, file) { sprintf(filename, "%s/%s", directory, file); o = evas_object_image_add(walle->evas); evas_object_image_file_set(o, filename, NULL); switch(evas_object_image_load_error_get(o)) { case EVAS_LOAD_ERROR_NONE: { evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _walle_picture_cb_resize, o); evas_object_image_size_get(o, &w, &h); oh = 200; ow = oh * (float)w/(float)h; evas_object_image_load_size_set(o, ow, oh); evas_object_image_fill_set(o, 0, 0, ow, oh); evas_object_resize(o, ow, oh); evas_object_size_hint_min_set(o, ow, oh); walle_wall_append(walle->o_wall, o); walle->pictures = eina_list_append(walle->pictures, o); } break; default: evas_object_del(o); break; } }
void ModuleManager::SearchModules() { for (uint i = 0; i < search_paths.size(); i++) { cInfoDom("module") << "ModuleManager: searching modules in: " << search_paths[i]; char *fname = NULL; void *data = NULL; Eina_List *subdir = ecore_file_ls(search_paths[i].c_str()); Eina_List *l = NULL; EINA_LIST_FOREACH(subdir, l, data) { fname = (char *)data; string p; p = search_paths[i]; if (fname) { p += "/"; p += fname; } if (p[p.length() - 1] != '/') p += "/"; if (!ecore_file_is_dir(p.c_str())) continue; p += "module.so"; if (!ecore_file_exists(p.c_str())) continue; bool alreadyin = false; for (uint im = 0; im < modules.size() && !alreadyin; im++) { ModuleDef mdef = modules[im]; if (p == mdef.mod_fname) alreadyin = true; } if (alreadyin) continue; //try to load the module void *handle = dlopen(p.c_str(), RTLD_LAZY); if (handle) { //object can be loaded, check version and CalaosModuleApi *api = (CalaosModuleApi *)dlsym(handle, "calaos_modapi"); if (!api) { dlclose(handle); cErrorDom("module") << "ModuleManager: module " << p << ". calaos_modapi export not found: " << dlerror(); continue; } if (api->api_version != CALAOS_MODULE_API_VERSION) { dlclose(handle); cErrorDom("module") << "ModuleManager: module " << p << ". The API version doesn't match"; continue; } string module_name; vector<string> tok; Utils::split(p, tok, "/"); if (tok.size() > 2) module_name = tok[tok.size() - 2]; string themepath = Prefix::Instance().dataDirectoryGet(); themepath += "/widgets/" + module_name; ModuleDef mdef; mdef.mod_name = gettext(api->name); mdef.mod_desc = gettext(api->desc); mdef.mod_version = api->version; mdef.mod_author = api->author; mdef.mod_icon = themepath + "/icon.edj"; mdef.mod_fname = p; mdef.handle = handle; mdef.inst = NULL; mdef.api = api; cInfoDom("module") << "ModuleManager: found module: " << mdef.mod_name; modules.push_back(mdef); } else { cWarningDom("module") << "ModuleManager: file " << p << " : failed to dlopen: " << dlerror(); } } EINA_LIST_FREE(subdir, data) free(data); }
/* Sets the folder displayed in the iconbox */ static void _etk_test_iconbox_folder_set(Etk_Iconbox *iconbox, const char *folder) { Eina_List *files; Eina_List *l; char *filename; char file_path[PATH_MAX]; Etk_Iconbox_Icon *iicon; if (!iconbox) return; if (!folder && !(folder = getenv("HOME"))) return; if (!(files = ecore_file_ls(folder))) return; etk_iconbox_clear(iconbox); etk_iconbox_append(iconbox, etk_theme_icon_path_get(), "actions/go-up_48", ".."); /* First, add the folders */ EINA_LIST_FOREACH(files, l, filename) { if (filename[0] == '.') continue; snprintf(file_path, PATH_MAX, "%s/%s", folder, filename); if (!ecore_file_is_dir(file_path)) continue; iicon = etk_iconbox_append(iconbox, etk_theme_icon_path_get(), "places/folder_48", filename); if (!ecore_file_can_read(file_path)) etk_iconbox_icon_emblem_set_from_stock(iicon, "unreadable"); else if (!ecore_file_can_write(file_path)) etk_iconbox_icon_emblem_set_from_stock(iicon, "readonly"); } /* Then the files */ EINA_LIST_FOREACH(files, l, filename) { const char *ext; char *icon = NULL; int i; if (filename[0] == '.') continue; snprintf(file_path, PATH_MAX, "%s/%s", folder, filename); if (ecore_file_is_dir(file_path)) continue; if ((ext = strrchr(filename, '.')) && (ext = ext + 1)) { for (i = 0; i < _etk_test_iconbox_num_types; i++) { if (strcasecmp(ext, _etk_test_iconbox_types[i].extension) == 0) { icon = _etk_test_iconbox_types[i].icon; break; } } } iicon = etk_iconbox_append(iconbox, etk_theme_icon_path_get(), icon ? icon : "mimetypes/text-x-generic_48", filename); if (!ecore_file_can_read(file_path)) etk_iconbox_icon_emblem_set_from_stock(iicon, "unreadable"); else if (!ecore_file_can_write(file_path)) etk_iconbox_icon_emblem_set_from_stock(iicon, "readonly"); else if (ecore_file_can_exec(file_path)) etk_iconbox_icon_emblem_set_from_stock(iicon, "system"); } EINA_LIST_FREE(files, filename) free(filename); if (!_etk_test_iconbox_current_folder) _etk_test_iconbox_current_folder = etk_string_new(NULL); etk_string_set(_etk_test_iconbox_current_folder, folder); etk_window_title_set(ETK_WINDOW(win), folder); }
E_API int wizard_page_shutdown(E_Wizard_Page *pg EINA_UNUSED) { return 1; } */ E_API int wizard_page_show(E_Wizard_Page *pg EINA_UNUSED) { int hav_bat = 0; Eina_List *dir; char buf[PATH_MAX], *file, *dname, *str; dname = "/sys/class/power_supply"; dir = ecore_file_ls(dname); if (dir) { EINA_LIST_FREE(dir, file) { snprintf(buf, sizeof(buf), "%s/%s/type", dname, file); str = read_file(buf); if (str) { if (!strcasecmp(str, "Battery")) hav_bat = 1; free(str); } } } dname = "/proc/acpi/battery/"; dir = ecore_file_ls(dname);
static void _fill_data_tempget(E_Config_Dialog_Data *cfdata) { cfdata->unit_method = cfdata->inst->units; cfdata->poll.interval = cfdata->inst->poll_interval; cfdata->temp.low = cfdata->inst->low; cfdata->temp.high = cfdata->inst->high; cfdata->sensor = 0; #ifdef HAVE_EEZE cfdata->backend = cfdata->inst->backend; if (cfdata->backend == TEMPGET) { #endif switch (cfdata->inst->sensor_type) { case SENSOR_TYPE_NONE: case SENSOR_TYPE_FREEBSD: case SENSOR_TYPE_OMNIBOOK: case SENSOR_TYPE_LINUX_MACMINI: case SENSOR_TYPE_LINUX_PBOOK: case SENSOR_TYPE_LINUX_INTELCORETEMP: break; case SENSOR_TYPE_LINUX_I2C: _fill_sensors(cfdata, "i2c"); break; case SENSOR_TYPE_LINUX_PCI: _fill_sensors(cfdata, "pci"); break; case SENSOR_TYPE_LINUX_ACPI: { Eina_List *l; if ((l = ecore_file_ls("/proc/acpi/thermal_zone"))) { char *name; int n = 0; EINA_LIST_FREE(l, name) { cfdata->sensors = eina_list_append(cfdata->sensors, name); if (!strcmp(cfdata->inst->sensor_name, name)) cfdata->sensor = n; n++; } } break; } case SENSOR_TYPE_LINUX_SYS: { Eina_List *l; if ((l = ecore_file_ls("/sys/class/thermal"))) { char *name; int n = 0; EINA_LIST_FREE(l, name) { if (!strncmp(name, "thermal", 7)) { cfdata->sensors = eina_list_append(cfdata->sensors, name); if (!strcmp(cfdata->inst->sensor_name, name)) cfdata->sensor = n; n++; } } } break; }
/* * List depends on: * - state->sort * - state->tags * - state->filter * - dir contents on FS */ static Eina_Array * _fill_files(const madshelf_state_t *state, const char *dir, int *old_pos) { char *old_file = curdir_get(dir); if(old_pos) *old_pos = -1; Eina_Array *files = eina_array_new(10); /* HACK: using global variable to pas state into sort function */ cur_dir = !strcmp(dir, "/") ? "" : dir; Eina_List *ls = ecore_file_ls(dir); ls = eina_list_sort(ls, eina_list_count(ls), state->sort == MADSHELF_SORT_NAME ? &_name : (state->sort == MADSHELF_SORT_NAMEREV ? &_namerev : &_daterev)); /* First select directories */ for (Eina_List *i = ls; i; i = eina_list_next(i)) { const char *file = eina_list_data_get(i); char *filename = xasprintf("%s/%s", !strcmp(dir, "/") ? "" : dir, file); if (!ecore_file_is_dir(filename)) { free(filename); continue; } if (!state->show_hidden && is_hidden(state, filename)) { free(filename); continue; } if (old_file && old_pos) if (!strcmp(old_file, file)) *old_pos = eina_array_count_get(files); eina_array_push(files, filename); } /* Then files */ for (Eina_List *i = ls; i; i = eina_list_next(i)) { const char *file = eina_list_data_get(i); char *filename = xasprintf("%s/%s", !strcmp(dir, "/") ? "" : dir, file); if (ecore_file_is_dir(filename)) { free(filename); continue; } if (!state->show_hidden && is_hidden(state, filename)) { free(filename); continue; } if (old_file && old_pos) if (!strcmp(old_file, file)) *old_pos = eina_array_count_get(files); eina_array_push(files, filename); } char* s; EINA_LIST_FREE(ls, s) free(s); free(old_file); return files; }
/** * @param path: The path to the directory to read * @param show_dot: TRUE shows dot files, FALSE does not * @param show_dot_dot: TRUE shows .. for navigating upwards, FALSE does not * @param filter: The Ewl_Filelist_Filter to use * @return Returns an Ewl_Filelist_Directory structure * @brief Retrieves all files in a directory */ Ewl_Filelist_Directory * ewl_filelist_model_directory_new(const char *path, unsigned char show_dot, unsigned int show_dot_dot, Ewl_Filelist_Filter *filter) { Ewl_Filelist_Directory *dir; Ewl_Filelist_File *file; char filename[PATH_MAX], *file_temp; int nf = 0, nd = 0; Eina_List *all_files; Ecore_List *dirs, *files; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET(path, NULL); files = ecore_list_new(); dirs = ecore_list_new(); ecore_list_free_cb_set(files, ECORE_FREE_CB(ewl_filelist_file_destroy)); ecore_list_free_cb_set(dirs, ECORE_FREE_CB(ewl_filelist_file_destroy)); all_files = ecore_file_ls(path); if (!all_files) DRETURN_PTR(NULL, DLEVEL_STABLE); /* Add in the ".." entry for now */ if ((show_dot_dot) && (strcmp(path, "/"))) all_files = eina_list_prepend(all_files, strdup(path)); EINA_LIST_FREE(all_files, file_temp) { /* allocate the memory for the file structure */ file = ewl_filelist_file_new(); if (!file) { ecore_list_destroy(files); ecore_list_destroy(dirs); DRETURN_PTR(NULL, DLEVEL_STABLE); } /* test for .. */ if (strcmp(file_temp, path)) { snprintf(filename, PATH_MAX, "%s/%s", path, file_temp); ewl_filelist_file_name_set(file, file_temp); } else { snprintf(filename, PATH_MAX, "%s", file_temp); ewl_filelist_file_name_set(file, ".."); } /* Generate the file information */ if (!ewl_filelist_file_path_set(file, filename)) { ewl_filelist_file_destroy(file); ecore_list_destroy(files); ecore_list_destroy(dirs); DRETURN_PTR(NULL, DLEVEL_STABLE); } if (ewl_filelist_file_is_dir(file)) { ecore_list_append(dirs, file); nd = nd + 1; } else { ecore_list_append(files, file); nf = nf + 1; } FREE(file_temp); }