Example #1
0
END_TEST

START_TEST(eina_hash_extended)
{
   Eina_Hash *hash = NULL;
   int i;

        fail_if(eina_init() != 2);

   hash = eina_hash_string_djb2_new(NULL);
        fail_if(hash == NULL);

        fail_if(eina_hash_direct_add(hash, "42", "42") != EINA_TRUE);

   for (i = 43; i < 3043; ++i)
     {
        char *tmp = malloc(10);
        fail_if(!tmp);
        eina_convert_itoa(i, tmp);
        fail_if(eina_hash_direct_add(hash, tmp, tmp) != EINA_TRUE);
     }

        fail_if(eina_hash_find(hash, "42") == NULL);

        eina_hash_free(hash);

   fail_if(eina_shutdown() != 1);
}
Example #2
0
END_TEST

START_TEST(eina_hash_int32_fuzze)
{
   Eina_Hash *hash;
   Eina_List *added = NULL;
   unsigned int *r;
   unsigned int i;
   unsigned int j;
   unsigned int seed;

   eina_init();

   seed = time(NULL);
   srand(seed);

   hash = eina_hash_int32_new(free);

   for (i = 0; i < 10000; ++i)
     {
        r = malloc(sizeof (unsigned int));
        *r = rand();
        eina_hash_direct_add(hash, r, r);
     }

   for (j = 0; j < 100; ++j)
     {
        for (i = 0; i < 1000; ++i)
          {
             do
               {
                  unsigned int tr;

                  tr = rand();
                  r = eina_hash_find(hash, &tr);
                  if (r)
                    {
                       r = NULL;
                       continue;
                    }

                  r = malloc(sizeof (unsigned int));
                  *r = tr;
                  eina_hash_direct_add(hash, r, r);
                  added = eina_list_append(added, r);
               }
             while (r == NULL);
          }

        EINA_LIST_FREE(added, r)
          {
             unsigned int *s;

             s = eina_hash_find(hash, r);
	     fail_if(s != r);
             eina_hash_del(hash, r, r);
          }
     }
Example #3
0
static Eina_Bool _lng_set(Language_XML *xml, char *value, char *attrvalue, const char *type)
{
    if ((!xml) || (!value))
    {
        DBG("One of values is NULL, returning with error.");
        return EINA_FALSE;
    }

    if (!strcmp(type, "atr"))
    {
        if (attrvalue) attrvalue = eina_stringshare_add(attrvalue);
        eina_hash_direct_add( xml->current->attributes, eina_stringshare_add(value), attrvalue );
    }
    else if (!strcmp(type, "tag"))
    {
        xml->current->tag = eina_stringshare_add(value);
        if (!xml->current->tag) return EINA_FALSE;
    }
    else if (!strcmp(type, "val"))
    {
        xml->current->value = eina_stringshare_add(value);
        if (!xml->current->value) return EINA_FALSE;
    }
    else return EINA_FALSE;

    return EINA_TRUE;
}
Example #4
0
Eina_Bool
evas_module_register(const Evas_Module_Api *module, Evas_Module_Type type)
{
   Evas_Module *em;

   if ((unsigned int)type > 3) return EINA_FALSE;
   if (!module) return EINA_FALSE;
   if (module->version != EVAS_MODULE_API_VERSION) return EINA_FALSE;

   em = eina_hash_find(evas_modules[type], module->name);
   if (em) return EINA_FALSE;

   em = calloc(1, sizeof (Evas_Module));
   if (!em) return EINA_FALSE;

   em->definition = module;

   if (type == EVAS_MODULE_TYPE_ENGINE)
     {
	eina_array_push(evas_engines, em);
	em->id_engine = eina_array_count(evas_engines);
     }

   eina_hash_direct_add(evas_modules[type], module->name, em);

   return EINA_TRUE;
}
Example #5
0
static E_Gadcon_Client *
_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
{
   Evas_Object *o;
   E_Gadcon_Client *gcc;
   Config_Face *inst;

   inst = eina_hash_find(temperature_config->faces, id);
   if (!inst)
     {
        inst = E_NEW(Config_Face, 1);
        inst->id = eina_stringshare_add(id);
        inst->poll_interval = 128;
        inst->low = 30;
        inst->high = 80;
        inst->sensor_type = SENSOR_TYPE_NONE;
        inst->sensor_name = NULL;
        inst->temp = -900;
        inst->units = CELSIUS;
#ifdef HAVE_EEZE
        inst->backend = UDEV;
#endif
        if (!temperature_config->faces)
          temperature_config->faces = eina_hash_string_superfast_new(NULL);
        eina_hash_direct_add(temperature_config->faces, inst->id, inst);
     }
   if (!inst->id) inst->id = eina_stringshare_add(id);
   E_CONFIG_LIMIT(inst->poll_interval, 1, 1024);
   E_CONFIG_LIMIT(inst->low, 0, 100);
   E_CONFIG_LIMIT(inst->high, 0, 220);
   E_CONFIG_LIMIT(inst->units, CELSIUS, FAHRENHEIT);
#ifdef HAVE_EEZE
   E_CONFIG_LIMIT(inst->backend, TEMPGET, UDEV);
#endif

   o = edje_object_add(gc->evas);
   e_theme_edje_object_set(o, "base/theme/modules/temperature",
                           "e/modules/temperature/main");

   gcc = e_gadcon_client_new(gc, name, id, style, o);
   gcc->data = inst;

   inst->gcc = gcc;
   inst->o_temp = o;
   inst->module = temperature_config->module;
   inst->have_temp = EINA_FALSE;
   temperature_face_update_config(inst);

   evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
                                  _temperature_face_cb_mouse_down, inst);
   return gcc;
}
Example #6
0
/**
 * @internal
 * Calculate the kerning between "left" and "right.
 *
 * @param fi the font instance to use
 * @param left the left glyph index
 * @param right the right glyph index
 * @param[out] kerning the kerning calculated.
 * @return FALSE on error, TRUE on success.
 */
