static void widget_table_input_by_items(variable *var) { GList *element; gchar *text; list_t *sliced; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ g_assert(var->Attributes != NULL && var->Widget != NULL); text = attributeset_get_first(&element, var->Attributes, ATTR_ITEM); while (text != NULL) { sliced = linecutter(g_strdup(text), '|'); gtk_clist_append(GTK_CLIST(var->Widget), sliced->line); if (sliced) list_t_free(sliced); /* Free linecutter memory */ text = attributeset_get_next(&element, var->Attributes, ATTR_ITEM); } #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
void search_state_t_free(search_state_t* p_state) { if (p_state->p_weight_list) list_t_free(p_state->p_weight_list); if (p_state->p_open_set) heap_t_free(p_state->p_open_set); if (p_state->p_closed_set) unordered_set_t_free(p_state->p_closed_set); if (p_state->p_parent_map) unordered_map_t_free(p_state->p_parent_map); if (p_state->p_cost_map) unordered_map_t_free(p_state->p_cost_map); }
static ssize_t data_list_t_free(data_t *data, fastcall_free *fargs){ // {{{ list_t *fdata = (list_t *)data->ptr; if(fdata == NULL) return -EINVAL; list_t_free(fdata); return 0; } // }}}
static void widget_colorbutton_input_by_file(variable *var, char *filename) { FILE *infile; GdkColor color; list_t *values = NULL; gchar line[512]; gint count; guint alpha; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif if (infile = fopen(filename, "r")) { /* Just one line */ if (fgets(line, 512, infile)) { /* Enforce end of string in case of max chars read */ line[512 - 1] = 0; /* Remove the trailing [CR]LFs */ for (count = strlen(line) - 1; count >= 0; count--) if (line[count] == 13 || line[count] == 10) line[count] = 0; values = linecutter(g_strdup(line), '|'); if (values->n_lines > 0) { /* Parse the RGB value to create the necessary GdkColor. * This function doesn't like trailing whitespace so it * needs to be stripped first with g_strstrip() */ if (gdk_color_parse(g_strstrip(values->line[0]), &color)) { #ifdef DEBUG_CONTENT fprintf(stderr, "%s:() valid colour found\n", __func__); #endif gtk_color_button_set_color(GTK_COLOR_BUTTON(var->Widget), &color); } } if (values->n_lines > 1) { /* Read alpha as an unsigned decimal integer */ if (sscanf(values->line[1], "%u", &alpha) == 1) { #ifdef DEBUG_CONTENT fprintf(stderr, "%s:() valid alpha=%u found\n", __func__, alpha); #endif /* This requires use-alpha="true" */ gtk_color_button_set_alpha(GTK_COLOR_BUTTON(var->Widget), alpha); } } /* Free linecutter memory */ if (values) list_t_free(values); } /* Close the file */ fclose(infile); } else { fprintf(stderr, "%s(): Couldn't open '%s' for reading.\n", __func__, filename); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
static void widget_table_input_by_command(variable *var, char *filename, gint command_or_file) { FILE *infile; gchar line[512]; gint count; list_t *sliced; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ if (command_or_file) { infile = widget_opencommand(filename); } else { infile = fopen(filename, "r"); } /* Opening pipe for reading... */ if (infile) { /* Read the file one line at a time (trailing [CR]LFs are read too) */ while (fgets(line, 512, infile) != NULL) { /* Enforce end of string in case of max chars read */ line[512 - 1] = 0; /* Remove the trailing [CR]LFs */ for (count = strlen(line) - 1; count >= 0; count--) if (line[count] == 13 || line[count] == 10) line[count] = 0; sliced = linecutter(g_strdup(line), '|'); gtk_clist_append(GTK_CLIST(var->Widget), sliced->line); if (sliced) list_t_free(sliced); /* Free linecutter memory */ } /* Close the file */ pclose(infile); } else { fprintf(stderr, "%s(): Couldn't open '%s' for reading.\n", __func__, filename); } #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
list_t * list_t_copy (list_t *list){ // {{{ ssize_t ret; list_t *new_list; list_chunk_t *chunk; data_t data_copy; new_list = list_t_alloc(); for(chunk = list->head; chunk; chunk = chunk->cnext){ holder_copy(ret, &data_copy, &chunk->data); if(ret < 0) goto error; list_t_push(new_list, &data_copy); } return new_list; error: list_t_free(new_list); return NULL; } // }}}
/*********************************************************************** * Create * ***********************************************************************/ GtkWidget *widget_table_create( AttributeSet *Attr, tag_attr *attr, gint Type) { GList *element; GtkWidget *widget; gchar *value; gint column; gint sort_function; list_t *sliced; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ if (attributeset_is_avail(Attr, ATTR_LABEL)) { sliced = linecutter(g_strdup(attributeset_get_first( &element, Attr, ATTR_LABEL)), '|'); widget = gtk_clist_new_with_titles(sliced->n_lines, sliced->line); if (sliced) list_t_free(sliced); /* Free linecutter memory */ } else { widget = gtk_clist_new(1); /* 1 column */ } if (attr) { /* Get sort-function (custom) */ if ((value = get_tag_attribute(attr, "sort-function"))) { sort_function = atoi(value); if (sort_function == 1) { gtk_clist_set_compare_func(GTK_CLIST(widget), widget_table_natcmp); } else if (sort_function == 2) { gtk_clist_set_compare_func(GTK_CLIST(widget), widget_table_natcasecmp); } } /* Get sort-type (auto-sort will require this preset) */ if ((value = get_tag_attribute(attr, "sort-type"))) { gtk_clist_set_sort_type(GTK_CLIST(widget), atoi(value)); } /* Get sort-column (custom) */ if ((value = get_tag_attribute(attr, "sort-column"))) { gtk_clist_set_sort_column(GTK_CLIST(widget), atoi(value)); } /* Get auto-sort (custom) */ if ((value = get_tag_attribute(attr, "auto-sort")) && ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1))) { gtk_clist_set_auto_sort(GTK_CLIST(widget), TRUE); } else { gtk_clist_set_auto_sort(GTK_CLIST(widget), FALSE); } /* Get column-header-active (custom) */ if ((value = get_tag_attribute(attr, "column-header-active"))) { sliced = linecutter(g_strdup(value), '|'); for (column = 0; column < sliced->n_lines; column++) { if ((strcasecmp(sliced->line[column], "true") == 0) || (strcasecmp(sliced->line[column], "yes") == 0) || (atoi(sliced->line[column]) == 1)) { gtk_clist_column_title_active(GTK_CLIST(widget), column); } else { gtk_clist_column_title_passive(GTK_CLIST(widget), column); } } if (sliced) list_t_free(sliced); /* Free linecutter memory */ } /* Get column-visible (custom) */ if ((value = get_tag_attribute(attr, "column-visible"))) { sliced = linecutter(g_strdup(value), '|'); for (column = 0; column < sliced->n_lines; column++) { if ((strcasecmp(sliced->line[column], "true") == 0) || (strcasecmp(sliced->line[column], "yes") == 0) || (atoi(sliced->line[column]) == 1)) { gtk_clist_set_column_visibility(GTK_CLIST(widget), column, TRUE); } else { gtk_clist_set_column_visibility(GTK_CLIST(widget), column, FALSE); } } if (sliced) list_t_free(sliced); /* Free linecutter memory */ } } #else fprintf(stderr, "%s(): The table (GtkCList) widget has been removed from GTK+ 3 and tree is recommended as a replacement.\n", __func__); exit(EXIT_FAILURE); #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }
static ssize_t data_list_t_convert_from(data_t *dst, fastcall_convert_from *fargs){ // {{{ ssize_t ret = 0; list_t *fdata; uintmax_t transfered = 0; data_t sl_input = DATA_SLIDERT(fargs->src, 0); switch(fargs->format){ case FORMAT(native): case FORMAT(human): case FORMAT(config):; return data_list_t(dst); case FORMAT(hash):; hash_t *config; data_get(ret, TYPE_HASHT, config, fargs->src); if(ret != 0) return -EINVAL; if((fdata = dst->ptr) == NULL){ if( (fdata = dst->ptr = list_t_alloc()) == NULL) return -ENOMEM; } if(hash_iter(config, (hash_iterator)&iter_list_t_convert_from, dst, 0) != ITER_OK){ list_t_free(dst->ptr); return -EFAULT; } return 0; case FORMAT(packed):; data_t item; data_t d_item = DATA_PTR_DATAT(&item); if((fdata = dst->ptr) == NULL){ if( (fdata = dst->ptr = list_t_alloc()) == NULL) return -ENOMEM; } while(1){ data_set_void(&item); fastcall_convert_from r_convert = { { 5, ACTION_CONVERT_FROM }, &sl_input, FORMAT(packed) }; if( (ret = data_query(&d_item, &r_convert)) < 0) break; data_slider_t_set_offset(&sl_input, r_convert.transfered, SEEK_CUR); if(item.type == TYPE_LISTENDT) break; if( (ret = list_t_push(fdata, &item)) < 0) break; } transfered = data_slider_t_get_offset(&sl_input); break; default: return -ENOSYS; }; if(fargs->header.nargs >= 5) fargs->transfered = transfered; return ret; } // }}}
/*********************************************************************** * Refresh * ***********************************************************************/ void widget_colorbutton_refresh(variable *var) { GdkColor color; GList *element; gchar *act; gint initialised = FALSE; guint alpha; list_t *values = NULL; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Get initialised state of widget */ if (g_object_get_data(G_OBJECT(var->Widget), "_initialised") != NULL) initialised = (gint)g_object_get_data(G_OBJECT(var->Widget), "_initialised"); /* The <input> tag... */ act = attributeset_get_first(&element, var->Attributes, ATTR_INPUT); while (act) { if (input_is_shell_command(act)) widget_colorbutton_input_by_command(var, act + 8); /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { if (!initialised) { /* Check for file-monitor and create if requested */ widget_file_monitor_try_create(var, act + 5); } widget_colorbutton_input_by_file(var, act + 5); } act = attributeset_get_next(&element, var->Attributes, ATTR_INPUT); } /* The <item> tags... */ if (attributeset_is_avail(var->Attributes, ATTR_ITEM)) widget_colorbutton_input_by_items(var); /* Initialise these only once at start-up */ if (!initialised) { /* Apply directives */ if (attributeset_is_avail(var->Attributes, ATTR_LABEL)) fprintf(stderr, "%s(): <label> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_DEFAULT)) { values = linecutter(g_strdup(attributeset_get_first(&element, var->Attributes, ATTR_DEFAULT)), '|'); if (values->n_lines > 0) { /* Parse the RGB value to create the necessary GdkColor. * This function doesn't like trailing whitespace so it * needs to be stripped first with g_strstrip() */ if (gdk_color_parse(g_strstrip(values->line[0]), &color)) { #ifdef DEBUG_CONTENT fprintf(stderr, "%s:() valid colour found\n", __func__); #endif gtk_color_button_set_color(GTK_COLOR_BUTTON(var->Widget), &color); } } if (values->n_lines > 1) { /* Read alpha as an unsigned decimal integer */ if (sscanf(values->line[1], "%u", &alpha) == 1) { #ifdef DEBUG_CONTENT fprintf(stderr, "%s:() valid alpha=%u found\n", __func__, alpha); #endif /* This requires use-alpha="true" */ gtk_color_button_set_alpha(GTK_COLOR_BUTTON(var->Widget), alpha); } } /* Free linecutter memory */ if (values) list_t_free(values); } if (attributeset_is_avail(var->Attributes, ATTR_HEIGHT)) fprintf(stderr, "%s(): <height> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_WIDTH)) fprintf(stderr, "%s(): <width> not implemented for this widget.\n", __func__); if ((attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "false")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "disabled")) || /* Deprecated */ (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "no")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "0"))) gtk_widget_set_sensitive(var->Widget, FALSE); /* Connect signals */ g_signal_connect(G_OBJECT(var->Widget), "color-set", G_CALLBACK(on_any_widget_color_set_event), (gpointer)var->Attributes); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }