<commit_before>/*
 * GeeXboX Enna Media Center.
 * Copyright (C) 2005-2009 The Enna Project
 *
 * This file is part of Enna.
 *
 * Enna 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.1 of the License, or (at your option) any later version.
 *
 * Enna 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 Enna; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <Eina.h>
#include <Ecore_File.h>
#include <Ecore_Str.h>
#include <Elementary.h>

#include "enna.h"
#include "enna_config.h"
#include "utils.h"
#include "logs.h"
#include "buffer.h"
#include "ini_parser.h"
#include "utils.h"
#include "xdg.h"

static Eina_List *cfg_parsers = NULL;
static ini_t *cfg_ini = NULL;

/****************************************************************************/
/*                       Config File Main Section                           */
/****************************************************************************/

#define SLIDESHOW_DEFAULT_TIMER 5.0

#define FILTER_DEFAULT_MUSIC \
    "3gp,aac,ape,apl,flac,m4a,mac,mka,mp2,mp3,mp4,mpc,ogg,ra,wav,wma"

#define FILTER_DEFAULT_VIDEO \
    "asf,avi,divx,dvr-ms,evo,flc,fli,flv,m1v,m2v,m4p,m4v,mkv,mov,mp4,mp4v,mpe,mpeg,mpg,ogm,qt,rm,rmvb,swf,ts,vdr,vob,vro,wmv,y4m"

#define FILTER_DEFAULT_PHOTO \
    "jpg,jpeg,png,gif,tif,tiff,xpm"

static void
cfg_main_section_set_default (void)
{

    enna_config->idle_timeout    = 0;
    enna_config->fullscreen      = 0;
    enna_config->slideshow_delay = SLIDESHOW_DEFAULT_TIMER;

    enna_config->theme     = strdup("default");
    enna_config->engine    = strdup("software_x11");
    enna_config->verbosity = strdup("warning");
    enna_config->log_file  = NULL;

    enna_config->music_filters =
        enna_util_tuple_get(FILTER_DEFAULT_MUSIC, ",");
    enna_config->video_filters =
        enna_util_tuple_get(FILTER_DEFAULT_VIDEO, ",");
    enna_config->photo_filters =
        enna_util_tuple_get(FILTER_DEFAULT_PHOTO, ",");

    if (!enna_config->theme)
        enna_config->theme = strdup("default");
    enna_config->theme_file = (char *)
        enna_config_theme_file_get(enna_config->theme);

    enna_log(ENNA_MSG_INFO, NULL, "Theme Name: %s", enna_config->theme);
    enna_log(ENNA_MSG_INFO, NULL, "Theme File: %s", enna_config->theme_file);

    if (enna_config->theme_file)
        elm_theme_overlay_add(enna_config->theme_file);
    else
        enna_log(ENNA_MSG_CRITICAL, NULL, "couldn't load theme file!");
}

