/** * @param ini The Efreet_Ini to work with * @param section The section of the ini file we want to add * @return Returns no value * @brief Adds a new working section of the ini file to @a section */ EAPI void efreet_ini_section_add(Efreet_Ini *ini, const char *section) { Eina_Hash *hash; if (!ini || !section) return; if (!ini->data) ini->data = eina_hash_string_small_new(EINA_FREE_CB(eina_hash_free)); if (eina_hash_find(ini->data, section)) return; hash = eina_hash_string_small_new(EINA_FREE_CB(eina_stringshare_del)); eina_hash_add(ini->data, section, hash); }
void lime_filters_init(void) { //TODO dynamic loading from filters as dynamic library! on-demand? (by short-name?) lime_filters = eina_hash_string_small_new(&free); eina_hash_add(lime_filters, filter_core_gauss.shortname, &filter_core_gauss); eina_hash_add(lime_filters, filter_core_compare.shortname, &filter_core_compare); eina_hash_add(lime_filters, filter_core_down.shortname, &filter_core_down); eina_hash_add(lime_filters, filter_core_memsink.shortname, &filter_core_memsink); eina_hash_add(lime_filters, filter_core_convert.shortname, &filter_core_convert); eina_hash_add(lime_filters, filter_core_loadtiff.shortname, &filter_core_loadtiff); eina_hash_add(lime_filters, filter_core_contrast.shortname, &filter_core_contrast); eina_hash_add(lime_filters, filter_core_exposure.shortname, &filter_core_exposure); eina_hash_add(lime_filters, filter_core_load.shortname, &filter_core_load); eina_hash_add(lime_filters, filter_core_savetiff.shortname, &filter_core_savetiff); eina_hash_add(lime_filters, filter_core_sharpen.shortname, &filter_core_sharpen); eina_hash_add(lime_filters, filter_core_denoise.shortname, &filter_core_denoise); eina_hash_add(lime_filters, filter_core_pretend.shortname, &filter_core_pretend); //eina_hash_add(lime_filters, filter_core_crop.shortname, &filter_core_crop); eina_hash_add(lime_filters, filter_core_simplerotate.shortname, &filter_core_simplerotate); eina_hash_add(lime_filters, filter_core_rotate.shortname, &filter_core_rotate); eina_hash_add(lime_filters, filter_core_savejpeg.shortname, &filter_core_savejpeg); eina_hash_add(lime_filters, filter_core_curves.shortname, &filter_core_curves); eina_hash_add(lime_filters, filter_core_lrdeconv.shortname, &filter_core_lrdeconv); eina_hash_add(lime_filters, filter_core_lensfun.shortname, &filter_core_lensfun); }
static Eina_Hash * _extrackt_eina_hash_add(Eina_Hash *hash, const char *key, void *data) { if (!hash) hash = eina_hash_string_small_new(NULL); if (!hash) return NULL; eina_hash_add(hash, key, data); return hash; }
/* this will alloc an Evas_Module struct for each module * it finds on the paths */ void evas_module_init(void) { int i; evas_module_paths_init(); evas_modules[EVAS_MODULE_TYPE_ENGINE] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); evas_modules[EVAS_MODULE_TYPE_IMAGE_LOADER] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); evas_modules[EVAS_MODULE_TYPE_IMAGE_SAVER] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); evas_modules[EVAS_MODULE_TYPE_OBJECT] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); evas_engines = eina_array_new(4); for (i = 0; evas_static_module[i].init; ++i) evas_static_module[i].init(); }
Jesus_Config* _config_standart_new() { Jesus_Config *config; config = calloc(1, sizeof(Jesus_Config)); config->mime_type_open = eina_hash_string_small_new(NULL); return config; }
int main(void) { double start; Eina_Hash *headers; eina_init(); ecore_init(); ecore_file_init(); if (ecore_file_exists(DST)) ecore_file_unlink(DST); start = ecore_time_get(); if (ecore_file_download(URL, DST, completion_cb, progress_cb, NULL, NULL)) { printf("Download started successfully:\n URL: %s\n DEST: %s\n", URL, DST); ecore_main_loop_begin(); printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start); printf("Downloaded %lld bytes\n", ecore_file_size(DST)); } else { printf("Error, can't start download\n"); goto done; } headers = eina_hash_string_small_new(NULL); eina_hash_add(headers, "Content-type", "application/x-gzip"); if (ecore_file_download_full(URL, DST_MIME, completion_cb, progress_cb, NULL, NULL, headers)) { printf("Download started successfully:\n URL: %s\n DEST: %s\n", URL, DST_MIME); ecore_main_loop_begin(); printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start); printf("Downloaded %lld bytes\n", ecore_file_size(DST)); } else { printf("Error, can't start download\n"); goto done; } done: if (headers) eina_hash_free(headers); ecore_file_shutdown(); ecore_shutdown(); eina_shutdown(); return 0; }
static My_Cache * _my_cache_new(void) { My_Cache *my_cache = calloc(1, sizeof(My_Cache)); if (!my_cache) { fprintf(stderr, "ERROR: could not calloc My_Cache\n"); return NULL; } my_cache->accounts = eina_hash_string_small_new(NULL); my_cache->version = 1; return my_cache; } /* _my_cache_new */
/** * The menu command parser. * * This parses menu a single command. * * This assumes that the emu_face->lines[].line pointers point into * a contiguous area of ram. * * @param emu_face the face, it includes the input lines that the command is a part of. * @param command the index of the command. * @param name any name that was included with this instance of the command. * @param start index of the start line of the command. * @param end index of the end line of the command. * @ingroup Emu_Module_Parser_Group */ static void _emu_parse_menu(Emu_Face *emu_face, char *name, int start, int end) { char *category = NULL; int length; /* Calculate the length of the menu data. */ length = (emu_face->lines[end].line + emu_face->lines[end].size) - emu_face->lines[start].line; if (length > 0) { Easy_Menu *menu; if (name == NULL) /* Default sub menu item text is the name of the face. */ name = (char *)emu_face->name; else { /* The category is after the name. */ category = name; while ((*category != '|') && (*category != '\0')) category++; if (*category == '|') *category++ = '\0'; else category = NULL; } /* Turn the command data into a menu. */ menu = easy_menu_add_menus(name, category, emu_face->lines[start].line, length, _emu_menu_cb_action, emu_face->exe); if (menu) { Easy_Menu *old_menu; if (!emu_face->menus) emu_face->menus = eina_hash_string_small_new(NULL); /* Associate this menu with it's category. Only one menu per category. */ old_menu = eina_hash_find(emu_face->menus, menu->category); if (old_menu) { /* Clean up the old one. */ eina_hash_del(emu_face->menus, menu->category, old_menu); eina_hash_del(emu_face->menus, NULL, old_menu); /* Just to be on the safe side. */ e_object_del(E_OBJECT(old_menu->menu->menu)); } /* eina_hash_direct_add is used because we allocate the key ourselves and don't deallocate it until after removing it. */ eina_hash_direct_add(emu_face->menus, menu->category, menu); } } }
Eina_Hash *read_histogram_file(char * input_file) { histogram_cache_t *histo_cache; Eina_Hash *map_histo; Eet_File *ef = eet_open(input_file, EET_FILE_MODE_READ); if (!ef) { map_histo = eina_hash_string_small_new( (void (*)(void *))&histogram_free); return map_histo; } histo_cache = eet_data_read(ef, _histogram_cache_descriptor , CACHE_FILE_ENTRY); if(cache_file) { eet_close(cache_file); } cache_file = ef; map_histo = histo_cache->map_histo; free(histo_cache); return map_histo; }
void * unmarshal_device_get_all_properties(DBusMessage *msg, DBusError *err) { E_Ukit_Get_All_Properties_Return *ret = NULL; DBusMessageIter iter, a_iter, s_iter, v_iter; int type; char *tmp; /* a{sv} = array of string+variants */ if (!dbus_message_has_signature(msg, "a{sv}")) { dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, ""); return NULL; } ret = calloc(1, sizeof(E_Ukit_Get_All_Properties_Return)); if (!ret) { dbus_set_error(err, DBUS_ERROR_NO_MEMORY, ""); return NULL; } ret->properties = eina_hash_string_small_new(EINA_FREE_CB(e_ukit_property_free)); dbus_message_iter_init(msg, &iter); dbus_message_iter_recurse(&iter, &a_iter); while (dbus_message_iter_get_arg_type(&a_iter) != DBUS_TYPE_INVALID) { const char *name; E_Ukit_Property *prop = calloc(1, sizeof(E_Ukit_Property)); dbus_message_iter_recurse(&a_iter, &s_iter); dbus_message_iter_get_basic(&s_iter, &name); dbus_message_iter_next(&s_iter); dbus_message_iter_recurse(&s_iter, &v_iter); type = dbus_message_iter_get_arg_type(&v_iter); switch(type) { case DBUS_TYPE_STRING: prop->type = E_UKIT_PROPERTY_TYPE_STRING; dbus_message_iter_get_basic(&v_iter, &tmp); prop->val.s = eina_stringshare_add(tmp); break; case DBUS_TYPE_INT32: prop->type = E_UKIT_PROPERTY_TYPE_INT; dbus_message_iter_get_basic(&v_iter, &(prop->val.i)); break; case DBUS_TYPE_UINT32: prop->type = E_UKIT_PROPERTY_TYPE_UINT32; dbus_message_iter_get_basic(&v_iter, &(prop->val.u)); break; case DBUS_TYPE_UINT64: prop->type = E_UKIT_PROPERTY_TYPE_UINT64; dbus_message_iter_get_basic(&v_iter, &(prop->val.t)); break; case DBUS_TYPE_INT64: prop->type = E_UKIT_PROPERTY_TYPE_INT64; dbus_message_iter_get_basic(&v_iter, &(prop->val.x)); break; case DBUS_TYPE_BOOLEAN: prop->type = E_UKIT_PROPERTY_TYPE_BOOL; dbus_message_iter_get_basic(&v_iter, &(prop->val.b)); break; case DBUS_TYPE_DOUBLE: prop->type = E_UKIT_PROPERTY_TYPE_DOUBLE; dbus_message_iter_get_basic(&v_iter, &(prop->val.d)); break; case DBUS_TYPE_ARRAY: prop->type = E_UKIT_PROPERTY_TYPE_STRLIST; { DBusMessageIter list_iter; prop->val.strlist = NULL; dbus_message_iter_recurse(&v_iter, &list_iter); while (dbus_message_iter_get_arg_type(&list_iter) != DBUS_TYPE_INVALID) { char *str; dbus_message_iter_get_basic(&list_iter, &str); tmp = (char*)eina_stringshare_add(str); prop->val.strlist = eina_list_append(prop->val.strlist, tmp); dbus_message_iter_next(&list_iter); } } break; default: WARN("EUkit Error: unexpected property type (%s): %c", name, dbus_message_iter_get_arg_type(&v_iter)); break; } eina_hash_add(ret->properties, name, prop); dbus_message_iter_next(&a_iter); } return ret; }
/* public functions */ EM_INTERN Eina_Bool em_gui_init(void) { Evas_Object *o, *oo; /* allocate our object */ gui = EM_OBJECT_ALLOC(Em_Gui, EM_GUI_TYPE, _em_gui_cb_free); if (!gui) return EINA_FALSE; /* create window */ gui->w_win = elm_win_add(NULL, "emote", ELM_WIN_BASIC); elm_win_title_set(gui->w_win, "Emote"); elm_win_keyboard_mode_set(gui->w_win, ELM_WIN_KEYBOARD_ALPHA); evas_object_smart_callback_add(gui->w_win, "delete,request", _em_gui_cb_win_del, NULL); /* create background */ o = elm_bg_add(gui->w_win); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(gui->w_win, o); evas_object_show(o); o = elm_box_add(gui->w_win); elm_box_homogeneous_set(o, EINA_FALSE); elm_win_resize_object_add(gui->w_win, o); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_box_align_set(o, 0.5, 0.5); evas_object_show(o); /* create main toolbar */ gui->w_tb = elm_toolbar_add(gui->w_win); elm_toolbar_icon_size_set(gui->w_tb, (8 * elm_config_scale_get())); elm_toolbar_align_set(gui->w_tb, 1.0); elm_toolbar_shrink_mode_set(gui->w_tb, ELM_TOOLBAR_SHRINK_SCROLL); elm_toolbar_item_append(gui->w_tb, "preferences-system", _("Settings"), _em_gui_cb_settings, NULL); elm_toolbar_item_append(gui->w_tb, "application-exit", _("Quit"), _em_gui_cb_quit, NULL); evas_object_size_hint_weight_set(gui->w_tb, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(gui->w_tb, EVAS_HINT_FILL, 0.0); evas_object_show(gui->w_tb); elm_box_pack_start(o, gui->w_tb); /* create packing box */ gui->w_box = elm_panes_add(gui->w_win); elm_panes_fixed_set(gui->w_box, EINA_FALSE); elm_panes_horizontal_set(gui->w_box, EINA_FALSE); elm_panes_content_left_size_set(gui->w_box, 0.20); evas_object_size_hint_weight_set(gui->w_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(gui->w_box, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_box_pack_end(o, gui->w_box); evas_object_show(gui->w_box); gui->w_chansel_itc = elm_genlist_item_class_new(); gui->w_chansel_itc->item_style = "default"; gui->w_chansel_itc->func.text_get = _em_gui_chansel_cb_label_get; gui->w_chansel_itc->func.content_get = NULL; gui->w_chansel_itc->func.state_get = NULL; gui->w_chansel_itc->func.del = NULL; /* create channel selector w/ frame */ gui->w_chansel = elm_genlist_add(gui->w_win); elm_genlist_mode_set(gui->w_chansel, ELM_LIST_SCROLL); evas_object_size_hint_min_set(gui->w_chansel, 200, MIN_WIN_HEIGHT); evas_object_size_hint_weight_set(gui->w_chansel, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_show(gui->w_chansel); o = elm_frame_add(gui->w_win); elm_object_part_text_set(o, "default", "Channels"); oo = elm_frame_add(gui->w_win); elm_object_style_set(oo, "pad_small"); elm_object_part_content_set(o, "default", oo); elm_object_part_content_set(oo, "default", gui->w_chansel); elm_object_part_content_set(gui->w_box, "left", o); evas_object_show(oo); evas_object_show(o); /* set min size of window and show it */ evas_object_show(gui->w_win); evas_object_resize(gui->w_win, MIN_WIN_WIDTH, MIN_WIN_HEIGHT); gui->servers = eina_hash_string_small_new(_em_gui_server_del); return EINA_TRUE; }
/** * @internal * @param file The file to parse * @return Returns an Eina_Hash with the contents of @a file, or NULL if the * file fails to parse or if the file doesn't exist * @brief Parses the ini file @a file into an Eina_Hash */ static Eina_Hash * efreet_ini_parse(const char *file) { const char *buffer, *line_start; FILE *f; Eina_Hash *data, *section = NULL; struct stat file_stat; int line_length, left; if (!file) return NULL; f = fopen(file, "rb"); if (!f) return NULL; if (fstat(fileno(f), &file_stat) || (file_stat.st_size < 1)) { fclose(f); return NULL; } if (!S_ISREG(file_stat.st_mode)) /* if not a regular file - close */ { fclose(f); return NULL; } left = file_stat.st_size; buffer = mmap(NULL, left, PROT_READ, MAP_SHARED, fileno(f), 0); if (buffer == MAP_FAILED) { fclose(f); return NULL; } data = eina_hash_string_small_new(EINA_FREE_CB(eina_hash_free)); line_start = buffer; while (left > 0) { int sep; /* find the end of line */ for (line_length = 0; (line_length < left) && (line_start[line_length] != '\n'); line_length++) ; /* check for all white space */ while (isspace(line_start[0]) && (line_length > 0)) { line_start++; line_length--; } /* skip empty lines and comments */ if ((line_length == 0) || (line_start[0] == '\r') || (line_start[0] == '\n') || (line_start[0] == '#') || (line_start[0] == '\0')) goto next_line; /* new section */ if (line_start[0] == '[') { int header_length; /* find the ']' */ for (header_length = 1; (header_length < line_length) && (line_start[header_length] != ']'); ++header_length) ; if (line_start[header_length] == ']') { const char *header; header = alloca(header_length * sizeof(unsigned char)); if (!header) goto next_line; memcpy((char*)header, line_start + 1, header_length - 1); ((char*)header)[header_length - 1] = '\0'; section = eina_hash_string_small_new(EINA_FREE_CB(eina_stringshare_del)); eina_hash_del_by_key(data, header); // if (old) INF("[efreet] Warning: duplicate section '%s' " // "in file '%s'", header, file); eina_hash_add(data, header, section); } else { /* invalid file - skip line? or refuse to parse file? */ /* just printf for now till we figure out what to do */ // printf("Invalid file (%s) (missing ] on group name)\n", file); } goto next_line; } if (!section) { // INF("Invalid file (%s) (missing section)", file); goto next_line; } /* find for '=' */ for (sep = 0; (sep < line_length) && (line_start[sep] != '='); ++sep) ; if (sep < line_length) { char *key, *value; int key_end, value_start, value_end; /* trim whitespace from end of key */ for (key_end = sep - 1; (key_end > 0) && isspace(line_start[key_end]); --key_end) ; if (!isspace(line_start[key_end])) key_end++; /* trim whitespace from start of value */ for (value_start = sep + 1; (value_start < line_length) && isspace(line_start[value_start]); ++value_start) ; /* trim \n off of end of value */ for (value_end = line_length; (value_end > value_start) && ((line_start[value_end] == '\n') || (line_start[value_end] == '\r')); --value_end) ; if (line_start[value_end] != '\n' && line_start[value_end] != '\r' && value_end < line_length) value_end++; /* make sure we have a key. blank values are allowed */ if (key_end == 0) { /* invalid file... */ // INF("Invalid file (%s) (invalid key=value pair)", file); goto next_line; } key = alloca(key_end + 1); value = alloca(value_end - value_start + 1); if (!key || !value) goto next_line; memcpy(key, line_start, key_end); key[key_end] = '\0'; memcpy(value, line_start + value_start, value_end - value_start); value[value_end - value_start] = '\0'; eina_hash_del_by_key(section, key); eina_hash_add(section, key, efreet_ini_unescape(value)); } // else // { // /* invalid file... */ // INF("Invalid file (%s) (missing = from key=value pair)", file); // } next_line: left -= line_length + 1; line_start += line_length + 1; } munmap((char*) buffer, file_stat.st_size); fclose(f); #if 0 if (!eina_hash_population(data)) { eina_hash_free(data); return NULL; } #endif return data; }
/** * @internal * @param file The file to parse * @return Returns an Eina_Hash with the contents of @a file, or NULL if the * file fails to parse or if the file doesn't exist * @brief Parses the ini file @a file into an Eina_Hash */ static Eina_Hash * efreet_ini_parse(const char *file) { Eina_Hash *data = NULL, *section = NULL; Eina_Iterator *it = NULL; Eina_File_Line *line; Eina_File *f; EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); f = eina_file_open(file, EINA_FALSE); if (!f) return NULL; data = eina_hash_string_small_new(EINA_FREE_CB(eina_hash_free)); if (!data) goto error; /* let's make mmap safe and just get 0 pages for IO erro */ eina_mmap_safety_enabled_set(EINA_TRUE); it = eina_file_map_lines(f); if (!it) goto error; EINA_ITERATOR_FOREACH(it, line) { const char *eq; unsigned int start = 0; /* skip empty lines */ if (line->length == 0) continue; /* skip white space at start of line */ while ((start < line->length) && (isspace((unsigned char)line->start[start]))) start++; /* skip empty lines */ if (start == line->length) continue; /* skip comments */ if (line->start[start] == '#') continue; /* new section */ if (line->start[start] == '[') { const char *head_start; const char *head_end; head_start = &(line->start[start]) + 1; head_end = memchr(line->start, ']', line->length); if (head_end) { char *header; size_t len; len = head_end - head_start + 1; header = alloca(len); memcpy(header, head_start, len - 1); header[len - 1] = '\0'; section = eina_hash_string_small_new(EINA_FREE_CB(eina_stringshare_del)); eina_hash_del_by_key(data, header); eina_hash_add(data, header, section); } else { /* invalid file - skip line? or refuse to parse file? */ /* just printf for now till we figure out what to do */ // ERR("Invalid file (%s) (missing ] on group name)", file); } continue; } if (!section) { INF("Invalid file (%s) (missing section)", file); goto error; } eq = memchr(line->start, '=', line->length); if (eq) { const char *key_start, *key_end; const char *value_start, *value_end; char *key, *value; size_t len; key_start = &(line->start[start]); key_end = eq - 1; /* trim whitespace from end of key */ while ((isspace((unsigned char)*key_end)) && (key_end > key_start)) key_end--; key_end++; /* make sure we have a key */ if (key_start == key_end) continue; value_start = eq + 1; value_end = line->end; /* line->end points to char after '\n' or '\r' */ value_end--; /* trim whitespace from end of value */ while ((isspace((unsigned char)*value_end)) && (value_end > value_start)) value_end--; value_end++; /* trim whitespace from start of value */ while ((isspace((unsigned char)*value_start)) && (value_start < value_end)) value_start++; len = key_end - key_start + 1; key = alloca(len); memcpy(key, key_start, len - 1); key[len - 1] = '\0'; /* empty value allowed */ if (value_end == value_start) { eina_hash_del_by_key(section, key); eina_hash_add(section, key, ""); } else { len = value_end - value_start + 1; value = alloca(len); memcpy(value, value_start, len - 1); value[len - 1] = '\0'; eina_hash_del_by_key(section, key); eina_hash_add(section, key, efreet_ini_unescape(value)); } } else { /* invalid file... */ INF("Invalid file (%s) (missing = from key=value pair)", file); goto error; } } eina_iterator_free(it); eina_file_close(f); #if 0 if (!eina_hash_population(data)) { eina_hash_free(data); return NULL; } #endif return data; error: if (data) eina_hash_free(data); if (it) eina_iterator_free(it); eina_file_close(f); return NULL; }
int main(int argc, const char *argv[]) { Eina_Hash *phone_book = NULL; int i; const char *entry_name = "Heitor Villa-Lobos"; char *phone = NULL; Eina_Bool r; Eina_Iterator *it; void *data; eina_init(); phone_book = eina_hash_string_small_new(_phone_entry_free_cb); // Add initial entries to our hash for (i = 0; _start_entries[i].name != NULL; i++) { eina_hash_add(phone_book, _start_entries[i].name, strdup(_start_entries[i].number)); } // Look for a specific entry and get its phone number phone = eina_hash_find(phone_book, entry_name); if (phone) { printf("Printing entry.\n"); printf("Name: %s\n", entry_name); printf("Number: %s\n\n", phone); } // Delete this entry r = eina_hash_del(phone_book, entry_name, NULL); printf("Hash entry successfully deleted? %d\n\n", r); // Modify the pointer data of an entry and free the old one phone = eina_hash_modify(phone_book, "Richard Georg Strauss", strdup("+23 45 111-11111")); free(phone); // Modify or add an entry to the hash with eina_hash_set // Let's first add a new entry eina_error_set(0); phone = eina_hash_set(phone_book, "Raul Seixas", strdup("+55 01 234-56789")); if (!phone) { Eina_Error err = eina_error_get(); if (!err) { printf("No previous phone found for Raul Seixas. "); printf("Creating new entry.\n"); } else printf("Error when setting phone for Raul Seixas\n"); } else { printf("Old phone for Raul Seixas was %s\n", phone); free(phone); } printf("\n"); // Now change the phone number eina_error_set(0); phone = eina_hash_set(phone_book, "Raul Seixas", strdup("+55 02 222-22222")); if (phone) { printf("Changing phone for Raul Seixas to +55 02 222-22222. "); printf("Old phone was %s\n", phone); free(phone); } else { Eina_Error err = eina_error_get(); if (err) printf("Error when changing phone for Raul Seixas\n"); else { printf("No previous phone found for Raul Seixas. "); printf("Creating new entry.\n"); } } // There are many ways to iterate over our Phone book. // First, iterate showing the names and associated numbers. printf("List of phones:\n"); eina_hash_foreach(phone_book, _phone_book_foreach_cb, NULL); printf("\n"); // Now iterate using an iterator printf("List of phones:\n"); it = eina_hash_iterator_tuple_new(phone_book); while (eina_iterator_next(it, &data)) { Eina_Hash_Tuple *t = data; const char *name = t->key; const char *number = t->data; printf("%s: %s\n", name, number); } eina_iterator_free(it); // Always free the iterator after its use printf("\n"); // Just iterate over the keys (names) printf("List of names in the phone book:\n"); it = eina_hash_iterator_key_new(phone_book); while (eina_iterator_next(it, &data)) { const char *name = data; printf("%s\n", name); } eina_iterator_free(it); printf("\n"); // Just iterate over the data (numbers) printf("List of numbers in the phone book:\n"); it = eina_hash_iterator_data_new(phone_book); while (eina_iterator_next(it, &data)) { const char *number = data; printf("%s\n", number); } eina_iterator_free(it); printf("\n"); // Check how many items are in the phone book printf("There are %d items in the hash.\n\n", eina_hash_population(phone_book)); // Change the name (key) on an entry eina_hash_move(phone_book, "Raul Seixas", "Alceu Valenca"); printf("List of phones after change:\n"); eina_hash_foreach(phone_book, _phone_book_foreach_cb, NULL); printf("\n"); // Empty the phone book, but don't destroy it eina_hash_free_buckets(phone_book); printf("There are %d items in the hash.\n\n", eina_hash_population(phone_book)); // Phone book could still be used, but we are freeing it since we are // done for now eina_hash_free(phone_book); eina_shutdown(); }
/* public functions */ EM_INTERN Eina_Bool em_gui_init(void) { Evas_Object *o; /* allocate our object */ gui = EM_OBJECT_ALLOC(Em_Gui, EM_GUI_TYPE, _em_gui_cb_free); if (!gui) return EINA_FALSE; // Set finger size to 4 to avoid huge widgets // elm_finger_size_set(4); /* create window */ gui->w_win = elm_win_add(NULL, "emote", ELM_WIN_BASIC); elm_win_title_set(gui->w_win, "Emote"); elm_win_keyboard_mode_set(gui->w_win, ELM_WIN_KEYBOARD_ALPHA); evas_object_smart_callback_add(gui->w_win, "delete-request", _em_gui_cb_win_del, NULL); /* create background */ o = elm_bg_add(gui->w_win); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); // evas_object_size_hint_min_set(o, MIN_WIN_WIDTH, MIN_WIN_HEIGHT); elm_win_resize_object_add(gui->w_win, o); evas_object_show(o); /* create packing box */ gui->w_box = elm_box_add(gui->w_win); elm_win_resize_object_add(gui->w_win, gui->w_box); evas_object_size_hint_weight_set(gui->w_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_show(gui->w_box); /* create main toolbar */ gui->w_tb = elm_toolbar_add(gui->w_win); elm_toolbar_icon_size_set(gui->w_tb, (16 * elm_scale_get())); elm_toolbar_align_set(gui->w_tb, 0.0); elm_toolbar_mode_shrink_set(gui->w_tb, ELM_TOOLBAR_SHRINK_SCROLL); evas_object_size_hint_weight_set(gui->w_tb, 0.0, 0.0); evas_object_size_hint_align_set(gui->w_tb, EVAS_HINT_FILL, 0.0); elm_toolbar_item_append(gui->w_tb, "preferences-system", _("Settings"), _em_gui_cb_settings, NULL); elm_toolbar_item_append(gui->w_tb, "application-exit", _("Quit"), _em_gui_cb_quit, NULL); evas_object_show(gui->w_tb); elm_box_pack_start(gui->w_box, gui->w_tb); /* create channel selector */ gui->w_chansel = elm_toolbar_add(gui->w_win); elm_toolbar_homogeneous_set(gui->w_chansel, EINA_FALSE); elm_toolbar_align_set(gui->w_chansel, 0.0); elm_toolbar_mode_shrink_set(gui->w_chansel, ELM_TOOLBAR_SHRINK_SCROLL); evas_object_size_hint_weight_set(gui->w_chansel, 0.0, 0.0); evas_object_size_hint_align_set(gui->w_chansel, EVAS_HINT_FILL, 0.0); evas_object_show(gui->w_chansel); elm_box_pack_end(gui->w_box, gui->w_chansel); /* set min size of window and show it */ // evas_object_size_hint_min_set(gui->w_win, MIN_WIN_WIDTH, MIN_WIN_HEIGHT); evas_object_resize(gui->w_win, MIN_WIN_WIDTH, MIN_WIN_HEIGHT); evas_object_show(gui->w_win); gui->servers = eina_hash_string_small_new(_em_gui_server_del); return EINA_TRUE; }
void _elm_module_init(void) { modules = eina_hash_string_small_new(NULL); modules_as = eina_hash_string_small_new(NULL); }
static Ewk_JS_Object* ewk_js_npobject_to_object(NPObject* npObject) { NPIdentifier* values; uint32_t np_props_count; Ewk_JS_Class* cls; Ewk_JS_Object* object; Eina_Iterator* it; Ewk_JS_Property* prop; JavaScriptObject* jso; if (EINA_MAGIC_CHECK(reinterpret_cast<Ewk_JS_Object*>(npObject), EWK_JS_OBJECT_MAGIC)) return reinterpret_cast<Ewk_JS_Object*>(npObject); if (!_NPN_Enumerate(0, npObject, &values, &np_props_count)) return 0; cls = static_cast<Ewk_JS_Class*>(malloc(sizeof(Ewk_JS_Class))); if (!cls) { ERR("Could not allocate memory for ewk_js_class"); return 0; } cls->meta = 0; Ewk_JS_Default def = { ewk_js_npobject_property_set, ewk_js_npobject_property_get, ewk_js_npobject_property_del }; cls->default_prop = def; cls->methods = eina_hash_pointer_new(0); cls->properties = eina_hash_pointer_new(reinterpret_cast<Eina_Free_Cb>(ewk_js_property_free)); for (uint32_t i = 0; i < np_props_count; i++) { if (_NPN_HasProperty(0, npObject, values[i])) { NPVariant var; Ewk_JS_Property* prop = static_cast<Ewk_JS_Property*>(calloc(sizeof(Ewk_JS_Property), 1)); if (!prop) { ERR("Could not allocate memory for ewk_js_property"); goto error; } _NPN_GetProperty(0, npObject, values[i], &var); ewk_js_npvariant_to_variant(&(prop->value), &var); prop->name = _NPN_UTF8FromIdentifier(values[i]); eina_hash_add(cls->properties, values[i], prop); } } // Can't use ewk_js_object_new(cls) because it expects cls->meta to exist. object = static_cast<Ewk_JS_Object*>(malloc(sizeof(Ewk_JS_Object))); if (!object) { ERR("Could not allocate memory for ewk_js_object"); goto error; } free(values); EINA_MAGIC_SET(object, EWK_JS_OBJECT_MAGIC); object->name = 0; object->cls = cls; object->view = 0; jso = reinterpret_cast<JavaScriptObject*>(npObject); if (!strcmp("Array", jso->imp->methodTable()->className(jso->imp).ascii().data())) object->type = EWK_JS_OBJECT_ARRAY; else if (!strcmp("Function", jso->imp->methodTable()->className(jso->imp).ascii().data())) object->type = EWK_JS_OBJECT_FUNCTION; else object->type = EWK_JS_OBJECT_OBJECT; if (eina_hash_population(cls->properties) < 25) object->properties = eina_hash_string_small_new(0); else object->properties = eina_hash_string_superfast_new(0); it = eina_hash_iterator_data_new(cls->properties); EINA_ITERATOR_FOREACH(it, prop) { const char* key = prop->name; Ewk_JS_Variant* value = &prop->value; eina_hash_add(object->properties, key, value); } eina_iterator_free(it); object->base = *reinterpret_cast<JavaScriptObject*>(npObject); return object; error: ewk_js_class_free(cls); free(values); return 0; }
int size; Eina_Hash *mime_type; } Elm_File_MimeType_Cache_Data; EOLIAN static Elm_File_MimeType_Cache* _elm_file_mimetype_cache_cache_generate(Eo *obj EINA_UNUSED, void *npd EINA_UNUSED, int size) { Eo *result; Elm_File_MimeType_Cache_Data *pd; result = eo_add(ELM_FILE_MIMETYPE_CACHE_CLASS, NULL); pd = eo_data_scope_get(result, ELM_FILE_MIMETYPE_CACHE_CLASS); pd->size = size; pd->mime_type = eina_hash_string_small_new(NULL); return result; } static const char* _elm_file_mimetype_cache_mimetype_get(Eo *obj EINA_UNUSED, Elm_File_MimeType_Cache_Data *pd, const char *name) { const char *result; result = eina_hash_find(pd->mime_type, name); if (!result) { const char *theme;
Ewk_JS_Object* ewk_js_object_new(const Ewk_JS_Class_Meta* jsMetaClass) { #if ENABLE(NETSCAPE_PLUGIN_API) Ewk_JS_Object* object; EINA_SAFETY_ON_NULL_RETURN_VAL(jsMetaClass, 0); object = static_cast<Ewk_JS_Object*>(malloc(sizeof(Ewk_JS_Object))); if (!object) { ERR("Could not allocate memory for ewk_js_object"); return 0; } EINA_MAGIC_SET(object, EWK_JS_OBJECT_MAGIC); object->cls = ewk_js_class_new(jsMetaClass); object->view = 0; object->name = 0; object->type = EWK_JS_OBJECT_OBJECT; if (eina_hash_population(object->cls->properties) < 25) object->properties = eina_hash_string_small_new(reinterpret_cast<Eina_Free_Cb>(ewk_js_variant_free)); else object->properties = eina_hash_string_superfast_new(reinterpret_cast<Eina_Free_Cb>(ewk_js_variant_free)); for (int i = 0; object->cls->meta->properties && object->cls->meta->properties[i].name; i++) { Ewk_JS_Property prop = object->cls->meta->properties[i]; const char* key = object->cls->meta->properties[i].name; Ewk_JS_Variant* value = static_cast<Ewk_JS_Variant*>(malloc(sizeof(Ewk_JS_Variant))); if (!value) { ERR("Could not allocate memory for ewk_js_variant"); goto error; } if (prop.get) prop.get(object, key, value); else { value->type = prop.value.type; switch (value->type) { case EWK_JS_VARIANT_VOID: case EWK_JS_VARIANT_NULL: value->value.o = 0; break; case EWK_JS_VARIANT_STRING: value->value.s = eina_stringshare_add(prop.value.value.s); break; case EWK_JS_VARIANT_BOOL: value->value.b = prop.value.value.b; break; case EWK_JS_VARIANT_INT32: value->value.i = prop.value.value.i; break; case EWK_JS_VARIANT_DOUBLE: value->value.d = prop.value.value.d; break; case EWK_JS_VARIANT_OBJECT: value->value.o = prop.value.value.o; break; } } eina_hash_add(object->properties, key, value); } object->base.object.referenceCount = 1; object->base.object._class = &EWK_NPCLASS; return object; error: ewk_js_object_free(object); return 0; #else UNUSED_PARAM(jsMetaClass); return 0; #endif }