<commit_before>/*  XMMS2 - X Music Multiplexer System
 *  Copyright (C) 2003-2006 XMMS2 Team
 *
 *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
 *
 *  This library 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.
 *
 *  This library 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.
 */

#include <locale.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "cmd_playback.h"
#include "cmd_mlib.h"
#include "cmd_config.h"
#include "cmd_status.h"
#include "cmd_pls.h"
#include "cmd_other.h"
#include "common.h"


/**
 * Function prototypes
 */
static void cmd_help (xmmsc_connection_t *conn, gint argc, gchar **argv);


/**
 * Globals
 */
gchar *statusformat = NULL;
gchar *listformat = NULL;
GHashTable *config = NULL;
gchar defaultconfig[] = "ipcpath=NULL\nstatusformat=${artist} - ${title}\nlistformat=${artist} - ${title} (${minutes}:${seconds})\n";


/**
 * Defines all available commands.
 */
cmds commands[] = {
	/* Playlist managment */
	{ "add", "adds a URL to the playlist", cmd_add },
	{ "addarg", "adds one URL with arguments to the playlist", cmd_addarg },
	{ "addid", "adds a Medialib id to the playlist", cmd_addid },
	{ "addpls", "adds a Playlist file to the current playlist", cmd_addpls },
	{ "insert", "inserts one URL at a specific position", cmd_insert },
	{ "insertid", "inserts one Medialib id at a specific position", cmd_insertid },
	{ "radd", "adds a directory recursively to the playlist", cmd_radd },
	{ "clear", "clears the playlist", cmd_clear },
	{ "shuffle", "shuffles the playlist", cmd_shuffle },
	{ "sort", "sort the playlist", cmd_sort },
	{ "remove", "removes something from the playlist", cmd_remove },
	{ "list", "lists the playlist", cmd_list },
	
	/* Playback managment */
	{ "play", "starts playback", cmd_play },
	{ "stop", "stops playback", cmd_stop },
	{ "pause", "pause playback", cmd_pause },
	{ "next", "play next song", cmd_next },
	{ "prev", "play previous song", cmd_prev },
	{ "seek", "seek to a specific place in current song", cmd_seek },
	{ "jump", "take a leap in the playlist", cmd_jump },
	{ "move", "move a entry in the playlist", cmd_move },
	{ "volume", "set volume for a channel", cmd_volume },
	{ "volume_list", "list volume levels for each channel", cmd_volume_list },

	{ "mlib", "medialib manipulation - type 'xmms2 mlib' for more extensive help", cmd_mlib },

	{ "browse", "browse server file lists", cmd_browse },

	{ "status", "go into status mode", cmd_status },
	{ "info", "information about current entry", cmd_info },
	{ "current", "formatted information about the current entry", cmd_current },
	{ "config", "set a config value", cmd_config },
	{ "config_list", "list all config values", cmd_config_list },
	{ "plugin_list", "list all plugins loaded in the server", cmd_plugin_list },
	{ "stats", "get statistics from server", cmd_stats },
	{ "quit", "make the server quit", cmd_quit },
	{ "help", "print help about a command", cmd_help},

	{ NULL, NULL, NULL },
};


/**
 * Config functions.
 */
static GHashTable *
read_config ()
{
	GHashTable *config;
	gchar **split, *buffer, *file;
	gint i, read_bytes = 0;
	struct stat st;
	FILE *fp;

	const gchar *userconf = xmmsc_userconfdir_get ();
	file = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), 
	                     userconf, "xmms2", "clients", "cli.conf", NULL);

	if (!g_file_test (file, G_FILE_TEST_EXISTS)) {
		gchar *dir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (),
		                           userconf, "xmms2", "clients", NULL);
		g_mkdir_with_parents (dir, 0755);
		g_free (dir);

		fp = fopen (file, "w+");
		if (!fp) {
			print_error ("Could not create default configfile!!");
		}
<commit_msg>OTHER: Improve error message when cli can't create configfile. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=383721<commit_after>/*  XMMS2 - X Music Multiplexer System
 *  Copyright (C) 2003-2006 XMMS2 Team
 *
 *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
 *
 *  This library 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.
 *
 *  This library 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.
 */

