Пример #1
0
static gboolean
gwy_app_recent_file_list_filter(GtkTreeModel *model,
                                GtkTreeIter *iter,
                                gpointer data)
{
    Controls *controls = (Controls*)data;
    GwyRecentFile *rf;

    if (!controls->pattern)
        return TRUE;

    gtk_tree_model_get(model, iter, 0, &rf, -1);
    /* This can happen when the row has been just created and rf is not set
     * yet. */
    if (!rf)
        return FALSE;

    if (controls->casesens)
        return g_pattern_match_string(controls->pattern, rf->file_utf8);
    else {
        if (!rf->file_utf8_lc)
            rf->file_utf8_lc = g_utf8_strdown(rf->file_utf8, -1);

        return g_pattern_match_string(controls->pattern, rf->file_utf8_lc);
    }
}
Пример #2
0
static gboolean
fuzzy_check_content_type (struct fuzzy_rule *rule, GMimeContentType *type)
{
	struct fuzzy_mime_type *ft;
	GList *cur;

	cur = rule->mime_types;
	while (cur) {
		ft = cur->data;
		if (ft->type) {

			if (g_pattern_match_string (ft->type, type->type)) {
				if (ft->subtype) {
					if (g_pattern_match_string (ft->subtype, type->subtype)) {
						return TRUE;
					}
				}
				else {
					return TRUE;
				}
			}
		}

		cur = g_list_next (cur);
	}

	return FALSE;
}
Пример #3
0
void
mud_connections_icon_fileset_cb(GtkFileChooserButton *chooser,
				MudConnections *conn)
{
    const gchar *file;
    gchar *current_folder =
	gtk_file_chooser_get_current_folder(
	    GTK_FILE_CHOOSER(conn->priv->icon_dialog_chooser));
    GDir *dir = g_dir_open(current_folder ,0, NULL);
    GPatternSpec *xpm_pattern = g_pattern_spec_new("*.xpm");
    GPatternSpec *svg_pattern = g_pattern_spec_new("*.svg");
    GPatternSpec *bmp_pattern = g_pattern_spec_new("*.bmp");
    GPatternSpec *png_pattern = g_pattern_spec_new("*.png");

    gtk_list_store_clear(
	GTK_LIST_STORE(conn->priv->icon_dialog_view_model));

    while( (file = g_dir_read_name(dir) ) != NULL)
	if( g_pattern_match_string(xpm_pattern, file) ||
	    g_pattern_match_string(svg_pattern, file) ||
	    g_pattern_match_string(bmp_pattern, file) ||
	    g_pattern_match_string(png_pattern, file))
	{
	    gchar *full_path = g_strconcat(current_folder,
					   G_DIR_SEPARATOR_S,
					   file, NULL);
	    GdkPixbuf *icon = gdk_pixbuf_new_from_file_at_size(
		full_path, 48, 48, NULL);
	    GtkTreeIter iter;

            if(icon)
            {
                gtk_list_store_append(
                        GTK_LIST_STORE(conn->priv->icon_dialog_view_model),
                        &iter);
                gtk_list_store_set(
                        GTK_LIST_STORE(conn->priv->icon_dialog_view_model),
                        &iter,
                        MODEL_COLUMN_STRING, file,
                        MODEL_COLUMN_PIXBUF, icon,
                        -1);

                g_object_unref(icon);
            }

	    g_free(full_path);
	}

    g_free(current_folder);
    g_dir_close(dir);
    g_pattern_spec_free(xpm_pattern);
    g_pattern_spec_free(svg_pattern);
    g_pattern_spec_free(bmp_pattern);
    g_pattern_spec_free(png_pattern);
}
Пример #4
0
/*! \brief Find all text objects that match a pattern
 *
 *  \param pages the list of pages to search
 *  \param text the pattern to match
 *  \return a list of objects that match the given pattern
 */
