<commit_before>#ifdef WIN32
#include <windows.h>
#endif
#include "bkd.h"

private	void	bkd_server(void);
private	void	do_cmds();
private	void	exclude(char *cmd);
private	int	findcmd(int ac, char **av);
private	int	getav(int *acp, char ***avp);
private	void	log_cmd(int i, int ac, char **av);
private	void	reap(int sig);
private	void	usage();
private	void	ids();
char 	*logRoot;


int
bkd_main(int ac, char **av)
{
	int	c;
	char	*uid = 0;

	if (ac == 2 && streq("--help", av[1])) {
		system("bk help bkd");
		return (1);
	}

	loadNetLib();


	while ((c = getopt(ac, av, "c:dDeE:hHil|L:p:P:qRs:St:u:x:")) != -1) {
		switch (c) {
		    case 'c': Opts.count = atoi(optarg); break;
		    case 'd': Opts.daemon = 1; break;
		    case 'D': Opts.debug = 1; break;
		    case 'e': Opts.errors_exit = 1; break;
		    case 'i': Opts.interactive = 1; break;
		    case 'h': Opts.http_hdr_out = 1; break;
		    case 'H': Opts.http_hdr_out = Opts.http_hdr_in = 1; break;
		    case 'l':
			Opts.log = optarg ? fopen(optarg, "a") : stderr;
			break;
		    case 'L':
			logRoot = strdup(optarg); break;
		    case 'p': Opts.port = atoi(optarg); break;
		    case 'P': Opts.pidfile = optarg; break;
		    case 'q': Opts.quiet = 1; break; /* need doc */
#ifdef WIN32
		    case 'E': putenv((strdup)(optarg)); break;
		    case 's': Opts.startDir = optarg; break;
		    case 'S': Opts.start = 1; Opts.daemon = 1; break;
		    case 'R': Opts.remove = 1; Opts.daemon = 1; break;
#endif
		    case 't': Opts.alarm = atoi(optarg); break;
		    case 'u': uid = optarg; break;
		    case 'x': exclude(optarg); break;
		    default: usage();
	    	}
	}

	if (logRoot && !IsFullPath(logRoot)) {
		fprintf(stderr,
		    "bad log root: %s: must be a full path name\n", logRoot);
		return (1);
	}

	if (Opts.port) {
		Opts.daemon = 1;
		if (Opts.interactive) {
			fprintf(stderr,
			    "Disabling interactive in daemon mode\n");
		    	Opts.interactive = 0;
		}
	}
#ifndef WIN32
	if (uid) ids(uid);
#endif
	putenv("PAGER=cat");
	if (Opts.daemon) {
		bkd_server();
		exit(1);
		/* NOTREACHED */
	} else {
		if (Opts.alarm) {
#ifdef WIN32
			fprintf(stderr,
				"-t option is not supported on WIN32\n");
#else
			signal(SIGALRM, exit);
			alarm(Opts.alarm);
#endif
		}
		do_cmds();
		return (0);
	}
}

private	void
usage()
{
	system("bk help -s bkd");
	exit(1);
}

private	void
reap(int sig)
{
	/*
	 * There is no need to reap process on NT
	 */
#ifndef WIN32
	while (waitpid((pid_t)-1, 0, WNOHANG) > 0);
	signal(SIGCHLD, reap);
#endif
}

#ifndef WIN32
private	void
bkd_server()
{
	int	sock = tcp_server(Opts.port ? Opts.port : BK_PORT);
	remote	r;<commit_msg>make bkd -q works on unix too. fix a display alignment in t.bkd_o2h<commit_after>#ifdef WIN32
#include <windows.h>
#endif
#include "bkd.h"

private	void	bkd_server(void);
private	void	do_cmds();
private	void	exclude(char *cmd);
private	int	findcmd(int ac, char **av);
private	int	getav(int *acp, char ***avp);
private	void	log_cmd(int i, int ac, char **av);
private	void	reap(int sig);
private	void	usage();
private	void	ids();
char 	*logRoot;


int
bkd_main(int ac, char **av)
{
	int	c;
	char	*uid = 0;

	if (ac == 2 && streq("--help", av[1])) {
		system("bk help bkd");
		return (1);
	}

	loadNetLib();


	while ((c = getopt(ac, av, "c:dDeE:hHil|L:p:P:qRs:St:u:x:")) != -1) {
		switch (c) {
		    case 'c': Opts.count = atoi(optarg); break;
		    case 'd': Opts.daemon = 1; break;
		    case 'D': Opts.debug = 1; break;
		    case 'e': Opts.errors_exit = 1; break;
		    case 'i': Opts.interactive = 1; break;
		    case 'h': Opts.http_hdr_out = 1; break;
		    case 'H': Opts.http_hdr_out = Opts.http_hdr_in = 1; break;
		    case 'l':
			Opts.log = optarg ? fopen(optarg, "a") : stderr;
			break;
		    case 'L':
			logRoot = strdup(optarg); break;
		    case 'p': Opts.port = atoi(optarg); break;
		    case 'P': Opts.pidfile = optarg; break;
		    case 'q': Opts.quiet = 1; break; /* need doc */
#ifdef WIN32
		    case 'E': putenv((strdup)(optarg)); break;
		    case 's': Opts.startDir = optarg; break;
		    case 'S': Opts.start = 1; Opts.daemon = 1; break;
		    case 'R': Opts.remove = 1; Opts.daemon = 1; break;
#endif
		    case 't': Opts.alarm = atoi(optarg); break;
		    case 'u': uid = optarg; break;
		    case 'x': exclude(optarg); break;
		    default: usage();
	    	}
	}

	if (logRoot && !IsFullPath(logRoot)) {
		fprintf(stderr,
		    "bad log root: %s: must be a full path name\n", logRoot);
		return (1);
	}

	if (Opts.port) {
		Opts.daemon = 1;
		if (Opts.interactive) {
			fprintf(stderr,
			    "Disabling interactive in daemon mode\n");
		    	Opts.interactive = 0;
		}
	}
#ifndef WIN32
	if (uid) ids(uid);
#endif
	putenv("PAGER=cat");
	if (Opts.daemon) {
		bkd_server();
		exit(1);
		/* NOTREACHED */
	} else {
		if (Opts.alarm) {
#ifdef WIN32
			fprintf(stderr,
				"-t option is not supported on WIN32\n");
#else
			signal(SIGALRM, exit);
			alarm(Opts.alarm);
#endif
		}
		do_cmds();
		return (0);
	}
}

private	void
usage()
{
	system("bk help -s bkd");
	exit(1);
}

private	void
reap(int sig)
{
	/*
	 * There is no need to reap process on NT
	 */
#ifndef WIN32
	while (waitpid((pid_t)-1, 0, WNOHANG) > 0);
	signal(SIGCHLD, reap);
#endif
}

#ifndef WIN32
private	void
bkd_server()
{
	int	sock = tcp_server(Opts.port ? Opts.port : BK_PORT, Opts.quiet);
	remote	r;
{'fraction_non_alphanumeric': 0.16998497370398197, 'fraction_numerical': 0.014838467317806161, 'mean_word_length': 3.083588957055215, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3562354', 'n_tokens_mistral': 2438, 'n_tokens_neox': 2210, 'n_words': 598}