/* root: directory in glib file name encoding */ Filetree filetree_init(char *roots[], size_t roots_size, gboolean recursive, gboolean follow_symlinks, gboolean no_sort, GSList **errors) { GTree *root_tree = g_tree_new_full(no_sort ? compare_insert_last : compare_filenames, NULL, filename_representations_free, filetree_destroy); size_t i; for (i = 0; i < roots_size; ++i) { GTree *sub_dir_tree; GDir *dir; GError *err; struct filename_representations *fr; if (!follow_symlinks && g_file_test(roots[i], G_FILE_TEST_IS_SYMLINK)) { continue; } if (g_file_test(roots[i], G_FILE_TEST_IS_DIR)) { if (!recursive) { *errors = g_slist_prepend(*errors, g_error_new(1, 1, "Skipping '%s', is a directory", roots[i])); continue; } err = NULL; dir = g_dir_open(roots[i], 0, &err); if (err) { *errors = g_slist_prepend(*errors, err); err = NULL; continue; } fr = filename_representations_new(roots[i], FILETREE_DIR); sub_dir_tree = g_tree_new_full(compare_filenames, NULL, filename_representations_free, filetree_destroy); g_tree_insert(root_tree, fr, sub_dir_tree); walk_recursive(roots[i], dir, sub_dir_tree, follow_symlinks, errors); g_dir_close(dir); } else if (g_file_test(roots[i], G_FILE_TEST_IS_REGULAR)) { fr = filename_representations_new(roots[i], FILETREE_FILE); g_tree_insert(root_tree, fr, NULL); } else { *errors = g_slist_prepend(*errors, g_error_new(1, 1, "File '%s' not found", roots[i])); } } *errors = g_slist_reverse(*errors); return root_tree; }
/* It updates controls from values of variables, and connects control * signals to callback functions */ void init_diagram (GladeXML *xml) { GtkStyle *style; GtkWidget *canvas; /* Creates trees */ canvas_nodes = g_tree_new_full ( (GCompareDataFunc)canvas_node_compare, NULL, NULL, (GDestroyNotify)canvas_node_delete); canvas_links = g_tree_new_full( (GCompareDataFunc)canvas_link_compare, NULL, NULL, (GDestroyNotify)canvas_link_delete); initialize_pref_controls(); /* Sets canvas background to black */ canvas = glade_xml_get_widget (appdata.xml, "canvas1"); gdk_color_parse ("black", &black_color); gdk_colormap_alloc_color (gdk_colormap_get_system (), &black_color, TRUE, TRUE); style = gtk_style_new (); style->bg[GTK_STATE_NORMAL] = black_color; style->base[GTK_STATE_NORMAL] = black_color; gtk_widget_set_style (canvas, style); gtk_style_set_background (canvas->style, canvas->window, GTK_STATE_NORMAL); /* Initialize the known_protocols table */ delete_gui_protocols (); /* Set the already_updating global flag */ already_updating = FALSE; stop_requested = FALSE; } /* init_diagram */
host *create_host(const char *name) { host *new_host = NULL; if (name == NULL || !strcmp(name, "")) { nm_log(NSLOG_CONFIG_ERROR, "Error: Host name is NULL\n"); return NULL; } if (contains_illegal_object_chars(name) == TRUE) { nm_log(NSLOG_VERIFICATION_ERROR, "Error: The name of host '%s' contains one or more illegal characters.", name); return NULL; } new_host = nm_calloc(1, sizeof(*new_host)); new_host->name = new_host->display_name = new_host->alias = new_host->address = nm_strdup(name); new_host->child_hosts = g_tree_new_full((GCompareDataFunc)g_strcmp0, NULL, g_free, NULL); new_host->parent_hosts = g_tree_new_full((GCompareDataFunc)g_strcmp0, NULL, g_free, NULL); new_host->check_type = CHECK_TYPE_ACTIVE; new_host->state_type = HARD_STATE; new_host->acknowledgement_type = ACKNOWLEDGEMENT_NONE; new_host->check_options = CHECK_OPTION_NONE; return new_host; }
static void MailboxState_uid_msn_new(T M) { if (M->msn) g_tree_destroy(M->msn); M->msn = g_tree_new_full((GCompareDataFunc)ucmpdata,NULL,NULL,NULL); if (M->ids) g_tree_destroy(M->ids); M->ids = g_tree_new_full((GCompareDataFunc)ucmpdata,NULL,NULL,(GDestroyNotify)g_free); }
static void rrc_init(void) { /*Initialize structure for muxed flow indication*/ hsdsch_muxed_flows = g_tree_new_full(rrc_key_cmp, NULL, /* data pointer, optional */ rrc_free_key, rrc_free_value); /*Initialize structure for muxed flow indication*/ rrc_ciph_inf = g_tree_new_full(rrc_key_cmp, NULL, /* data pointer, optional */ NULL, rrc_free_value); }
GTree* meta0_utils_list_to_tree(GSList *list) { GSList *l; GTree *result = NULL; EXTRA_ASSERT(list != NULL); result = g_tree_new_full( hashstr_quick_cmpdata, NULL, g_free, (GDestroyNotify)garray_free); for (l=list; l ;l=l->next) { struct meta0_info_s *m0i; if (!(m0i = l->data)) continue; gchar url[STRLEN_ADDRINFO]; grid_addrinfo_to_string(&(m0i->addr), url, sizeof(url)); gsize len = m0i->prefixes_size; len = len / 2; GArray *pfx = g_array_new(FALSE, FALSE, sizeof(guint16)); g_array_append_vals(pfx, m0i->prefixes, len); g_tree_replace(result, hashstr_create(url), pfx); } return result; }
static rrc_ciphering_info* get_or_create_cipher_info(fp_info *fpinf, rlc_info *rlcinf) { rrc_ciphering_info *cipher_info = NULL; guint32 ueid; int i; if (!fpinf || !rlcinf) return NULL; ueid = rlcinf->ueid[fpinf->cur_tb]; cipher_info = (rrc_ciphering_info *)g_tree_lookup(rrc_ciph_info_tree, GINT_TO_POINTER((gint)ueid)); if( cipher_info == NULL ){ cipher_info = g_new0(rrc_ciphering_info,1); /*Initiate tree with START_PS values.*/ if(!cipher_info->start_ps) cipher_info->start_ps = g_tree_new_full(rrc_key_cmp, NULL,NULL,rrc_free_value); /*Clear and initialize seq_no matrix*/ for(i = 0; i< 31; i++){ cipher_info->seq_no[i][0] = -1; cipher_info->seq_no[i][1] = -1; } g_tree_insert(rrc_ciph_info_tree, GINT_TO_POINTER((gint)rlcinf->ueid[fpinf->cur_tb]), cipher_info); } return cipher_info; }
GTree * mc_event_get_event_group_by_name (const gchar * event_group_name, gboolean create_new, GError ** mcerror) { GTree *event_group; event_group = (GTree *) g_tree_lookup (mc_event_grouplist, (gconstpointer) event_group_name); if (event_group == NULL && create_new) { event_group = g_tree_new_full ((GCompareDataFunc) g_ascii_strcasecmp, NULL, (GDestroyNotify) g_free, (GDestroyNotify) mc_event_group_destroy_value); if (event_group == NULL) { g_propagate_error (mcerror, g_error_new (MC_ERROR, 1, _("Unable to create group '%s' for events!"), event_group_name)); return NULL; } g_tree_insert (mc_event_grouplist, g_strdup (event_group_name), (gpointer) event_group); } return event_group; }
sqlx_cache_t * sqlx_cache_init(void) { guint i; sqlx_cache_t *cache; cache = g_malloc0(sizeof(*cache)); cache->cool_grace_delay = SQLX_GRACE_DELAY_COOL; cache->hot_grace_delay = SQLX_GRACE_DELAY_HOT; cache->heat_threshold = 1; cache->used = FALSE; g_mutex_init(&cache->lock); cache->bases_by_name = g_tree_new_full(hashstr_quick_cmpdata, NULL, NULL, NULL); cache->bases_count = SQLX_MAX_BASES; cache->cond_count = SQLX_MAX_COND; cache->cond_array = g_malloc0(cache->cond_count * sizeof(GCond)); cache->open_timeout = DEFAULT_CACHE_OPEN_TIMEOUT; BEACON_RESET(&(cache->beacon_free)); BEACON_RESET(&(cache->beacon_idle)); BEACON_RESET(&(cache->beacon_idle_hot)); BEACON_RESET(&(cache->beacon_used)); for (i=0; i<cache->cond_count ;i++) g_cond_init(cache->cond_array + i); sqlx_cache_reset_bases(cache, cache->bases_count); return cache; }
/* * Add new breakpoint. * arguments: * file - breakpoints filename * line - breakpoints line * condition - breakpoints line * enabled - is new breakpoint enabled * hitscount - breakpoints hitscount */ void breaks_add(const char* file, int line, char* condition, int enabled, int hitscount) { /* do not process async break manipulation on modules that do not support async interuppt */ enum dbs state = debug_get_state(); if (DBS_RUNNING == state && !debug_supports_async_breaks()) return; /* allocate memory */ breakpoint* bp = break_new_full(file, line, condition, enabled, hitscount); /* check whether GTree for this file exists and create if doesn't */ GTree *tree; if (!(tree = g_hash_table_lookup(files, bp->file))) { char *newfile = g_strdup(bp->file); tree = g_tree_new_full(compare_func, NULL, NULL, (GDestroyNotify)g_free); g_hash_table_insert(files, newfile, tree); } /* insert to internal storage */ g_tree_insert(tree, GINT_TO_POINTER(bp->line), bp); /* handle creation instantly if debugger is idle or stopped and request debug module interruption overwise */ if (DBS_IDLE == state) { on_add(bp); config_set_debug_changed(); } else if (DBS_STOPPED == state) breaks_add_debug(bp); else if (DBS_STOP_REQUESTED != state) debug_request_interrupt((bs_callback)breaks_add_debug, (gpointer)bp); }
FilterExprNode * filter_in_list_new(const gchar *list_file, const gchar *property) { FilterInList *self; FILE *stream; gchar line[16384]; stream = fopen(list_file, "r"); if (!stream) { msg_error("Error opening in-list filter list file", evt_tag_str("file", list_file), evt_tag_errno("errno", errno), NULL); return NULL; } self = g_new0(FilterInList, 1); filter_expr_node_init_instance(&self->super); self->value_handle = log_msg_get_value_handle(property); self->tree = g_tree_new_full((GCompareDataFunc)strcmp, NULL, g_free, NULL); while (fgets(line, sizeof(line), stream) != NULL) { line[strlen(line) - 1] = '\0'; if (line[0]) g_tree_insert(self->tree, g_strdup(line), GINT_TO_POINTER(1)); } fclose(stream); self->super.eval = filter_in_list_eval; self->super.free_fn = filter_in_list_free; return &self->super; }
static gchar *symbol_bd_sql_get_symbols_matches (Symbolizable *self, const gchar *symbol_prefix, gint flags) { gphpedit_debug (DEBUG_SYMBOLIZABLE); SymbolBdSQLDetails *symbolbddet; symbolbddet = SYMBOL_BD_SQL_GET_PRIVATE(self); symbolbddet->completion_prefix = (gchar *) symbol_prefix; symbolbddet->completion_string = NULL; if (symbol_bd_sql_has_cache(symbolbddet->cache_str, symbolbddet->cache_completion, symbolbddet->cache_flags, symbol_prefix, flags)){ symbolbddet->completion_string = symbol_bd_get_autocomp_from_cache(symbolbddet->cache_str, symbolbddet->cache_completion, symbol_prefix); } else { symbolbddet->completion_tree = g_tree_new_full ((GCompareDataFunc) g_strcmp0, NULL, NULL,(GDestroyNotify) g_free); if (((flags & SYMBOL_ALL) == SYMBOL_ALL) || ((flags & SYMBOL_FUNCTION) == SYMBOL_FUNCTION)) { /* add api functions */ g_tree_foreach (symbolbddet->sql_api_tree, add_api_item, symbolbddet); } g_tree_foreach (symbolbddet->completion_tree, make_result_string, symbolbddet); g_tree_destroy (symbolbddet->completion_tree); if (symbolbddet->completion_string) symbol_bd_sql_save_result_in_cache(symbolbddet, symbolbddet->completion_string->str, symbol_prefix); } if (symbolbddet->completion_string){ gphpedit_debug_message(DEBUG_CLASSBROWSER, "prefix: %s autocomplete list:%s\n", symbol_prefix, symbolbddet->completion_string->str); return g_string_free(symbolbddet->completion_string, FALSE); } gphpedit_debug_message(DEBUG_CLASSBROWSER, "prefix: %s autocomplete list:%s\n", symbol_prefix, "null"); return NULL; }
/**************************************************************************************************** * constructor ****************************************************************************************************/ void osm_reader_constructor(OsmReader * osm_reader) { osm_reader -> tree_ids = g_tree_new_full(osm_reader_compare_ints, NULL, destroy_int_p, NULL); osm_reader -> current_level = 0; osm_reader -> current_element = 0; osm_reader -> current_id = 0; }
static GTree* service_filegetter_import_download_specs(service_filegetter_tp sfg, service_filegetter_multi_args_tp args) { /* reads file with lines of the form: * fileserver.shd:8080:/5mb.urnd */ if(args->server_specification_filepath == NULL) { service_filegetter_log(sfg, SFG_CRITICAL, "please specify a path to a download specification file"); return NULL; } FILE* specs = fopen(args->server_specification_filepath, "r"); if(specs == NULL) { service_filegetter_log(sfg, SFG_CRITICAL, "could not open file"); perror(args->server_specification_filepath); return NULL; } gchar linebuffer[512]; GTree* dlTree = g_tree_new_full(_treeIntCompare, NULL, g_free, g_free); gint counter = 0; while(fgets(linebuffer, sizeof(linebuffer), specs) != NULL) { /* strip off the newline */ if (linebuffer[strlen(linebuffer) - 1] == '\n') { linebuffer[strlen(linebuffer) - 1] = '\0'; } gchar** tokens = g_strsplit((const gchar*) linebuffer, (const gchar*)":", 3); if(g_strrstr(tokens[2], ":") != NULL) { service_filegetter_log(sfg, SFG_CRITICAL, "format of download specification file incorrect. expected something like \"fileserver.shd:8080:/5mb.urnd\" on each line"); g_strfreev(tokens); g_tree_destroy(dlTree); return NULL; } service_filegetter_server_args_t http; http.host = tokens[0]; http.port = tokens[1]; gchar* filepath = tokens[2]; service_filegetter_download_tp dl = service_filegetter_get_download_from_args(sfg, &http, &args->socks_proxy, filepath, args->hostbyname_cb); g_strfreev(tokens); if(dl == NULL) { service_filegetter_log(sfg, SFG_CRITICAL, "error parsing download specification file"); g_tree_destroy(dlTree); return NULL; } gint* key = g_new(gint, 1); *key = counter++; g_tree_insert(dlTree, key, dl); } fclose(specs); return dlTree; }
static void init_query_all_evt_vars(void) { query_all_evt_called_end = 0; query_all_evt_result = HGLERR_UNKNOWN_REASON; g_gtree = g_tree_new_full(sample_compare_func, NULL, sample_key_destory_func, sample_value_destroy_func); }
/** * g_tree_new: * @key_compare_func: the function used to order the nodes in the #GTree. * It should return values similar to the standard strcmp() function - * 0 if the two arguments are equal, a negative value if the first argument * comes before the second, or a positive value if the first argument comes * after the second. * * Creates a new #GTree. * * Returns: a newly allocated #GTree */ GTree * g_tree_new (GCompareFunc key_compare_func) { g_return_val_if_fail (key_compare_func != NULL, NULL); return g_tree_new_full ((GCompareDataFunc) key_compare_func, NULL, NULL, NULL); }
VARLIST *varlist_new (SESSION_STATE *s) { VARLIST * v = g_new0(VARLIST, 1); v->tree = g_tree_new_full((GCompareDataFunc) mystrcmp, NULL, g_free, (GDestroyNotify) variable_destroy); v->sess = s; return v; }
ITTree *it_tree_new(void) { ITTree *ittree = g_new0(ITTree, 1); /* We don't have values actually, no need to free */ ittree->tree = g_tree_new_full(it_tree_compare, NULL, g_free, NULL); return ittree; }
static int do_validate_prepare () { already_traversed_commits = g_tree_new_full ((GCompareDataFunc)strcmp_wrapper, NULL, (GDestroyNotify)g_free, NULL); if (!already_traversed_commits) { fprintf (stderr, "[ERROR] Failed to create tree already_traversed_commits\n"); return -1; } already_traversed_blocks = g_tree_new_full ((GCompareDataFunc)strcmp_wrapper, NULL, (GDestroyNotify)g_free, NULL); if (!already_traversed_blocks) { fprintf (stderr, "[ERROR] Failed to create tree already_traversed_blocks\n"); return -1; } return 0; }
TGenPool* tgenpool_new(GDestroyNotify valueDestroyFunc) { TGenPool* pool = g_new0(TGenPool, 1); pool->magic = TGEN_MAGIC; pool->items = g_tree_new_full(_tgenpool_intCompare, NULL, g_free, valueDestroyFunc); pool->refcount = 1; return pool; }
/** * g_tree_new_with_data: * @key_compare_func: qsort()-style comparison function * @key_compare_data: data to pass to comparison function * * Creates a new #GTree with a comparison function that accepts user data. * See g_tree_new() for more details. * * Returns: a newly allocated #GTree */ GTree * g_tree_new_with_data (GCompareDataFunc key_compare_func, gpointer key_compare_data) { g_return_val_if_fail (key_compare_func != NULL, NULL); return g_tree_new_full (key_compare_func, key_compare_data, NULL, NULL); }
static void context_flush_pending(struct sqlx_repctx_s *ctx) { if (!ctx) return; if (ctx->pending) g_tree_destroy(ctx->pending); ctx->pending = g_tree_new_full(hashstr_quick_cmpdata, NULL, g_free, _clean_value); }
static struct http_request_s * http_request_create(struct network_client_s *client) { struct http_request_s *req; req = g_malloc0(sizeof(*req)); req->client = client; req->tree_headers = g_tree_new_full(metautils_strcmp3, NULL, g_free, g_free); req->body = g_byte_array_new(); return req; }
static /*@dependent@*/ GTree * register_incremental(CPIncrementals self, const char *key) /*@modifies *self@*/ { GTree *result = g_tree_lookup(self->incrementals, key); if (result == NULL) { result = g_tree_new_full((GCompareDataFunc)strcmp, NULL, g_free, NULL); g_tree_insert(self->incrementals, g_strdup(key), result); } return result; }
void cap_file_provider_set_user_comment(struct packet_provider_data *prov, frame_data *fd, const char *new_comment) { if (!prov->frames_user_comments) prov->frames_user_comments = g_tree_new_full(frame_cmp, NULL, NULL, g_free); /* insert new packet comment */ g_tree_replace(prov->frames_user_comments, fd, g_strdup(new_comment)); fd->has_user_comment = TRUE; }
static GTree* context_get_pending_table(GTree *tree, const hashstr_t *key) { GTree *subtree; if (NULL != (subtree = g_tree_lookup(tree, key))) return subtree; subtree = g_tree_new_full(hashstr_quick_cmpdata, NULL, g_free, NULL); g_tree_insert(tree, hashstr_dup(key), subtree); return subtree; }
GTree* mlSaveModuleState() { GTree *state = NULL; state = g_tree_new_full(gcmp, NULL, g_free, NULL); if(!state) return NULL; processModuleLines(cb_savestate, state); return state; }
print_manager_t print_manager_init(unsigned int block_size, unsigned long long start_block) { struct print_manager *pm = (struct print_manager *) g_malloc(sizeof(struct print_manager)); pm->magic = PRINT_MANAGER_MAGIC; pm->block_size = block_size; pm->current_offset = start_block; pm->abs_tree = g_tree_new_full((GCompareDataFunc) abs_tree_compare, NULL, (GDestroyNotify) g_free, (GDestroyNotify) g_node_safe_destroy); pm->continuation_tree = g_tree_new_full((GCompareDataFunc) continuation_tree_compare, NULL, (GDestroyNotify) block_range_close, (GDestroyNotify) continuation_node_free); pm->print_array = NULL; pm->destroy_array = NULL; pm->lookup_offset = 0; pm->lookup_range = block_range_init(NULL, 0); // Work out which output format to use int print_style = 0; if (config_get_int_with_default_macro(NULL, CONFIG_OUTPUT_STYLE, &print_style) != 0) { print_style = CONFIG_OUTPUT_STYLE_DEFAULT; } switch (print_style) { case CONFIG_DFRWS_OUTPUT_STYLE: pm->print_handler = get_dfrws_print_handler(); break; case CONFIG_PATH_OUTPUT_STYLE: pm->print_handler = get_basic_print_handler(); break; default: warning_log("Unknown print style selected!!"); pm->print_handler = get_dfrws_print_handler(); } // Print out the header pm->print_handler->print_header(); return (print_manager_t) pm; }
int main() { printf("Create a new GTree using g_tree_new_full().\n"); GTree *tree = g_tree_new_full((GCompareDataFunc)g_ascii_strcasecmp, NULL, (GDestroyNotify)destroy_key, (GDestroyNotify)destroy_val); printf("Add items to the tree.\n"); g_tree_insert(tree, "c", "Captain America"); g_tree_insert(tree, "i", "Iron Man"); g_tree_insert(tree, "h", "Hawk Eye"); g_tree_insert(tree, "s", "Spider Man"); printf("Tree height from g_tree_height(): %d\n", g_tree_height(tree)); printf("Number of nodes from g_tree_nnodes(): %d\n", g_tree_nnodes(tree)); printf("List the tree using g_tree_foreach() and a GTraverseFunc.\n"); printf("Tree Contents:\n"); g_tree_foreach(tree, (GTraverseFunc)print_iterator, NULL); printf("\n"); printf("Find items using g_tree_lookup().\n"); printf("The data at 'i' is '%s'\n", g_tree_lookup(tree, "i")); printf("%s\n\n", g_tree_lookup(tree, "d") ? "Unexpected value!!" : "No data found for 'd'"); printf("Find items using g_tree_search() and a GCompareFunc.\n"); gpointer val = g_tree_search(tree, (GCompareFunc)finder, NULL); printf("The value is %s\n\n", val); printf("Remove an item using g_tree_remove().\n"); g_tree_remove(tree, "h"); printf("Number of nodes is now: %d\n", g_tree_nnodes(tree)); printf("Tree Contents:\n"); g_tree_foreach(tree, (GTraverseFunc)print_iterator, NULL); printf("\n"); printf("Replacing 's', destroy functions will be called.\n"); g_tree_replace(tree, "s", "Storm"); printf("Number of nodes is now: %d\n", g_tree_nnodes(tree)); printf("Tree Contents:\n"); g_tree_foreach(tree, (GTraverseFunc)print_iterator, NULL); printf("\n"); printf("Stealing 'c' with g_tree_steal(), no drstroy functions now.\n"); g_tree_steal(tree, "c"); printf("Number of nodes is now: %d\n", g_tree_nnodes(tree)); printf("Tree Contents:\n"); g_tree_foreach(tree, (GTraverseFunc)print_iterator, NULL); printf("\n"); printf("Destroying the tree using g_tree_destroy().\n"); g_tree_destroy(tree); }
static void ibus_hotkey_profile_init (IBusHotkeyProfile *profile) { IBusHotkeyProfilePrivate *priv; priv = IBUS_HOTKEY_PROFILE_GET_PRIVATE (profile); priv->hotkeys = g_tree_new_full ((GCompareDataFunc) ibus_hotkey_cmp_with_data, NULL, (GDestroyNotify) ibus_hotkey_free, NULL); priv->events = g_array_new (TRUE, TRUE, sizeof (IBusHotkeyEvent)); priv->mask = IBUS_SHIFT_MASK | IBUS_CONTROL_MASK | IBUS_MOD1_MASK | IBUS_RELEASE_MASK; }