/* Sorts the whole filelist, at the moment used by filelist_search */ void filelist_sort_all(struct filelist *filelist, GCompareFunc compare_func) { g_ptr_array_sort_with_data(filelist->entries, filelist_compare_indirect, compare_func); }
/* Sort items in logical order */ static void post_cache_init (struct symbols_cache *cache) { struct cache_item *it, *dit; struct cache_dependency *dep, *rdep; struct delayed_cache_dependency *ddep; GList *cur; guint i, j; g_ptr_array_sort_with_data (cache->items_by_order, cache_logic_cmp, cache); cur = cache->delayed_deps; while (cur) { ddep = cur->data; it = g_hash_table_lookup (cache->items_by_symbol, ddep->from); if (it == NULL) { msg_err ("cannot register delayed dependency between %s and %s, " "%s is missing", ddep->from, ddep->to, ddep->from); } else { rspamd_symbols_cache_add_dependency (cache, it->id, ddep->to); } cur = g_list_next (cur); } for (i = 0; i < cache->items_by_id->len; i ++) { it = g_ptr_array_index (cache->items_by_id, i); for (j = 0; j < it->deps->len; j ++) { dep = g_ptr_array_index (it->deps, j); dit = g_hash_table_lookup (cache->items_by_symbol, dep->sym); if (dit != NULL) { if (dit->parent != -1) { dit = g_ptr_array_index (cache->items_by_id, dit->parent); } rdep = rspamd_mempool_alloc (cache->static_pool, sizeof (*rdep)); rdep->sym = dep->sym; rdep->item = it; rdep->id = i; g_ptr_array_add (dit->rdeps, rdep); dep->item = dit; dep->id = dit->id; msg_debug ("add dependency from %d on %d", it->id, dit->id); } else { msg_err ("cannot find dependency on symbol %s", dep->sym); } } } }
/** * ggd_tag_sort_by_line: * @tags: A #GPtrArray of #TMTag<!-- -->s * @direction: Sort direction: %GGD_SORT_ASC for an ascending sort or * %GGD_SORT_DESC for a descending sort. * * Sorts a #GPtrArray of #TMTag<!-- -->s by the tags' line position. The sort * direction depend on @direction. */ void ggd_tag_sort_by_line (GPtrArray *tags, gint direction) { g_return_if_fail (tags != NULL); g_return_if_fail (direction != 0); g_ptr_array_sort_with_data (tags, tag_cmp_by_line_ptr_array, GINT_TO_POINTER (direction)); }
/* Sort an array of tags on the specified attribuites using the inbuilt comparison function. @param tags_array The array of tags to be sorted @param sort_attributes Attributes to be sorted on (int array terminated by 0) @param dedup Whether to deduplicate the sorted array */ void tm_tags_sort(GPtrArray *tags_array, TMTagAttrType *sort_attributes, gboolean dedup, gboolean unref_duplicates) { TMSortOptions sort_options; g_return_if_fail(tags_array); sort_options.sort_attrs = sort_attributes; sort_options.cmp_len = -1; g_ptr_array_sort_with_data(tags_array, tm_tag_compare, &sort_options); if (dedup) tm_tags_dedup(tags_array, sort_attributes, unref_duplicates); }
/* Sort an array of tags on the specified attribuites using the inbuilt comparison function. @param tags_array The array of tags to be sorted @param sort_attributes Attributes to be sorted on (int array terminated by 0) @param dedup Whether to deduplicate the sorted array @return TRUE on success, FALSE on failure */ gboolean tm_tags_sort(GPtrArray *tags_array, TMTagAttrType *sort_attributes, gboolean dedup, gboolean unref_duplicates) { TMSortOptions sort_options; if ((!tags_array) || (!tags_array->len)) return TRUE; sort_options.sort_attrs = sort_attributes; sort_options.partial = FALSE; g_ptr_array_sort_with_data(tags_array, tm_tag_compare, &sort_options); if (dedup) tm_tags_dedup(tags_array, sort_attributes, unref_duplicates); return TRUE; }
int cmd_list(int argc, const char **argv) { const char *program_usage_string = _( "& list [options]" ); int opt_not_reported = 0; int opt_detailed = 0; int opt_since = 0; int opt_until = 0; struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_BOOL('n', "not-reported" , &opt_not_reported, _("List only not-reported problems")), /* deprecate -d option with --pretty=full*/ OPT_BOOL('d', "detailed" , &opt_detailed, _("Show detailed report")), OPT_INTEGER('s', "since" , &opt_since, _("List only the problems more recent than specified timestamp")), OPT_INTEGER('u', "until" , &opt_until, _("List only the problems older than specified timestamp")), OPT_END() }; parse_opts(argc, (char **)argv, program_options, program_usage_string); vector_of_problem_data_t *ci = fetch_crash_infos(); if (ci == NULL) return 1; g_ptr_array_sort_with_data(ci, &cmp_problem_data, (char *) FILENAME_LAST_OCCURRENCE); #if SUGGEST_AUTOREPORTING != 0 const bool output = #endif print_crash_list(ci, opt_detailed, opt_not_reported, opt_since, opt_until, CD_TEXT_ATT_SIZE_BZ); free_vector_of_problem_data(ci); #if SUGGEST_AUTOREPORTING != 0 load_abrt_conf(); if (!g_settings_autoreporting) { if (output) putc('\n', stderr); fprintf(stderr, _("The Autoreporting feature is disabled. Please consider enabling it by issuing\n" "'abrt-auto-reporting enabled' as a user with root privileges\n")); } #endif return 0; }
static void rspamd_symbols_cache_resort_cb (gint fd, short what, gpointer ud) { struct timeval tv; gdouble tm; struct symbols_cache *cache = ud; struct cache_item *item, *parent; guint i; /* Plan new event */ tm = rspamd_time_jitter (cache->reload_time, 0); msg_info ("resort symbols cache, next reload in %.2f seconds", tm); g_assert (cache != NULL); evtimer_set (&cache->resort_ev, rspamd_symbols_cache_resort_cb, cache); double_to_tv (tm, &tv); event_add (&cache->resort_ev, &tv); rspamd_mempool_lock_mutex (cache->mtx); /* Gather stats from shared execution times */ for (i = 0; i < cache->items_by_order->len; i ++) { item = g_ptr_array_index (cache->items_by_order, i); if (item->type == SYMBOL_TYPE_CALLBACK || item->type == SYMBOL_TYPE_NORMAL) { if (item->cd->number > 0) { item->avg_counter += item->cd->number + 1; item->avg_time = item->avg_time + (item->cd->value - item->avg_time) / item->avg_counter; item->cd->value = item->avg_time; item->cd->number = item->avg_counter; } } } /* Sync virtual symbols */ for (i = 0; i < cache->items_by_id->len; i ++) { if (item->parent != -1) { parent = g_ptr_array_index (cache->items_by_id, item->parent); item->avg_time = parent->avg_time; item->avg_counter = parent->avg_counter; } } rspamd_mempool_unlock_mutex (cache->mtx); g_ptr_array_sort_with_data (cache->items_by_order, cache_logic_cmp, cache); }
/** Put the country matching the local language to the beginning of the array if possible. */ void language_pick_country(GPtrArray *country_files) { #ifdef DEBUG printf("language_pick_country\n"); #endif gint i, j; GPtrArray *codes = misc_separate_strings(const_str("string_language_codes")); GPtrArray *defs = misc_separate_strings(const_str("string_language_defs")); gpointer prefdef = NULL; const gchar *lang = g_getenv("LANGUAGE"); if(lang == NULL || strcmp(lang, "") == 0) lang = g_getenv("LANG"); if(lang == NULL || strcmp(lang, "") == 0) lang = g_getenv("LC_ALL"); if(lang != NULL) for(i=0;i<codes->len;i++) { if(((g_str_has_prefix(lang, "en") && strcmp((gchar*)g_ptr_array_index(codes, i), "C") == 0) || g_str_has_prefix(lang, (gchar*)g_ptr_array_index(codes, i))) && strcmp((gchar*)g_ptr_array_index(defs, i), "NONE") != 0) { for(j=0;j<country_files->len;j++) if(g_str_has_suffix((gchar*)g_ptr_array_index(country_files, j), (gchar*)g_ptr_array_index(defs, i))) { prefdef = g_ptr_array_index(country_files, j); break; } break; } } g_ptr_array_sort_with_data( country_files, (GCompareDataFunc)language_compare_country_files, prefdef); free_gchar_array(&codes); free_gchar_array(&defs); }
static void rspamd_symbols_cache_resort (struct symbols_cache *cache) { struct symbols_cache_order *ord; guint i; gpointer p; ord = rspamd_symbols_cache_order_new (cache->used_items); for (i = 0; i < cache->used_items; i ++) { p = g_ptr_array_index (cache->items_by_id, i); g_ptr_array_add (ord->d, p); } g_ptr_array_sort_with_data (ord->d, cache_logic_cmp, cache); if (cache->items_by_order) { REF_RELEASE (cache->items_by_order); } cache->items_by_order = ord; }
static void list_wifi_access_points (const GPtrArray * aps, NMAccessPoint * active_ap, guint32 device_caps) { guint i; GPtrArray * sorted_aps; if (!aps || aps->len == 0) { g_print ("%-9s No access points found\n", ""); return; } /* make copy of access points array and sort it */ sorted_aps = g_malloc0 (sizeof (GPtrArray)); sorted_aps->len = aps->len; sorted_aps->pdata = g_memdup (aps->pdata, sizeof (gpointer) * aps->len); g_ptr_array_sort_with_data (sorted_aps, compare_aps, active_ap); g_print ("%-9s Access points in range:\n", ""); for (i = 0; i < sorted_aps->len; i++) { gboolean active; NMAccessPoint * ap = g_ptr_array_index(sorted_aps, i); if (active_ap) { const char * bssid1 = nm_access_point_get_hw_address(ap); const char * bssid2 = nm_access_point_get_hw_address(active_ap); active = !g_strcmp0 (bssid1, bssid2); } else active = FALSE; print_access_point_info(ap, active, device_caps); } g_free (sorted_aps->pdata); g_free (sorted_aps); }
static void read_connections (SCPluginIfcfg *plugin) { SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); GDir *dir; GError *err = NULL; const char *item; GHashTable *alive_connections; GHashTableIter iter; NMIfcfgConnection *connection; GPtrArray *dead_connections = NULL; guint i; GPtrArray *filenames; GHashTable *paths; dir = g_dir_open (IFCFG_DIR, 0, &err); if (!dir) { _LOGW ("Could not read directory '%s': %s", IFCFG_DIR, err->message); g_error_free (err); return; } alive_connections = g_hash_table_new (NULL, NULL); filenames = g_ptr_array_new_with_free_func (g_free); while ((item = g_dir_read_name (dir))) { char *full_path; if (utils_should_ignore_file (item, TRUE)) continue; if (utils_is_ifcfg_alias_file (item, NULL)) continue; full_path = g_build_filename (IFCFG_DIR, item, NULL); if (!utils_get_ifcfg_name (full_path, TRUE)) g_free (full_path); else g_ptr_array_add (filenames, full_path); } g_dir_close (dir); /* While reloading, we don't replace connections that we already loaded while * iterating over the files. * * To have sensible, reproducible behavior, sort the paths by last modification * time prefering older files. */ paths = _paths_from_connections (priv->connections); g_ptr_array_sort_with_data (filenames, (GCompareDataFunc) _sort_paths, paths); g_hash_table_destroy (paths); for (i = 0; i < filenames->len; i++) { connection = update_connection (plugin, NULL, filenames->pdata[i], NULL, FALSE, alive_connections, NULL); if (connection) g_hash_table_add (alive_connections, connection); } g_ptr_array_free (filenames, TRUE); g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &connection)) { if ( !g_hash_table_contains (alive_connections, connection) && nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection))) { if (!dead_connections) dead_connections = g_ptr_array_new (); g_ptr_array_add (dead_connections, connection); } } g_hash_table_destroy (alive_connections); if (dead_connections) { for (i = 0; i < dead_connections->len; i++) remove_connection (plugin, dead_connections->pdata[i]); g_ptr_array_free (dead_connections, TRUE); } }
static void read_connections (NMSystemConfigInterface *config) { SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config); SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self); GDir *dir; GError *error = NULL; const char *item; GHashTable *alive_connections; GHashTableIter iter; NMKeyfileConnection *connection; GPtrArray *dead_connections = NULL; guint i; GPtrArray *filenames; GHashTable *paths; dir = g_dir_open (KEYFILE_DIR, 0, &error); if (!dir) { nm_log_warn (LOGD_SETTINGS, "keyfile: cannot read directory '%s': (%d) %s", KEYFILE_DIR, error ? error->code : -1, error && error->message ? error->message : "(unknown)"); g_clear_error (&error); return; } alive_connections = g_hash_table_new (NULL, NULL); filenames = g_ptr_array_new_with_free_func (g_free); while ((item = g_dir_read_name (dir))) { if (nm_keyfile_plugin_utils_should_ignore_file (item)) continue; g_ptr_array_add (filenames, g_build_filename (KEYFILE_DIR, item, NULL)); } g_dir_close (dir); /* While reloading, we don't replace connections that we already loaded while * iterating over the files. * * To have sensible, reproducible behavior, sort the paths by last modification * time prefering older files. */ paths = _paths_from_connections (priv->connections); g_ptr_array_sort_with_data (filenames, (GCompareDataFunc) _sort_paths, paths); g_hash_table_destroy (paths); for (i = 0; i < filenames->len; i++) { connection = update_connection (self, NULL, filenames->pdata[i], NULL, FALSE, alive_connections, NULL); if (connection) g_hash_table_add (alive_connections, connection); } g_ptr_array_free (filenames, TRUE); g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &connection)) { if ( !g_hash_table_contains (alive_connections, connection) && nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection))) { if (!dead_connections) dead_connections = g_ptr_array_new (); g_ptr_array_add (dead_connections, connection); } } g_hash_table_destroy (alive_connections); if (dead_connections) { for (i = 0; i < dead_connections->len; i++) remove_connection (self, dead_connections->pdata[i]); g_ptr_array_free (dead_connections, TRUE); } }
CLFEXP void claro_list_sort(claro_list_t * list, list_compare_func * compare_func, void * user_arg) { GPtrArray * array = (GPtrArray *)list; g_ptr_array_sort_with_data(array, (GCompareDataFunc)compare_func, user_arg); }
static void mex_view_model_refresh_external_items (MexViewModel *model) { MexViewModelPrivate *priv = model->priv; gint i, count; GHashTable *groups = NULL; /* clear the references from the external items */ for (i = 0; i < priv->external_items->len; i++) g_object_unref (g_ptr_array_index (priv->external_items, i)); /* allocate the full array to start with */ g_ptr_array_set_size (priv->external_items, priv->internal_items->len); if (priv->group_by_key) { groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); } /* add the items to the external list */ for (i = 0, count = 0; i < priv->internal_items->len; i++) { MexContent *content; content = g_ptr_array_index (priv->internal_items, i); /* check the item matches the filter */ if (priv->filter_by_key) { const gchar *v; v = mex_content_get_metadata (content, priv->filter_by_key); /* skip this item if it does not match the filter */ if (g_strcmp0 (v, priv->filter_by_value)) continue; } /* create a group item if necessary */ if (priv->group_by_key) { const gchar* g; g = mex_content_get_metadata (content, priv->group_by_key); if (g) { /* build up the group list */ if (!g_hash_table_lookup (groups, g)) { content = g_object_new (MEX_TYPE_GENERIC_CONTENT, "title", g, "mimetype", "x-mex/group", NULL); g_hash_table_insert (groups, g_strdup (g), content); g_object_set_data (G_OBJECT (content), "filter-key", GINT_TO_POINTER (priv->group_by_key)); g_object_set_data_full (G_OBJECT (content), "filter-value", g_strdup (g), g_free); g_object_set_data_full (G_OBJECT (content), "source-model", g_object_ref (model), g_object_unref); } else continue; } } /* add the item to the external list */ g_object_ref_sink (content); priv->external_items->pdata[count] = content; count++; } /* set the final size */ if (count < priv->external_items->len) g_ptr_array_set_size (priv->external_items, count); /* this should not happen */ if (count > priv->external_items->len) g_error (G_STRLOC "More items added to view model than in original model"); /* destroy the groups hash table */ if (groups) { g_hash_table_destroy (groups); groups = NULL; } /* sort the items */ if (priv->order_by_key) { SortFuncInfo info = { priv->order_by_key, priv->order_by_descending }; g_ptr_array_sort_with_data (priv->external_items, order_by_func, &info); } if (priv->controller) { GControllerReference *ref; ref = g_controller_create_reference (priv->controller, G_CONTROLLER_REPLACE, G_TYPE_NONE, 0); g_controller_emit_changed (priv->controller, ref); } }