<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <mpd/client.h>

#include "randompd.h"

void print_usage(const char* arg0)
{
	printf("Usage: %s\n", arg0);
	printf("randompd version: %s\n\n", VERSION);
}

int main(int argc, char** argv)
{
	int o = 0;
	int success = 0;
	int option_index = 0;
	const char* mpd_host = 0;
	unsigned int mpd_port = 0;
	struct mpd_pair* item = 0;

	static struct option long_options[] =
	{
		/* Use flags like so:
		{"verbose",	no_argument,	&verbose_flag, 'V'}*/
		/* Argument styles: no_argument, required_argument, optional_argument */
		{"version", no_argument,	0,	'v'},
		{"help",	no_argument,	0,	'h'},
		{"host",    optional_argument, 0, 'm'},
		{"port",    optional_argument, 0, 'p'},
		
		{0,0,0,0}
	};

	while ((o = getopt_long(argc, argv, "vhm:p:", long_options, &option_index)) != -1)
	{
		if (o == 'h') {
			printf("Usage: %s\n", argv[0]);
			printf("randompd " VERSION " © 2014 <NAME>\n\n");
			printf("Options:\n");
			printf("  -m, --host=<host>  Connect to server on <host>\n");
			printf("  -p, --port=<port>  Connect to server port <port>\n\n");

			return EXIT_SUCCESS;

		} else if (o == 'm') {
			mpd_host = optarg;
		} else if (o == 'p') {
			mpd_port = atoi(optarg);

		} else if (o == 'v') {
			printf("randompd " VERSION " © 2014 <NAME>\n");

			return EXIT_SUCCESS;
		} else {
			return EXIT_FAILURE;
		}
	}
	
	g_mpd_connection = mpd_connection_new(mpd_host, mpd_port, 0);

	if (!g_mpd_connection) {
		fprintf(stderr, "could not allocate mpd connection\n");
		return 1;
	}

	success = mpd_send_list_all(g_mpd_connection, 0);

	if (!success) {
		fprintf(stderr, "could not read media library\n");
		return 1;
	}

	while ((item = mpd_recv_pair_named(g_mpd_connection, "file"))) {
		printf("%s\n", item->value);
		mpd_return_pair(g_mpd_connection, item);
	}

	mpd_response_finish(g_mpd_connection);

	return 0;
}<commit_msg>Free the global mpd connection<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <mpd/client.h>

#include "randompd.h"

void print_usage(const char* arg0)
{
	printf("Usage: %s\n", arg0);
	printf("randompd version: %s\n\n", VERSION);
}

int main(int argc, char** argv)
{
	int o = 0;
	int success = 0;
	int option_index = 0;
	const char* mpd_host = 0;
	unsigned int mpd_port = 0;
	struct mpd_pair* item = 0;

	static struct option long_options[] =
	{
		/* Use flags like so:
		{"verbose",	no_argument,	&verbose_flag, 'V'}*/
		/* Argument styles: no_argument, required_argument, optional_argument */
		{"version", no_argument,	0,	'v'},
		{"help",	no_argument,	0,	'h'},
		{"host",    optional_argument, 0, 'm'},
		{"port",    optional_argument, 0, 'p'},
		
		{0,0,0,0}
	};

	while ((o = getopt_long(argc, argv, "vhm:p:", long_options, &option_index)) != -1)
	{
		if (o == 'h') {
			printf("Usage: %s\n", argv[0]);
			printf("randompd " VERSION " © 2014 <NAME>\n\n");
			printf("Options:\n");
			printf("  -m, --host=<host>  Connect to server on <host>\n");
			printf("  -p, --port=<port>  Connect to server port <port>\n\n");

			return EXIT_SUCCESS;

		} else if (o == 'm') {
			mpd_host = optarg;
		} else if (o == 'p') {
			mpd_port = atoi(optarg);

		} else if (o == 'v') {
			printf("randompd " VERSION " © 2014 <NAME>\n");

			return EXIT_SUCCESS;
		} else {
			return EXIT_FAILURE;
		}
	}
	
	g_mpd_connection = mpd_connection_new(mpd_host, mpd_port, 0);

	if (!g_mpd_connection) {
		fprintf(stderr, "could not allocate mpd connection\n");
		return 1;
	}

	success = mpd_send_list_all(g_mpd_connection, 0);

	if (!success) {
		fprintf(stderr, "could not read media library\n");
		return 1;
	}

	while ((item = mpd_recv_pair_named(g_mpd_connection, "file"))) {
		printf("%s\n", item->value);
		mpd_return_pair(g_mpd_connection, item);
	}

	mpd_response_finish(g_mpd_connection);

	mpd_connection_free(g_mpd_connection);

	return 0;
}
{'fraction_non_alphanumeric': 0.17897727272727273, 'fraction_numerical': 0.016012396694214875, 'mean_word_length': 3.91497461928934, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '1483787', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1552, 'n_words': 371}