aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-26 20:42:24 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-26 20:42:24 +0000
commit218e82129414af91c6fab89bea8deae4c9ddda6b (patch)
treecefad088130bf986b5971db0ffb23d49c74fc521
parent0d401d34bc811c43cfb13d72c667d2a9e90c4163 (diff)
downloadpaludis-218e82129414af91c6fab89bea8deae4c9ddda6b.tar.gz
paludis-218e82129414af91c6fab89bea8deae4c9ddda6b.tar.xz
Count lines properly.
-rw-r--r--paludis/repositories/e/qa/default_functions.cc45
-rw-r--r--paludis/repositories/e/qa/deprecated_functions.cc13
-rw-r--r--paludis/repositories/e/qa/function_keyword.cc13
-rw-r--r--paludis/repositories/e/qa/header.cc19
-rw-r--r--paludis/repositories/e/qa/kv_variables.cc19
-rw-r--r--paludis/repositories/e/qa/root_variable.cc20
-rw-r--r--paludis/repositories/e/qa/subshell_die.cc13
-rw-r--r--paludis/repositories/e/qa/variable_assigns.cc22
-rw-r--r--paludis/repositories/e/qa/whitespace.cc33
9 files changed, 96 insertions, 101 deletions
diff --git a/paludis/repositories/e/qa/default_functions.cc b/paludis/repositories/e/qa/default_functions.cc
index ae3a0c4..33bb5a3 100644
--- a/paludis/repositories/e/qa/default_functions.cc
+++ b/paludis/repositories/e/qa/default_functions.cc
@@ -20,9 +20,8 @@
#include "default_functions.hh"
#include <paludis/qa.hh>
#include <paludis/util/log.hh>
-#include <paludis/util/tokeniser.hh>
#include <pcre++.h>
-#include <list>
+#include <sstream>
using namespace paludis;
@@ -58,49 +57,47 @@ paludis::erepository::default_functions_check(
Log::get_instance()->message(ll_debug, lc_context) << "default_functions '"
<< entry << "', '" << *id << "', '" << name << "'";
- std::list<std::string> lines;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+ std::istringstream ff(content);
State state(st_default);
std::string line;
bool src_compile_changed(false), src_unpack_changed(false);
- for (std::list<std::string>::const_iterator l(lines.begin()), l_end(lines.end()) ;
- l != l_end ; ++l)
+ while (std::getline(ff, line))
{
switch (state)
{
case st_default:
{
- if (*l == "src_compile() {")
+ if (line == "src_compile() {")
state = st_src_compile;
- else if (*l == "src_unpack() {")
+ else if (line == "src_unpack() {")
state = st_src_unpack;
}
continue;
case st_src_compile:
{
- if (*l == "}")
+ if (line == "}")
{
state = st_default;
if (! src_compile_changed)
reporter.message(QAMessage(entry, qaml_minor, name, "src_compile is redundant")
.with_associated_id(id));
}
- else if (l->empty())
+ else if (line.empty())
;
- else if (r_econf.search(*l))
+ else if (r_econf.search(line))
;
- else if (r_emake.search(*l))
+ else if (r_emake.search(line))
;
- else if (r_echo.search(*l))
+ else if (r_echo.search(line))
;
- else if (r_colon.search(*l))
+ else if (r_colon.search(line))
;
- else if (r_true.search(*l))
+ else if (r_true.search(line))
;
- else if (r_comment.search(*l))
+ else if (r_comment.search(line))
;
else
src_compile_changed = true;
@@ -109,26 +106,26 @@ paludis::erepository::default_functions_check(
case st_src_unpack:
{
- if (*l == "}")
+ if (line == "}")
{
state = st_default;
if (! src_unpack_changed)
reporter.message(QAMessage(entry, qaml_minor, name, "src_unpack is redundant")
.with_associated_id(id));
}
- else if (l->empty())
+ else if (line.empty())
;
- else if (r_unpack.search(*l))
+ else if (r_unpack.search(line))
;
- else if (r_cd_s.search(*l))
+ else if (r_cd_s.search(line))
;
- else if (r_echo.search(*l))
+ else if (r_echo.search(line))
;
- else if (r_colon.search(*l))
+ else if (r_colon.search(line))
;
- else if (r_true.search(*l))
+ else if (r_true.search(line))
;
- else if (r_comment.search(*l))
+ else if (r_comment.search(line))
;
else
src_unpack_changed = true;
diff --git a/paludis/repositories/e/qa/deprecated_functions.cc b/paludis/repositories/e/qa/deprecated_functions.cc
index 2e8f479..ff2c7c9 100644
--- a/paludis/repositories/e/qa/deprecated_functions.cc
+++ b/paludis/repositories/e/qa/deprecated_functions.cc
@@ -26,12 +26,12 @@
#include <paludis/util/log.hh>
#include <paludis/util/options.hh>
#include <paludis/util/system.hh>
-#include <paludis/util/tokeniser.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/name.hh>
#include <paludis/package_id.hh>
#include <list>
#include <string>
+#include <sstream>
#include <utility>
#include <pcre++.h>
@@ -95,22 +95,21 @@ paludis::erepository::deprecated_functions_check(
Log::get_instance()->message(ll_debug, lc_context) << "deprecated_functions '"
<< entry << "', '" << name << "'";
- std::list<std::string> lines;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+ std::stringstream ff(content);
+ std::string s;
unsigned line_number(0);
- for (std::list<std::string>::iterator it(lines.begin()),
- it_end(lines.end()); it_end != it; ++it)
+ while (std::getline(ff, s))
{
++line_number;
- if (it->empty() || r_comment.search(*it))
+ if (s.empty() || r_comment.search(s))
continue;
for (std::list<std::pair<std::string, pcrepp::Pcre::Pcre> >::iterator
r(deprecated_functions.begin()), r_end(deprecated_functions.end()) ;
r != r_end ; ++r )
- if (r->second.search(*it))
+ if (r->second.search(s))
reporter.message(with_id(QAMessage(entry, qaml_normal, name,
"Deprecated call to '" + r->first + "' on line " + stringify(line_number)), id));
}
diff --git a/paludis/repositories/e/qa/function_keyword.cc b/paludis/repositories/e/qa/function_keyword.cc
index e0e55dd..7f25746 100644
--- a/paludis/repositories/e/qa/function_keyword.cc
+++ b/paludis/repositories/e/qa/function_keyword.cc
@@ -20,9 +20,9 @@
#include "function_keyword.hh"
#include <paludis/qa.hh>
#include <paludis/util/log.hh>
-#include <paludis/util/tokeniser.hh>
#include <pcre++.h>
#include <list>
+#include <sstream>
using namespace paludis;
@@ -54,19 +54,18 @@ paludis::erepository::function_keyword_check(
Log::get_instance()->message(ll_debug, lc_context) << "function_keyword '"
<< entry << "', '" << name << "'";
- std::list<std::string> lines;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+ std::stringstream ff(content);
+ std::string s;
unsigned line_number(0);
- for (std::list<std::string>::iterator it(lines.begin()),
- it_end(lines.end()); it_end != it; ++it)
+ while (std::getline(ff, s))
{
++line_number;
- if (it->empty())
+ if (s.empty())
continue;
- if (r_function.search(*it))
+ if (r_function.search(s))
reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Use of the keyword 'function' on line " + stringify(line_number)), id));
}
diff --git a/paludis/repositories/e/qa/header.cc b/paludis/repositories/e/qa/header.cc
index adb23c4..79e0240 100644
--- a/paludis/repositories/e/qa/header.cc
+++ b/paludis/repositories/e/qa/header.cc
@@ -20,10 +20,10 @@
#include "header.hh"
#include <paludis/qa.hh>
#include <paludis/util/log.hh>
-#include <paludis/util/tokeniser.hh>
#include <pcre++.h>
#include <time.h>
#include <vector>
+#include <sstream>
using namespace paludis;
@@ -58,24 +58,31 @@ paludis::erepository::header_check(
pcrepp::Pcre::Pcre r_cvs_header("^#\\s*\\$Header.*\\s(\\d{4})/\\d{2}/\\d{2}\\s.*\\$$");
pcrepp::Pcre::Pcre r_cvs_empty_header("^#\\s*\\$Header:\\s*\\$$");
+ std::stringstream ff(content);
+
+ std::string s;
std::vector<std::string> lines;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+ for (unsigned line_number(0) ; line_number < 3 ; ++line_number)
+ {
+ std::getline(ff, s);
+ lines.push_back(s);
+ }
do
{
- if (! (lines.size() > 1 && r_licence.search(lines[1])))
+ if (! r_licence.search(lines[1]))
reporter.message(with_id(QAMessage(entry, qaml_normal, name, "Wrong licence statement in line 2"), id));
std::string year;
// Check line 3 before line 1 to extract date of last commit
- if (lines.size() > 2 && r_cvs_empty_header.search(lines[2]))
+ if (r_cvs_empty_header.search(lines[2]))
{
time_t now(time(NULL));
struct tm now_struct;
year = stringify(localtime_r(&now, &now_struct)->tm_year + 1900);
}
- else if (lines.size() > 2 && r_cvs_header.search(lines[2]))
+ else if (r_cvs_header.search(lines[2]))
year = r_cvs_header[0];
else
{
@@ -86,7 +93,7 @@ paludis::erepository::header_check(
Log::get_instance()->message(ll_debug, lc_context, "Expected copyright year is " + year);
pcrepp::Pcre::Pcre r_copyright("^# Copyright ((1999|200\\d)-)?" + year + " Gentoo Foundation$");
- if (! (lines.size() > 0 && r_copyright.search(lines[0])))
+ if (! r_copyright.search(lines[0]))
reporter.message(with_id(QAMessage(entry, qaml_normal, name, "Wrong copyright assignment in line 1, possibly date related"), id));
} while (false);
diff --git a/paludis/repositories/e/qa/kv_variables.cc b/paludis/repositories/e/qa/kv_variables.cc
index 9125756..f222bcd 100644
--- a/paludis/repositories/e/qa/kv_variables.cc
+++ b/paludis/repositories/e/qa/kv_variables.cc
@@ -21,9 +21,9 @@
#include <paludis/qa.hh>
#include <paludis/util/strip.hh>
#include <paludis/util/log.hh>
-#include <paludis/util/tokeniser.hh>
#include <pcre++.h>
#include <list>
+#include <sstream>
using namespace paludis;
@@ -43,21 +43,20 @@ paludis::erepository::kv_variables_check(
Log::get_instance()->message(ll_debug, lc_context) << "kv_variables '"
<< entry << "', '" << *id << "', '" << name << "'";
- std::list<std::string> lines;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+ std::stringstream ff(content);
- unsigned line(0);
- for (std::list<std::string>::const_iterator l(lines.begin()), l_end(lines.end()) ;
- l != l_end ; ++l)
+ std::string line;
+ unsigned line_number(0);
+ while (std::getline(ff, line))
{
- ++line;
+ ++line_number;
- if (r_detect_version.search(*l))
+ if (r_detect_version.search(line))
break;
- if (r_global.search(*l))
+ if (r_global.search(line))
reporter.message(QAMessage(entry, qaml_normal, name, "KV variable with no detect_version on line "
- + stringify(line) + ": " + strip_leading(*l, " \t")));
+ + stringify(line_number) + ": " + strip_leading(line, " \t")));
}
return true;
diff --git a/paludis/repositories/e/qa/root_variable.cc b/paludis/repositories/e/qa/root_variable.cc
index fc28731..463ef38 100644
--- a/paludis/repositories/e/qa/root_variable.cc
+++ b/paludis/repositories/e/qa/root_variable.cc
@@ -21,9 +21,9 @@
#include <paludis/qa.hh>
#include <paludis/util/log.hh>
#include <paludis/util/strip.hh>
-#include <paludis/util/tokeniser.hh>
#include <pcre++.h>
#include <list>
+#include <sstream>
using namespace paludis;
@@ -53,15 +53,13 @@ paludis::erepository::root_variable_check(
Log::get_instance()->message(ll_debug, lc_context) << "root_variable '"
<< entry << "', '" << *id << "', '" << name << "'";
- std::list<std::string> lines;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+ std::stringstream ff(content);
State state(st_default);
- std::string func;
+ std::string line, func;
unsigned line_number(0);
- for (std::list<std::string>::const_iterator l(lines.begin()), l_end(lines.end()) ;
- l != l_end ; ++l)
+ while (std::getline(ff, line))
{
++line_number;
@@ -69,10 +67,10 @@ paludis::erepository::root_variable_check(
{
case st_default:
{
- if (r_start.search(*l))
+ if (r_start.search(line))
{
state = st_in_src;
- func = *l;
+ func = line;
if (std::string::npos != func.find('('))
func = func.substr(0, func.find('('));
}
@@ -81,11 +79,11 @@ paludis::erepository::root_variable_check(
case st_in_src:
{
- if (r_end.search(*l))
+ if (r_end.search(line))
state = st_default;
- else if (r_root.search(*l))
+ else if (r_root.search(line))
reporter.message(QAMessage(entry, qaml_maybe, name, "ROOT abuse in " + func + " on line "
- + stringify(line_number) + ": " + strip_leading(*l, " \t"))
+ + stringify(line_number) + ": " + strip_leading(line, " \t"))
.with_associated_id(id));
}
continue;
diff --git a/paludis/repositories/e/qa/subshell_die.cc b/paludis/repositories/e/qa/subshell_die.cc
index f368157..17a272d 100644
--- a/paludis/repositories/e/qa/subshell_die.cc
+++ b/paludis/repositories/e/qa/subshell_die.cc
@@ -20,9 +20,9 @@
#include <paludis/repositories/e/qa/subshell_die.hh>
#include <paludis/qa.hh>
#include <paludis/util/log.hh>
-#include <paludis/util/tokeniser.hh>
#include <pcre++.h>
#include <list>
+#include <sstream>
using namespace paludis;
@@ -55,19 +55,18 @@ paludis::erepository::subshell_die_check(
Log::get_instance()->message(ll_debug, lc_context) << "subshell_die '"
<< entry << "', '" << name << "'";
- std::list<std::string> lines;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+ std::stringstream ff(content);
+ std::string s;
unsigned line(0);
- for (std::list<std::string>::const_iterator l(lines.begin()), l_end(lines.end()) ;
- l != l_end ; ++l)
+ while (std::getline(ff, s))
{
++line;
- if (l->empty() || r_comment.search(*l))
+ if (s.empty() || r_comment.search(s))
continue;
- if (r_subshell_die.search(*l))
+ if (r_subshell_die.search(s))
{
reporter.message(with_id(QAMessage(entry, qaml_normal, name, "Invalid call of 'die' within subshell on line "
+ stringify(line)), id));
diff --git a/paludis/repositories/e/qa/variable_assigns.cc b/paludis/repositories/e/qa/variable_assigns.cc
index 5bf49cb..d17b08c 100644
--- a/paludis/repositories/e/qa/variable_assigns.cc
+++ b/paludis/repositories/e/qa/variable_assigns.cc
@@ -20,9 +20,9 @@
#include "variable_assigns.hh"
#include <paludis/qa.hh>
#include <paludis/util/log.hh>
-#include <paludis/util/tokeniser.hh>
#include <pcre++.h>
#include <list>
+#include <sstream>
using namespace paludis;
@@ -64,37 +64,35 @@ paludis::erepository::variable_assigns_check(
Log::get_instance()->message(ll_debug, lc_context) << "variable_assigns '"
<< entry << "', '" << name << "'";
- std::list<std::string> lines;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+ std::stringstream ff(content);
+ std::string s;
unsigned line_number(0);
bool in_make_continuation(false);
-
- for (std::list<std::string>::iterator it(lines.begin()),
- it_end(lines.end()); it_end != it; ++it)
+ while (std::getline(ff, s))
{
++line_number;
- if (it->empty() || r_comment.search(*it))
+ if (s.empty() || r_comment.search(s))
continue;
- *it = r_strip_quotes.replace(*it, "");
+ s = r_strip_quotes.replace(s, "");
- if (r_make_line.search(*it))
+ if (r_make_line.search(s))
{
- if (r_make_continuation_line.search(*it))
+ if (r_make_continuation_line.search(s))
in_make_continuation = true;
continue;
}
if (in_make_continuation)
{
- in_make_continuation = r_make_continuation_line.search(*it);
+ in_make_continuation = r_make_continuation_line.search(s);
continue;
}
for (std::map<std::string, pcrepp::Pcre::Pcre>::iterator r(r_vars.begin()),
r_end(r_vars.end()) ; r != r_end ; ++r)
- if (r->second.search(*it))
+ if (r->second.search(s))
reporter.message(with_id(QAMessage(entry, qaml_normal, name, "Attempting to assign to " +
r->first + " on line " + stringify(line_number)), id));
}
diff --git a/paludis/repositories/e/qa/whitespace.cc b/paludis/repositories/e/qa/whitespace.cc
index eec675d..525de30 100644
--- a/paludis/repositories/e/qa/whitespace.cc
+++ b/paludis/repositories/e/qa/whitespace.cc
@@ -21,8 +21,8 @@
#include <paludis/qa.hh>
#include <paludis/util/strip.hh>
#include <paludis/util/log.hh>
-#include <paludis/util/tokeniser.hh>
#include <list>
+#include <sstream>
using namespace paludis;
@@ -52,16 +52,15 @@ paludis::erepository::whitespace_check(
Log::get_instance()->message(ll_debug, lc_context) << "whitespace '"
<< entry << "', '" << name << "'";
- std::list<std::string> lines;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+ std::stringstream ff(content);
+ std::string s;
unsigned line(0), err_count(0);
- for (std::list<std::string>::const_iterator l(lines.begin()), l_end(lines.end()) ;
- l != l_end ; ++l)
+ while (std::getline(ff, s))
{
++line;
- if (l->empty())
+ if (s.empty())
continue;
if (err_count >= 3)
@@ -70,43 +69,43 @@ paludis::erepository::whitespace_check(
break;
}
- if (' ' == l->at(0))
+ if (' ' == s.at(0))
{
reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Spaces for indenting on line "
- + stringify(line) + ": " + strip_leading(*l, " \t")), id));
+ + stringify(line) + ": " + strip_leading(s, " \t")), id));
++err_count;
continue;
}
- else if ('\t' == l->at(0))
+ else if ('\t' == s.at(0))
{
- std::string::size_type p(l->find_first_of("\t"));
+ std::string::size_type p(s.find_first_of("\t"));
if (std::string::npos == p)
{
reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Indent followed by no content on line "
- + stringify(line) + ": " + strip_leading(*l, " \t")), id));
+ + stringify(line) + ": " + strip_leading(s, " \t")), id));
++err_count;
continue;
}
- else if (' ' == l->at(p))
+ else if (' ' == s.at(p))
{
reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Mixed tabs and spaces for indenting on line "
- + stringify(line) + ": " + strip_leading(*l, " \t")), id));
+ + stringify(line) + ": " + strip_leading(s, " \t")), id));
++err_count;
continue;
}
- else if (std::string::npos != l->find(p, '\t'))
+ else if (std::string::npos != s.find(p, '\t'))
{
reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Non-intent tab on line "
- + stringify(line) + ": " + strip_leading(*l, " \t")), id));
+ + stringify(line) + ": " + strip_leading(s, " \t")), id));
++err_count;
continue;
}
}
- if (' ' == l->at(l->length() - 1) || '\t' == l->at(l->length() - 1))
+ if (' ' == s.at(s.length() - 1) || '\t' == s.at(s.length() - 1))
{
reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Trailing space on line "
- + stringify(line) + ": " + strip_leading(*l, " \t")), id));
+ + stringify(line) + ": " + strip_leading(s, " \t")), id));
++err_count;
continue;
}