]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #954 in SNORT/snort3 from snort2lua_fnames to master
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 12 Jul 2017 17:48:32 +0000 (13:48 -0400)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 12 Jul 2017 17:48:32 +0000 (13:48 -0400)
Squashed commit of the following:

commit 3e50cb7c54a20d79b402ec424fa8195bd4078d54
Author: Carter Waxman <cwaxman@cisco.com>
Date:   Wed Jul 12 12:21:48 2017 -0400

    refactored line and file number to method in snort2lua

commit 7b734b33ce1d569c52d86d822a0cc8b03eceb8a5
Author: Carter Waxman <cwaxman@cisco.com>
Date:   Tue Jul 11 16:48:35 2017 -0400

    added line number and file name to snort2lua error output

tools/snort2lua/data/dt_data.cc
tools/snort2lua/data/dt_data.h
tools/snort2lua/helpers/converter.cc

index 6480337e02245aa1c2b65d6819d158f94551f606..c50f8bb12e60d063152ea640b8c05d3d3f4077a0 100644 (file)
@@ -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++;
index bee0897c43307d6ff92c62ee57ac79a71e105264..fe3aa24155bd629d3a944c9466481b78e0567f48 100644 (file)
@@ -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
index a5c18bb5fb20b20e6c8c095ed53c168b9ca46496..3cf3e45cb427fcc196d67191fab1df76f129ab17 100644 (file)
@@ -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] == '#') ||