Пример #1
0
/* Create and init matcher. */
struct _vte_matcher *
_vte_matcher_new(const char *emulation, struct _vte_termcap *termcap)
{
	struct _vte_matcher *ret = NULL;
	g_static_mutex_lock(&_vte_matcher_mutex);

	if (emulation == NULL) {
		emulation = "";
	}

	if (_vte_matcher_cache == NULL) {
		_vte_matcher_cache = g_cache_new(_vte_matcher_create,
				_vte_matcher_destroy,
				(GCacheDupFunc) g_strdup, g_free,
				g_str_hash, g_direct_hash, g_str_equal);
	}

	ret = g_cache_insert(_vte_matcher_cache, (gpointer) emulation);

	if (ret->match == NULL) {
		ret->impl = ret->impl->klass->create();
		ret->match = ret->impl->klass->match;
		_vte_matcher_init(ret, emulation, termcap);
	}

	g_static_mutex_unlock(&_vte_matcher_mutex);
	return ret;
}
Пример #2
0
void cache_test()
{
	char *str1,*str2,*str3;
	GCache *cache = NULL;
	gint user_data = 0;
	
	g_assert((cache = g_cache_new( (GCacheNewFunc) g_ascii_strup,
					g_free, (GCacheDupFunc) g_strdup, g_free, g_str_hash, 
    				g_str_hash, g_str_equal)) != NULL);
    				
    str1 = g_cache_insert(cache,"test");
    
    g_assert(!strcmp("TEST",str1));
    
	str2 = g_cache_insert(cache,"test");

	g_assert(!strcmp("TEST",str1));
	
	str3 = g_cache_insert(cache,"glib");
	
	g_assert(!strcmp("GLIB",str3));
	
	g_cache_key_foreach (cache,(GHFunc)function,&user_data);
	
	//g_cache_key_foreach would call function twice and make user_data == 2
	g_assert(user_data == 2);
	
	g_cache_value_foreach (cache,(GHFunc)function,&user_data);
	
	//g_cache_value_foreach would call function twice and make user_data == 4
	g_assert(user_data == 4);
	
	g_cache_remove(cache,str1);
	g_cache_remove(cache,str2);	
	g_cache_remove(cache,str3);	
	
	g_cache_destroy(cache);
	
}
Пример #3
0
Файл: vtetc.c Проект: Cordia/vte
VteTermcap *
_vte_termcap_new(const char *filename)
{
  VteTermcap *result;

  g_static_mutex_lock (&_vte_termcap_mutex);

  if (_vte_termcap_cache == NULL)
    _vte_termcap_cache = g_cache_new((GCacheNewFunc) _vte_termcap_create,
                                     (GCacheDestroyFunc) _vte_termcap_destroy,
                                     (GCacheDupFunc) g_strdup,
                                     (GCacheDestroyFunc) g_free,
                                     g_str_hash, g_direct_hash, g_str_equal);

  result = g_cache_insert (_vte_termcap_cache, (gpointer) filename);

  g_static_mutex_unlock (&_vte_termcap_mutex);

  return result;
}
Пример #4
0
static guint
mgicchikn_rc_parse_check_image (MgicChiknRcStyle * rc_style,
								GtkSettings * settings,
								GScanner * scanner)
{
	guint token;
	gchar *value = NULL;
	gboolean state_mask[GTK_STATE_LAST] = { 0 },
	  shadow_mask[MGICCHIKN_SHADOW_LAST] = { 0 };
	gint i, i2;

	token = mgicchikn_rc_parse_state_shadow_equals (scanner, state_mask, shadow_mask);
	if (token != G_TOKEN_NONE)
		return token;

	token = g_scanner_get_next_token (scanner);
	if (token != G_TOKEN_STRING)
		return G_TOKEN_STRING;

	value = gtk_rc_find_pixmap_in_path (settings, scanner, scanner->value.v_string);

	if (value != NULL)
	{
		g_cache_insert (MGICCHIKN_RC_STYLE_GET_CLASS (rc_style)->raw_pixbufs, value);
		for (i = 0; i < GTK_STATE_LAST; i++)
		{
			if (state_mask[i] == TRUE)
			{
				for (i2 = 0; i2 < MGICCHIKN_SHADOW_LAST; i++)
				{
					if (shadow_mask[i] == TRUE)
					{
						rc_style->check_image[i][i2] = value;
					}
				}
			}
		}
	}

	return G_TOKEN_NONE;
}
Пример #5
0
GdkGC*
gtk_gc_get (gint             depth,
	    GdkColormap     *colormap,
	    GdkGCValues     *values,
	    GdkGCValuesMask  values_mask)
{
  GtkGCKey key;
  GdkGC *gc;

  if (initialize)
    gtk_gc_init ();

  key.depth = depth;
  key.colormap = colormap;
  key.values = *values;
  key.mask = values_mask;

  gc = g_cache_insert (gc_cache, &key);

  return gc;
}