EAPI int
evas_common_font_query_kerning(RGBA_Font_Int *fi, FT_UInt left, FT_UInt right,
			       int *kerning)
{
   int *result;
   FT_Vector delta;
   int key[2];
   int error = 1;

   key[0] = left;
   key[1] = right;

   result = eina_hash_find(fi->kerning, key);
   if (result)
     {
	*kerning = result[2];
	goto on_correct;
     }

   /* NOTE: ft2 seems to have a bug. and sometimes returns bizarre
    * values to kern by - given same font, same size and same
    * prev_index and index. auto/bytecode or none hinting doesn't
    * matter */
   evas_common_font_int_reload(fi);
   FTLOCK();
   if (FT_Get_Kerning(fi->src->ft.face,
		      key[0], key[1],
		      FT_KERNING_DEFAULT, &delta) == 0)
     {
	int *push;

        FTUNLOCK();
	*kerning = delta.x;

	push = malloc(sizeof (int) * 3);
	if (!push) return 1;

	push[0] = key[0];
	push[1] = key[1];
	push[2] = *kerning;

	eina_hash_direct_add(fi->kerning, push, push);

	goto on_correct;
     }

        FTUNLOCK();
   error = 0;

 on_correct:
   return error;
}
Example #7
0
Elm_Module *
_elm_module_add(const char *name, const char *as)
{
   Elm_Module *m;

   if (name[0] == '/') return NULL;

   m = eina_hash_find(modules, name);
   if (m)
     {
        m->references++;
        return m;
     }
   m = calloc(1, sizeof(Elm_Module));
   if (!m) return NULL;
   m->version = 1;
   m->name = eina_stringshare_add(name);
   m->references = 1;
   eina_hash_direct_add(modules, m->name, m);
   m->as = eina_stringshare_add(as);
   eina_hash_direct_add(modules_as, m->as, m);
   return m;
}
Example #8
0
static void _meta2hash(Eina_Hash *hash, Meta *tree)
{
  int i;
  Meta *found = eina_hash_find(hash, tree);
  
  if (found)
    return;
  
  eina_hash_direct_add(hash, tree, tree);
  
  if (tree->childs)
    for(i=0;i<tree->childs->count;i++)
      _meta2hash(hash, ma_data(tree->childs, i));
}
Example #9
0
/**
 * 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);
          }
     }
}
Example #10
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);
            }
        }
Eina_Bool
evas_cserve2_loader_register(Evas_Loader_Module_Api *api)
{
   eina_hash_direct_add(loaders, api->type, api);
   return EINA_TRUE;
}
Example #12
0
int
main(int argc, char **argv)
{
   Eina_File *f;
   Eina_Iterator *it;
   Eina_File_Line *l;
   GeoIP *geo;
   Community_Country *country;
   unsigned long long correct = 0;
   unsigned long long lines = 0;
   int i;

   if (argc != 2) return -1;

   eina_init();

   community = eina_hash_stringshared_new(NULL);
   days = eina_hash_new(_community_day_key_length,
                             _community_day_key_cmp,
                             _community_day_key_hash,
                             NULL, 5);
   countries = eina_hash_string_superfast_new(NULL);
   geo = GeoIP_new(GEOIP_STANDARD);
   memset(months, 0, sizeof (months));

   /* Read real name country to tld file */
   f = eina_file_open("country_tld.csv", EINA_FALSE);
   if (!f) return -1;

   it = eina_file_map_lines(f);
   EINA_ITERATOR_FOREACH(it, l)
     {
        const char *s;
        int i;

        s = memchr(l->start, ',', l->length);
        if (!s) continue ;

        country = calloc(1, sizeof (Community_Country));
        country->tld = _eina_stringshare_up(l->start, s - l->start);
        country->country = _eina_stringshare_up(s + 1, l->length - (s - l->start + 1));
        country->access = eina_hash_stringshared_new(NULL);

        eina_hash_direct_add(countries, country->tld, country);
     }
   eina_iterator_free(it);
   eina_file_close(f);

   /* Read population information */
   f = eina_file_open("country_population.csv", EINA_FALSE);
   if (!f) return -1;

   it = eina_file_map_lines(f);
   EINA_ITERATOR_FOREACH(it, l)
     {
        Eina_Iterator *it2;
        const char *s;
        const char *country_name;
        const char *r;

        for (s = l->start; s < l->end; s++)
          {
             const char *convert = VIGRID_NUMBER_SEARCH;

             r = strchr(convert, *s);
             if (r) break ;
          }

        if (!r) continue;

        country = NULL;
        country_name = _eina_stringshare_up(l->start, s - l->start - 1);

        it2 = eina_hash_iterator_data_new(countries);
        EINA_ITERATOR_FOREACH(it2, country)
          {
             if (country->country == country_name)
               {
                  unsigned long long offset = s - l->start;

                  country->population = _eina_file_int_get(l, &offset);
                  break;
               }
          }
        eina_iterator_free(it2);
     }