static GSList*
find_objects_using_pattern (GSList *pages, const char *text)
{
  GSList *object_list = NULL;
  GSList *page_iter = pages;
  GPatternSpec *pattern;

  g_return_val_if_fail (text != NULL, NULL);

  pattern = g_pattern_spec_new (text);

  while (page_iter != NULL) {
    const GList *object_iter;
    PAGE *page = (PAGE*) page_iter->data;

    page_iter = g_slist_next (page_iter);

    if (page == NULL) {
      g_warning ("NULL page encountered");
      continue;
    }

    object_iter = s_page_objects (page);

    while (object_iter != NULL) {
      OBJECT *object = (OBJECT*) object_iter->data;
      const char *str;

      object_iter = g_list_next (object_iter);

      if (object == NULL) {
        g_warning ("NULL object encountered");
        continue;
      }

      if (object->type != OBJ_TEXT) {
        continue;
      }

      if (!(o_is_visible (page->toplevel, object) || page->toplevel->show_hidden_text)) {
        continue;
      }

      str = geda_text_object_get_string (object);

      if (str == NULL) {
        g_warning ("NULL string encountered");
        continue;
      }

      if (g_pattern_match_string (pattern, str)) {
        object_list = g_slist_prepend (object_list, object);
      }
    }
  }

  g_pattern_spec_free (pattern);

  return g_slist_reverse (object_list);
}
Пример #5
0
static void
_handle_file_created(WildcardSourceDriver *self, const DirectoryMonitorEvent *event)
{
  if (g_pattern_match_string(self->compiled_pattern, event->name))
    {
      WildcardFileReader *reader = g_hash_table_lookup(self->file_readers, event->full_path);

      if (!reader)
        {
          _create_file_reader(self, event->full_path);
          msg_debug("Wildcard: file created", evt_tag_str("filename", event->full_path));
        }
      else
        {
          if (wildcard_file_reader_is_deleted(reader))
            {
              msg_info("File is deleted, new file create with same name. "
                       "While old file is reading, skip the new one",
                       evt_tag_str("filename", event->full_path));
              pending_file_list_add(self->waiting_list, event->full_path);
            }
          else if (!log_pipe_init(&reader->super.super))
            {
              msg_error("Can not re-initialize reader for file",
                        evt_tag_str("filename", event->full_path));
            }
          else
            {
              msg_debug("Wildcard: file reader reinitialized", evt_tag_str("filename", event->full_path));
            }
        }
    }
}
Пример #6
0
gchar *
value_pairs_transform_set_apply(ValuePairsTransformSet *vpts, gchar *key)
{
  if (g_pattern_match_string(vpts->pattern, key))
    {
      GList *l;
      SBGString *sb;
      gchar *new_key;

      sb = sb_gstring_acquire ();
      g_string_assign(sb_gstring_string(sb), key);

      l = vpts->transforms;
      while (l)
        {
          value_pairs_transform_apply((ValuePairsTransform *)l->data, sb);
          l = l->next;
        }

      new_key = sb_gstring_string(sb)->str;
      g_string_steal(sb_gstring_string(sb));
      sb_gstring_release (sb);

      return new_key;
    }
  return g_strdup(key);
}
Пример #7
0
void
search_foreach(playlist_t * pl, GPatternSpec * pattern, GtkTreeIter * list_iter, int album_node) {

    char text[MAXLEN];
    char * tmp = NULL;
    playlist_data_t * pldata;

    gtk_tree_model_get(GTK_TREE_MODEL(pl->store), list_iter, PL_COL_DATA, &pldata, -1);
    if (album_node) {
        snprintf(text, MAXLEN-1, "%s: %s", pldata->artist, pldata->album);
    } else {
        playlist_data_get_display_name(text, pldata);
    }

    if (casesens) {
        tmp = strdup(text);
    } else {
        tmp = g_utf8_strup(text, -1);
    }

    if (g_pattern_match_string(pattern, tmp)) {

        GtkTreeIter iter;
        GtkTreePath * path;

        path = gtk_tree_model_get_path(GTK_TREE_MODEL(pl->store), list_iter);
        gtk_list_store_append(search_store, &iter);
        gtk_list_store_set(search_store, &iter, 0, text,
                           1, (gpointer)path, 2, pl->name, 3, (gpointer)pl, -1);
    }

    g_free(tmp);
}
Пример #8
0
GList *
nautilus_directory_match_pattern (NautilusDirectory *directory, const char *pattern)
{
	GList *files, *l, *ret;
	GPatternSpec *spec;


	ret = NULL;
	spec = g_pattern_spec_new (pattern);
	
	files = nautilus_directory_get_file_list (directory);
	for (l = files; l; l = l->next) {
		NautilusFile *file;
		char *name;
	       
	        file = NAUTILUS_FILE (l->data);
		name = nautilus_file_get_display_name (file);

		if (g_pattern_match_string (spec, name)) {
			ret = g_list_prepend(ret, nautilus_file_ref (file));	
		}

		g_free (name);
	}

	g_pattern_spec_free (spec);
	nautilus_file_list_free (files);

	return ret;
}
Пример #9
0
static GList *
games_file_list_new_internal (const gchar * glob, va_list path)
{
  GPatternSpec *filespec = g_pattern_spec_new (glob);
  gchar *pathelement;
  GList *list = NULL;
  GDir *dir;
  const gchar *filename;
  gchar *fullname;

  while ((pathelement = va_arg (path, gchar *)) != NULL) {
    dir = g_dir_open (pathelement, 0, NULL);
    if (dir != NULL) {
      while ((filename = g_dir_read_name (dir)) != NULL) {
	if (g_pattern_match_string (filespec, filename)) {
	  fullname = g_build_filename (pathelement, filename, NULL);
	  if (g_file_test (fullname, G_FILE_TEST_IS_REGULAR)) {
	    list = g_list_append (list, fullname);
	  } else
	    g_free (fullname);
	}
      }
      g_dir_close (dir);
    }
  }

  g_pattern_spec_free (filespec);

  return list;
}
Пример #10
0
static gboolean filter_tag(tagEntry *entry, GPatternSpec *name, gboolean declaration, gboolean case_sensitive)
{
	gboolean filter = TRUE;
	gchar *entry_name;

	if (!EMPTY(entry->kind))
	{
		gboolean is_prototype;

		is_prototype = g_strcmp0(entry->kind, "prototype") == 0;
		filter = (declaration && !is_prototype) || (!declaration && is_prototype);
		if (filter)
			return TRUE;
	}

	if (case_sensitive)
		entry_name = g_strdup(entry->name);
	else
		entry_name = g_utf8_strdown(entry->name, -1);

	filter = !g_pattern_match_string(name, entry_name);

	g_free(entry_name);

	return filter;
}
Пример #11
0
/*
 * Return policy for given context based on the otr_policy /setting
 */
