gboolean
get_task_list (GArray *task_list)
{
	GDir *dir;
	const gchar *name;
	GPid pid;
	Task task;

	if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL)
		return FALSE;

	while ((name = g_dir_read_name(dir)) != NULL)
	{
		if ((pid = (GPid)g_ascii_strtoull (name, NULL, 0)) > 0)
		{
			if (get_task_details (pid, &task))
				g_array_append_val(task_list, task);
		}
	}

	g_dir_close (dir);

	g_array_sort (task_list, task_pid_compare_fn);

	return FALSE;
}
Exemplo n.º 2
0
void 
g_mount_spec_set_with_len (GMountSpec *spec,
			   const char *key,
			   const char *value,
			   int value_len)
{
  int i;
  char *value_copy;

  g_return_if_fail (key != NULL);
  g_return_if_fail (value != NULL);

  if (value_len == -1)
    value_copy = g_strdup (value);
  else
    value_copy = g_strndup (value, value_len);

  for (i = 0; i < spec->items->len; i++)
    {
      GMountSpecItem *item = &g_array_index (spec->items, GMountSpecItem, i);
      if (strcmp (item->key, key) == 0)
	{
	  g_free (item->value);
	  item->value = value_copy;
	  return;
	}
    }

  add_item (spec, key, value_copy);
  g_array_sort (spec->items, item_compare);
}
Exemplo n.º 3
0
GMountSpec *
g_mount_spec_from_dbus (GVariant *value)
{
  GMountSpec *spec;
  const gchar *key;
  const gchar *mount_prefix;
  GVariantIter *iter_mount_spec_items;
  GVariant *v;

  mount_prefix = NULL;
  g_variant_get (value, "(^&aya{sv})",
                 &mount_prefix,
                 &iter_mount_spec_items);
  
  spec = g_mount_spec_new (NULL);
  g_free (spec->mount_prefix);
  spec->mount_prefix = NULL;
  if (mount_prefix && mount_prefix[0])
    spec->mount_prefix = g_strdup (mount_prefix);

  while (g_variant_iter_loop (iter_mount_spec_items, "{&sv}", &key, &v))
    {
      add_item (spec, key, g_variant_dup_bytestring (v, NULL));
    }

  g_variant_iter_free (iter_mount_spec_items);

  /* Sort on key */
  g_array_sort (spec->items, item_compare);
  
  return spec;
}
Exemplo n.º 4
0
void
eos_shard_writer_v1_write_to_fd (EosShardWriterV1 *self, int fd)
{
  GVariant *variant;

  /* Sort our records to allow for binary searches on retrieval. */
  g_array_sort (self->entries, &compare_records);

  variant = header_entry_variant (self->entries);
  uint64_t header_size = g_variant_get_size (variant);
  header_size = GUINT64_TO_LE (header_size);
  g_variant_unref (variant);

  lseek (fd, ALIGN (sizeof (header_size) + header_size), SEEK_SET);

  int i;
  for (i = 0; i < self->entries->len; i++) {
    struct eos_shard_writer_v1_record_entry *e = &g_array_index (self->entries, struct eos_shard_writer_v1_record_entry, i);

    write_blob (fd, &e->metadata);
    write_blob (fd, &e->data);
  }

  lseek (fd, 0, SEEK_SET);
  g_assert (write (fd, &header_size, sizeof (header_size)) >= 0);
  variant = header_entry_variant (self->entries);
  write_variant (fd, variant);
  g_variant_unref (variant);
}
Exemplo n.º 5
0
static void
mex_music_player_shuffle_toggled (MexMusicPlayer *player,
                                  GParamSpec     *spec,
                                  MxButton       *button)
{
  MexMusicPlayerPrivate *priv = player->priv;
  gint i;

  if (mx_button_get_toggled (button))
    {
      gint length;

      length = mex_model_get_length (priv->model);

      priv->shuffle = g_array_sized_new (FALSE, FALSE, sizeof (gint), length);

      for (i = 0; i < length; i++)
        g_array_insert_val (priv->shuffle, i, i);

      /* shuffle the list */
      g_array_sort (priv->shuffle, mex_music_player_random_sort);
    }
  else
    {
      if (priv->shuffle)
        {
          g_array_free (priv->shuffle, TRUE);
          priv->shuffle = NULL;
        }
    }
}
GkmFactory*
gkm_module_find_factory (GkmModule *self, CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
{
	GkmFactory *factory;
	gboolean matched;
	gulong j;
	gsize i;

	g_return_val_if_fail (GKM_IS_MODULE (self), NULL);
	g_return_val_if_fail (attrs || !n_attrs, NULL);

	if (!self->pv->factories_sorted) {
		g_array_sort (self->pv->factories, sort_factory_by_n_attrs);
		self->pv->factories_sorted = TRUE;
	}

	for (i = 0; i < self->pv->factories->len; ++i) {
		factory = &(g_array_index (self->pv->factories, GkmFactory, i));

		matched = TRUE;
		for (j = 0; j < factory->n_attrs; ++j) {
			if (!gkm_attributes_contains (attrs, n_attrs, &factory->attrs[j])) {
				matched = FALSE;
				break;
			}
		}

		if (matched)
			return factory;
	}

	return NULL;
}
Exemplo n.º 7
0
TwitterRequestParams *twitter_request_params_add_oauth_params(PurpleAccount * account, gboolean post, const gchar * url, const TwitterRequestParams * params, const gchar * token, const gchar * signing_key)
{
    gboolean        use_https = twitter_option_use_https(account) && purple_ssl_is_supported();
    TwitterRequestParams *oauth_params = twitter_request_params_clone(params);
    gchar          *signme;
    gchar          *signature;
    if (oauth_params == NULL)
        oauth_params = twitter_request_params_new();

    twitter_request_params_add(oauth_params, twitter_request_param_new("oauth_consumer_key", prpltwtr_auth_get_oauth_key(account)));
    twitter_request_params_add(oauth_params, twitter_request_param_new_ll("oauth_nonce", twitter_oauth_generate_nonce()));
    twitter_request_params_add(oauth_params, twitter_request_param_new("oauth_signature_method", "HMAC-SHA1"));
    /* Added for status.net. Twitter doesn't seem to care */
    twitter_request_params_add(oauth_params, twitter_request_param_new("oauth_callback", "oob"));
    twitter_request_params_add(oauth_params, twitter_request_param_new_ll("oauth_timestamp", time(NULL)));
    if (token)
        twitter_request_params_add(oauth_params, twitter_request_param_new("oauth_token", token));

    g_array_sort(oauth_params, (GCompareFunc) twitter_request_params_sort_do);
    signme = twitter_oauth_get_text_to_sign(post, use_https, url, oauth_params);
    signature = twitter_oauth_sign(signme, signing_key);

    g_free(signme);

    if (!signature) {
        twitter_request_params_free(oauth_params);
        return NULL;
    } else {
        twitter_request_params_add(oauth_params, twitter_request_param_new("oauth_signature", signature));
        g_free(signature);
        return oauth_params;
    }
}
Exemplo n.º 8
0
int
phraser_get_phrases(GArray * result, GString * input, PHRASER * phraser)
{
  char * ptr, *start_ptr,*p;
  int i,size;
  MATCHED mt;

  result = g_array_set_size(result, 0);

  for (start_ptr = ptr = phraser->start_ptr; (ptr - start_ptr) < phraser->fsize; ptr
      += 64)
    {

      if (memcmp(ptr, input->str, input->len) == 0)
        {
          memset(&mt, 0,64);
          p = ptr;
          while (*p != ' ' && *p != '\t')
            ++p;
          memcpy(mt.code, ptr, p - ptr  );
          while (*p == ' ' || *p == '\t')
            ++p;
          strcpy(mt.hanzi, p);
          result = g_array_append_val(result,mt );
          size++;
        }
    }
  //调节顺序
  g_array_sort(result, mysort);
  return size;
}
int
main (int argc, char **argv)
{
  GMappedFile *f;
  gchar *xml_data;
  gsize xml_len;

  f = g_mapped_file_new (ISO_639_XML_PATH, FALSE, NULL);
  if (f != NULL) {
    xml_data = (gchar *) g_mapped_file_get_contents (f);
    xml_len = g_mapped_file_get_length (f);
  } else {
    GError *err = NULL;

    if (!g_file_get_contents (ISO_639_XML_PATH, &xml_data, &xml_len, &err))
      g_error ("Could not read %s: %s", ISO_639_XML_PATH, err->message);
  }

  languages = g_array_new (FALSE, TRUE, sizeof (IsoLang));

  parse_iso_639_xml (xml_data, xml_len);

  g_array_sort (languages, (GCompareFunc) languages_sort_func);

  dump_languages ();

  g_array_free (languages, TRUE);

  if (f != NULL)
    g_mapped_file_unref (f);
  else
    g_free (xml_data);

  return 0;
}
Exemplo n.º 10
0
void GLibArrayImpl::Sort(LArrayInst * inst, int (* list_compare_func) (const void * value1, 
                                            const void * value2))
{
	g_return_if_fail(inst != NULL);
	g_return_if_fail(list_compare_func != NULL);
	g_array_sort(dynamic_cast<GLibArrayInst *>(inst)->m_array, (GCompareFunc)list_compare_func);    
}
Exemplo n.º 11
0
static GArray *
_get_ref_frame_cache (GstValidateSsim * self, const gchar * ref_file)
{
  GFile *ref_dir_file = NULL;
  GFileInfo *info;
  GFileEnumerator *fenum;
  GArray *frames = NULL;
  gchar *ref_dir = NULL;

  ref_dir = g_path_get_dirname (ref_file);

  frames = g_hash_table_lookup (self->priv->ref_frames_cache, ref_file);
  if (frames)
    goto done;

  ref_dir_file = g_file_new_for_path (ref_dir);
  if (!(fenum = g_file_enumerate_children (ref_dir_file,
              "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) {
    GST_INFO ("%s is not a folder", ref_dir);

    goto done;
  }

  for (info = g_file_enumerator_next_file (fenum, NULL, NULL);
      info; info = g_file_enumerator_next_file (fenum, NULL, NULL)) {
    Frame iframe;
    const gchar *display_name = g_file_info_get_display_name (info);

    if (!_filename_get_timestamp (self, display_name, &iframe.ts)) {
      g_object_unref (info);
      continue;
    }

    iframe.path = g_build_path (G_DIR_SEPARATOR_S,
        ref_dir, g_file_info_get_name (info), NULL);

    g_object_unref (info);

    if (!frames) {
      frames = g_array_new (TRUE, TRUE, sizeof (Frame));

      g_array_set_clear_func (frames, (GDestroyNotify) _free_frame);
    }
    g_array_append_val (frames, iframe);
  }

  if (frames) {
    g_array_sort (frames, (GCompareFunc) _sort_frames);

    g_hash_table_insert (self->priv->ref_frames_cache, g_strdup (ref_dir),
        frames);
  }

done:
  g_clear_object (&ref_dir_file);
  g_free (ref_dir);

  return frames;
}
Exemplo n.º 12
0
static void
gbl_symbols_vs_ext_new(void) {
  DISSECTOR_ASSERT(gbl_symbols_vs_ext == NULL);
  DISSECTOR_ASSERT(gbl_symbols_array != NULL);
  g_array_sort(gbl_symbols_array, gbl_symbols_compare_vs);
  gbl_symbols_vs_ext = value_string_ext_new((value_string *)(void *)gbl_symbols_array->data,
                                            gbl_symbols_array->len+1,
                                            "etch-global-symbols" );
}
Exemplo n.º 13
0
/**
 * fuzzy_insert:
 * @fuzzy: (in): A #Fuzzy.
 * @key: (in): An ASCII string.
 * @value: (in): A value to associate with key.
 *
 * Inserts a string into the fuzzy matcher.
 *
 * Note that @key MUST be an ascii string. UTF-8 is not supported.
 */
void
fuzzy_insert (Fuzzy       *fuzzy,
              const gchar *key,
              gpointer     value)
{
   FuzzyItem item;
   GArray *table;
   gchar *downcase = NULL;
   gsize offset;
   guint idx;
   gint id;
   gint i;

   g_return_if_fail(fuzzy);
   g_return_if_fail(key);
   g_return_if_fail(fuzzy->id_to_text_offset->len < ((1 << 20) - 1));

   if (!*key) {
      return;
   }

   if (!fuzzy->case_sensitive) {
      downcase = g_ascii_strdown(key, -1);
   }

   /*
    * Insert the string into our heap.
    * Track the offset within the heap since the heap could realloc.
    */
   offset = fuzzy_heap_insert(fuzzy, key);
   g_array_append_val(fuzzy->id_to_text_offset, offset);
   g_ptr_array_add(fuzzy->id_to_value, value);
   g_assert_cmpint(fuzzy->id_to_value->len, ==, fuzzy->id_to_text_offset->len);

   id = fuzzy->id_to_text_offset->len - 1;

   if (!fuzzy->case_sensitive) {
      key = downcase;
   }

   for (i = 0; key[i]; i++) {
      idx = key[i];
      table = g_ptr_array_index(fuzzy->char_tables, idx);

      item.id = id;
      item.pos = i;
      g_array_append_val(table, item);

      if (!fuzzy->in_bulk_insert) {
         g_array_sort(table, fuzzy_item_compare);
      }
   }

   if (!fuzzy->case_sensitive) {
      g_free(downcase);
   }
}
Exemplo n.º 14
0
static void
view_remove_contact_cb (EBookClientView *client_view,
                        const GSList *ids,
                        EAddressbookModel *model)
{
	/* XXX we should keep a hash around instead of this O(n*m) loop */
	const GSList *iter;
	GArray *indices;
	GPtrArray *array;
	gint ii;

	array = model->priv->contacts;
	indices = g_array_new (FALSE, FALSE, sizeof (gint));

	for (iter = ids; iter != NULL; iter = iter->next) {
		const gchar *target_uid = iter->data;

		for (ii = 0; ii < array->len; ii++) {
			EContact *contact;
			const gchar *uid;

			contact = array->pdata[ii];
			/* check if already removed */
			if (!contact)
				continue;

			uid = e_contact_get_const (contact, E_CONTACT_UID);
			g_return_if_fail (uid != NULL);

			if (strcmp (uid, target_uid) == 0) {
				g_object_unref (contact);
				g_array_append_val (indices, ii);
				array->pdata[ii] = NULL;
				break;
			}
		}
	}

	/* Sort the 'indices' array in descending order, since
	 * g_ptr_array_remove_index() shifts subsequent elements
	 * down one position to fill the gap. */
	g_array_sort (indices, sort_descending);

	for (ii = 0; ii < indices->len; ii++) {
		gint index;

		index = g_array_index (indices, gint, ii);
		g_ptr_array_remove_index (array, index);
	}

	g_signal_emit (model, signals[CONTACTS_REMOVED], 0, indices);
	g_array_free (indices, FALSE);

	update_folder_bar_message (model);
}
Exemplo n.º 15
0
GMountSpec *
g_mount_spec_from_dbus (DBusMessageIter *iter)
{
  GMountSpec *spec;
  DBusMessageIter array_iter, struct_iter, spec_iter;
  const char *key;
  char *value;
  char *mount_prefix;

  if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_STRUCT)
    return NULL;

  dbus_message_iter_recurse (iter, &spec_iter);

  mount_prefix = NULL;
  if (!_g_dbus_message_iter_get_args (&spec_iter, NULL,
				      G_DBUS_TYPE_CSTRING, &mount_prefix,
				      0))
    return NULL;

  spec = g_mount_spec_new (NULL);
  g_free (spec->mount_prefix);
  spec->mount_prefix = mount_prefix;
  
  if (dbus_message_iter_get_arg_type (&spec_iter) != DBUS_TYPE_ARRAY ||
      dbus_message_iter_get_element_type (&spec_iter) != DBUS_TYPE_STRUCT)
    {
      g_mount_spec_unref (spec);
      return NULL;
    }

  dbus_message_iter_recurse (&spec_iter, &array_iter);
  while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRUCT)
    {
      dbus_message_iter_recurse (&array_iter, &struct_iter);
      if (_g_dbus_message_iter_get_args (&struct_iter, NULL,
					 DBUS_TYPE_STRING, &key,
					 G_DBUS_TYPE_CSTRING, &value,
					 0))
	add_item (spec, key, value);
      dbus_message_iter_next (&array_iter);
    }

  dbus_message_iter_next (iter);
  
  /* Sort on key */
  g_array_sort (spec->items, item_compare);
  
  return spec;
}
Exemplo n.º 16
0
static void read_ntp_units(void) {
	gchar path[PATH_MAX], **unit_dir, **unit_dirs, *contents, **lines, **line;
	const gchar *entry;
	struct ntp_unit unit;
	GDir *dir;

	free_ntp_units();

	g_assert(!ntp_units);
	ntp_units = g_array_new(FALSE, FALSE, sizeof (struct ntp_unit));

	/* Read the NTP unit names from files in ntp-unit.d directories */

	unit_dirs = g_strsplit(NTP_UNITS_PATHS, ":", -1);

	for (unit_dir = unit_dirs; *unit_dir; unit_dir++) {
		dir = g_dir_open(*unit_dir, 0, NULL);
		if (!dir)
			continue;

		while ((entry = g_dir_read_name(dir))) {
			snprintf(path, sizeof path, "%s/%s", *unit_dir, entry);
			if (!g_file_get_contents(path, &contents, NULL, NULL))
				continue;
			lines = g_strsplit_set(contents, "\r\n", -1);
			g_free(contents);

			for (line = lines; *line; line++) {
				if (!**line || **line == '#')
					continue;

				/* Ignore units that can't be loaded */
				if (!call_systemd_noresult("LoadUnit", g_variant_new("(s)", *line)))
					continue;

				unit.name = g_strdup(*line);
				unit.sort_name = g_strdup(entry);
				g_array_append_val(ntp_units, unit);
			}
			g_strfreev(lines);
		}

		g_dir_close(dir);
	}

	g_strfreev(unit_dirs);

	/* Sort the units by filename */
	g_array_sort(ntp_units, compare_ntp_units);
}
Exemplo n.º 17
0
gint
is_permutation(a, b)
{
    GArray *array_a, *array_b;
    gint i = 0;

    array_a = g_array_new(FALSE, FALSE, sizeof (gint));
    array_b = g_array_new(FALSE, FALSE, sizeof (gint));

    i = a % 10;
    g_array_prepend_val(array_a, i);
    i = b % 10;
    g_array_prepend_val(array_b, i);
    while(a > 0)
    {
        i = a % 10;
        g_array_prepend_val(array_a, i);
        a /= 10;
    }
    i = 0;
    while(b > 0)
    {
        i = b % 10;
        g_array_prepend_val(array_b, i);
        b /= 10;
    }
    g_array_remove_index_fast(array_a, array_a->len-1);
    g_array_remove_index_fast(array_b, array_b->len-1);

    g_array_sort(array_a, compare);
    g_array_sort(array_b, compare);

    print_array(array_a);
    print_array(array_b);

    return 0;
}
Exemplo n.º 18
0
/**
 * fuzzy_end_bulk_insert:
 * @fuzzy: (in): A #Fuzzy.
 *
 * Complete a bulk insert and resort the index.
 */
void
fuzzy_end_bulk_insert (Fuzzy *fuzzy)
{
   GArray *table;
   gint i;

   g_return_if_fail(fuzzy);
   g_return_if_fail(fuzzy->in_bulk_insert);

   fuzzy->in_bulk_insert = FALSE;

   for (i = 0; i < fuzzy->char_tables->len; i++) {
      table = g_ptr_array_index(fuzzy->char_tables, i);
      g_array_sort(table, fuzzy_item_compare);
   }
}
Exemplo n.º 19
0
GArray *
sblb_block_change_map_get_indexes (SBlbBlockChangeMap *block_change_map)
{
    SBlbBlockChangeMapPrivate *priv;
    GArray *indexes;

    g_return_val_if_fail (SBLB_IS_BLOCK_CHANGE_MAP (block_change_map), NULL);

    priv = block_change_map->priv;

    indexes = g_array_sized_new (FALSE, FALSE, sizeof (gint), g_hash_table_size (priv->run_changed_blocks));
    g_hash_table_foreach (priv->run_changed_blocks, (GHFunc) key_to_array, indexes);

    g_array_sort (indexes, (GCompareFunc) compare_ints);
    return indexes;
}
Exemplo n.º 20
0
/* Takes ownership of passed in data */
GMountSpec *
g_mount_spec_new_from_data (GArray *items,
			    char *mount_prefix)
{
  GMountSpec *spec;

  spec = g_new0 (GMountSpec, 1);
  spec->ref_count = 1;
  spec->items = items;
  if (mount_prefix == NULL)
    spec->mount_prefix = g_strdup ("/");
  else
    spec->mount_prefix = g_mount_spec_canonicalize_path (mount_prefix);

  g_array_sort (spec->items, item_compare);
  
  return spec;
}
Exemplo n.º 21
0
static GArray *
get_kernel_symbols (void)
{
    static GArray *kernel_syms;
    static gboolean initialized = FALSE;

#if 0
    find_kernel_binary();
#endif

    if (!initialized)
    {
	char *kallsyms;
	if (g_file_get_contents ("/proc/kallsyms", &kallsyms, NULL, NULL))
	{
	    if (kallsyms)
	    {
		kernel_syms = g_array_new (TRUE, TRUE, sizeof (kernel_symbol_t));

		if (parse_kallsyms (kallsyms, kernel_syms))
		{
		    g_array_sort (kernel_syms, compare_syms);
		}
		else
		{
		    g_array_free (kernel_syms, TRUE);
		    kernel_syms = NULL;
		}
	    }

	    g_free (kallsyms);
	}

	if (!kernel_syms)
	{
	    g_print ("Warning: /proc/kallsyms could not be "
		     "read. Kernel symbols will not be available\n");
	}

	initialized = TRUE;
    }

    return kernel_syms;
}
Exemplo n.º 22
0
/**
 * news_parser_register_format:
 * @parser: (in): A #NewsParser.
 * @priority: (in): The discoverer priority.
 *
 * Registers a format discoverer with the given priority. The first match
 * is used when discovering formats. Lowest priorities first.
 *
 * Returns: None.
 */
void
news_parser_register_format (NewsFormatDiscoverer discoverer,
                             gint                 priority)
{
   static gsize initialized = FALSE;
   Discoverer disc = { 0 };

   g_return_if_fail(discoverer != NULL);

   if (g_once_init_enter(&initialized)) {
      gDiscoverers = g_array_new(FALSE, FALSE, sizeof disc);
      g_once_init_leave(&initialized, TRUE);
   }

   disc.func = discoverer;
   disc.priority = priority;
   g_array_append_val(gDiscoverers, disc);
   g_array_sort(gDiscoverers, discoverer_sort);
}
gboolean
get_task_list (GArray *task_list)
{
	GPid pid = 0;
	Task task;

	//while (/* read all PIDs */)
	{
		// if (/* pid is valid */)
		{
			if (get_task_details (pid, &task))
			{
				g_array_append_val (task_list, task);
			}
		}
	}

	g_array_sort (task_list, task_pid_compare_fn);

	return TRUE;
}
Exemplo n.º 24
0
void
context_info_db_index(ContextInfoDB *self)
{
  if (self->data->len > 0)
    {
      g_array_sort(self->data, _contextual_data_record_cmp);
      gsize range_start = 0;
      ContextualDataRecord range_start_record =
        g_array_index(self->data, ContextualDataRecord, 0);

      for (gsize i = 1; i < self->data->len; ++i)
        {
          ContextualDataRecord current_record =
            g_array_index(self->data, ContextualDataRecord, i);

          if (_contextual_data_record_cmp
              (&range_start_record, &current_record))
            {
              element_range *current_range = g_new(element_range, 1);
              current_range->offset = range_start;
              current_range->length = i - range_start;

              g_hash_table_insert(self->index, range_start_record.selector->str,
                                  current_range);

              range_start_record = current_record;
              range_start = i;
            }
        }

      {
        element_range *last_range = g_new(element_range, 1);
        last_range->offset = range_start;
        last_range->length = self->data->len - range_start;
        g_hash_table_insert(self->index, range_start_record.selector->str,
                            last_range);
      }
      self->is_data_indexed = TRUE;
    }
}
Exemplo n.º 25
0
/* Convert swissprot name suffixes to organisms */
static void suffix2organism(GArray *alignArr, GArray *organismArr) 
{
  int i = 0;
  char *cp = NULL;
  
  for (i = 0; i < (int)alignArr->len; ++i) 
    {
      ALN *alnp = g_array_index(alignArr, ALN*, i);
      
      if (!alnp->markup && (cp = strchr(alnp->name, '_'))) 
        {
          char *suffix = (char*)g_malloc(strlen(cp) + 1);
          strcpy(suffix, cp + 1);
          
          /* Add organism to table of organisms.  This is necessary to make all 
           sequences of the same organism point to the same place and to make a 
           non-redundant list of present organisms */
          alnp->organism = suffix;
          
          /* Only insert a new organism if it is not already in the array */
          int ip = 0;
          if (!alnArrayFind(organismArr, alnp, &ip, organism_order))
            {
	      ALN *organism = createEmptyAln();
	      alncpy(organism, alnp);
	      organism->organism = alnp->organism;
	    
              g_array_append_val(organismArr, organism);
              g_array_sort(organismArr, organism_order);
            }
          else
            {
              /* Store pointer to existing organism in ALN struct */
              ALN *alnTmp = g_array_index(organismArr, ALN*, ip);
	      g_free(alnp->organism);
              alnp->organism = alnTmp->organism;
            }
        }
    }
Exemplo n.º 26
0
static struct beans_content_s *
_beans_to_content(const GSList *beans)
{
	struct beans_content_s *c = g_malloc0(sizeof(struct beans_content_s));
	GPtrArray *contents, *chunks;
	chunk_pair_t pair;
	contents = g_ptr_array_new();
	chunks = g_ptr_array_new();

	/*dispatch */
	for(; beans; beans = beans->next) {
		if (DESCR(beans->data) == &descr_struct_CHUNKS)
			g_ptr_array_add(chunks, _bean_dup(beans->data));
		else if (DESCR(beans->data) == &descr_struct_CONTENTS)
			g_ptr_array_add(contents, _bean_dup(beans->data));
		else if (DESCR(beans->data) == &descr_struct_CONTENTS_HEADERS)
			c->header = _bean_dup(beans->data);
		else if (DESCR(beans->data) == &descr_struct_ALIASES)
			c->alias = _bean_dup(beans->data);
		else if (DESCR(beans->data) == &descr_struct_PROPERTIES)
			c->properties = g_slist_append(c->properties, _bean_dup(beans->data));
	}

	/* build pairs */
	c->pairs = g_array_new(FALSE, FALSE, sizeof(chunk_pair_t));
	for(guint i=0; i < contents->len ; i++) {
		init_chunk_pair(chunks, &pair, g_ptr_array_index(contents, i));
		if(pair.chunk != NULL)
			g_array_append_vals(c->pairs, &pair, 1);
	}
	g_array_sort(c->pairs, (GCompareFunc) compare_pairs_positions);                                             

	// what we want to preserve are the pointers to beans created by
	// _bean_dup, not the GPtrArray -> we can safely free the arrays.
	g_ptr_array_unref(contents);
	g_ptr_array_unref(chunks);

	return c;
}
Exemplo n.º 27
0
static gboolean
set_content_hash_type_from_classes (EmpathyFTHandler *handler,
    GPtrArray *classes)
{
  GArray *possible_values;
  guint value;
  gboolean valid;
  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
  gboolean support_ft = FALSE;
  guint i;

  possible_values = g_array_new (TRUE, TRUE, sizeof (guint));

  for (i = 0; i < classes->len; i++)
    {
      GHashTable *fixed;
      GStrv allowed;
      const gchar *chan_type;

      tp_value_array_unpack (g_ptr_array_index (classes, i), 2,
          &fixed, &allowed);

      chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);

      if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
        continue;

      if (tp_asv_get_uint32 (fixed, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) !=
          TP_HANDLE_TYPE_CONTACT)
        continue;

      support_ft = TRUE;

      value = tp_asv_get_uint32
        (fixed, TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH_TYPE,
         &valid);

      if (valid)
        g_array_append_val (possible_values, value);
    }

  if (!support_ft)
    {
      g_array_free (possible_values, TRUE);
      return FALSE;
    }

  if (possible_values->len == 0)
    {
      /* there are no channel classes with hash support, disable it. */
      priv->use_hash = FALSE;
      priv->content_hash_type = TP_FILE_HASH_TYPE_NONE;

      goto out;
    }

  priv->use_hash = TRUE;

  if (possible_values->len == 1)
    {
      priv->content_hash_type = g_array_index (possible_values, guint, 0);
    }
  else
    {
      /* order the array and pick the first non zero, so that MD5
       * is the preferred value.
       */
      g_array_sort (possible_values, empathy_uint_compare);

      if (g_array_index (possible_values, guint, 0) == 0)
        priv->content_hash_type = g_array_index (possible_values, guint, 1);
      else
        priv->content_hash_type = g_array_index (possible_values, guint, 0);
    }

out:
  g_array_free (possible_values, TRUE);

  DEBUG ("Hash enabled %s; setting content hash type as %u",
         priv->use_hash ? "True" : "False", priv->content_hash_type);

  return TRUE;
}
Exemplo n.º 28
0
Arquivo: garray.c Projeto: Babelz/SaNi
/**
 * g_byte_array_sort:
 * @array: a #GByteArray
 * @compare_func: comparison function
 *
 * Sorts a byte array, using @compare_func which should be a
 * qsort()-style comparison function (returns less than zero for first
 * arg is less than second arg, zero for equal, greater than zero if
 * first arg is greater than second arg).
 *
 * If two array elements compare equal, their order in the sorted array
 * is undefined. If you want equal elements to keep their order (i.e.
 * you want a stable sort) you can write a comparison function that,
 * if two elements would otherwise compare equal, compares them by
 * their addresses.
 */
void
g_byte_array_sort (GByteArray   *array,
                   GCompareFunc  compare_func)
{
  g_array_sort ((GArray *)array, compare_func);
}
Exemplo n.º 29
0
static PeasExtension *
peas_plugin_loader_seed_create_extension (PeasPluginLoader *loader,
                                          PeasPluginInfo   *info,
                                          GType             exten_type,
                                          guint             n_parameters,
                                          GParameter       *parameters)
{
  PeasPluginLoaderSeed *sloader = PEAS_PLUGIN_LOADER_SEED (loader);
  SeedInfo *sinfo;
  SeedValue extension_ctor, extension;
  guint i, j;
  SeedValue value;
  GValue gvalue = { 0 };
  GArray *interfaces;
  gchar **property_names;

  sinfo = (SeedInfo *) g_hash_table_lookup (sloader->loaded_plugins, info);

  /* FIXME: instantiate new object and pass the parameters */
  extension_ctor = seed_object_get_property (sinfo->context,
                                             sinfo->extensions,
                                             g_type_name (exten_type));
  if (!extension_ctor ||
      seed_value_is_undefined (sinfo->context, extension_ctor) ||
      seed_value_is_null (sinfo->context, extension_ctor))
    return NULL;

  if (!seed_value_is_object (sinfo->context, extension_ctor))
    {
      g_warning ("Extension '%s' in plugin '%s' is not a Seed object",
                 g_type_name (exten_type), peas_plugin_info_get_module_name (info));
      return NULL;
    }

  /* Instantiate the ctor object into a new specific object. */
  extension = JSObjectCallAsConstructor (sinfo->context, extension_ctor, 0, NULL, NULL);

  if (extension == NULL)
    {
#ifndef PEAS_DISABLE_DEPRECATED_FEATURES
      gchar **property_names;

      g_warning ("DEPRECATION WARNING: Extension '%s' in plugin '%s' is not a valid "
                 "constructor function. Support for extension initialization by array "
                 "copy will be dropped soon.",
                 g_type_name (exten_type), peas_plugin_info_get_module_name (info));

      extension = seed_make_object (sinfo->context, NULL, NULL);
      property_names = seed_object_copy_property_names (sinfo->context,
                                                        extension_ctor);
      for (i = 0; property_names[i] != NULL; i++)
        {
          SeedValue value;
          value = seed_object_get_property (sinfo->context,
                                            extension_ctor,
                                            property_names[i]);
          seed_object_set_property (sinfo->context,
                                    extension,
                                    property_names[i],
                                    value);
        }

        g_strfreev (property_names);
#else
      g_warning ("Extension '%s' in plugin '%s' is not a valid constructor",
                 g_type_name (exten_type), peas_plugin_info_get_module_name (info));
      return NULL;
#endif
    }

  /* Set the properties as well, cannot use
   * g_object_set_property() because it may be construct-only
   */
  for (i = 0; i < n_parameters; i++)
    {
      gchar *key;

      /* We want to normalize the property names to have a '_' instead of the
       * conventional '-', to make them accessible through this.property_name */
      key = g_strdup (parameters[i].name);
      for (j = 0; key[j] != '\0'; j++)
        {
          if (key[j] == '-')
            key[j] = '_';
        }

      value = seed_value_from_gvalue (sinfo->context,
                                      &parameters[i].value,
                                      NULL);
      seed_object_set_property (sinfo->context,
                                extension,
                                key,
                                value);

      g_free (key);
    }

  /* Set the plugin info as an attribute of the instance */
  g_value_init (&gvalue, PEAS_TYPE_PLUGIN_INFO);
  g_value_set_boxed (&gvalue, info);

  value = seed_value_from_gvalue (sinfo->context, &gvalue, NULL);
  seed_object_set_property (sinfo->context, extension, "plugin_info", value);

  g_value_unset (&gvalue);


  /* Do not add exten_type as it will be added below */
  interfaces = g_array_new (TRUE, FALSE, sizeof (GType));

  property_names = seed_object_copy_property_names (sinfo->context,
                                                    sinfo->extensions);

  for (i = 0; property_names[i] != NULL; ++i)
    {
      gchar *property_name = property_names[i];
      SeedValue *prop_extension_ctor;
      GType the_type;

      prop_extension_ctor = seed_object_get_property (sinfo->context,
                                                      sinfo->extensions,
                                                      property_name);

      if (prop_extension_ctor != extension_ctor)
        continue;

      if (!seed_value_is_object (sinfo->context, extension_ctor))
        {
          g_warning ("Extension '%s' in plugin '%s' is not a Seed object",
                     property_name, peas_plugin_info_get_module_name (info));
          continue;
        }

      the_type = peas_gi_get_type_from_name (property_name);

      if (the_type == G_TYPE_INVALID)
        {
          g_warning ("Could not find GType for '%s', "
                     "did you forget to import it?", property_name);
        }
      else
        {
          g_array_append_val (interfaces, the_type);
        }
    }

  g_array_sort (interfaces, (GCompareFunc) prerequisites_sort);

  g_strfreev (property_names);

  return peas_extension_seed_new (exten_type,
                                  (GType *) g_array_free (interfaces, FALSE),
                                  sinfo->context, extension);
}
Exemplo n.º 30
0
/**
 * gcr_importer_create_for_parsed:
 * @parsed: a parser with a parsed item to import
 *
 * Create a set of importers which can import this parsed item.
 * The parsed item is represented by the state of the GcrParser at the
 * time of calling this method.
 *
 * Returns: (element-type Gcr.Importer) (transfer full): a list of importers
 *          which can import the parsed item, which should be freed with
 *          g_object_unref(), or %NULL if no types of importers can be created
 */
GList *
gcr_importer_create_for_parsed (GcrParsed *parsed)
{
	GcrRegistered *registered;
	GcrImporterIface *iface;
	gpointer instance_class;
	GckAttributes *attrs;
	gboolean matched;
	gulong n_attrs;
	GList *results = NULL;
	GHashTable *seen;
	gulong j;
	gsize i;

	g_return_val_if_fail (parsed != NULL, NULL);

	gcr_importer_register_well_known ();

	if (!registered_importers)
		return NULL;

	if (!registered_sorted) {
		g_array_sort (registered_importers, sort_registered_by_n_attrs);
		registered_sorted = TRUE;
	}

	attrs = gcr_parsed_get_attributes (parsed);
	if (attrs != NULL)
		gck_attributes_ref (attrs);
	else
		attrs = gck_attributes_new_empty (GCK_INVALID);

	seen = g_hash_table_new (g_direct_hash, g_direct_equal);

	if (_gcr_debugging) {
		gchar *a = gck_attributes_to_string (attrs);
		_gcr_debug ("looking for importer for: %s", a);
		g_free (a);
	}

	for (i = 0; i < registered_importers->len; ++i) {
		registered = &(g_array_index (registered_importers, GcrRegistered, i));
		n_attrs = gck_attributes_count (registered->attrs);

		matched = TRUE;

		for (j = 0; j < n_attrs; ++j) {
			if (!gck_attributes_contains (attrs, gck_attributes_at (registered->attrs, j))) {
				matched = FALSE;
				break;
			}
		}

		if (_gcr_debugging) {
			gchar *a = gck_attributes_to_string (registered->attrs);
			_gcr_debug ("importer %s %s: %s", g_type_name (registered->importer_type),
			            matched ? "matched" : "didn't match", a);
			g_free (a);
		}

		if (matched) {
			if (check_if_seen_or_add (seen, GUINT_TO_POINTER (registered->importer_type)))
				continue;

			instance_class = g_type_class_ref (registered->importer_type);

			iface = g_type_interface_peek (instance_class, GCR_TYPE_IMPORTER);
			g_return_val_if_fail (iface != NULL, NULL);
			g_return_val_if_fail (iface->create_for_parsed, NULL);
			results = g_list_concat (results, (iface->create_for_parsed) (parsed));

			g_type_class_unref (instance_class);
		}
	}

	g_hash_table_unref (seen);
	gck_attributes_unref (attrs);
	return results;
}