コード例 #1
0
ファイル: eldbus_service.c プロジェクト: tguillem/efl
static void
_introspect_append_interface(Eina_Strbuf *buf, Eldbus_Service_Interface *iface)
{
   const Eldbus_Method *method;
   Property *prop;
   Eina_Iterator *iterator;
   unsigned short i;

   eina_strbuf_append_printf(buf, "<interface name=\"%s\">", iface->name);

   iterator = eina_hash_iterator_data_new(iface->methods);
   EINA_ITERATOR_FOREACH(iterator, method)
     _introspect_append_method(buf, method);
   eina_iterator_free(iterator);

   for (i = 0; i < eina_array_count(iface->sign_of_signals); i++)
     _introspect_append_signal(buf, &iface->signals[i]);

   iterator = eina_hash_iterator_data_new(iface->properties);
   EINA_ITERATOR_FOREACH(iterator, prop)
     _instrospect_append_property(buf, prop->property, iface);
   eina_iterator_free(iterator);

   eina_strbuf_append(buf, "</interface>");
}
コード例 #2
0
ファイル: evas_cserve2_shm.c プロジェクト: RomainNaour/efl
static void
_cserve2_shm_cleanup()
{
   Eina_Iterator *iter;
   const Eina_File_Direct_Info *f_info;
   char pattern[NAME_MAX];

   sprintf(pattern, "evas-shm-%05d-", (int) getuid());
   iter = eina_file_direct_ls("/dev/shm");
   EINA_ITERATOR_FOREACH(iter, f_info)
     {
        if (strstr(f_info->path, pattern))
          {
             const char *shmname = strrchr(f_info->path, '/');
             if (!shmname) continue;

             if (shm_unlink(shmname) == -1)
               ERR("Failed to remove shm entry at %s: %d %s", shmname, errno, strerror(errno));
             else
               DBG("cserve2 cleanup: removed %s", shmname);
          }
        else
          DBG("cserve2 cleanup: ignoring %s", f_info->path);
     }
   eina_iterator_free(iter);
}
コード例 #3
0
EAPI Eina_List *
edje_file_collection_list(const char *file)
{
   Eina_List *lst = NULL;
   Edje_File *edf;
   int error_ret = 0;

   if ((!file) || (!*file)) return NULL;
   edf = _edje_cache_file_coll_open(file, NULL, &error_ret, NULL);
   if (edf)
     {
	Eina_Iterator *i;
	const char *key;

	i = eina_hash_iterator_key_new(edf->collection);

	EINA_ITERATOR_FOREACH(i, key)
	  lst = eina_list_append(lst, eina_stringshare_add(key));

	eina_iterator_free(i);

	_edje_cache_file_unref(edf);
     }
   return lst;
}
コード例 #4
0
ファイル: evas_path.c プロジェクト: tasn/efl
Eina_List *
evas_file_path_list(char *path, const char *match, int match_case)
{
   Eina_File_Direct_Info *info;
   Eina_Iterator *it;
   Eina_List *files = NULL;
   int flags;

   flags = FNM_PATHNAME;
#ifdef FNM_CASEFOLD
   if (!match_case)
     flags |= FNM_CASEFOLD;
#elif defined FNM_IGNORECASE
   if (!match_case)
     flags |= FNM_IGNORECASE;
#else
/*#warning "Your libc does not provide case-insensitive matching!"*/
#endif

   it = eina_file_direct_ls(path);
   EINA_ITERATOR_FOREACH(it, info)
     {
        if (match)
          {
             if (fnmatch(match, info->path + info->name_start, flags) == 0)
               files = eina_list_append(files, strdup(info->path + info->name_start));
          }
        else
          files = eina_list_append(files, strdup(info->path + info->name_start));
     }
   if (it) eina_iterator_free(it);
   return files;
}
コード例 #5
0
static int
cache_scan(const char *path, const char *base_id, int priority, int recurse, int *changed)
{
    char *file_id = NULL;
    char id[PATH_MAX];
    char buf[PATH_MAX];
    Eina_Iterator *it;
    Eina_File_Direct_Info *info;

    if (!ecore_file_is_dir(path)) return 1;

    it = eina_file_direct_ls(path);
    if (!it) return 1;

    id[0] = '\0';
    EINA_ITERATOR_FOREACH(it, info)
    {
        const char *fname;
       
        fname = info->path + info->name_start;
        if (base_id)
        {
            if (*base_id)
                snprintf(id, sizeof(id), "%s-%s", base_id, fname);
            else
                strcpy(id, fname);
            file_id = id;
        }

        snprintf(buf, sizeof(buf), "%s/%s", path, fname);
        if (ecore_file_is_dir(buf))
        {
            if (recurse)
                cache_scan(buf, file_id, priority, recurse, changed);
        }
        else
        {
            if (!cache_add(buf, file_id, priority, changed))
            {
                eina_iterator_free(it);
                return 0;
            }
        }
    }
    eina_iterator_free(it);
    return 1;
}
コード例 #6
0
ファイル: database_fill.c プロジェクト: tguillem/efl
 EINA_ITERATOR_FOREACH(itr, dep)
   {
      if (!eina_hash_find(_parsingeos, dep) && !eolian_file_parse(dep))
        {
           eina_iterator_free(itr);
           eina_hash_free_buckets(_defereos);
           goto error;
        }
   }
