Ejemplo n.º 1
0
int main(int argc, char** argv) {
 GList* list = g_list_append(NULL, "Austin ");
 list = g_list_append(list, "Bowie ");
 list = g_list_append(list, "Charleston ");
 printf("Here's the list: ");
 g_list_foreach(list, (GFunc)printf, NULL);
 GList* last = g_list_last(list);
 printf("\nThe first item (using g_list_first) is '%s'\n", g_list_first(last)->data);
 printf("The next-to-last item is '%s'\n", g_list_previous(last)->data);
 printf("The next-to-last item is '%s'\n", g_list_nth_prev(last, 1)->data);
 g_list_free(list);
 return 0;
}
Ejemplo n.º 2
0
static gboolean
eval_cb (const GMatchInfo *info, GString *res, gpointer data)
{
	gchar *var;
	gchar *n;
	gchar *key;
	gint nth;

	var = g_match_info_fetch(info, 1);
	n = g_match_info_fetch(info, 2);
	key = g_match_info_fetch(info, 3);
	nth = atoi(n);

	if (g_strcmp0(var, "prev") == 0) {
		GList *last = g_list_last(data);
		GList *item = g_list_nth_prev(last, nth - 1);

		if (item) {
			const gchar *val;
			hashfs_db_entry_t *entry = item->data;

			if (g_strcmp0(key, "pkey") == 0) {
				val = hashfs_db_entry_pkey(entry);
				g_string_append(res, val);
			} else {
				if (hashfs_db_entry_lookup(entry, key, &val))
					g_string_append(res, val);
			}
		}
	}

	g_free(var);
	g_free(n);
	g_free(key);

	return FALSE;
}
Ejemplo n.º 3
0
int main (int   argc,char *argv[])
{
	
	GList *list1 = NULL,*list2 = NULL,*l,*l1,*list3 = NULL;
	int i;
	int *value;
	const char mem_allocator[]  = "mem_allocator";
	GAllocator *allocator;
	
	int num1[] = 
	{
		1,2,3
	};
	
	int num2[] = 
	{
		4,5,6
	};
	
	#ifdef SYMBIAN
	
	g_log_set_handler (NULL,  G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
	#endif /*SYMBIAN*/
	
	allocator = g_allocator_new(mem_allocator,500);

	for(i=0;i<3;i++)
		list1 = g_list_append (list1, &num1[i]);
		
	for(i=0;i<3;i++)
		list2 = g_list_append (list2, &num2[i]);
	
	
	list1 = g_list_concat(list1,list2);
	
	for(i=0;i<6;i++)
	{
		l = g_list_nth(list1,i);
		g_assert(*(gint *)(l->data) == i+1);
	}
	
	list2 = g_list_copy(list1);
	
	for(i=0;i<3;i++)
	{
		l = g_list_nth(list2,i);
		g_assert(*(gint *)(l->data) == i+1);
	}
	
	l = g_list_first(list2);
	g_assert(*(gint *)(l->data) == 1);
	
	value = (int *)g_list_nth_data(list1,1);
	
	g_assert(*value == 2);
	
	l = g_list_nth(list1,3);
	
	l1 = g_list_nth_prev(l,2);

	for(i=0;i<5;i++)
	{
		l = g_list_nth(l1,i);
		g_assert(*(gint *)(l->data) == i+2);
	}
	
	g_list_push_allocator(allocator);
	
	list3 = g_list_append(list3,&num1[2]);
	
	g_assert(*(gint *)(list3->data) == 3);
	
	g_list_pop_allocator();
	
	list3 = g_list_append(list3,&num1[0]);
	
	g_assert(*(gint *)(list3->next->data) == 1);
	
	list1 = g_list_append(list1,&num1[0]);
	
	i = g_list_length(list1);
	
	list1 = g_list_remove_all(list1,&num1[0]);
	
	i = g_list_length(list1);
	
	g_assert(g_list_length(list1) == 5); // should be this value as we will remove 2 1's from the list
	
	for(i==0;i<g_list_length(list1);i++)
	{
		l = g_list_nth(list1,i);
		g_assert(*(gint *)(l->data) != 1);
	}
	
	g_allocator_free(allocator);
	
	#ifdef SYMBIAN
  	testResultXml("list_test");
  	#endif /* EMULATOR */
	
	return 0;
}
Ejemplo n.º 4
0
static void
gnt_text_view_draw(GntWidget *widget)
{
	GntTextView *view = GNT_TEXT_VIEW(widget);
	int n;
	int i = 0;
	GList *lines;
	int rows, scrcol;
	int comp = 0;          /* Used for top-aligned text */
	gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL);

	wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL));
	werase(widget->window);

	n = g_list_length(view->list);
	if ((view->flags & GNT_TEXT_VIEW_TOP_ALIGN) &&
			n < widget->priv.height) {
		GList *now = view->list;
		comp = widget->priv.height - n;
		view->list = g_list_nth_prev(view->list, comp);
		if (!view->list) {
			view->list = g_list_first(now);
			comp = widget->priv.height - g_list_length(view->list);
		} else {
			comp = 0;
		}
	}

	for (i = 0, lines = view->list; i < widget->priv.height && lines; i++, lines = lines->next)
	{
		GList *iter;
		GntTextLine *line = lines->data;

		wmove(widget->window, widget->priv.height - 1 - i - comp, 0);

		for (iter = line->segments; iter; iter = iter->next)
		{
			GntTextSegment *seg = iter->data;
			char *end = view->string->str + seg->end;
			char back = *end;
			chtype fl = seg->flags;
			*end = '\0';
			if (select_start && select_start < view->string->str + seg->start && select_end > view->string->str + seg->end) {
				fl |= A_REVERSE;
				wattrset(widget->window, fl);
				wprintw(widget->window, "%s", C_(view->string->str + seg->start));
			} else if (select_start && select_end &&
				((select_start >= view->string->str + seg->start && select_start <= view->string->str + seg->end) ||
				(select_end <= view->string->str + seg->end && select_start <= view->string->str + seg->start))) {
				char *cur = view->string->str + seg->start;
				while (*cur != '\0') {
					gchar *last = g_utf8_next_char(cur);
					gchar *str;
					if (cur >= select_start && cur <= select_end)
						fl |= A_REVERSE;
					else
						fl = seg->flags;
					str = g_strndup(cur, last - cur);
					wattrset(widget->window, fl);
					waddstr(widget->window, C_(str));
					g_free(str);
					cur = g_utf8_next_char(cur);
				}
			} else {
				wattrset(widget->window, fl);
				wprintw(widget->window, "%s", C_(view->string->str + seg->start));
			}
			*end = back;
		}
		wattroff(widget->window, A_UNDERLINE | A_BLINK | A_REVERSE);
		whline(widget->window, ' ', widget->priv.width - line->length - has_scroll);
	}

	scrcol = widget->priv.width - 1;
	rows = widget->priv.height - 2;
	if (has_scroll && rows > 0)
	{
		int total = g_list_length(g_list_first(view->list));
		int showing, position, up, down;

		showing = rows * rows / total + 1;
		showing = MIN(rows, showing);

		total -= rows;
		up = g_list_length(lines);
		down = total - up;

		position = (rows - showing) * up / MAX(1, up + down);
		position = MAX((lines != NULL), position);

		if (showing + position > rows)
			position = rows - showing;

		if (showing + position == rows && view->list && view->list->prev)
			position = MAX(1, rows - 1 - showing);
		else if (showing + position < rows && view->list && !view->list->prev)
			position = rows - showing;

		mvwvline(widget->window, position + 1, scrcol,
				ACS_CKBOARD | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D), showing);
	}

	if (has_scroll) {
		mvwaddch(widget->window, 0, scrcol,
				(lines ? ACS_UARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
		mvwaddch(widget->window, widget->priv.height - 1, scrcol,
				((view->list && view->list->prev) ? ACS_DARROW : ' ') |
					gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
	}

	wmove(widget->window, 0, 0);
}