<commit_before>/* GXK - Gtk+ Extension Kit
 * Copyright (C) 2003 <NAME>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include "gxkaction.h"
#include <string.h>
#include <libintl.h>


#define intern_null_string(s,sconst)      (s ? (sconst ? g_intern_static_string : g_intern_string) (s) : NULL)
#define intern_i18n_string(idom,s,sconst) (intern_null_string (idom && s ? dgettext (idom, s) : s, sconst))


/* --- action class ---- */
typedef struct {
  GxkActionCheck  acheck;
  GxkActionExec   aexec;
  gpointer        user_data;
  GxkActionGroup *agroup;
  guint           class_flags;
  /* non-key fields */
  guint           ref_count;
} ActionClass;
static GHashTable *action_class_ht = NULL;

static gboolean
action_class_equals (gconstpointer v1,
                     gconstpointer v2)
{
  const ActionClass *c1 = v1;
  const ActionClass *c2 = v2;
  return (c1->acheck      == c2->acheck &&
          c1->aexec       == c2->aexec &&
          c1->user_data   == c2->user_data &&
          c1->agroup      == c2->agroup &&
          c1->class_flags == c2->class_flags);
}

static guint
action_class_hash (gconstpointer v)
{
  const ActionClass *c = v;
  return (G_HASH_POINTER (c->acheck) ^
          G_HASH_POINTER (c->aexec) ^
          G_HASH_POINTER (c->user_data) ^
          G_HASH_POINTER (c->agroup) ^
          c->class_flags);
}

static ActionClass*
action_class_ref_new (GxkActionCheck  acheck,
                      GxkActionExec   aexec,
                      gpointer        user_data,
                      GxkActionGroup *agroup,
                      guint           class_flags)
{
  ActionClass key, *c;
  key.acheck = acheck;
  key.aexec = aexec;
  key.user_data = user_data;
  key.agroup = agroup;
  key.class_flags = class_flags;
  c = g_hash_table_lookup (action_class_ht, &key);
  if (!c)
    {
      key.agroup = agroup ? g_object_ref (agroup) : NULL;
      key.ref_count = 1;
      c = g_memdup (&key, sizeof (key));
      g_hash_table_insert (action_class_ht, c, c);
    }
  else
    c->ref_count++;
  return c;
}

static ActionClass*
action_class_ref (ActionClass *aclass)
{
  g_return_val_if_fail (aclass->ref_count > 0, NULL);
  aclass->ref_count++;
  return aclass;
}

static void
action_class_unref (ActionClass *aclass)
{
  g_return_if_fail (aclass->ref_count > 0);
  aclass->ref_count--;
  if (!aclass->ref_count)
    {
      g_hash_table_remove (action_class_ht, aclass);
      if (aclass->agroup)
        g_object_unref (aclass->agroup);
      g_free (aclass);
    }
}


/* --- action list --- */
typedef struct {
  ActionClass   *klass;
  const gchar   *key;
  GxkStockAction action;
  GSList        *widgets;
} ActionEntry;
static GQuark quark_action_entry = 0;

struct GxkActionList {
  guint           n_entries;
  ActionEntry   **entries;
  GxkActionGroup *agroup;
};

static void
action_list_add (GxkActionList        *alist,
                 ActionClass          *klass,
                 gboolean              sconst,
                 const gchar          *key,
                 const GxkStockAction *action,
                 const gchar          *i18n_domain)
{
  ActionEntry *entry = g_new (ActionEntry, 1);
  guint j;
  entry->klass = action_class_ref (klass);
  entry->key = g_intern_string (key);
  entry->action = *action;
  entry->action.name = intern_i18n_string (i18n_domain, action->name, sconst);
  entry->action.accelerator = intern_null_string (action->accelerator, sconst);
  entry->action.tooltip = intern_i18n_string (i18n_domain, action->tooltip, sconst);
  entry->action.stock_icon = intern_null_string (action->stock_icon, sconst);
  entry->widgets = NULL;
  j = alist->n_entries++;
  alist->entries = g_renew (ActionEntry*, alist->entries, alist->n_entries);
  alist->entries[j] = entry;
}

