Commit 588df27f authored by Mathieu Valois's avatar Mathieu Valois
Browse files

print some infos only in debug mode

parent 8844bf02
Loading
Loading
Loading
Loading
+2 −2
Changes for Statsgen/include/statsgen.h: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -194,13 +194,13 @@ public:
	 * @brief print the warning message
	 * @param message: the warning message
	 */
	void warn(const std::string & message);
	void warn(const char* messages...);

	/**
	 * @brief print the debug message if debug enabled
	 * @param message: the debug message
	 * */
	void debug(const std::string & message);
	void debug(const char* messages...);

	/**
	 * @brief Calculate all statistics for a database
+5 −1
Changes for Statsgen/src/main.cpp: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ static struct option long_options[] = {
	{"top", required_argument, NULL, 't'},
	{"regex", required_argument, NULL, 'r'},
	{"out", required_argument, NULL, 'o'},
	{"debug", no_argument, NULL, 'd'},
	{"limit-advanced-masks", required_argument, NULL, 'A'},
	{"limit-simple-masks", required_argument, NULL, 'S'},
	{"parallel", required_argument, NULL, 'p'},
@@ -47,6 +48,7 @@ void showHelp() {
		"	--top, -t [value]   Show only [value] first results",
		"	--regex, -r [value] Show result for password, using the regular expression [value]",
		"	--out, -o [value]   Writes masks into [value] file",
		"	--debug, -d         Enable debug printing",
		"",
		"Optimisation options to reduce the execution time : ",
		"	--limit-advanced-masks, -A [value]  Limit the size of the advanced masks at [value], if size>[value]: othermasks",
@@ -72,7 +74,7 @@ int main(int argc,char* argv[]) {
	string filename;

	int opt;
	while ((opt = getopt_long(argc, argv, "hwHt:r:o:A:S:p:s", long_options, NULL)) != -1){
	while ((opt = getopt_long(argc, argv, "hwHt:r:o:dA:S:p:s", long_options, NULL)) != -1){
		switch(opt){
			case 'h':
				showHelp(); break;
@@ -86,6 +88,8 @@ int main(int argc,char* argv[]) {
				statsgen.setRegex(optarg); break;
			case 'o':
				statsgen.setOutfile(optarg); break;
			case 'd':
				statsgen.enableDebug(); break;
			case 'A':
				statsgen.setLimitAdvancedmask(atoi(optarg)); break;
			case 'S':
+36 −6
Changes for Statsgen/src/statsgen.cpp: 36 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <vector>
#include <thread>
#include <pthread.h>
#include <cstdarg>


#include "statsgen.h"
@@ -88,12 +89,41 @@ void Statsgen::enableDebug(){
	debug_enabled = true;
}

void Statsgen::warn(const string & message){
	cerr << "[Warning] " << message << endl;
void Statsgen::warn(const char* messages...){
	va_list args;
	va_start(args, messages);
	cerr << "[Warning]";
	while (*messages != '\0'){
			cerr << " ";
			if (*messages == 'd') {
				cerr << va_arg(args, int);
			}
void Statsgen::debug(const string & message){
	if (debug_enabled)
		cerr << "[Debug] " << message << endl;
			else{
				cerr << va_arg(args, char*);
			}
			messages++;
	}
	cerr << endl;
	va_end(args);
}

void Statsgen::debug(const char* messages...){
	if (!debug_enabled) return;
	va_list args;
	va_start(args, messages);
	cerr << "[Debug]";
	while (*messages != '\0'){
			cerr << " ";
			if (*messages == 'd') {
				cerr << va_arg(args, int);
			}
			else{
				cerr << va_arg(args, char*);
			}
			messages++;
	}
	cerr << endl;
	va_end(args);
}


@@ -171,7 +201,7 @@ int Statsgen::generate_stats() {
		td[i].sr.minLower = minLower;
		td[i].sr.minUpper = minUpper;

		wcout << "Thread " << td[i].thread_id << " analyse : " << td[i].lineBegin << " --> " << td[i].lineEnd << endl;
		debug("Thread", td[i].thread_id, "analyse :", td[i].lineBegin, " -->", td[i].lineEnd);
		// We use std::queue if input is from stdin
		if (is_stdin) {
			rc = pthread_create(&threads[i], NULL, generate_stats_thread_queue, (void *)&td[i] );