コード例 #7
0
static int
cache_scan(Eet_File *ef,
           Eina_Inarray *stack, const char *path, const char *base_id,
           int priority, int recurse, int *changed)
{
    char *file_id = NULL;
    char id[PATH_MAX];
    Eina_Iterator *it;
    Eina_File_Direct_Info *info;
    struct stat st;
    int ret = 1;

    if (!ecore_file_is_dir(path)) return 1;
    if (stat(path, &st) == -1) return 1;
    if (eina_inarray_search(stack, &st, stat_cmp) >= 0) return 1;
    eina_inarray_push(stack, &st);

    it = eina_file_stat_ls(path);
    if (!it) goto end;
    id[0] = '\0';
    EINA_ITERATOR_FOREACH(it, info)
    {
        const char *fname = info->path + info->name_start;

        if (info->path[info->name_start] == '.') continue;
        if (base_id)
        {
            if (*base_id) snprintf(id, sizeof(id), "%s-%s", base_id, fname);
            else
            {
                strncpy(id, fname, PATH_MAX);
                id[PATH_MAX - 1] = 0;
            }
            file_id = id;
        }

        if (((info->type == EINA_FILE_LNK) && (ecore_file_is_dir(info->path))) ||
            (info->type == EINA_FILE_DIR))
        {
           if (recurse)
             {
                ret = cache_scan(ef, stack, info->path, file_id, priority, recurse, changed);
                if (!ret) break;
             }
        }
        else
        {
           ret = cache_add(ef, info->path, file_id, priority, changed);
           if (!ret) break;
        }
    }
    eina_iterator_free(it);
end:
    eina_inarray_pop(stack);
    return ret;
}
コード例 #8
0
ファイル: database_fill.c プロジェクト: tguillem/efl
Eina_Bool
eo_parser_database_fill(const char *filename, Eina_Bool eot)
{
   Eolian_Constructor *ctor;
   Eolian_Implement *impl;
   Eina_Iterator *itr;
   Eolian_Class *cl;
   Eo_Lexer *ls;
   const char *dep;

   if (eina_hash_find(_parsedeos, filename))
     return EINA_TRUE;

   eina_hash_set(_parsingeos, filename, (void *)EINA_TRUE);

   ls = eo_lexer_new(filename);
   if (!ls)
     {
        fprintf(stderr, "eolian: unable to create lexer for file '%s'\n", filename);
        goto error;
     }

   /* read first token */
   eo_lexer_get(ls);

   if (!eo_parser_walk(ls, eot))
     goto error;

   if (eot) goto done;

   if (!(cl = ls->tmp.kls))
     {
        fprintf(stderr, "eolian: no class for file '%s'\n", filename);
        goto error;
     }
   ls->tmp.kls = NULL;

   if (!_db_fill_class(cl))
     goto error;

   itr = eolian_class_implements_get(cl);
   EINA_ITERATOR_FOREACH(itr, impl)
     {
        Eolian_Function_Type impl_type = EOLIAN_UNRESOLVED;
        const Eolian_Function *impl_func = eolian_implement_function_get(impl, &impl_type);
        if (!impl_func)
          {
             fprintf(stderr, "eolian: unable to find function '%s'\n",
                     eolian_implement_full_name_get(impl));
             eina_iterator_free(itr);
             goto error;
          }
        else if (eolian_function_is_constructor(impl->foo_id, impl->klass))
          database_function_constructor_add((Eolian_Function*)impl->foo_id, cl);
     }
コード例 #9
0
EAPI void
efreet_hash_free(Eina_Hash *hash, Eina_Free_Cb free_cb)
{
    Eina_Iterator *it;
    void *data;

    it = eina_hash_iterator_data_new(hash);
    EINA_ITERATOR_FOREACH(it, data)
        (*free_cb)(data);
    eina_iterator_free(it);
    eina_hash_free(hash);
}
コード例 #10
0
ファイル: database_fill.c プロジェクト: tguillem/efl
 EINA_ITERATOR_FOREACH(itr, ctor)
   {
      const Eolian_Function *ctor_func = eolian_constructor_function_get(ctor);
      if (!ctor_func)
        {
           fprintf(stderr, "eolian: unable to find function '%s'\n",
                   eolian_constructor_full_name_get(ctor));
           eina_iterator_free(itr);
           goto error;
        }
      else
        database_function_constructor_add((Eolian_Function*)ctor_func, ctor->klass);
   }
コード例 #11
0
ファイル: evas_module.c プロジェクト: antognolli/Evas
Eina_List *
evas_module_engine_list(void)
{
   Evas_Module *em;
   Eina_List *r = NULL, *l, *ll;
   Eina_Array_Iterator iterator;
   Eina_Iterator *it, *it2;
   unsigned int i;
   const char *s, *s2;
   char buf[4096];

   EINA_LIST_FOREACH(evas_module_paths, l, s)
     {
        snprintf(buf, sizeof(buf), "%s/engines", s);
        it = eina_file_direct_ls(buf);
        if (it)
          {
             Eina_File_Direct_Info *fi;

             EINA_ITERATOR_FOREACH(it, fi)
               {
                  const char *fname = fi->path + fi->name_start;
                  snprintf(buf, sizeof(buf), "%s/engines/%s/%s", 
                           s, fname, MODULE_ARCH);
                  it2 = eina_file_ls(buf);
                  if (it2)
                    {
                       EINA_LIST_FOREACH(r, ll, s2)
                         {
                            if (!strcmp(fname, s2)) break;
                         }
                       if (!ll)
                         r = eina_list_append(r, eina_stringshare_add(fname));
                       eina_iterator_free(it2);
                    }
               }
             eina_iterator_free(it);
          }
     }
コード例 #12
0
ファイル: eldbus_core.c プロジェクト: tguillem/efl
static void
print_live_connection(Eldbus_Connection *conn)
{
   if (!conn->names)
     ERR("conn=%p has no alive objects", conn);
   else
     {
        Eina_Iterator *iter = eina_hash_iterator_data_new(conn->names);
        Eldbus_Connection_Name *name;
        EINA_ITERATOR_FOREACH(iter, name)
          {
             Eldbus_Object *obj;
             Eina_Iterator *inner_itr;
             if (!name->objects) continue;

             inner_itr = eina_hash_iterator_data_new(name->objects);
             EINA_ITERATOR_FOREACH(inner_itr, obj)
                ERR("conn=%p alive object=%p %s of bus=%s", conn, obj,
                    obj->name, name->name);
             eina_iterator_free(inner_itr);
          }
        eina_iterator_free(iter);
     }
コード例 #13
0
ファイル: test_sqlite.c プロジェクト: carloslack/esskyuehl
static void
on_query_results(Esql_Res *res, void *data)
{
   struct ctx *ctx = data;
   const Esql_Row *row;
   Eina_Iterator *itr;
   const char *cname;
   int i;

   assert(esql_res_rows_count(res) == INSERTED_ROWS);
   assert(esql_res_cols_count(res) == 2);

   ctx->res++;
   printf("results %u: rows=%d, columns=%d\n",
          ctx->res,
          esql_res_rows_count(res),
          esql_res_cols_count(res));

   cname = esql_res_col_name_get(res, 0);
   assert(cname!=NULL);
   assert(strcmp(cname, "i") == 0);

   cname = esql_res_col_name_get(res, 1);
   assert(cname!=NULL);
   assert(strcmp(cname, "s") == 0);

   i = 0;
   itr = esql_res_row_iterator_new(res);
   EINA_ITERATOR_FOREACH(itr, row)
     {
        const Eina_Value *val = esql_row_value_struct_get(row);
        const char *str;
        char buf[100];
        int num;

        assert(eina_value_struct_get(val, "i", &num));
        assert(i == num);

        snprintf(buf, sizeof(buf), "some-text-%10d", i);

        assert(eina_value_struct_get(val, "s", &str));
        assert(str!=NULL);
        assert(strcmp(str, buf) == 0);

        i++;
     }
   eina_iterator_free(itr);

   ecore_main_loop_quit();
}
コード例 #14
0
void Config::loadStateCache()
{
    ConfigStateCache *cache;
    std::string file = Utils::getCacheFile("iostates.cache");

    Eet_File *ef = eet_open(file.c_str(), EET_FILE_MODE_READ);
    if (!ef)
    {
        cWarning() <<  "Could not open iostates.cache for read !";
        return;
    }

    cache = (ConfigStateCache *)eet_data_read(ef, edd_cache, "calaos/states/cache");
    if (!cache)
    {
        eet_close(ef);
        cWarning() <<  "Could not read iostates.cache, corrupted file?";
        return;
    }

    if (cache->version < CONFIG_STATES_CACHE_VERSION)
    {
        cWarning() <<  "File version too old, upgrading to new format";
        cache->version = CONFIG_STATES_CACHE_VERSION;
    }

    //read all states and put it in cache_states
    Eina_Iterator *it = eina_hash_iterator_tuple_new(cache->states);
    void *data;
    while (eina_iterator_next(it, &data))
    {
        Eina_Hash_Tuple *t = (Eina_Hash_Tuple *)data;
        ConfigStateValue *state = (ConfigStateValue *)t->data;
        std::string skey = state->id;
        std::string svalue = state->value;
        SaveValueIO(skey, svalue, false);
    }
    eina_iterator_free(it);

    eina_hash_free(cache->states);
    free(cache);
    eet_close(ef);

    cInfo() <<  "States cache read successfully.";
}
コード例 #15
0
ファイル: edje_watch.c プロジェクト: wjhendr/enlightenment
static void
read_watch_file(const char *file)
{
   Eina_File *f;
   Eina_Iterator *it;
   Eina_File_Line *ln;
   Eio_Monitor *mon;
   Eina_List *r = NULL;

   f = eina_file_open(file, EINA_FALSE);
   if (!f) return ;

   it = eina_file_map_lines(f);
   if (!it) goto err;

   EINA_ITERATOR_FOREACH(it, ln)
     {
        const char *path;
        Eina_Bool do_append = EINA_TRUE;

	if (ln->length < 4) continue ;
        if (anotate)
          {
             path = eina_stringshare_add_length(ln->start + 3, ln->length - 3);
             fprintf(stdout, "%c: %s\n", *ln->start, path);
             if (*ln->start == 'O')
               do_append = EINA_FALSE;
          }
        else
          {
             path = eina_stringshare_add_length(ln->start, ln->length);
          }
        if (do_append)
	  r = eina_list_append(r, eio_monitor_add(path));
        eina_stringshare_del(path);
     }
   eina_iterator_free(it);

   EINA_LIST_FREE(watching, mon)
     eio_monitor_del(mon);
   watching = r;

 err:
   eina_file_close(f);
}
コード例 #16
0
ファイル: eina_list_03.c プロジェクト: RomainNaour/efl
int
main(int argc, char **argv)
{
   (void)argc;
   (void)argv;
   Eina_List *list = NULL, *r_list;
   Eina_List *l;
   Eina_Iterator *itr;
   void *list_data;

   eina_init();

   list = eina_list_append(list, "caprica");
   list = eina_list_append(list, "sagitarius");
   list = eina_list_append(list, "aerilon");
   list = eina_list_append(list, "gemenon");

   list = eina_list_promote_list(list, eina_list_nth_list(list, 2));
   list = eina_list_demote_list(list, eina_list_nth_list(list, 2));

   list = eina_list_remove(list, "sagitarius");

   l = eina_list_data_find_list(list, "aerilon");
   eina_list_data_set(l, "aquarius");

   printf("size: %d\n", eina_list_count(list));

   r_list = eina_list_reverse_clone(list);

   itr = eina_list_iterator_new(r_list);
   EINA_ITERATOR_FOREACH(itr, list_data)
     printf("%s\n", (char*)list_data);
   eina_iterator_free(itr);

   eina_list_free(list);
   eina_list_free(r_list);

   eina_shutdown();

   return 0;
}
コード例 #17
0
ファイル: job_handler.c プロジェクト: bonnefoa/imagecmp
void clean_inexistant_files(Eina_Hash *map_histo)
{
    struct stat st;
    Eina_Iterator *iter = eina_hash_iterator_data_new(map_histo);
    void **data = malloc(sizeof(void**));
    list_t *to_delete = NULL;
    while(eina_iterator_next(iter, data)) {
        histogram_t *current = *data;
        if(stat(current->file, &st) != 0) {
            to_delete = list_append(to_delete, current->file);
        }
    }
    eina_iterator_free(iter);

    list_t *current = to_delete;
    while(current) {
        printf("Deleting cache for %s\n", current->value);
        eina_hash_del_by_key(map_histo, current->value);
        current = current->next;
    }
}
コード例 #18
0
ファイル: elm_module.c プロジェクト: tasn/elementary
void
_elm_module_shutdown(void)
{
   Eina_Iterator *it;
   Elm_Module *m;

   if (modules)
     {
        Eina_List *tl = NULL;

        it = eina_hash_iterator_data_new(modules);

        EINA_ITERATOR_FOREACH(it, m) tl = eina_list_append(tl, m);
        eina_iterator_free(it);

        EINA_LIST_FREE(tl, m) _elm_module_del(m);

        ELM_SAFE_FREE(modules, eina_hash_free);
     }

   ELM_SAFE_FREE(modules_as, eina_hash_free);
}
コード例 #19
0
Vector<String> listDirectory(const String& path, const String& filter)
{
    Vector<String> matchingEntries;
    CString cfilter = filter.utf8();
    const char *f_name;

    Eina_Iterator* it = eina_file_ls(path.utf8().data());
    // FIXME: Early return if the iterator is null to avoid error messages from eina_iterator_free().
    // This check can be removed once the magic check on _free() removed in Eina.
    // http://www.mail-archive.com/[email protected]/msg42944.html
    if (!it)
        return matchingEntries;

    EINA_ITERATOR_FOREACH(it, f_name) {
        if (!fnmatch(cfilter.data(), f_name, 0))
            matchingEntries.append(String::fromUTF8(f_name));
        eina_stringshare_del(f_name);
    }
    eina_iterator_free(it);

    return matchingEntries;
}
コード例 #20
0
ファイル: ecore_file.c プロジェクト: caivega/efl-1
/**
 * @brief Delete the given directory and all its contents.
 *
 * @param  dir The name of the directory to delete.
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * This function delete @p dir and all its contents. If @p dir is a
 * link only the link is removed. It returns @c EINA_TRUE on success,
 * @c EINA_FALSE otherwise.
 */
EAPI Eina_Bool
ecore_file_recursive_rm(const char *dir)
{
   struct stat st;

#ifdef _WIN32
   char buf[PATH_MAX];

   if (readlink(dir, buf, sizeof(buf) - 1) > 0)
     return ecore_file_unlink(dir);
   if (stat(dir, &st) == -1)
     return EINA_FALSE;
#else
   if (lstat(dir, &st) == -1)
     return EINA_FALSE;
#endif

   if (S_ISDIR(st.st_mode))
     {
        Eina_File_Direct_Info *info;
        Eina_Iterator *it;
        int ret;

        ret = 1;
        it = eina_file_direct_ls(dir);
        EINA_ITERATOR_FOREACH(it, info)
          {
             if (!ecore_file_recursive_rm(info->path))
               ret = 0;
          }
        eina_iterator_free(it);

        if (!ecore_file_rmdir(dir)) ret = 0;
        if (ret)
            return EINA_TRUE;
        else
            return EINA_FALSE;
     }
コード例 #21
0
static int
data_write_header(Eet_File *ef)
{
    int bytes = 0;

    if (edje_file)
    {
        if (edje_file->collection)
        {
            Edje_Part_Collection_Directory_Entry *ce;

            /* copy aliases into collection directory */
            EINA_LIST_FREE(aliases, ce)
            {
                Edje_Part_Collection_Directory_Entry *sce;
                Eina_Iterator *it;

                if (!ce->entry)
                    error_and_abort(ef, "Collection %i: name missing.\n", ce->id);

                it = eina_hash_iterator_data_new(edje_file->collection);

                EINA_ITERATOR_FOREACH(it, sce)
                if (ce->id == sce->id)
                {
                    memcpy(&ce->count, &sce->count, sizeof (ce->count));
                    break;
                }

                if (!sce)
                    error_and_abort(ef, "Collection %s (%i) can't find an correct alias.\n", ce->entry, ce->id);

                eina_iterator_free(it);

                eina_hash_direct_add(edje_file->collection, ce->entry, ce);
            }
        }
コード例 #22
0
ファイル: ewk_js.cpp プロジェクト: dog-god/iptv
static bool ewk_js_properties_enumerate(NPObject* npObject, NPIdentifier** value, uint32_t* count)
{
    Ewk_JS_Object* object = reinterpret_cast<Ewk_JS_Object*>(npObject);
    Eina_Iterator* it;
    char* key;
    int i = 0;

    EINA_SAFETY_ON_NULL_RETURN_VAL(npObject, false);
    EINA_MAGIC_CHECK_OR_RETURN(object, false);

    *count = eina_hash_population(object->properties);
    *value = static_cast<NPIdentifier*>(malloc(sizeof(NPIdentifier) * *count));
    if (!*value) {
        ERR("Could not allocate memory for NPIdentifier");
        return false;
    }

    it = eina_hash_iterator_key_new(object->properties);
    EINA_ITERATOR_FOREACH(it, key)
        (*value)[i++] = _NPN_GetStringIdentifier(key);

    eina_iterator_free(it);
    return true;
}
コード例 #23
0
ファイル: eina_hash_06.c プロジェクト: Limsik/e17
int
main(int argc, const char *argv[])
{
   Eina_Hash *phone_book = NULL;
   int i;
   int64_t entry_id = 4;
   char *phone = NULL;
   Eina_Bool r;
   Eina_Iterator *it;
   void *data;

   eina_init();

   phone_book = eina_hash_int64_new(_phone_entry_free_cb);

   // Add initial entries to our hash
   for (i = 0; _start_entries[i].id != -1; i++)
     {
	eina_hash_add(phone_book, &_start_entries[i].id,
		      strdup(_start_entries[i].number));
     }

   // Look for a specific entry and get its phone number
   phone = eina_hash_find(phone_book, &entry_id);
   if (phone)
     {
	printf("Printing entry.\n");
	printf("Id: %lld\n", entry_id);
	printf("Number: %s\n\n", phone);
     }

   // Delete this entry
   r = eina_hash_del(phone_book, &entry_id, NULL);
   printf("Hash entry successfully deleted? %d\n\n", r);

   // Modify the pointer data of an entry and free the old one
   int64_t id3 = 3;
   phone = eina_hash_modify(phone_book, &id3,
			    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
   int64_t id5 = 5;
   eina_error_set(0);
   phone = eina_hash_set(phone_book, &id5,
			 strdup("+55 01 234-56789"));
   if (!phone)
     {
	Eina_Error err = eina_error_get();
	if (!err)
	  {
	     printf("No previous phone found for id5. ");
	     printf("Creating new entry.\n");
	  }
	else
	  printf("Error when setting phone for Raul Seixas\n");
     }
   else
     {
	printf("Old phone for id5 was %s\n", phone);
	free(phone);
     }

   printf("\n");

   // Now change the phone number
   eina_error_set(0);
   phone = eina_hash_set(phone_book, &id5,
			 strdup("+55 02 222-22222"));
   if (phone)
     {
	printf("Changing phone for id5 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 id5\n");
	else
	  {
	     printf("No previous phone found for id5. ");
	     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 int64_t *id = t->key;
	const char *number = t->data;
	printf("%lld: %s\n", *id, number);
     }
   eina_iterator_free(it); // Always free the iterator after its use
   printf("\n");

   // Just iterate over the keys (names)
   printf("List of ids in the phone book:\n");
   it = eina_hash_iterator_key_new(phone_book);
   while (eina_iterator_next(it, &data))
     {
	const int64_t *id = data;
	printf("%lld\n", *id);
     }
   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
   int64_t id6 = 6;
   eina_hash_move(phone_book, &id5, &id6);
   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();
}
コード例 #24
0
ファイル: efreet_ini.c プロジェクト: jgfenix/efl
/**
 * @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;
}
コード例 #25
0
ファイル: sources.c プロジェクト: Stefan-Schmidt/efl
static void
_gen_func(const Eolian_Unit *src, const Eolian_Class *cl,
          const Eolian_Function *fid, Eolian_Function_Type ftype,
          Eina_Strbuf *buf, const Eolian_Implement *impl, Eina_Strbuf *lbuf)
{
   Eina_Bool is_empty = eolian_implement_is_empty(impl, ftype);
   Eina_Bool is_auto = eolian_implement_is_auto(impl, ftype);

   if ((ftype != EOLIAN_PROP_GET) && (ftype != EOLIAN_PROP_SET))
     ftype = eolian_function_type_get(fid);

   Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET);
   Eina_Bool var_as_ret = EINA_FALSE;

   const Eolian_Expression *def_ret = NULL;
   const Eolian_Type *rtp = eolian_function_return_type_get(fid, ftype);
   if (rtp)
     {
        is_auto = EINA_FALSE; /* can't do auto if func returns */
        def_ret = eolian_function_return_default_value_get(fid, ftype);
     }

   const char *func_suffix = "";
   if (ftype == EOLIAN_PROP_GET)
     {
        func_suffix = "_get";
        if (!rtp)
          {
             void *d1, *d2;
             Eina_Iterator *itr = eolian_property_values_get(fid, ftype);
             if (eina_iterator_next(itr, &d1) && !eina_iterator_next(itr, &d2))
               {
                  Eolian_Function_Parameter *pr = d1;
                  rtp = eolian_parameter_type_get(pr);
                  var_as_ret = EINA_TRUE;
                  def_ret = eolian_parameter_default_value_get(pr);
               }
             eina_iterator_free(itr);
          }
     }
   else if (ftype == EOLIAN_PROP_SET)
     func_suffix = "_set";

   Eina_Strbuf *params = eina_strbuf_new(); /* par1, par2, par3, ... */
   Eina_Strbuf *params_full = eina_strbuf_new(); /* T par1, U par2, ... for decl */
   Eina_Strbuf *params_full_imp = eina_strbuf_new(); /* as above, for impl */
   Eina_Strbuf *params_init = eina_strbuf_new(); /* default value inits */

   Eina_Stringshare *promise_param_name = NULL;
   Eina_Stringshare *promise_param_type = NULL;

   /* property keys */
   {
      Eina_Iterator *itr = eolian_property_keys_get(fid, ftype);
      Eolian_Function_Parameter *pr;
      EINA_ITERATOR_FOREACH(itr, pr)
        {
           const char *prn = eolian_parameter_name_get(pr);
           const Eolian_Type *pt = eolian_parameter_type_get(pr);
           Eina_Stringshare *ptn = eolian_type_c_type_get(pt);

           if (eina_strbuf_length_get(params))
             eina_strbuf_append(params, ", ");
           eina_strbuf_append(params, prn);

           eina_strbuf_append_printf(params_full, ", %s", ptn);
           eina_strbuf_append_printf(params_full_imp, ", %s", ptn);
           if (ptn[strlen(ptn) - 1] != '*')
             {
                eina_strbuf_append_char(params_full, ' ');
                eina_strbuf_append_char(params_full_imp, ' ');
             }
           eina_strbuf_append(params_full, prn);
           eina_strbuf_append(params_full_imp, prn);
           if (is_empty || is_auto)
             eina_strbuf_append(params_full_imp, " EINA_UNUSED");

           eina_stringshare_del(ptn);
        }
      eina_iterator_free(itr);
   }

   /* property values or method params if applicable */
   if (!var_as_ret)
     {
        Eina_Iterator *itr;
        if (is_prop)
          itr = eolian_property_values_get(fid, ftype);
        else
          itr = eolian_function_parameters_get(fid);
        Eolian_Function_Parameter *pr;
        EINA_ITERATOR_FOREACH(itr, pr)
          {
             Eolian_Parameter_Dir pd = eolian_parameter_direction_get(pr);
             const Eolian_Expression *dfv = eolian_parameter_default_value_get(pr);
             const char *prn = eolian_parameter_name_get(pr);
             const Eolian_Type *pt = eolian_parameter_type_get(pr);
             Eina_Stringshare *ptn = eolian_type_c_type_get(pt);

             Eina_Bool had_star = ptn[strlen(ptn) - 1] == '*';
             const char *add_star = _get_add_star(ftype, pd);

             if (eina_strbuf_length_get(params))
               eina_strbuf_append(params, ", ");

             eina_strbuf_append(params_full_imp, ", ");
             eina_strbuf_append(params_full_imp, ptn);
             if (!had_star)
               eina_strbuf_append_char(params_full_imp, ' ');
             eina_strbuf_append(params_full_imp, add_star);
             eina_strbuf_append(params_full_imp, prn);
             if (!dfv && is_empty)
               eina_strbuf_append(params_full_imp, " EINA_UNUSED");
             eina_strbuf_append(params, prn);

             eina_strbuf_append(params_full, ", ");
             eina_strbuf_append(params_full, ptn);
             if (!had_star)
               eina_strbuf_append_char(params_full, ' ');
             eina_strbuf_append(params_full, add_star);
             eina_strbuf_append(params_full, prn);

             if (is_auto)
               {
                  if (ftype == EOLIAN_PROP_SET)
                    eina_strbuf_append_printf(params_init, "   %s = pd->%s;\n", prn, prn);
                  else
                    {
                       eina_strbuf_append_printf(params_init, "   if (%s) *%s = pd->%s;\n",
                                                 prn, prn, prn);
                    }
               }
             else if ((ftype != EOLIAN_PROP_SET) && dfv)
               {
                  Eolian_Value val = eolian_expression_eval(src, dfv, EOLIAN_MASK_ALL);
                  if (val.type)
                    {
                       Eina_Stringshare *vals = eolian_expression_value_to_literal(&val);
                       eina_strbuf_append_printf(params_init, "   if (%s) *%s = %s;",
                                                 prn, prn, vals);
                       eina_stringshare_del(vals);
                       if (eolian_expression_type_get(dfv) == EOLIAN_EXPR_NAME)
                         {
                            Eina_Stringshare *vs = eolian_expression_serialize(dfv);
                            eina_strbuf_append_printf(params_init, " /* %s */", vs);
                            eina_stringshare_del(vs);
                         }
                       eina_strbuf_append_char(params_init, '\n');
                    }
               }

             eina_stringshare_del(ptn);
          }
コード例 #26
0
static void
_evas_object_table_iterator_free(Evas_Object_Table_Iterator *it)
{
   eina_iterator_free(it->real_iterator);
   free(it);
}
コード例 #27
0
ファイル: headers.c プロジェクト: Stefan-Schmidt/efl
static void
_gen_func(const Eolian_Unit *src, const Eolian_Function *fid,
          Eolian_Function_Type ftype, Eina_Strbuf *buf, char *cname,
          char *cnameu, Eina_Bool legacy)
{
   Eina_Stringshare *fcn = eolian_function_full_c_name_get(fid, ftype, legacy);
   if (!fcn)
     return;

   Eina_Bool var_as_ret = EINA_FALSE;
   const Eolian_Type *rtp = eolian_function_return_type_get(fid, ftype);
   if (ftype == EOLIAN_PROP_GET && !rtp)
     {
        void *d1, *d2;
        Eina_Iterator *itr = eolian_property_values_get(fid, ftype);
        if (eina_iterator_next(itr, &d1) && !eina_iterator_next(itr, &d2))
          {
             rtp = eolian_parameter_type_get((Eolian_Function_Parameter *)d1);
             var_as_ret = EINA_TRUE;
          }
        eina_iterator_free(itr);
     }

   Eolian_Object_Scope fsc = eolian_function_scope_get(fid, ftype);

   /* this one will never be satisfied in legacy */
   if (eolian_function_is_beta(fid))
     eina_strbuf_append_printf(buf, "#ifdef %s_BETA\n", cnameu);
   /* XXX: is this right? we expose potentially internal stuff into legacy */
   if (!legacy && (fsc == EOLIAN_SCOPE_PROTECTED))
     eina_strbuf_append_printf(buf, "#ifdef %s_PROTECTED\n", cnameu);

   const Eolian_Implement *fimp = eolian_function_implement_get(fid);

   Eina_Bool hasdoc = !!eolian_implement_documentation_get(fimp, ftype);
   if (!hasdoc && ((ftype == EOLIAN_PROP_GET) || (ftype == EOLIAN_PROP_SET)))
     hasdoc = !!eolian_implement_documentation_get(fimp, EOLIAN_PROPERTY);
   if (hasdoc)
     {
        Eina_Strbuf *dbuf = eo_gen_docs_func_gen(src, fid, ftype, 0, legacy);
        eina_strbuf_append(buf, eina_strbuf_string_get(dbuf));
        eina_strbuf_append_char(buf, '\n');
        eina_strbuf_free(dbuf);
     }
   eina_strbuf_append(buf, legacy ? "EAPI " : "EOAPI ");
   if (rtp)
     {
        Eina_Stringshare *rtps = eolian_type_c_type_get(rtp);
        eina_strbuf_append(buf, rtps);
        if (rtps[strlen(rtps) - 1] != '*')
          eina_strbuf_append_char(buf, ' ');
        eina_stringshare_del(rtps);
     }
   else
     eina_strbuf_append(buf, "void ");

   eina_strbuf_append(buf, fcn);
   eina_stringshare_del(fcn);

   Eina_Bool first = EINA_TRUE;
   Eina_Strbuf *flagbuf = NULL;
   int nidx = !legacy || !eolian_function_is_class(fid);

   eina_strbuf_append_char(buf, '(');
   if (nidx)
     {
        if ((ftype == EOLIAN_PROP_GET) || eolian_function_object_is_const(fid)
            || eolian_function_is_class(fid))
          {
             eina_strbuf_append(buf, "const ");
          }
        if (legacy)
          eina_strbuf_append_printf(buf, "%s *obj", cname);
        else
          eina_strbuf_append(buf, "Eo *obj");
        first = EINA_FALSE;
     }

   {
      Eolian_Function_Parameter *pr = NULL;
      Eina_Iterator *itr = eolian_property_keys_get(fid, ftype);
      EINA_ITERATOR_FOREACH(itr, pr)
        {
           const Eolian_Type *prt = eolian_parameter_type_get(pr);
           const char *prn = eolian_parameter_name_get(pr);
           Eina_Stringshare *prtn = eolian_type_c_type_get(prt);
           ++nidx;
           if (!first)
             eina_strbuf_append(buf, ", ");
           eina_strbuf_append_printf(buf, "%s %s", prtn, prn);
           eina_stringshare_del(prtn);
           first = EINA_FALSE;
           if (!eolian_parameter_is_nonull(pr))
             continue;
           if (!flagbuf)
             {
                flagbuf = eina_strbuf_new();
                eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx);
             }
           else
             eina_strbuf_append_printf(flagbuf, ", %d", nidx);
        }
      eina_iterator_free(itr);
   }

   if (!var_as_ret)
     {
        Eina_Iterator *itr = NULL;
        if (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET)
          itr = eolian_property_values_get(fid, ftype);
        else
          itr = eolian_function_parameters_get(fid);

        Eolian_Function_Parameter *pr = NULL;
        EINA_ITERATOR_FOREACH(itr, pr)
          {
             const Eolian_Type *prt = eolian_parameter_type_get(pr);
             const char *prn = eolian_parameter_name_get(pr);
             Eina_Stringshare *prtn = eolian_type_c_type_get(prt);

             ++nidx;
             if (!first)
               eina_strbuf_append(buf, ", ");
             eina_strbuf_append(buf, prtn);
             if (prtn[strlen(prtn) - 1] != '*')
               eina_strbuf_append_char(buf, ' ');
             eina_strbuf_append(buf,
                 _get_add_star(ftype, eolian_parameter_direction_get(pr)));
             eina_strbuf_append(buf, prn);
             eina_stringshare_del(prtn);
             first = EINA_FALSE;
             if (!eolian_parameter_is_nonull(pr))
               continue;
             if (!flagbuf)
               {
                  flagbuf = eina_strbuf_new();
                  eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx);
               }
             else
               eina_strbuf_append_printf(flagbuf, ", %d", nidx);
          }

        eina_iterator_free(itr);
     }
コード例 #28
0
ファイル: evas_object_grid.c プロジェクト: Limsik/e17
static void
_evas_object_grid_iterator_free(Evas_Object_Grid_Iterator *it)
{
   eina_iterator_free(it->real_iterator);
   free(it);
}
コード例 #29
0
static int
_info_list(void)
{
   Eina_Iterator *itr;
   Eina_List *types;
   const Eina_Hash_Tuple *tuple;
   const Eina_List *l;
   const char *name, *last_module;
   Eina_Bool module_found = EINA_FALSE, type_found = EINA_FALSE;
   Eina_Bool in_module = EINA_FALSE;

   EINA_LIST_FOREACH(modules, l, name)
     {
        if (!module_matches(name))
          {
             DBG("filter out module '%s': does not match '%s'",
                 name, module_patterns_str);
             continue;
          }

        if (!edje_module_load(name))
          {
             ERR("error loading external '%s'", name);
             continue;
          }

        module_found = EINA_TRUE;
     }

   itr = edje_external_iterator_get();
   types = NULL;
   EINA_ITERATOR_FOREACH(itr, tuple)
     {
        const Edje_External_Type *type = tuple->data;
        name = tuple->key;

        if (!type)
          {
             ERR("no type value for '%s'", name);
             continue;
          }
        else if (type->abi_version != edje_external_type_abi_version_get())
          {
             ERR("type '%s' with incorrect abi_version %u (expected %u)",
                 name, type->abi_version, edje_external_type_abi_version_get());
             continue;
          }

        if (!type_matches(name))
          {
             DBG("filter out type '%s': does not match '%s'", name, type_glob);
             continue;
          }

        types = eina_list_append(types, tuple);
        type_found = EINA_TRUE;
     }
   eina_iterator_free(itr);

   last_module = NULL;
   types = eina_list_sort(types, 0, _types_sort);
   EINA_LIST_FREE(types, tuple)
     {
        Eina_Bool changed_module = EINA_FALSE;
        const Edje_External_Type *type = tuple->data;
        const Edje_External_Param_Info *param;
        name = tuple->key;

        if ((last_module) && (type->module))
          {
             changed_module = ((last_module != type->module) &&
                               (!strcmp(last_module, type->module)));
          }
        else if ((!last_module) && (type->module))
          changed_module = EINA_TRUE;

        if (changed_module)
          {
             if (in_module)
               {
                  if (machine) puts("TYPES-END\nMODULE-END");
                  else puts(INDENT "}\n}");
               }

             if (machine)
               printf("MODULE-BEGIN\n"
                      "NAME: %s\n"
                      "FRIENDLY-NAME: %s\n"
                      "TYPES-BEGIN\n",
                      type->module, type->module_name);
             else
               printf("module {\n"
                      INDENT "name: \"%s\";\n"
                      INDENT "friendly_name: \"%s\";\n"
                      INDENT "types {\n",
                      type->module, type->module_name);

             in_module = EINA_TRUE;
          }

        if (machine) printf("TYPE-BEGIN\nNAME: %s\n", name);
        else printf(INDENT2 "type {\n" INDENT3 "name: \"%s\";\n", name);

        if (detail > 1)
          {
             const char *str;

             if (!type->label_get) str = NULL;
             else str = type->label_get(type->data);
             if (machine) printf("LABEL: %s\n", str ? str : "");
             else if (str) printf(INDENT3 "label: \"%s\";\n", str);

             if (!type->description_get) str = NULL;
             else str = type->description_get(type->data);
             if (machine) printf("DESCRIPTION: %s\n", str ? str : "");
             else if (str) printf(INDENT3 "description: \"%s\";\n", str);
          }

        if (machine) puts("PARAMS-BEGIN");
        else puts(INDENT3 "params {");

        for (param = type->parameters_info; param->name != NULL; param++)
          {
             const char *pt = _param_type_str_get(param);
             char buf[128];

             if (machine)
               printf("PARAM-BEGIN\nNAME: %s\nTYPE: %s\n", param->name, pt);
             else printf(INDENT4 "%s: \"%s\"", pt, param->name);

             if (detail > 0)
               {
                  const char *str = _param_value_str_get
                    (type, param, buf, sizeof(buf));
                  if (machine) printf("DEFAULT: %s\n", str ? str : "");
                  else if (str) printf(" \"%s\"", str);

                  if (detail > 1)
                    {
                       if (!machine) putchar(';');
                       _param_extra_details(type, param);
                    }
               }

             if (machine) puts("PARAM-END");
             else if (detail > 1) putchar('\n');
             else puts(";");
          }

        if (machine) puts("PARAMS-END\nTYPE-END");
        else puts(INDENT3 "}\n" INDENT2 "}");

        last_module = type->module;
     }
コード例 #30
0
ファイル: eina_xattr_01.c プロジェクト: jigpu/efl
int
main(int argc, char **argv)
{
    if (argc < 3)
    {
        fprintf(stderr, "ERROR: incorrect usage.\n"
                "Usage:\n"
                "\t%s list <file>\n"
                "\t%s get <file> <key>\n"
                "\t%s del <file> <key>\n"
                "\t%s set <file> <key> <value>\n",
                argv[0], argv[0], argv[0], argv[0]);
        return EXIT_FAILURE;
    }

    if (strcmp(argv[1], "list") == 0)
    {
        Eina_Iterator *itr;
        Eina_Xattr *xattr;

        printf("xattrs of %s:\n", argv[2]);

        eina_init();

        itr = eina_xattr_value_ls(argv[2]);
        EINA_ITERATOR_FOREACH(itr, xattr)
        printf("\t%s: %.*s\n", xattr->name, (int)xattr->length, xattr->value);
        eina_iterator_free(itr);

        eina_shutdown();

    }
    else if (strcmp(argv[1], "get") == 0)
    {
        size_t size = 0;
        const char *value;

        if (argc < 4)
        {
            fputs("ERROR: missing key\n", stderr);
            return EXIT_FAILURE;
        }

        eina_init();
        value = eina_xattr_get(argv[2], argv[3], &size);
        printf("%s: %.*s\n", argv[3], (int)size, value);
        eina_shutdown();
    }
    else if (strcmp(argv[1], "del") == 0)
    {
        Eina_Bool ret;

        if (argc < 4)
        {
            fputs("ERROR: missing key\n", stderr);
            return EXIT_FAILURE;
        }

        eina_init();
        ret = eina_xattr_del(argv[2], argv[3]);
        printf("del xattr '%s': %s\n", argv[3], ret ? "success" : "failure");
        eina_shutdown();
    }
    else if (strcmp(argv[1], "set") == 0)
    {
        Eina_Bool ret;

        if (argc < 5)
        {
            fputs("ERROR: missing key or value\n", stderr);
            return EXIT_FAILURE;
        }

        eina_init();
        ret = eina_xattr_set(argv[2], argv[3], argv[4], strlen(argv[4]), 0);

        printf("set xattr '%s=%s' on '%s': %s\n",
               argv[3], argv[4], argv[2], ret ? "success" : "failure");

        eina_shutdown();
    }
    else
        fprintf(stderr, "ERROR: unknown command '%s'\n", argv[1]);

    return 0;
}