<commit_before># include <iostream>
# include <cstdlib>
# include <cstdio>
# include <cstring>

# include <unistd.h>
# include <wordexp.h>

# include <sys/types.h>
# include <sys/select.h>
# include <sys/socket.h>
# include <arpa/inet.h>
# include <netinet/in.h>

# include <microhttpd.h>

# include "webcli.hpp"

void print_usage(const char *program_name)
{
	std::cerr<<"Usage: "<<program_name<<" [-he] [-p PORT] [-c FILE]"<<std::endl;

	std::cerr<<"\t -h: start http daemon" << std::endl;
	std::cerr<<"\t -e: if no command was given, just echo back the request" << std::endl;
	std::cerr<<"\t -p PORT: use PORT for http daemon" << std::endl;
	std::cerr<<"\t -c FILE: read commadns from FILE" << std::endl;
}

int http_callback(void *cls,
		  MHD_Connection *connection,
		  const char *url,
		  const char *method, const char *version,
		  const char *upload_data, size_t *upload_data_size,
		  void **con_cls)
{
	WebCLI *webcli = (WebCLI*)cls;
	MHD_Response *response;
	int return_value;

	const char *query = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "q");
	std::string result;
	if(!query)
	{
		result = webcli->resolveCommand(std::string());
	}
	else
	{
		result = webcli->resolveCommand(std::string(query));
	}
	std::cerr<<query<<" -> "<<result<<std::endl;
	
	response = MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT);
	if(!response) { std::cerr<<1<<std::endl; return MHD_NO; }

	if(MHD_add_response_header(response, "Location", result.c_str()) == MHD_NO)
	{
		MHD_destroy_response(response);
		return MHD_NO;
	}

	return_value = MHD_queue_response(connection, MHD_HTTP_FOUND, response);
	MHD_destroy_response(response);

	return return_value;
}

int main(int argc, char**argv)
{
	bool enable_http = false;
	bool echo = false;
	unsigned short http_port = 8023;
	const char *commands_file = "~/.webcli-commands";

	int opt;
	while((opt = getopt(argc, argv, "hep:c:")) != -1)
	{
		switch(opt)
		{
		case 'h':
			enable_http = true;
			break;<commit_msg>removed debug output<commit_after># include <iostream>
# include <cstdlib>
# include <cstdio>
# include <cstring>

# include <unistd.h>
# include <wordexp.h>

# include <sys/types.h>
# include <sys/select.h>
# include <sys/socket.h>
# include <arpa/inet.h>
# include <netinet/in.h>

# include <microhttpd.h>

# include "webcli.hpp"

void print_usage(const char *program_name)
{
	std::cerr<<"Usage: "<<program_name<<" [-he] [-p PORT] [-c FILE]"<<std::endl;

	std::cerr<<"\t -h: start http daemon" << std::endl;
	std::cerr<<"\t -e: if no command was given, just echo back the request" << std::endl;
	std::cerr<<"\t -p PORT: use PORT for http daemon" << std::endl;
	std::cerr<<"\t -c FILE: read commadns from FILE" << std::endl;
}

int http_callback(void *cls,
		  MHD_Connection *connection,
		  const char *url,
		  const char *method, const char *version,
		  const char *upload_data, size_t *upload_data_size,
		  void **con_cls)
{
	WebCLI *webcli = (WebCLI*)cls;
	MHD_Response *response;
	int return_value;

	const char *query = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "q");
	std::string result;
	if(!query)
	{
		result = webcli->resolveCommand(std::string());
	}
	else
	{
		result = webcli->resolveCommand(std::string(query));
	}

	response = MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT);
	if(!response) { return MHD_NO; }

	if(MHD_add_response_header(response, "Location", result.c_str()) == MHD_NO)
	{
		MHD_destroy_response(response);
		return MHD_NO;
	}

	return_value = MHD_queue_response(connection, MHD_HTTP_FOUND, response);
	MHD_destroy_response(response);

	return return_value;
}

int main(int argc, char**argv)
{
	bool enable_http = false;
	bool echo = false;
	unsigned short http_port = 8023;
	const char *commands_file = "~/.webcli-commands";

	int opt;
	while((opt = getopt(argc, argv, "hep:c:")) != -1)
	{
		switch(opt)
		{
		case 'h':
			enable_http = true;
			break;
{'fraction_non_alphanumeric': 0.16050955414012738, 'fraction_numerical': 0.0033121019108280254, 'mean_word_length': 4.877245508982036, 'pattern_counts': {'":': 0, '<': 87, '<?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': '2039632', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1498, 'n_words': 340}