<commit_before>/*
 * peas-plugin-info.c
 * This file is part of libpeas
 *
 * Copyright (C) 2002-2005 - <NAME>
 * Copyright (C) 2007 - <NAME>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Library 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 Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library 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.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>
#include <glib.h>

#include "peas-i18n.h"
#include "peas-plugin-info-priv.h"

/**
 * SECTION:peas-plugin-info
 * @short_description: Information about a plugin.
 *
 * A #PeasPluginInfo contains all the information available about a plugin.
 **/

PeasPluginInfo *
_peas_plugin_info_ref (PeasPluginInfo *info)
{
  g_atomic_int_inc (&info->refcount);
  return info;
}

void
_peas_plugin_info_unref (PeasPluginInfo *info)
{
  if (!g_atomic_int_dec_and_test (&info->refcount))
    return;

  if (info->keys != NULL)
    g_hash_table_destroy (info->keys);
  g_free (info->file);
  g_free (info->module_dir);
  g_free (info->data_dir);
  g_free (info->module_name);
  g_strfreev (info->dependencies);
  g_free (info->name);
  g_free (info->desc);
  g_free (info->icon_name);
  g_free (info->website);
  g_free (info->copyright);
  g_free (info->loader);
  g_free (info->version);
  g_strfreev (info->authors);

  g_free (info);
}

/**
 * peas_plugin_info_get_type:
 *
 * Retrieves the #GType object which is associated with the #PeasPluginInfo
 * class.
 *
 * Return value: the GType associated with #PeasPluginInfo.
 **/
GType
peas_plugin_info_get_type (void)
{
  static GType the_type = 0;

  if (G_UNLIKELY (!the_type))
    the_type = g_boxed_type_register_static ("PeasPluginInfo",
                                             (GBoxedCopyFunc) _peas_plugin_info_ref,
                                             (GBoxedFreeFunc) _peas_plugin_info_unref);

  return the_type;
}

static void
value_free (gpointer data)
{
  GValue *value = (GValue *) data;

  g_value_unset (value);
  g_free (value);
}