#define GET_STRING(v)                                                   \
    value = enna_config_string_get(section, #v);                        \
    if (value)                                                          \
    {                                                                   \
        ENNA_FREE(enna_config->v);                                      \
        enna_config->v = strdup(value);                                 \
    }

#define GET_INT(v)                                                      \
    i = enna_config_int_get(section, #v);                               \
    if (i)                                                              \
        enna_config->v = i;                                             \

#define GET_TUPLE(f,v)                                                  \
    value = enna_config_string_get(section, v);                         \
    if (value)                                                          \
        enna_config->f = enna_util_tuple_get(value, ",");

static void
cfg_main_section_free (void)
{
    char *c;

    ENNA_FREE(enna_config->theme);
    ENNA_FREE(enna_config->engine);
    ENNA_FREE(enna_config->verbosity);
    ENNA_FREE(enna_config->log_file);

    EINA_LIST_FREE(enna_config->video_filters, c)
        ENNA_FREE(c);

    EINA_LIST_FREE(enna_config->video_filters, c)
        ENNA_FREE(c);

    EINA_LIST_FREE(enna_config->photo_filters, c)
        ENNA_FREE(c);
}

static void
cfg_main_section_load (const char *section)
{
    const char *value;
    int i;

    cfg_main_section_free();

    GET_STRING(theme);
    GET_STRING(engine);
    GET_STRING(verbosity);
    GET_STRING(log_file);

    GET_INT(idle_timeout);
    GET_INT(fullscreen);
    GET_INT(slideshow_delay);

    GET_TUPLE(music_filters, "music_ext");
    GET_TUPLE(video_filters, "video_ext");
    GET_TUPLE(photo_filters, "photo_ext");<commit_msg>free the right list name<commit_after>/*
 * GeeXboX Enna Media Center.
 * Copyright (C) 2005-2009 The Enna Project
 *
 * This file is part of Enna.
 *
 * Enna 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.1 of the License, or (at your option) any later version.
 *
 * Enna 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 Enna; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <Eina.h>
#include <Ecore_File.h>
#include <Ecore_Str.h>
#include <Elementary.h>

#include "enna.h"
#include "enna_config.h"
#include "utils.h"
#include "logs.h"
#include "buffer.h"
#include "ini_parser.h"
#include "utils.h"
#include "xdg.h"

static Eina_List *cfg_parsers = NULL;
static ini_t *cfg_ini = NULL;

/****************************************************************************/
/*                       Config File Main Section                           */
/****************************************************************************/

#define SLIDESHOW_DEFAULT_TIMER 5.0

#define FILTER_DEFAULT_MUSIC \
    "3gp,aac,ape,apl,flac,m4a,mac,mka,mp2,mp3,mp4,mpc,ogg,ra,wav,wma"

#define FILTER_DEFAULT_VIDEO \
    "asf,avi,divx,dvr-ms,evo,flc,fli,flv,m1v,m2v,m4p,m4v,mkv,mov,mp4,mp4v,mpe,mpeg,mpg,ogm,qt,rm,rmvb,swf,ts,vdr,vob,vro,wmv,y4m"

#define FILTER_DEFAULT_PHOTO \
    "jpg,jpeg,png,gif,tif,tiff,xpm"

static void
cfg_main_section_set_default (void)
{

    enna_config->idle_timeout    = 0;
    enna_config->fullscreen      = 0;
    enna_config->slideshow_delay = SLIDESHOW_DEFAULT_TIMER;

    enna_config->theme     = strdup("default");
    enna_config->engine    = strdup("software_x11");
    enna_config->verbosity = strdup("warning");
    enna_config->log_file  = NULL;

    enna_config->music_filters =
        enna_util_tuple_get(FILTER_DEFAULT_MUSIC, ",");
    enna_config->video_filters =
        enna_util_tuple_get(FILTER_DEFAULT_VIDEO, ",");
    enna_config->photo_filters =
        enna_util_tuple_get(FILTER_DEFAULT_PHOTO, ",");

    if (!enna_config->theme)
        enna_config->theme = strdup("default");
    enna_config->theme_file = (char *)
        enna_config_theme_file_get(enna_config->theme);

    enna_log(ENNA_MSG_INFO, NULL, "Theme Name: %s", enna_config->theme);
    enna_log(ENNA_MSG_INFO, NULL, "Theme File: %s", enna_config->theme_file);

    if (enna_config->theme_file)
        elm_theme_overlay_add(enna_config->theme_file);
    else
        enna_log(ENNA_MSG_CRITICAL, NULL, "couldn't load theme file!");
}

#define GET_STRING(v)                                                   \
    value = enna_config_string_get(section, #v);                        \
    if (value)                                                          \
    {                                                                   \
        ENNA_FREE(enna_config->v);                                      \
        enna_config->v = strdup(value);                                 \
    }

#define GET_INT(v)                                                      \
    i = enna_config_int_get(section, #v);                               \
    if (i)                                                              \
        enna_config->v = i;                                             \

#define GET_TUPLE(f,v)                                                  \
    value = enna_config_string_get(section, v);                         \
    if (value)                                                          \
        enna_config->f = enna_util_tuple_get(value, ",");

static void
cfg_main_section_free (void)
{
    char *c;

    ENNA_FREE(enna_config->theme);
    ENNA_FREE(enna_config->engine);
    ENNA_FREE(enna_config->verbosity);
    ENNA_FREE(enna_config->log_file);

    EINA_LIST_FREE(enna_config->music_filters, c)
        ENNA_FREE(c);

    EINA_LIST_FREE(enna_config->video_filters, c)
        ENNA_FREE(c);

    EINA_LIST_FREE(enna_config->photo_filters, c)
        ENNA_FREE(c);
}

static void
cfg_main_section_load (const char *section)
{
    const char *value;
    int i;

    cfg_main_section_free();

    GET_STRING(theme);
    GET_STRING(engine);
    GET_STRING(verbosity);
    GET_STRING(log_file);

    GET_INT(idle_timeout);
    GET_INT(fullscreen);
    GET_INT(slideshow_delay);

    GET_TUPLE(music_filters, "music_ext");
    GET_TUPLE(video_filters, "video_ext");
    GET_TUPLE(photo_filters, "photo_ext");
{'fraction_non_alphanumeric': 0.13504498129990902, 'fraction_numerical': 0.00788436268068331, 'mean_word_length': 2.3595925297113753, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '197718', 'n_tokens_mistral': 3292, 'n_tokens_neox': 3092, 'n_words': 633}