<commit_before>#include "mpdas.h"

void
onclose()
{
	iprintf("%s", "Closing mpdas.");

	if(MPD) delete MPD;
	if(AudioScrobbler) delete AudioScrobbler;
	if(Cache) delete Cache;
	if(Config) delete Config;
}

void
setid(const char* username)
{
	if(strlen(username) == 0)
		return;

	passwd* userinfo = 0;

	if(getuid() != 0) {
		eprintf("%s", "You are not root. Not changing user ..");
		return;
	}

	userinfo = getpwnam(username);
	if(!userinfo) {
		eprintf("%s", "The user you specified does not exist.");
		exit(EXIT_FAILURE);
	}

	if(setgid(userinfo->pw_gid == -1 || setuid(userinfo->pw_uid)) == -1) {
			eprintf("%s %s", "Could not switch to user", username);
			exit(EXIT_FAILURE);
	}

	setenv("HOME", userinfo->pw_dir, 1);

	// Load config in home dir as well (if possible)
	std::string path = getenv("HOME");
	path.append("/.mpdasrc");
	Config->LoadConfig(path);
}

void
printversion()
{
	fprintf(stdout, "mpdas-"VERSION", (C) 2008 <NAME>.\n");
}

void
printhelp()
{
	fprintf(stderr, "\nusage: mpdas [-h] [-v] [-c config]\n");

	fprintf(stderr, "\n\th: print this help");
	fprintf(stderr, "\n\tv: print program version");
	fprintf(stderr, "\n\tc: load specified config file");

	fprintf(stderr, "\n");
}

int
main(int argc, char* argv[])
{
	int i;
	char* config = 0;

	if(argc >= 2) {
		for(i = 1; i <=  argc-1; i++) {
			if(strstr(argv[i], "-h") == argv[i]) {
				printversion();
				printhelp();
				return EXIT_SUCCESS;
			}
			if(strstr(argv[i], "-v") == argv[i]) {
				printversion();
				return EXIT_SUCCESS;
			}

			else if(strstr(argv[i], "-c") == argv[i]) {
				if(i >= argc-1) {
					fprintf(stderr, "mpdas: config path missing!\n");
					printhelp();
					return EXIT_FAILURE;
				}
				config = argv[i+1];
			}
		}
	}

	atexit(onclose);

	Config = new CConfig(config);

	setid(Config->getRUser().c_str());

	if(!Config->gotNecessaryData()) {
		eprintf("%s", "AudioScrobbler username or password not set.");
		return EXIT_FAILURE;
	}

	MPD = new CMPD();
	if(!MPD->isConnected())
		return EXIT_FAILURE;

	AudioScrobbler = new CAudioScrobbler();
	AudioScrobbler->Handshake();
	Cache = new CCache();
	Cache->LoadCache();

scan:
	MPD->Update();
	Cache->WorkCache();
	usleep(500000);
	goto scan;

	return EXIT_SUCCESS;
}<commit_msg>check pipe in mainloop<commit_after>#include "mpdas.h"

void
onclose()
{
	iprintf("%s", "Closing mpdas.");

	if(MPD) delete MPD;
	if(AudioScrobbler) delete AudioScrobbler;
	if(Cache) delete Cache;
	if(Config) delete Config;
}

void
setid(const char* username)
{
	if(strlen(username) == 0)
		return;

	passwd* userinfo = 0;

	if(getuid() != 0) {
		eprintf("%s", "You are not root. Not changing user ..");
		return;
	}

	userinfo = getpwnam(username);
	if(!userinfo) {
		eprintf("%s", "The user you specified does not exist.");
		exit(EXIT_FAILURE);
	}

	if(setgid(userinfo->pw_gid == -1 || setuid(userinfo->pw_uid)) == -1) {
			eprintf("%s %s", "Could not switch to user", username);
			exit(EXIT_FAILURE);
	}

	setenv("HOME", userinfo->pw_dir, 1);

	// Load config in home dir as well (if possible)
	std::string path = getenv("HOME");
	path.append("/.mpdasrc");
	Config->LoadConfig(path);
}

void
printversion()
{
	fprintf(stdout, "mpdas-"VERSION", (C) 2008 <NAME>.\n");
	fprintf(stdout, "Global config path is set to \"%s\"\n", CONFDIR);
}

void
printhelp()
{
	fprintf(stderr, "\nusage: mpdas [-h] [-v] [-c config]\n");

	fprintf(stderr, "\n\th: print this help");
	fprintf(stderr, "\n\tv: print program version");
	fprintf(stderr, "\n\tc: load specified config file");

	fprintf(stderr, "\n");
}

int
main(int argc, char* argv[])
{
	int i;
	char* config = 0;

	if(argc >= 2) {
		for(i = 1; i <=  argc-1; i++) {
			if(strstr(argv[i], "-h") == argv[i]) {
				printversion();
				printhelp();
				return EXIT_SUCCESS;
			}
			if(strstr(argv[i], "-v") == argv[i]) {
				printversion();
				return EXIT_SUCCESS;
			}

			else if(strstr(argv[i], "-c") == argv[i]) {
				if(i >= argc-1) {
					fprintf(stderr, "mpdas: config path missing!\n");
					printhelp();
					return EXIT_FAILURE;
				}
				config = argv[i+1];
			}
		}
	}

	atexit(onclose);

	Config = new CConfig(config);

	setid(Config->getRUser().c_str());

	if(!Config->gotNecessaryData()) {
		eprintf("%s", "AudioScrobbler username or password not set.");
		return EXIT_FAILURE;
	}

	MPD = new CMPD();
	if(!MPD->isConnected())
		return EXIT_FAILURE;

	AudioScrobbler = new CAudioScrobbler();
	AudioScrobbler->Handshake();
	Cache = new CCache();
	Cache->LoadCache();

scan:
	MPD->Update();
	AudioScrobbler->GetLove();
	Cache->WorkCache();
	usleep(500000);
	goto scan;

	return EXIT_SUCCESS;
}
{'fraction_non_alphanumeric': 0.19203135205747876, 'fraction_numerical': 0.009579795340735902, 'mean_word_length': 3.8976545842217485, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 32, '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': '6210783', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1794, 'n_words': 411}