static void
parse_extra_keys (PeasPluginInfo   *info,
                  GKeyFile         *plugin_file,
                  const gchar      *section_header,
                  const gchar     **keys)
{
  guint i;

  for (i = 0; keys[i] != NULL; i++)
    {
      GValue *value = NULL;
      gboolean b;
      GError *error = NULL;

      if (g_str_equal (keys[i], "IAge") ||
          g_str_equal (keys[i], "Module") ||
          g_str_equal (keys[i], "Depends") ||
          g_str_equal (keys[i], "Loader") ||
          g_str_equal (keys[i], "Name") ||
          g_str_has_prefix (keys[i], "Name[") ||
          g_str_equal (keys[i], "Description") ||
          g_str_has_prefix (keys[i], "Description[") ||
          g_str_equal (keys[i], "Icon") ||
          g_str_equal (keys[i], "Authors") ||
          g_str_equal (keys[i], "Copyright") ||
          g_str_equal (keys[i], "Website") ||
          g_str_equal (keys[i], "Version"))
        continue;

      b = g_key_file_get_boolean (plugin_file, section_header, keys[i], &error);
      if (b == FALSE)
        {
          if (error != NULL)
            {
              gchar *str;
              g_error_free (error);
              error = NULL;
              str = g_key_file_get_string (plugin_file, section_header, keys[i], NULL);
              if (str != NULL)
                {
                  value = g_new0 (GValue, 1);
                  g_value_init (value, G_TYPE_STRING);
                  g_value_take_string (value, str);
                }
            }
          else
            {
              value = g_new0 (GValue, 1);
              g_value_init (value, G_TYPE_BOOLEAN);
              g_value_set_boolean (value, b);
            }<commit_msg>Fix loading TRUE value from the plugin info file<commit_after>/*
 * peas-plugin-info.c
 * This file is part of libpeas
 *
 * Copyright (C) 2002-2005 - <NAME>
 * Copyright (C) 2007 - <NAME>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Library 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 Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library 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.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>
#include <glib.h>

#include "peas-i18n.h"
#include "peas-plugin-info-priv.h"

/**
 * SECTION:peas-plugin-info
 * @short_description: Information about a plugin.
 *
 * A #PeasPluginInfo contains all the information available about a plugin.
 **/

PeasPluginInfo *
_peas_plugin_info_ref (PeasPluginInfo *info)
{
  g_atomic_int_inc (&info->refcount);
  return info;
}

void
_peas_plugin_info_unref (PeasPluginInfo *info)
{
  if (!g_atomic_int_dec_and_test (&info->refcount))
    return;

  if (info->keys != NULL)
    g_hash_table_destroy (info->keys);
  g_free (info->file);
  g_free (info->module_dir);
  g_free (info->data_dir);
  g_free (info->module_name);
  g_strfreev (info->dependencies);
  g_free (info->name);
  g_free (info->desc);
  g_free (info->icon_name);
  g_free (info->website);
  g_free (info->copyright);
  g_free (info->loader);
  g_free (info->version);
  g_strfreev (info->authors);

  g_free (info);
}

/**
 * peas_plugin_info_get_type:
 *
 * Retrieves the #GType object which is associated with the #PeasPluginInfo
 * class.
 *
 * Return value: the GType associated with #PeasPluginInfo.
 **/
GType
peas_plugin_info_get_type (void)
{
  static GType the_type = 0;

  if (G_UNLIKELY (!the_type))
    the_type = g_boxed_type_register_static ("PeasPluginInfo",
                                             (GBoxedCopyFunc) _peas_plugin_info_ref,
                                             (GBoxedFreeFunc) _peas_plugin_info_unref);

  return the_type;
}

static void
value_free (gpointer data)
{
  GValue *value = (GValue *) data;

  g_value_unset (value);
  g_free (value);
}

static void
parse_extra_keys (PeasPluginInfo   *info,
                  GKeyFile         *plugin_file,
                  const gchar      *section_header,
                  const gchar     **keys)
{
  guint i;

  for (i = 0; keys[i] != NULL; i++)
    {
      GValue *value = NULL;
      gboolean b;
      GError *error = NULL;

      if (g_str_equal (keys[i], "IAge") ||
          g_str_equal (keys[i], "Module") ||
          g_str_equal (keys[i], "Depends") ||
          g_str_equal (keys[i], "Loader") ||
          g_str_equal (keys[i], "Name") ||
          g_str_has_prefix (keys[i], "Name[") ||
          g_str_equal (keys[i], "Description") ||
          g_str_has_prefix (keys[i], "Description[") ||
          g_str_equal (keys[i], "Icon") ||
          g_str_equal (keys[i], "Authors") ||
          g_str_equal (keys[i], "Copyright") ||
          g_str_equal (keys[i], "Website") ||
          g_str_equal (keys[i], "Version"))
        continue;

      b = g_key_file_get_boolean (plugin_file, section_header, keys[i], &error);
      if (b == FALSE && error != NULL)
        {
          gchar *str;
          g_error_free (error);
          error = NULL;
          str = g_key_file_get_string (plugin_file, section_header, keys[i], NULL);
          if (str != NULL)
            {
              value = g_new0 (GValue, 1);
              g_value_init (value, G_TYPE_STRING);
              g_value_take_string (value, str);
            }
        }
      else
        {
          value = g_new0 (GValue, 1);
          g_value_init (value, G_TYPE_BOOLEAN);
          g_value_set_boolean (value, b);
{'fraction_non_alphanumeric': 0.11591471315820473, 'fraction_numerical': 0.00824596536694546, 'mean_word_length': 2.541927409261577, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2102864', 'n_tokens_mistral': 2876, 'n_tokens_neox': 2783, 'n_words': 765}