static OtrlPolicy ops_policy (void *opdata, ConnContext *context)
{
	struct co_info *coi = context->app_data;
	char *server = strchr (context->accountname, '@') + 1;
	OtrlPolicy op = IO_DEFAULT_OTR_POLICY;
	GSList *pl;
	char fullname[1024];

	g_snprintf (fullname, sizeof(fullname), "%s@%s", context->username, server);

	/* loop through otr_policy */

	if (plistunknown)
	{
		pl = plistunknown;
		do
		{
			struct plistentry *ple = pl->data;

			if (g_pattern_match_string (ple->namepat, fullname))
				op = ple->policy;

		} while ((pl = g_slist_next (pl)));
	}

	if (plistknown && context->fingerprint_root.next)
	{
		pl = plistknown;

		/* loop through otr_policy_known */

		do
		{
			struct plistentry *ple = pl->data;

			if (g_pattern_match_string (ple->namepat, fullname))
				op = ple->policy;

		} while ((pl = g_slist_next (pl)));
	}

	if (coi && coi->finished && (op == OTRL_POLICY_OPPORTUNISTIC || op == OTRL_POLICY_ALWAYS))
		op = OTRL_POLICY_MANUAL | OTRL_POLICY_WHITESPACE_START_AKE;
	return op;
}
Пример #12
0
gboolean patterns_match(GSList *patterns, const gchar *str)
{
	GSList *elem;
	foreach_slist (elem, patterns)
	{
		GPatternSpec *pattern = elem->data;
		if (g_pattern_match_string(pattern, str))
			return TRUE;
	}
Пример #13
0
gboolean patterns_match(GSList *patterns, const gchar *str)
{
	GSList *elem;
	for (elem = patterns; elem != NULL; elem = g_slist_next(elem))
	{
		GPatternSpec *pattern = elem->data;
		if (g_pattern_match_string(pattern, str))
			return TRUE;
	}
	return FALSE;
}
Пример #14
0
static void find_file_recursive(GtkTreeIter *iter, gboolean case_sensitive, gboolean full_path, GPatternSpec *pattern)
{
	GtkTreeModel *model = GTK_TREE_MODEL(s_file_store);
	GtkTreeIter child;
	gboolean iterate;

	iterate = gtk_tree_model_iter_children(model, &child, iter);
	if (iterate)
	{
		while (iterate)
		{
			find_file_recursive(&child, case_sensitive, full_path, pattern);
			iterate = gtk_tree_model_iter_next(model, &child);
		}
	}
	else
	{
		gchar *utf8_name;

		if (iter == NULL)
			return;

		if (full_path)
		{
			gchar *utf8_path, *utf8_base_path;

			utf8_path = build_path(iter);
			utf8_base_path = get_project_base_path();
			utf8_name = get_relative_path(utf8_base_path, utf8_path);
			g_free(utf8_path);
			g_free(utf8_base_path);
		}
		else
			gtk_tree_model_get(GTK_TREE_MODEL(model), iter, FILEVIEW_COLUMN_NAME, &utf8_name, -1);

		if (!case_sensitive)
			SETPTR(utf8_name, g_utf8_strdown(utf8_name, -1));

		if (g_pattern_match_string(pattern, utf8_name))
		{
			gchar *utf8_base_path = get_project_base_path();
			gchar *utf8_path, *rel_path;

			utf8_path = build_path(iter);
			rel_path = get_relative_path(utf8_base_path, utf8_path);
			msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s", rel_path ? rel_path : utf8_path);
			g_free(utf8_path);
			g_free(rel_path);
			g_free(utf8_base_path);
		}

		g_free(utf8_name);
	}
}
Пример #15
0
static gboolean to_ignore(const char *filename, GPatternSpec **patterns)
{
        int i;
        if(patterns==NULL) {
                return FALSE;
        }
        for(i=0; patterns[i]!=NULL; i++) {
                if(g_pattern_match_string(patterns[i], filename))
                        return TRUE;
        }
        return FALSE;
}
Пример #16
0
/*
 * gst_validate_runner_get_reporting_level_for_name:
 *
 * Returns: the #GstValidateReportingDetails that will be applied for a given name.
 * If no pattern was set for such a name, this function will return
 * #GST_VALIDATE_SHOW_UNKNOWN, and reporting for that name will
 * default to the global reporting level.
 */
GstValidateReportingDetails
gst_validate_runner_get_reporting_level_for_name (GstValidateRunner * runner,
    const gchar * name)
{
  GList *tmp;

  for (tmp = runner->priv->report_pattern_levels; tmp; tmp = tmp->next) {
    PatternLevel *pattern_level = (PatternLevel *) tmp->data;
    if (g_pattern_match_string (pattern_level->pattern, name))
      return pattern_level->level;
  }

  return GST_VALIDATE_SHOW_UNKNOWN;
}
Пример #17
0
gboolean
g_pattern_match_simple (const gchar *pattern,
			const gchar *string)
{
  GPatternSpec *pspec;
  gboolean ergo;

  g_return_val_if_fail (pattern != NULL, FALSE);
  g_return_val_if_fail (string != NULL, FALSE);

  pspec = g_pattern_spec_new (pattern);
  ergo = g_pattern_match_string (pspec, string);
  g_pattern_spec_free (pspec);

  return ergo;
}
Пример #18
0
static gboolean match(TMTag *tag, const gchar *name, gboolean declaration, gboolean case_sensitive,
	MatchType match_type, GPatternSpec *pspec, gchar *utf8_path)
{
	const gint forward_types = tm_tag_prototype_t | tm_tag_externvar_t;
	gboolean matches = FALSE;
	gint type;

	type = declaration ? forward_types : tm_tag_max_t - forward_types;
	matches = tag->type & type;

	if (matches)
	{
		gchar *name_case;

		if (case_sensitive)
			name_case = g_strdup(tag->name);
		else
			name_case = g_utf8_strdown(tag->name, -1);

		switch (match_type)
		{
			case MATCH_FULL:
				matches = g_strcmp0(name_case, name) == 0;
				break;
			case MATCH_PATTERN:
				matches = g_pattern_match_string(pspec, name_case);
				break;
			case MATCH_PREFIX:
				matches = g_str_has_prefix(name_case, name);
				break;
		}
		g_free(name_case);
	}

	if (matches && utf8_path)
	{
		gchar *utf8_file_name = utils_get_utf8_from_locale(tag->file->file_name);
		gchar *relpath;

		relpath = get_relative_path(utf8_path, utf8_file_name);
		matches = relpath != NULL;
		g_free(relpath);
		g_free(utf8_file_name);
	}

	return matches;
}
Пример #19
0
/* Override vanilla g_log() to take $Msg_filter into account.
 * Cannot use #GLogFunc:s because mafw-log may (and should) be active. */
void g_log(const gchar *domain, GLogLevelFlags level, const gchar *fmt, ...)
{
	guint i;
	va_list args;

	/* Change the level of the message to G_LOG_LEVEL_INFO if it matches
	 * any of $Msg_filters.  It only makes sense if the level is above. */
	if (Msg_filters && (level & (G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING
		     | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR))) {
		for (i = 0; i < Msg_filters->len; i++)
			if (g_pattern_match_string(Msg_filters->pdata[i], fmt)){
				level &= ~G_LOG_LEVEL_MASK;
				level |=  G_LOG_LEVEL_INFO;
				break;
			}
	}

	va_start(args, fmt);
	g_logv(domain, level, fmt, args);
	va_end(args);
}
Пример #20
0
static void engine_scan_dir(gchar * dir)
{
    GDir * d;
    d = g_dir_open(dir,0,NULL);
    if (d)
    {
        gchar * n;
        GPatternSpec * ps;
        ps = g_pattern_spec_new("lib*.so");
        while ((n = (gchar *) g_dir_read_name(d)))
        {
            if (g_pattern_match_string(ps,n))
            {
                gchar * dln = g_strjoin("/",dir,n,NULL);
                append_engine(dln);
            }
        }
        g_pattern_spec_free(ps);
        g_dir_close(d);
    }
}
static char *
find_file_with_pattern (const char *dir, const char *pattern)
{
	GDir *filedir;
	char *found_filename;
	const char *filename;
	GPatternSpec *pat;

	filedir = g_dir_open (dir, 0, NULL);
	if (filedir == NULL)
		return NULL;

	pat = g_pattern_spec_new (pattern);
	if (pat == NULL)
	{
		g_dir_close (filedir);
		return NULL;
	}

	found_filename = NULL;

	while ((filename = g_dir_read_name (filedir)))
	{
		if (g_pattern_match_string (pat, filename))
		{
			char *tmp = g_build_filename (dir, filename, NULL);
			if (is_owned_by_user_and_socket (tmp))
				found_filename = g_strdup (filename);
			g_free (tmp);
		}

		if (found_filename != NULL)
			break;
	}

	g_pattern_spec_free (pat);
	g_dir_close (filedir);

	return found_filename;
}
Пример #22
0
GList* get_files_by_pattern(const gchar* dirpath, FcitxSubConfigPattern* pattern, int index)
{
    GList* result = NULL;

    DIR* dir = opendir(dirpath);
    if (!dir)
        return result;

    gchar* filter = pattern->patternlist[index];

    struct dirent* drt;
    GPatternSpec * patternspec = g_pattern_spec_new(filter);
    while ((drt = readdir(dir)) != NULL) {
        if (strcmp(drt->d_name , ".") == 0 || strcmp(drt->d_name, "..") == 0)
            continue;

        if (!g_pattern_match_string(patternspec, drt->d_name))
            continue;

        if (pattern->patternlist[index + 1] == 0) {
            char *path;
            asprintf(&path, "%s/%s", dirpath, drt->d_name);
            struct stat statbuf;
            if (stat(path, &statbuf) == 0) {
                result = g_list_append(result, realpath(path, NULL));
            }
            free(path);
        } else {
            char *path;
            asprintf(&path, "%s/%s", dirpath, drt->d_name);
            GList* r = get_files_by_pattern(path, pattern, index + 1);
            result = g_list_concat(result, r);
            free(path);
        }
    }

    closedir(dir);
    g_pattern_spec_free(patternspec);
    return result;
}
Пример #23
0
Vector<String> listDirectory(const String& path, const String& filter)
{
    Vector<String> entries;

    GUniquePtr<gchar> filename = unescapedFilename(path);
    if (!filename)
        return entries;

    GUniquePtr<GDir> dir(g_dir_open(filename.get(), 0, nullptr));
    if (!dir)
        return entries;

    GUniquePtr<GPatternSpec> pspec(g_pattern_spec_new((filter.utf8()).data()));
    while (const char* name = g_dir_read_name(dir.get())) {
        if (!g_pattern_match_string(pspec.get(), name))
            continue;

        GUniquePtr<gchar> entry(g_build_filename(filename.get(), name, nullptr));
        entries.append(filenameToString(entry.get()));
    }

    return entries;
}
Пример #24
0
/**
 * file_plugin_proxy_detect:
 * @filename: File information.
 * @only_name: Whether only name should be used for detection (otherwise
 *             trying to open the file is allowed).  Note this parameter is
 *             formal, as the proxy always decides only on filename basis.
 * @name: Plug-in name (i.e. file-detection function) to run.
 *
 * The plug-in proxy itself.  Emulates filetype detection based on file
 * name glob given by the plug-in during registration.
 *
 * Returns: The score (as defined in gwyddion filetype module interface).
 **/
static gint
file_plugin_proxy_detect(const GwyFileDetectInfo *fileinfo,
                         G_GNUC_UNUSED gboolean only_name,
                         const gchar *name)
{
    FilePluginInfo *info;
    gint i, max;

    gwy_debug("called as %s with file `%s'", name, fileinfo->name);
    if (!(info = file_find_plugin(name, GWY_FILE_OPERATION_MASK)))
        return 0;

    max = G_MININT;
    for (i = 0; info->pattern[i]; i++) {
        if (info->specificity[i] > max
            && g_pattern_match_string(info->pattern[i], fileinfo->name))
            max = info->specificity[i];
    }
    if (max == G_MININT)
        return 0;

    return CLAMP(max, 1, 40);
}
Пример #25
0
/**
 * gtk_accel_map_foreach:
 * @data: (allow-none): data to be passed into @foreach_func
 * @foreach_func: (scope call): function to be executed for each accel
 *                map entry which is not filtered out
 *
 * Loops over the entries in the accelerator map whose accel path 
 * doesn’t match any of the filters added with gtk_accel_map_add_filter(), 
 * and execute @foreach_func on each. The signature of @foreach_func is 
 * that of #GtkAccelMapForeach, the @changed parameter indicates whether
 * this accelerator was changed during runtime (thus, would need
 * saving during an accelerator map dump).
 */
void
gtk_accel_map_foreach (gpointer           data,
		       GtkAccelMapForeach foreach_func)
{
  GSList *entries, *slist, *node;

  g_return_if_fail (foreach_func != NULL);

  entries = g_hash_table_slist_values (accel_entry_ht);
  for (slist = entries; slist; slist = slist->next)
    {
      AccelEntry *entry = slist->data;
      gboolean changed = entry->accel_key != entry->std_accel_key || entry->accel_mods != entry->std_accel_mods;

      for (node = accel_filters; node; node = node->next)
	if (g_pattern_match_string (node->data, entry->accel_path))
	  goto skip_accel;
      foreach_func (data, entry->accel_path, entry->accel_key, entry->accel_mods, changed);
    skip_accel:
      /* noop */;
    }
  g_slist_free (entries);
}
Пример #26
0
static void swap_clean (void)
{
  const gchar  *swap_dir = gegl_swap_dir ();
  GDir         *dir;

  if (! swap_dir)
    return;

  dir = g_dir_open (gegl_swap_dir (), 0, NULL);

  if (dir != NULL)
    {
      GPatternSpec *pattern = g_pattern_spec_new ("*");
      const gchar  *name;

      while ((name = g_dir_read_name (dir)) != NULL)
        {
          if (g_pattern_match_string (pattern, name))
            {
              gint readpid = atoi (name);

              if (!pid_is_running (readpid))
                {
                  gchar *fname = g_build_filename (gegl_swap_dir (),
                                                   name,
                                                   NULL);
                  g_unlink (fname);
                  g_free (fname);
                }
            }
         }

      g_pattern_spec_free (pattern);
      g_dir_close (dir);
    }
}
Пример #27
0
static gboolean try_swap_header_source(gchar *file_name, gboolean is_header, GSList *file_list, GSList *header_patterns, GSList *source_patterns)
{
	gchar *name_pattern;
	gchar *base_name = NULL;
	GSList *elem;
	GPatternSpec *pattern;
	gboolean found = FALSE;

	name_pattern = g_path_get_basename(file_name);
	setptr(name_pattern, utils_remove_ext_from_filename(name_pattern));
	setptr(name_pattern, g_strconcat(name_pattern, ".*", NULL));
	pattern = g_pattern_spec_new(name_pattern);
	g_free(name_pattern);

	for (elem = file_list; elem != NULL; elem = g_slist_next(elem))
	{
		gchar *full_name = elem->data;
		base_name = g_path_get_basename(full_name);

		if (g_pattern_match_string(pattern, base_name) &&
		    gprj_project_is_in_project(full_name))
		{
			if ((is_header && patterns_match(source_patterns, base_name)) ||
				(!is_header && patterns_match(header_patterns, base_name)))
			{
				open_file(full_name);
				found = TRUE;
				break;
			}
		}
	}

	g_free(base_name);
	g_pattern_spec_free(pattern);
	return found;
}
Пример #28
0
/*! \brief Find all symbols matching a pattern.
 *
 *  \par Function Description
 *  Searches the library, returning all symbols whose
 *  names match \a pattern.
 *
 *  Two search modes are available: \b CLIB_EXACT, where \a pattern is
 *  compared to the symbol name using strcmp(), and \b CLIB_GLOB,
 *  where \a pattern is assumed to be a glob pattern (see the GLib
 *  documentation for details of the glob syntax applicable).
 *
 *  \warning The #CLibSymbol instances in the \b GList returned belong
 *  to the component library, and should be considered constants; they
 *  should not be manipulated or free()'d.  On the other hand, the \b
 *  GList returned must be freed with \b g_list_free() when no longer
 *  needed.  Note that the values returned will be invalidated by a
 *  call to s_clib_free() or s_clib_refresh().
 *
 *  \param pattern The pattern to match against.
 *  \param mode    The search mode to use.
 *  \return A \b GList of matching #CLibSymbol structures.
 */
GList *s_clib_search (const gchar *pattern, const CLibSearchMode mode)
{
  GList *sourcelist;
  GList *symlist;
  GList *result = NULL;
  CLibSource *source;
  CLibSymbol *symbol;
  GPatternSpec *globpattern = NULL;
  gchar *key;
  gchar keytype;

  if (pattern == NULL) return NULL;

  /* Use different cache keys depending on what sort of search is being done */
  switch (mode)
    {
    case CLIB_GLOB:
      keytype = 'g';
      break;
    case CLIB_EXACT:
      keytype = 's';
      break;
    default:
      g_critical ("s_clib_search: Bad search mode %1$i\n", mode);
      return NULL;
    }
  key = g_strdup_printf("%c%s", keytype, pattern);

  /* Check to see if the query is already in the cache */
  result = (GList *) g_hash_table_lookup (clib_search_cache, key);
  if (result != NULL) {
    g_free (key);
    return g_list_copy (result);
  }

  if (mode == CLIB_GLOB) {
    globpattern = g_pattern_spec_new(pattern);
  }

  for (sourcelist = clib_sources;
       sourcelist != NULL;
       sourcelist = g_list_next(sourcelist)) {

    source = (CLibSource *) sourcelist->data;

    for (symlist = source->symbols;
	 symlist != NULL;
	 symlist = g_list_next(symlist)) {

      symbol = (CLibSymbol *) symlist->data;

      switch (mode)
	{
	case CLIB_EXACT:
	  if (strcmp (pattern, symbol->name) == 0) {
	    result = g_list_prepend (result, symbol);
	  }
	  break;
	case CLIB_GLOB:
	  if (g_pattern_match_string (globpattern, symbol->name)) {
	    result = g_list_prepend (result, symbol);
	  }
	  break;
	}
    }
  }

  result = g_list_reverse (result);

  if (globpattern != NULL) {
    g_pattern_spec_free (globpattern);
  }

  g_hash_table_insert (clib_search_cache, key, g_list_copy (result));
  /* __don't__ free key here, it's stored by the hash table! */

  return result;
}
Пример #29
0
void
gegl_exit (void)
{
  glong timing = gegl_ticks ();

  gegl_tile_storage_cache_cleanup ();
  gegl_tile_cache_destroy ();
  gegl_operation_gtype_cleanup ();
  gegl_extension_handler_cleanup ();

  if (module_db != NULL)
    {
      g_object_unref (module_db);
      module_db = NULL;
    }

  babl_exit ();

  timing = gegl_ticks () - timing;
  gegl_instrument ("gegl", "gegl_exit", timing);

  /* used when tracking buffer and tile leaks */
  if (g_getenv ("GEGL_DEBUG_BUFS") != NULL)
    {
      gegl_buffer_stats ();
      gegl_tile_backend_ram_stats ();
      gegl_tile_backend_file_stats ();
#if HAVE_GIO
      gegl_tile_backend_tiledir_stats ();
#endif
    }
  global_time = gegl_ticks () - global_time;
  gegl_instrument ("gegl", "gegl", global_time);

  if (g_getenv ("GEGL_DEBUG_TIME") != NULL)
    {
      g_printf ("\n%s", gegl_instrument_utf8 ());
    }

  if (gegl_buffer_leaks ())
    g_printf ("  buffer-leaks: %i\n", gegl_buffer_leaks ());
  gegl_tile_cache_destroy ();

  if (gegl_swap_dir ())
    {
      /* remove all files matching <$GEGL_SWAP>/GEGL-<pid>-*.swap */

      guint         pid     = getpid ();
      GDir         *dir     = g_dir_open (gegl_swap_dir (), 0, NULL);

      gchar        *glob    = g_strdup_printf ("%i-*", pid);
      GPatternSpec *pattern = g_pattern_spec_new (glob);
      g_free (glob);

      if (dir != NULL)
        {
          const gchar *name;

          while ((name = g_dir_read_name (dir)) != NULL)
            {
              if (g_pattern_match_string (pattern, name))
                {
                  gchar *fname = g_build_filename (gegl_swap_dir (),
                                                   name,
                                                   NULL);
                  g_unlink (fname);
                  g_free (fname);
                }
            }

          g_dir_close (dir);
        }

      g_pattern_spec_free (pattern);
    }
  g_object_unref (config);
  config = NULL;
}
Пример #30
0
/* Funcion loadDispatcher
 * Precondiciones:
 * Postcondiciones:
 * Entrada:
 * Salida:
 * Proceso:
 * */
gpointer
loadDispatcher					(gpointer data)
{
	ThreadData* tData;
	Message* msg;
	Plugin* plugin;
	RoutingEntry* entry;
	GData** dPlugins;
	GAsyncQueue* qMessages;
	gint tableLength, i;

	GError* ioError;
	gchar** funcError;
	
	tData = data;
	dPlugins = tData->dPlugins;
	qMessages = tData->qMessages;
	tableLength = g_queue_get_length(routingTable);
	
	/* Now the dispatcher is fully functional. */
	g_debug("Dispatcher up & running");

	/* Keeps sending data */
	while (dPlugins != NULL)
	{
		/* Gets a new message to dispatch.
		 * Trying to pop a message is actually more efficient than
		 * search for at least one element in the queue.
		 * */
		if ((msg = (Message*)g_async_queue_try_pop(qMessages)) != NULL)
		{	
			/* Chooses a default plugin using the original message protocol. */
			plugin = g_datalist_get_data(dPlugins, msg->proto);
			
			/* Checks if the message has already reached its destination.
			 * - If it has, it will be logged into a file.
			 * - If it has not reached its destination and there is not a
			 *   'route' defined for it, dispatch.
			 * - If it has not reached its destination and there is a
			 *   'route' defined for it, dispatch it through that way.
			 * */
			if (g_str_equal(msg->dest, plugin->pluginAddress()))
			{
				ioError = NULL;
				
				/* Write to disk cache. */
				if (!((g_io_channel_write_chars(msgLog,
						g_strconcat(msg->proto, DELIMITER, msg->src, DELIMITER, msg->data, EOL, NULL),
						-1, NULL,
						&ioError) == (G_IO_STATUS_ERROR | G_IO_STATUS_AGAIN)) &&
					(g_io_channel_flush(msgLog,
						&ioError) == (G_IO_STATUS_ERROR | G_IO_STATUS_AGAIN))))
				{
					if (ioError != NULL)
					{
						g_warning("%s: %s", CANNOTWRITEDATA, ioError->message);
					}
					else
					{
						g_warning("%s: %s", CANNOTWRITEDATA, NOERRORAVAILABLE);
					}
				}
				else
				{
					g_debug(MSGWRITEONLOG);
				}
			}
			else
			{	
				i = 0;
				
				/* Search for a route in the route table. */
				while (i < tableLength)
				{
					entry = g_queue_peek_nth(routingTable, i);
					
					if (g_str_equal(entry->msgProto, msg->proto) &&
						g_pattern_match_string(entry->msgAddrPattern, msg->dest))
					{
						plugin = g_datalist_get_data(dPlugins, entry->destProto);
						i = tableLength;	
					}
					else
					{
						i++;
					}
				}

				if (!plugin->pluginSend((gpointer)msg->dest, (gpointer)msg, funcError))
				{
					g_warning("%s: %s", CANNOTSENDDATA, *funcError);
				}		
			}
		}
		else
		{
			g_usleep(WAITPERIOD);
		}
	}

	g_debug("End dispatching process");
	return (NULL);
}