static void
action_entry_free (ActionEntry *entry)
{<commit_msg>cosmetics<commit_after>/* GXK - Gtk+ Extension Kit
 * Copyright (C) 2003 <NAME>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include "gxkaction.h"
#include <string.h>
#include <libintl.h>


#define intern_null_string(s,sconst)      (s ? (sconst ? g_intern_static_string : g_intern_string) (s) : NULL)
#define intern_i18n_string(idom,s,sconst) (intern_null_string (idom && s ? dgettext (idom, s) : s, sconst))


/* --- action class ---- */
typedef struct {
  GxkActionCheck  acheck;
  GxkActionExec   aexec;
  gpointer        user_data;
  GxkActionGroup *agroup;
  guint           class_flags;
  /* non-key fields */
  guint           ref_count;
} ActionClass;
static GHashTable *action_class_ht = NULL;

static gboolean
action_class_equals (gconstpointer v1,
                     gconstpointer v2)
{
  const ActionClass *c1 = v1;
  const ActionClass *c2 = v2;
  return (c1->acheck      == c2->acheck &&
          c1->aexec       == c2->aexec &&
          c1->user_data   == c2->user_data &&
          c1->agroup      == c2->agroup &&
          c1->class_flags == c2->class_flags);
}

static guint
action_class_hash (gconstpointer v)
{
  const ActionClass *c = v;
  return (G_HASH_POINTER (c->acheck) ^
          G_HASH_POINTER (c->aexec) ^
          G_HASH_POINTER (c->user_data) ^
          G_HASH_POINTER (c->agroup) ^
          c->class_flags);
}

static ActionClass*
action_class_ref_new (GxkActionCheck  acheck,
                      GxkActionExec   aexec,
                      gpointer        user_data,
                      GxkActionGroup *agroup,
                      guint           class_flags)
{
  ActionClass key, *c;
  key.acheck = acheck;
  key.aexec = aexec;
  key.user_data = user_data;
  key.agroup = agroup;
  key.class_flags = class_flags;
  c = g_hash_table_lookup (action_class_ht, &key);
  if (!c)
    {
      key.agroup = agroup ? g_object_ref (agroup) : NULL;
      key.ref_count = 1;
      c = g_memdup (&key, sizeof (key));
      g_hash_table_insert (action_class_ht, c, c);
    }
  else
    c->ref_count++;
  return c;
}

static ActionClass*
action_class_ref (ActionClass *aclass)
{
  g_return_val_if_fail (aclass->ref_count > 0, NULL);
  aclass->ref_count++;
  return aclass;
}

static void
action_class_unref (ActionClass *aclass)
{
  g_return_if_fail (aclass->ref_count > 0);
  aclass->ref_count--;
  if (!aclass->ref_count)
    {
      g_hash_table_remove (action_class_ht, aclass);
      if (aclass->agroup)
        g_object_unref (aclass->agroup);
      g_free (aclass);
    }
}


/* --- action list --- */
typedef struct {
  ActionClass   *klass;
  const gchar   *key;
  GxkStockAction action;
  GSList        *widgets;
} ActionEntry;
static GQuark quark_action_entry = 0;

struct GxkActionList {
  guint           n_entries;
  ActionEntry   **entries;
  GxkActionGroup *agroup;
};

static void
action_list_add (GxkActionList        *alist,
                 ActionClass          *klass,
                 gboolean              sconst,
                 const gchar          *key,
                 const GxkStockAction *action,
                 const gchar          *i18n_domain)
{
  ActionEntry *entry = g_new0 (ActionEntry, 1);
  entry->klass = action_class_ref (klass);
  entry->key = g_intern_string (key);
  entry->action = *action;
  entry->action.name = intern_i18n_string (i18n_domain, action->name, sconst);
  entry->action.accelerator = intern_null_string (action->accelerator, sconst);
  entry->action.tooltip = intern_i18n_string (i18n_domain, action->tooltip, sconst);
  entry->action.stock_icon = intern_null_string (action->stock_icon, sconst);
  entry->widgets = NULL;
  guint j = alist->n_entries++;
  alist->entries = g_renew (ActionEntry*, alist->entries, alist->n_entries);
  alist->entries[j] = entry;
}

static void
action_entry_free (ActionEntry *entry)
{
{'fraction_non_alphanumeric': 0.10551372896368467, 'fraction_numerical': 0.01162533215234721, 'mean_word_length': 2.7826633165829144, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7287347', 'n_tokens_mistral': 3110, 'n_tokens_neox': 3018, 'n_words': 787}