From: Michael Altizer (mialtize) Date: Wed, 12 Jul 2017 17:48:32 +0000 (-0400) Subject: Merge pull request #954 in SNORT/snort3 from snort2lua_fnames to master X-Git-Tag: 3.0.0-239~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5fcedd73edb2bbeaf20eefe4492afbb6408f2a09;p=thirdparty%2Fsnort3.git Merge pull request #954 in SNORT/snort3 from snort2lua_fnames to master Squashed commit of the following: commit 3e50cb7c54a20d79b402ec424fa8195bd4078d54 Author: Carter Waxman Date: Wed Jul 12 12:21:48 2017 -0400 refactored line and file number to method in snort2lua commit 7b734b33ce1d569c52d86d822a0cc8b03eceb8a5 Author: Carter Waxman Date: Tue Jul 11 16:48:35 2017 -0400 added line number and file name to snort2lua error output --- diff --git a/tools/snort2lua/data/dt_data.cc b/tools/snort2lua/data/dt_data.cc index 6480337e0..c50f8bb12 100644 --- a/tools/snort2lua/data/dt_data.cc +++ b/tools/snort2lua/data/dt_data.cc @@ -230,13 +230,21 @@ bool DataApi::failed_conversions() const std::size_t DataApi::num_errors() const { return errors_count; } +std::string DataApi::get_file_line() +{ + std::string error_string = "Failed to convert "; + error_string += current_file + ":"; + error_string += std::to_string(current_line); + return error_string; +} + void DataApi::failed_conversion(const std::istringstream& stream) { // we only need to go through this once. if (!curr_data_bad) { errors->add_text(std::string()); - errors->add_text("Failed to convert the following line:"); + errors->add_text(get_file_line()); errors->add_text(stream.str()); curr_data_bad = true; errors_count++; @@ -250,7 +258,7 @@ void DataApi::failed_conversion(const std::istringstream& stream, if (!curr_data_bad) { errors->add_text(std::string()); - errors->add_text("Failed to convert the following line:"); + errors->add_text(get_file_line()); errors->add_text(stream.str()); curr_data_bad = true; errors_count++; diff --git a/tools/snort2lua/data/dt_data.h b/tools/snort2lua/data/dt_data.h index bee0897c4..fe3aa2415 100644 --- a/tools/snort2lua/data/dt_data.h +++ b/tools/snort2lua/data/dt_data.h @@ -113,6 +113,12 @@ public: // caused the failure. void failed_conversion(const std::istringstream& stream, const std::string unkown_option); + void set_current_file(std::string& file) + { current_file = file; } + + void set_current_line(unsigned line) + { current_line = line; } + private: enum class PrintMode @@ -133,6 +139,10 @@ private: Comments* errors; bool curr_data_bad; // keep track whether current 'conversion' is already bad + std::string current_file; + unsigned current_line; + + std::string get_file_line(); }; #endif diff --git a/tools/snort2lua/helpers/converter.cc b/tools/snort2lua/helpers/converter.cc index a5c18bb5f..3cf3e45cb 100644 --- a/tools/snort2lua/helpers/converter.cc +++ b/tools/snort2lua/helpers/converter.cc @@ -147,6 +147,8 @@ int Converter::parse_include_file(std::string input_file) int Converter::parse_file(std::string input_file) { + data_api.set_current_file(input_file); + std::ifstream in; std::string orig_text; @@ -159,12 +161,15 @@ int Converter::parse_file(std::string input_file) return -1; in.open(input_file, std::ifstream::in); + unsigned line_num = 0; while (!in.eof()) { std::string tmp; std::getline(in, tmp); util::rtrim(tmp); + data_api.set_current_line(++line_num); + std::size_t first_non_white_char = tmp.find_first_not_of(' '); if ((first_non_white_char == std::string::npos) || (tmp[first_non_white_char] == '#') ||