#include <locale.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "cmd_playback.h"
#include "cmd_mlib.h"
#include "cmd_config.h"
#include "cmd_status.h"
#include "cmd_pls.h"
#include "cmd_other.h"
#include "common.h"


/**
 * Function prototypes
 */
static void cmd_help (xmmsc_connection_t *conn, gint argc, gchar **argv);


/**
 * Globals
 */
gchar *statusformat = NULL;
gchar *listformat = NULL;
GHashTable *config = NULL;
gchar defaultconfig[] = "ipcpath=NULL\nstatusformat=${artist} - ${title}\nlistformat=${artist} - ${title} (${minutes}:${seconds})\n";


/**
 * Defines all available commands.
 */
cmds commands[] = {
	/* Playlist managment */
	{ "add", "adds a URL to the playlist", cmd_add },
	{ "addarg", "adds one URL with arguments to the playlist", cmd_addarg },
	{ "addid", "adds a Medialib id to the playlist", cmd_addid },
	{ "addpls", "adds a Playlist file to the current playlist", cmd_addpls },
	{ "insert", "inserts one URL at a specific position", cmd_insert },
	{ "insertid", "inserts one Medialib id at a specific position", cmd_insertid },
	{ "radd", "adds a directory recursively to the playlist", cmd_radd },
	{ "clear", "clears the playlist", cmd_clear },
	{ "shuffle", "shuffles the playlist", cmd_shuffle },
	{ "sort", "sort the playlist", cmd_sort },
	{ "remove", "removes something from the playlist", cmd_remove },
	{ "list", "lists the playlist", cmd_list },
	
	/* Playback managment */
	{ "play", "starts playback", cmd_play },
	{ "stop", "stops playback", cmd_stop },
	{ "pause", "pause playback", cmd_pause },
	{ "next", "play next song", cmd_next },
	{ "prev", "play previous song", cmd_prev },
	{ "seek", "seek to a specific place in current song", cmd_seek },
	{ "jump", "take a leap in the playlist", cmd_jump },
	{ "move", "move a entry in the playlist", cmd_move },
	{ "volume", "set volume for a channel", cmd_volume },
	{ "volume_list", "list volume levels for each channel", cmd_volume_list },

	{ "mlib", "medialib manipulation - type 'xmms2 mlib' for more extensive help", cmd_mlib },

	{ "browse", "browse server file lists", cmd_browse },

	{ "status", "go into status mode", cmd_status },
	{ "info", "information about current entry", cmd_info },
	{ "current", "formatted information about the current entry", cmd_current },
	{ "config", "set a config value", cmd_config },
	{ "config_list", "list all config values", cmd_config_list },
	{ "plugin_list", "list all plugins loaded in the server", cmd_plugin_list },
	{ "stats", "get statistics from server", cmd_stats },
	{ "quit", "make the server quit", cmd_quit },
	{ "help", "print help about a command", cmd_help},

	{ NULL, NULL, NULL },
};


/**
 * Config functions.
 */
static GHashTable *
read_config ()
{
	GHashTable *config;
	gchar **split, *buffer, *file;
	gint i, read_bytes = 0;
	struct stat st;
	FILE *fp;

	const gchar *userconf = xmmsc_userconfdir_get ();
	file = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), 
	                     userconf, "xmms2", "clients", "cli.conf", NULL);

	if (!g_file_test (file, G_FILE_TEST_EXISTS)) {
		gchar *dir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (),
		                           userconf, "xmms2", "clients", NULL);
		g_mkdir_with_parents (dir, 0755);
		g_free (dir);

		fp = fopen (file, "w+");
		if (!fp) {
			print_error ("Could not create configfile: %s\nMake sure you have write permissions to that location.", file);
		}

{'fraction_non_alphanumeric': 0.14046782208217184, 'fraction_numerical': 0.005575081808265664, 'mean_word_length': 4.1639549436796, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4855805', 'n_tokens_mistral': 2884, 'n_tokens_neox': 2765, 'n_words': 928}