void viewer_add_renderer (Viewer *self, Renderer *renderer, int priority) { renderer->priority = priority; renderer->cmi = gtk_check_menu_item_new_with_label (renderer->name); gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (renderer->cmi), renderer->enabled); g_object_set_data (G_OBJECT (renderer->cmi), "Viewer:plugin", renderer); g_signal_connect (G_OBJECT (renderer->cmi), "toggled", G_CALLBACK (on_renderer_enabled_toggled), self); g_ptr_array_add(self->renderers, renderer); g_ptr_array_add(self->renderers_sorted, renderer); g_ptr_array_sort(self->renderers_sorted, renderer_name_compare_function); // What position in the sorted array is this item? unsigned int menu_idx = g_ptr_array_find_index(self->renderers_sorted, renderer); // add the menu item, accounting for the tear-off tab at index 0 gtk_menu_shell_insert (GTK_MENU_SHELL (self->renderers_menu), renderer->cmi, menu_idx + 1); gtk_widget_show (renderer->cmi); // create a control widget if (renderer->widget) { g_ptr_array_add(self->renderers_sorted_with_controls, renderer); g_ptr_array_sort(self->renderers_sorted_with_controls, renderer_name_compare_function); unsigned int control_idx = g_ptr_array_find_index(self->renderers_sorted_with_controls, renderer); renderer->expander = gtk_expander_new (renderer->name); gtk_expander_set_expanded (GTK_EXPANDER (renderer->expander), TRUE); renderer->control_frame = gtk_frame_new (NULL); if (renderer->enabled) { gtk_widget_show (renderer->control_frame); } else { gtk_widget_hide (renderer->control_frame); } gtk_frame_set_label_widget (GTK_FRAME (renderer->control_frame), renderer->expander); gtk_container_add (GTK_CONTAINER (renderer->control_frame), renderer->widget); gtk_box_pack_start (GTK_BOX (self->controls_box), renderer->control_frame, FALSE, TRUE, 0); gtk_box_reorder_child (GTK_BOX (self->controls_box), renderer->control_frame, control_idx); gtk_widget_show (renderer->expander); gtk_widget_show (renderer->widget); g_signal_connect (G_OBJECT (renderer->expander), "notify::expanded", G_CALLBACK (on_renderer_widget_expander_notify), self); g_object_set_data (G_OBJECT (renderer->expander), "Viewer:plugin", renderer); g_object_set_data (G_OBJECT (renderer->widget), "Viewer:expander", renderer->expander); g_object_set_data (G_OBJECT (renderer->widget), "Viewer:frame", renderer->control_frame); } g_ptr_array_sort(self->renderers, sort_renderers_priority_decreasing); }
/** * pk_package_sack_sort_package_id: * @sack: a valid #PkPackageSack instance * @type: the type of sorting, e.g. #PK_PACKAGE_SACK_SORT_TYPE_NAME * * Sorts the package sack * * Since: 0.6.1 **/ void pk_package_sack_sort (PkPackageSack *sack, PkPackageSackSortType type) { g_return_if_fail (PK_IS_PACKAGE_SACK (sack)); if (type == PK_PACKAGE_SACK_SORT_TYPE_NAME) g_ptr_array_sort (sack->priv->array, (GCompareFunc) pk_package_sack_sort_compare_name_func); else if (type == PK_PACKAGE_SACK_SORT_TYPE_PACKAGE_ID) g_ptr_array_sort (sack->priv->array, (GCompareFunc) pk_package_sack_sort_compare_package_id_func); else if (type == PK_PACKAGE_SACK_SORT_TYPE_SUMMARY) g_ptr_array_sort (sack->priv->array, (GCompareFunc) pk_package_sack_sort_compare_summary_func); else if (type == PK_PACKAGE_SACK_SORT_TYPE_INFO) g_ptr_array_sort (sack->priv->array, (GCompareFunc) pk_package_sack_sort_compare_info_func); }
Encodings *encodings_load(void) { char *filename = options_file_build_filename("Encodings", NULL); if (filename) { GKeyFile *kf = options_file_open("Encodings", encodings_group_name); int count = options_file_lookup_int_with_default(kf, encodings_group_name, "n", 0); GPtrArray *enc = g_ptr_array_sized_new(count); int n; for (n = 0; n < count; ++n) { char *v = options_file_lookup_string_with_default(kf, encodings_group_name, encodings_get_key(n), NULL); g_ptr_array_add(enc, v); } g_free(filename); g_key_file_free(kf); g_ptr_array_sort(enc, (GCompareFunc) encodings_compare); return enc; } else { return encodings_build_default(); } }
static struct event_idle * event_sdl_add_idle(int priority, struct callback *cb) { dbg(lvl_debug,"add idle priority(%d) cb(%p)\n", priority, cb); struct idle_task *task = g_new0(struct idle_task, 1); task->priority = priority; task->cb = cb; g_ptr_array_add(idle_tasks, (gpointer)task); if (idle_tasks->len < 2) { SDL_Event event; SDL_UserEvent userevent; dbg(lvl_debug,"poking eventloop because of new idle_events\n"); userevent.type = SDL_USEREVENT; userevent.code = SDL_USEREVENT_CODE_IDLE_EVENT; userevent.data1 = NULL; userevent.data2 = NULL; event.type = SDL_USEREVENT; event.user = userevent; SDL_PushEvent (&event); } else // more than one entry => sort the list g_ptr_array_sort(idle_tasks, sdl_sort_idle_tasks); return (struct event_idle *)task; }
static void calculate_places(MosesOverview* self) { MosesOverviewPrivate* priv = self->priv; GPtrArray* clones = priv->clones; if (priv->clones->len) { g_ptr_array_sort(clones, window_compare); // get the area used by the expo algorithms together MetaScreen* screen = meta_plugin_get_screen(priv->plugin); MetaRectangle geom; int focused_monitor = meta_screen_get_current_monitor(screen); meta_screen_get_monitor_geometry(screen, focused_monitor, &geom); int HEAD_SIZE = TOP_GAP; g_object_get(priv->ov_head, "height", &HEAD_SIZE, NULL); g_debug("%s ov height: %d", __func__, HEAD_SIZE); MetaRectangle area = {(int)floorf (geom.x + BORDER), (int)floorf (geom.y + TOP_GAP + HEAD_SIZE), (int)floorf (geom.width - BORDER * 2), (int)floorf (geom.height - BOTTOM_GAP - TOP_GAP - HEAD_SIZE)}; natural_placement(self, area); } else { //NOTE: I can not set ready flag here because a conflict of super-e key release g_timeout_add(500, (GSourceFunc)on_ready_timeout, self); } clutter_actor_show(overview_head_get_content(priv->ov_head)); }
void test_load_cpp_data_driven_test (void) { GList *test_cases, *test_case_node; gchar *expected_functions[] = { "data_driven_test::test_string", NULL }; loader = loader_new("cpp", "stub-data-driven-test." G_MODULE_SUFFIX); test_cases = cut_loader_load_test_cases(loader); cut_assert_equal_int(1, g_list_length(test_cases)); test_names = g_ptr_array_new_with_free_func(g_free); for (test_case_node = test_cases; test_case_node; test_case_node = g_list_next(test_case_node)) { CutTestContainer *container; GList *tests, *test_node; container = CUT_TEST_CONTAINER(test_case_node->data); tests = (GList *)cut_test_container_get_children(container); for (test_node = tests; test_node; test_node = g_list_next(test_node)) { CutTest *test = test_node->data; cut_assert(CUT_IS_TEST(test)); g_ptr_array_add(test_names, g_strdup(cut_test_get_name(test))); } } g_ptr_array_sort(test_names, compare_test_name); g_ptr_array_add(test_names, NULL); cut_assert_equal_string_array(expected_functions, (gchar **)test_names->pdata); }
/* Returns an array listing all the names in the directory 'path'. * The array is sorted. * '.' and '..' are skipped. * On error, the error is reported with g_warning and NULL is returned. */ GPtrArray* list_dir(const guchar *path) { GDir *dir; GError *error = NULL; const char *leaf; GPtrArray *names; dir = g_dir_open((char*)path, 0, &error); if (error) { g_warning("Can't list directory:\n%s", error->message); g_error_free(error); return NULL; } names = g_ptr_array_new(); while ((leaf = g_dir_read_name(dir))) { if (leaf[0] != '.') g_ptr_array_add(names, g_strdup(leaf)); } g_dir_close(dir); g_ptr_array_sort(names, strcmp2); return names; }
RESULT ptrarray_sort() { GPtrArray *array = g_ptr_array_new(); guint i; gchar *letters [] = { "A", "B", "C", "D", "E" }; g_ptr_array_add(array, letters[0]); g_ptr_array_add(array, letters[1]); g_ptr_array_add(array, letters[2]); g_ptr_array_add(array, letters[3]); g_ptr_array_add(array, letters[4]); g_ptr_array_sort(array, ptrarray_sort_compare); for(i = 0; i < array->len; i++) { if(array->pdata[i] != letters[i]) { return FAILED("Array out of order, expected %s got %s", (gchar *)array->pdata[i], letters[i]); } } g_ptr_array_free(array, TRUE); return OK; }
static void get_theme_names(GPtrArray* names) { void add_themes_from_dir(GPtrArray* names, const char* dir) { if (access(dir, F_OK) != 0) return; GPtrArray* list = list_dir((guchar*)dir); g_return_if_fail(list != NULL); int i; for (i = 0; i < list->len; i++){ char* index_path = g_build_filename(dir, list->pdata[i], "index.theme", NULL); if (access(index_path, F_OK) == 0){ g_ptr_array_add(names, list->pdata[i]); } else g_free(list->pdata[i]); g_free(index_path); } g_ptr_array_free(list, TRUE); } gint n_dirs = 0; gchar** theme_dirs = NULL; gtk_icon_theme_get_search_path(icon_theme, &theme_dirs, &n_dirs); // dir list is derived from XDG_DATA_DIRS int i; for (i = 0; i < n_dirs; i++) add_themes_from_dir(names, theme_dirs[i]); g_strfreev(theme_dirs); g_ptr_array_sort(names, strcmp2); }
void p2t_sweepcontext_init_triangulation (P2tSweepContext *THIS) { guint i; double xmax = point_index (THIS->points_, 0)->x, xmin = point_index (THIS->points_, 0)->x; double ymax = point_index (THIS->points_, 0)->y, ymin = point_index (THIS->points_, 0)->y; double dx, dy; /* Calculate bounds. */ for (i = 0; i < THIS->points_->len; i++) { P2tPoint* p = point_index (THIS->points_, i); if (p->x > xmax) xmax = p->x; if (p->x < xmin) xmin = p->x; if (p->y > ymax) ymax = p->y; if (p->y < ymin) ymin = p->y; } dx = kAlpha * (xmax - xmin); dy = kAlpha * (ymax - ymin); THIS->head_ = p2t_point_new_dd (xmax + dx, ymin - dy); THIS->tail_ = p2t_point_new_dd (xmin - dx, ymin - dy); /* Sort points along y-axis */ g_ptr_array_sort (THIS->points_, p2t_point_cmp); }
static void fr_command_done (FrProcess *process, FrProcError *error, gpointer data) { FrCommand *comm = FR_COMMAND (data); comm->process->restart = FALSE; if (error->type != FR_PROC_ERROR_STOPPED) fr_command_handle_error (comm, error); if (comm->process->restart) { fr_process_start (comm->process); return; } if (comm->action == FR_ACTION_LISTING_CONTENT) { /* order the list by name to speed up search */ g_ptr_array_sort (comm->files, file_data_compare_by_path); } g_signal_emit (G_OBJECT (comm), fr_command_signals[DONE], 0, comm->action, error); }
void rpmostree_print_transaction (HifContext *hifctx) { guint i; g_autoptr(GPtrArray) install; install = hif_goal_get_packages (hif_context_get_goal (hifctx), HIF_PACKAGE_INFO_INSTALL, HIF_PACKAGE_INFO_REINSTALL, HIF_PACKAGE_INFO_DOWNGRADE, HIF_PACKAGE_INFO_UPDATE, -1); g_print ("Transaction: %u packages\n", install->len); if (install->len == 0) g_print (" (empty)\n"); else { g_ptr_array_sort (install, (GCompareFunc) pkg_array_compare); for (i = 0; i < install->len; i++) { HyPackage pkg = install->pdata[i]; g_print (" %s\n", hif_package_get_nevra (pkg)); } } }
/** * pk_main_set_auto_backend: **/ static gboolean pk_main_set_auto_backend (GKeyFile *conf, GError **error) { const gchar *tmp; gboolean ret = TRUE; gchar *name_tmp; GDir *dir = NULL; GPtrArray *array = NULL; dir = g_dir_open (LIBDIR "/packagekit-backend", 0, error); if (dir == NULL) goto out; array = g_ptr_array_new_with_free_func (g_free); do { tmp = g_dir_read_name (dir); if (tmp == NULL) break; if (!g_str_has_prefix (tmp, "libpk_backend_")) continue; if (!g_str_has_suffix (tmp, G_MODULE_SUFFIX)) continue; if (g_strstr_len (tmp, -1, "libpk_backend_dummy")) continue; if (g_strstr_len (tmp, -1, "libpk_backend_test")) continue; /* turn 'libpk_backend_test.so' into 'test' */ name_tmp = g_strdup (tmp + 14); g_strdelimit (name_tmp, ".", '\0'); g_ptr_array_add (array, name_tmp); } while (1); /* need to sort by id predictably */ g_ptr_array_sort (array, (GCompareFunc) pk_main_sort_backends_cb); /* set best backend */ if (array->len == 0) { g_set_error_literal (error, 1, 0, "No backends found"); ret = FALSE; goto out; } tmp = g_ptr_array_index (array, 0); g_key_file_set_string (conf, "Daemon", "DefaultBackend", tmp); out: if (array != NULL) g_ptr_array_unref (array); if (dir != NULL) g_dir_close (dir); return ret; }
static void create_dicts_array(void) { sc_speller_dicts_free(); sc_info->dicts = g_ptr_array_new(); enchant_broker_list_dicts(sc_speller_broker, add_dict_array, sc_info->dicts); g_ptr_array_sort(sc_info->dicts, sort_dicts); }
static void on_notify_priority_cb (GbCommandProvider *provider, GParamSpec *pspec, GbCommandManager *manager) { g_return_if_fail (GB_IS_COMMAND_PROVIDER (provider)); g_return_if_fail (GB_IS_COMMAND_MANAGER (manager)); g_ptr_array_sort (manager->providers, provider_compare_func); }
DeepStyleWalker::DeepStyleWalker (Style **styles, Types *types) { // Create a list of all Setters in the style sorted by their DP. // Use the hashtable to ensure that we only take the first setter // declared for each DP (i.e. if the BasedOn style and main style // have setters for the same DP, we ignore the BasedOn one // NOTE: This can be pre-computed and cached as once a style is // sealed it can never be changed. this->offset = 0; this->types = types || !styles[0] ? types : styles[0]->GetDeployment ()->GetTypes (); this->setter_list = g_ptr_array_new (); if (!styles) return; GHashTable *styles_seen = g_hash_table_new (g_direct_hash, g_direct_equal); GHashTable *dps = g_hash_table_new (g_direct_hash, g_direct_equal); for (int i = 0; styles[i]; i ++) { Style *style = styles[i]; while (style != NULL) { if (g_hash_table_lookup (styles_seen, style)) continue; SetterBaseCollection *setters = style->GetSetters (); int count = setters ? setters->GetCount () : 0; for (int i = count-1; i >= 0; i--) { Value *v = setters->GetValueAt (i); if (Value::IsNull (v) || !types->IsSubclassOf (v->GetKind (), Type::SETTER)) continue; Setter *setter = v->AsSetter (); Value* dpVal = setter->GetValue (Setter::PropertyProperty); if (Value::IsNull (dpVal)) continue; DependencyProperty *prop = dpVal->AsDependencyProperty (); if (!g_hash_table_lookup_extended (dps, prop, NULL, NULL)) { g_hash_table_insert (dps, prop, setter); g_ptr_array_add (setter_list, setter); } } g_hash_table_insert (styles_seen, style, style); style = style->GetBasedOn (); } } g_hash_table_destroy (dps); g_hash_table_destroy (styles_seen); g_ptr_array_sort (setter_list, SetterComparer); }
/* needs faster algorithm -- if we find that parenting is slow. * If it works, don't optimize it until it's a hotspot. */ void diagram_parent_selected(Diagram *dia) { GList *list = dia->data->selected; int length = g_list_length(list); int idx, idx2; ObjectExtent *oe; gboolean any_parented = FALSE; GPtrArray *extents = g_ptr_array_sized_new(length); while (list) { oe = g_new(ObjectExtent, 1); oe->object = list->data; parent_handle_extents(list->data, &oe->extent); g_ptr_array_add(extents, oe); list = g_list_next(list); } /* sort all the objects by their left position */ g_ptr_array_sort(extents, diagram_parent_sort_cb); for (idx = 0; idx < length; idx++) { ObjectExtent *oe1 = g_ptr_array_index(extents, idx); if (oe1->object->parent) continue; for (idx2 = idx + 1; idx2 < length; idx2++) { ObjectExtent *oe2 = g_ptr_array_index(extents, idx2); if (!object_flags_set(oe2->object, DIA_OBJECT_CAN_PARENT)) continue; if (oe1->extent.right <= oe2->extent.right && oe1->extent.bottom <= oe2->extent.bottom) { Change *change; change = undo_parenting(dia, oe2->object, oe1->object, TRUE); (change->apply)(change, dia); any_parented = TRUE; /* oe1->object->parent = oe2->object; oe2->object->children = g_list_append(oe2->object->children, oe1->object); */ break; } } } g_ptr_array_free(extents, TRUE); if (any_parented) { diagram_modified(dia); diagram_flush(dia); undo_set_transactionpoint(dia->undo); } }
static void retrieve_messagebook_callback(GError * error, GPtrArray * messages, struct MessageListViewData *data) { g_debug("retrieve messagebook callback(error=%d)", error); data->messages = messages; g_ptr_array_foreach(data->messages, add_integer_timestamp_to_message, NULL); g_ptr_array_sort(data->messages, compare_messages); async_trigger(retrieve_messagebook_callback2, data); }
static void merge_traces_with_same_uuid(struct ctf_fs_component *ctf_fs) { GPtrArray *traces = ctf_fs->traces; guint range_start_idx = 0; unsigned int num_traces = 0; guint i; /* Sort the traces by uuid, then collapse traces with the same uuid in a single one. */ g_ptr_array_sort(traces, sort_traces_by_uuid); /* Find ranges of consecutive traces that share the same UUID. */ while (range_start_idx < traces->len) { guint range_len; struct ctf_fs_trace *range_start_trace = g_ptr_array_index(traces, range_start_idx); /* Exclusive end of range. */ guint range_end_exc_idx = range_start_idx + 1; while (range_end_exc_idx < traces->len) { struct ctf_fs_trace *this_trace = g_ptr_array_index(traces, range_end_exc_idx); if (!range_start_trace->metadata->tc->is_uuid_set || (bt_uuid_compare(range_start_trace->metadata->tc->uuid, this_trace->metadata->tc->uuid) != 0)) { break; } range_end_exc_idx++; } /* If we have two or more traces with matching UUIDs, merge them. */ range_len = range_end_exc_idx - range_start_idx; if (range_len > 1) { struct ctf_fs_trace **range_start = (struct ctf_fs_trace **) &traces->pdata[range_start_idx]; merge_ctf_fs_traces(range_start, range_len); } num_traces++; range_start_idx = range_end_exc_idx; } /* Clear any NULL slot (traces that got merged in another one) in the array. */ for (i = 0; i < traces->len;) { if (g_ptr_array_index(traces, i) == NULL) { g_ptr_array_remove_index_fast(traces, i); } else { i++; } } BT_ASSERT(num_traces == traces->len); }
GPtrArray * mc_skin_list (void) { GPtrArray *list; list = g_ptr_array_new (); mc_skin_get_list_from_dir (mc_config_get_data_path (), list); mc_skin_get_list_from_dir (mc_global.sysconfig_dir, list); mc_skin_get_list_from_dir (mc_global.share_data_dir, list); g_ptr_array_sort (list, (GCompareFunc) string_array_comparator); return list; }
void print_dates_sorted (void) { /* Choose five dates randomly from a time interval, sort them, and send to stdio. */ GTimeZone *tz; GPtrArray *dates; GDateTime *dt; gchar *str; gint i; tz = (GTimeZone *)g_time_zone_new_local(); dates = g_ptr_array_new(); g_ptr_array_set_free_func(dates, (GDestroyNotify)g_date_time_unref); /* * Insert some random dates into the array. */ for (i = 0; i < 5; i++) { dt = (GDateTime *)g_date_time_new(tz, g_random_int_range(1900, 2020), g_random_int_range(1, 12), g_random_int_range(1, 28), 0, 0, 0); g_ptr_array_add(dates, dt); } /* * Sort dates. Remember that GPtrArray returns a pointer to the * pointer type in sorting methods so they need to be dereferenced. */ g_ptr_array_sort(dates, gdt_sorter); /* * Print out the dates */ g_print("Dates sorted in order:\n"); for (i = 0; i < dates->len; i++) { dt = g_ptr_array_index(dates, i); str = g_date_time_format(dt, "%b %d, %Y"); g_print(" %s\n", str); g_free(str); } g_ptr_array_unref(dates); g_time_zone_unref(tz); }
int add_solution_refset(SS *scatter_search) { int i; int val = 0; REFSET *refset = scatter_search->rs; P *pool = scatter_search->p; switch (scatter_search->status) { case init: pool->list = g_list_sort(pool->list, order_totalweightcomptime_list); for (i = 0; i < scatter_search->b1; ++i) { void *data = pool->list->data; pool->list = g_list_remove(pool->list, data); g_ptr_array_add(refset->list1, data); } scatter_search->status = add; break; case add: for (i = 0; i < scatter_search->b2; ++i) { void *data = maximum_distance(scatter_search); CCcheck_NULL_2(data, "Failed in maximum_distance"); pool->list = g_list_remove(pool->list, data); update_distance(scatter_search, (solution *)data); g_ptr_array_add(refset->list2, data); } g_ptr_array_sort(refset->list2, order_distance); scatter_search->status = update; for (GList *it = pool->list; it; it = it->next) { solution_free((solution *)it->data); CC_IFFREE(it->data, solution); } g_list_free(pool->list); pool->list = (GList *) NULL; break; case update: diversification_update(scatter_search); break; case opt: break; } CLEAN: return val; }
int8_t _PtnReduceCraft(THREAD_CRAFT *p_Param) { GPtrArray *a_BlkCand = p_Param->p_Grp->a_BlkCand; /* Remove the blocks with the number of noisy bytes exceeding the threshold. */ g_ptr_array_sort(a_BlkCand, DsCompBlockCandNoise); uint8_t ucThld = p_Conf->ucSizeBlk * p_Conf->ucRatNoise / THLD_DNMNTR; uint32_t uiLen = a_BlkCand->len; uint32_t uiIdx; for (uiIdx = 0 ; uiIdx < uiLen ; uiIdx++) { BLOCK_CAND *p_BlkCand = g_ptr_array_index(a_BlkCand, uiIdx); if (p_BlkCand->ucCntNoise >= ucThld) break; } if (uiIdx < uiLen) g_ptr_array_remove_range(a_BlkCand, uiIdx, (uiLen - uiIdx)); /* Early return if all the blocks are eliminated. */ if (a_BlkCand->len == 0) return SUCCESS; /* Sort the blocks and retrieve the candidates with top quality. */ g_ptr_array_sort(a_BlkCand, DsCompBlockCandWildCard); ucThld = p_Conf->ucSizeBlk * p_Conf->ucRatWild / THLD_DNMNTR; uiLen = a_BlkCand->len; for (uiIdx = 0 ; uiIdx < uiLen ; uiIdx++) { BLOCK_CAND *p_BlkCand = g_ptr_array_index(a_BlkCand, uiIdx); if (p_BlkCand->ucCntWild >= ucThld) break; if (uiIdx == p_Conf->ucCntBlk) break; } if (uiIdx < uiLen) g_ptr_array_remove_range(a_BlkCand, uiIdx, (uiLen - uiIdx)); return SUCCESS; }
void edit_syntax_dialog (WEdit * edit) { GPtrArray *names; int syntax; names = g_ptr_array_new (); /* We fill the list of syntax files every time the editor is invoked. Instead we could save the list to a file and update it once the syntax file gets updated (either by testing or by explicit user command). */ edit_load_syntax (NULL, names, NULL); g_ptr_array_sort (names, pstrcmp); syntax = exec_edit_syntax_dialog (names, edit->syntax_type); if (syntax >= 0) { gboolean force_reload = FALSE; char *current_syntax; int old_auto_syntax; current_syntax = g_strdup (edit->syntax_type); old_auto_syntax = option_auto_syntax; switch (syntax) { case 0: /* auto syntax */ option_auto_syntax = 1; break; case 1: /* reload current syntax */ force_reload = TRUE; break; default: option_auto_syntax = 0; g_free (edit->syntax_type); edit->syntax_type = g_strdup (g_ptr_array_index (names, syntax - N_DFLT_ENTRIES)); } /* Load or unload syntax rules if the option has changed */ if (force_reload || (option_auto_syntax && !old_auto_syntax) || old_auto_syntax || (current_syntax != NULL && edit->syntax_type != NULL && strcmp (current_syntax, edit->syntax_type) != 0)) edit_load_syntax (edit, NULL, edit->syntax_type); g_free (current_syntax); } g_ptr_array_foreach (names, (GFunc) g_free, NULL); g_ptr_array_free (names, TRUE); }
static GString * get_directory_listing (int dfd, const char *path) { g_autoptr(GPtrArray) entries = g_ptr_array_new_with_free_func (g_free); g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; g_autoptr(GError) local_error = NULL; GError **error = &local_error; guint i; char *escaped; GString *listing; listing = g_string_new ("<html>\r\n"); if (!glnx_dirfd_iterator_init_at (dfd, path, FALSE, &dfd_iter, error)) goto out; while (TRUE) { struct dirent *dent; if (!glnx_dirfd_iterator_next_dent (&dfd_iter, &dent, NULL, error)) goto out; if (dent == NULL) break; escaped = g_markup_escape_text (dent->d_name, -1); g_ptr_array_add (entries, escaped); } g_ptr_array_sort (entries, (GCompareFunc)compare_strings); escaped = g_markup_escape_text (strchr (path, '/'), -1); g_string_append_printf (listing, "<head><title>Index of %s</title></head>\r\n", escaped); g_string_append_printf (listing, "<body><h1>Index of %s</h1>\r\n<p>\r\n", escaped); g_free (escaped); for (i = 0; i < entries->len; i++) { g_string_append_printf (listing, "<a href=\"%s\">%s</a><br>\r\n", (char *)entries->pdata[i], (char *)entries->pdata[i]); g_free (g_steal_pointer (&entries->pdata[i])); } g_string_append (listing, "</body>\r\n</html>\r\n"); out: if (local_error) g_printerr ("%s\n", local_error->message); return listing; }
void gb_command_manager_add_provider (GbCommandManager *manager, GbCommandProvider *provider) { g_return_if_fail (GB_IS_COMMAND_MANAGER (manager)); g_return_if_fail (GB_IS_COMMAND_PROVIDER (provider)); g_signal_connect_object (provider, "notify::priority", G_CALLBACK (on_notify_priority_cb), manager, 0); g_ptr_array_add (manager->providers, g_object_ref (provider)); g_ptr_array_sort (manager->providers, provider_compare_func); }
/* check if two arrays of urls contains the same items. */ static gboolean __match_urlv (struct meta1_service_url_s **all, struct meta1_service_url_s **kept, struct meta1_service_url_s **replaced) { struct meta1_service_url_s *ref = kept && *kept ? *kept : *replaced; gboolean rc = FALSE; GPtrArray *gpa_inplace = g_ptr_array_new (); GPtrArray *gpa_told = g_ptr_array_new (); /* build two array of URL we can safely sort */ for (; *all ; ++all) { if ((*all)->seq == ref->seq) g_ptr_array_add (gpa_inplace, *all); } if (kept) while (*kept) g_ptr_array_add (gpa_told, *(kept++)); if (replaced) while (*replaced) g_ptr_array_add (gpa_told, *(replaced++)); /* sort them */ if (gpa_told->len != gpa_inplace->len) goto out; g_ptr_array_sort (gpa_inplace, (GCompareFunc)_sorter); g_ptr_array_sort (gpa_told, (GCompareFunc)_sorter); /* identical sorted arrays have equal items at each position */ for (guint i=0; i<gpa_told->len ; ++i) { if (0 != strcmp(M1U(gpa_told->pdata[i])->host, M1U(gpa_inplace->pdata[i])->host)) goto out; } rc = TRUE; out: g_ptr_array_free (gpa_inplace, TRUE); g_ptr_array_free (gpa_told, TRUE); return rc; }
static GPtrArray * create_sorted_descendant_tree_nodes (GPtrArray *funcs) { int i; GPtrArray *functions; functions = g_ptr_array_sized_new (funcs->len); for (i = 0; i < funcs->len; ++i) g_ptr_array_add (functions, funcs->pdata [i]); g_ptr_array_sort (functions, compare_descendant_tree_nodes); return functions; }
static gboolean remmina_plugin_manager_register_plugin(RemminaPlugin *plugin) { if (plugin->type == REMMINA_PLUGIN_TYPE_SECRET) { if (remmina_secret_plugin) { g_print("Remmina plugin %s (type=%s) bypassed.\n", plugin->name, _(remmina_plugin_type_name[plugin->type])); return FALSE; } remmina_secret_plugin = (RemminaSecretPlugin*) plugin; } g_ptr_array_add(remmina_plugin_table, plugin); g_ptr_array_sort(remmina_plugin_table, (GCompareFunc) remmina_plugin_manager_compare_func); g_print("Remmina plugin %s (type=%s) registered.\n", plugin->name, _(remmina_plugin_type_name[plugin->type])); return TRUE; }
void test_load_function (void) { CutTestContainer *container; GList *tests, *list; gint i; const gchar *target_test_names[] = {"/.*/", NULL}; gchar *expected_functions[] = { "test_abcdefghijklmnopqratuvwzyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789", "test_stub_function1", "test_stub_function2", "test_stub_function3", NULL }; loader = loader_new("test", "stub-test-functions." G_MODULE_SUFFIX); test_case = cut_loader_load_test_case(loader); cut_assert(test_case); container = CUT_TEST_CONTAINER(test_case); cut_assert_equal_int(4, cut_test_container_get_n_tests(container, NULL)); run_context = cut_test_runner_new(); cut_run_context_set_target_test_names(run_context, target_test_names); cut_assert_equal_int(4, cut_test_container_get_n_tests(container, run_context)); tests = (GList *)cut_test_container_get_children(container); cut_assert(tests); test_names = g_ptr_array_new_with_free_func(g_free); for (list = tests, i = 0; list; list = g_list_next(list), i++) { CutTest *test; cut_assert(list->data); cut_assert(CUT_IS_TEST(list->data)); test = CUT_TEST(list->data); g_ptr_array_add(test_names, g_strdup(cut_test_get_name(test))); } g_ptr_array_sort(test_names, compare_test_name); g_ptr_array_add(test_names, NULL); cut_assert_equal_string_array(expected_functions, (gchar **)test_names->pdata); }