Commit 411d76a2 authored by Mathieu Valois's avatar Mathieu Valois
Browse files

fix debug issue

parent 19f50be4
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -197,20 +197,6 @@ public:
	 */
	inline void enableDebug() { debug_enabled = true; }


	void message(const char* messages...) const;
	/**
	 * @brief print the warning message
	 * @param message: the warning message
	 */
	void warn(const char* messages...) const ;

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

	/**
	 * @brief Calculate all statistics for a database
	 * @return 0 if error, 1 if success
+3 −32
Original line number Diff line number Diff line
@@ -28,43 +28,13 @@ using namespace std;
Statsgen::Statsgen(const std::string& name) {
	if (name == "-"){
		is_stdin = true;
		warn("reading from stdin enabled, loading the whole list in memory");
		cerr << "[WARNING]" << " reading from stdin enabled, loading the whole list in memory" << endl;
	}
	else {
		filename = name;
	}
}

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

void Statsgen::warn(const char* messages...) const{
	cerr << "[Warning]";
	message(messages);
	cerr << endl;
}

void Statsgen::debug(const char* messages...) const {
	if (!debug_enabled) return;
	cerr << "[Debug]";
	message(messages);
	cerr << endl;
}


void Statsgen::askSecurityRules() {
	wcout << "\nMinimal length of a password:" << endl;
	cin >> minLength;
@@ -147,7 +117,8 @@ int Statsgen::generate_stats() {
		td[i].sr.minLower = minLower;
		td[i].sr.minUpper = minUpper;

		debug("Thread", td[i].thread_id, "analyse :", td[i].lineBegin, " -->", td[i].lineEnd);
		if(debug_enabled)
			cerr << "[DEBUG]" << "Thread" << td[i].thread_id << "analyse :" << td[i].lineBegin << " -->" << td[i].lineEnd << endl;
		// 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] );