<commit_before>#include "burp.h"
#include "prog.h"
#include "cmd.h"

void reset_filecounter(struct cntr *c)
{
	if(!c) return;
	c->totalcounter=0;
	c->filecounter=0;
	c->changedcounter=0;
	c->unchangedcounter=0;
	c->newcounter=0;
	c->directorycounter=0;
	c->specialcounter=0;
	c->hardlinkcounter=0;
	c->softlinkcounter=0;
	c->warningcounter=0;
	c->bytecounter=0;
	c->recvbytecounter=0;
	c->sentbytecounter=0;
	c->encryptedcounter=0;
	c->metadatacounter=0;
	c->encmetadatacounter=0;
}

static const char *bytes_to_human(unsigned long long counter)
{
	static char ret[32]="";
	float div=(float)counter;
	char units[3]="";

	if(div<1024) return "";

	if((div/=1024)<1024)
		snprintf(units, sizeof(units), "KB");
	else if((div/=1024)<1024)
		snprintf(units, sizeof(units), "MB");
	else if((div/=1024)<1024)
		snprintf(units, sizeof(units), "GB");
	else if((div/=1024)<1024)
		snprintf(units, sizeof(units), "TB");
	else if((div/=1024)<1024)
		snprintf(units, sizeof(units), "EB");
	else
	{
		div/=1024;
		snprintf(units, sizeof(units), "PB");
	}
	snprintf(ret, sizeof(ret), " (%.2f %s)", div, units);
	//strcat(ret, units);
	//strcat(ret, ")");
	return ret;
}

const char *bytes_to_human_str(const char *str)
{
	return bytes_to_human(strtoull(str, NULL, 10));
}

static void pcounter(const char *str, unsigned long long counter)
{
	if(counter) logp(str, counter);
}

static void bcounter(const char *str, unsigned long long counter)
{
	if(counter)
	{
		char msg[128]="";
		snprintf(msg, sizeof(msg),
			str, counter, bytes_to_human(counter));
		logp("%s", msg);
	}
}

void end_filecounter(struct cntr *c, int print, enum action act)
{
	if(!c) return;
	if(print) printf(" %llu\n\n", c->totalcounter);

	if(act==ACTION_RESTORE)
	{
		logp("Files:                     %llu\n", c->filecounter);
		pcounter("Encrypted files:           %llu\n", c->encryptedcounter);
		logp("Meta data:                 %llu\n", c->metadatacounter);
		pcounter("Encrypted meta data:       %llu\n", c->encmetadatacounter);
	}
	else if(act==ACTION_VERIFY)
	{
		logp("Verified files:            %llu\n", c->filecounter);
		pcounter("Verified encrypted files:  %llu\n", c->encryptedcounter);
		logp("Verified meta data:        %llu\n", c->metadatacounter);
		pcounter("Verified encrypted meta:   %llu\n", c->encmetadatacounter);
	}
	else
	{<commit_msg>Tweak meta counter messages.<commit_after>#include "burp.h"
#include "prog.h"
#include "cmd.h"

void reset_filecounter(struct cntr *c)
{
	if(!c) return;
	c->totalcounter=0;
	c->filecounter=0;
	c->changedcounter=0;
	c->unchangedcounter=0;
	c->newcounter=0;
	c->directorycounter=0;
	c->specialcounter=0;
	c->hardlinkcounter=0;
	c->softlinkcounter=0;
	c->warningcounter=0;
	c->bytecounter=0;
	c->recvbytecounter=0;
	c->sentbytecounter=0;
	c->encryptedcounter=0;
	c->metadatacounter=0;
	c->encmetadatacounter=0;
}

static const char *bytes_to_human(unsigned long long counter)
{
	static char ret[32]="";
	float div=(float)counter;
	char units[3]="";

	if(div<1024) return "";

	if((div/=1024)<1024)
		snprintf(units, sizeof(units), "KB");
	else if((div/=1024)<1024)
		snprintf(units, sizeof(units), "MB");
	else if((div/=1024)<1024)
		snprintf(units, sizeof(units), "GB");
	else if((div/=1024)<1024)
		snprintf(units, sizeof(units), "TB");
	else if((div/=1024)<1024)
		snprintf(units, sizeof(units), "EB");
	else
	{
		div/=1024;
		snprintf(units, sizeof(units), "PB");
	}
	snprintf(ret, sizeof(ret), " (%.2f %s)", div, units);
	//strcat(ret, units);
	//strcat(ret, ")");
	return ret;
}

const char *bytes_to_human_str(const char *str)
{
	return bytes_to_human(strtoull(str, NULL, 10));
}

static void pcounter(const char *str, unsigned long long counter)
{
	if(counter) logp(str, counter);
}

static void bcounter(const char *str, unsigned long long counter)
{
	if(counter)
	{
		char msg[128]="";
		snprintf(msg, sizeof(msg),
			str, counter, bytes_to_human(counter));
		logp("%s", msg);
	}
}

void end_filecounter(struct cntr *c, int print, enum action act)
{
	if(!c) return;
	if(print) printf(" %llu\n\n", c->totalcounter);

	if(act==ACTION_RESTORE)
	{
		logp("Files:                     %llu\n", c->filecounter);
		pcounter("Encrypted files:           %llu\n", c->encryptedcounter);
		pcounter("Meta data:                 %llu\n", c->metadatacounter);
		pcounter("Encrypted meta data:       %llu\n", c->encmetadatacounter);
	}
	else if(act==ACTION_VERIFY)
	{
		logp("Verified files:            %llu\n", c->filecounter);
		pcounter("Verified encrypted files:  %llu\n", c->encryptedcounter);
		pcounter("Verified meta data:        %llu\n", c->metadatacounter);
		pcounter("Verified encrypted meta:   %llu\n", c->encmetadatacounter);
	}
	else
	{
{'fraction_non_alphanumeric': 0.18222794591113972, 'fraction_numerical': 0.03133719682335265, 'mean_word_length': 4.5410225921522, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 53, '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': '861063', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1830, 'n_words': 359}