//
// aegis - project change supervisor
// Copyright (C) 2007, 2008, 2010, 2012, 2014 Peter Miller
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
validation_files_white_space::~validation_files_white_space()
{
}
validation_files_white_space::validation_files_white_space()
{
}
validation::pointer
validation_files_white_space::create(void)
{
return pointer(new validation_files_white_space());
}
bool
validation_files_white_space::check_branches()
const
{
return false;
}
bool
validation_files_white_space::check_downloaded()
const
{
return false;
}
bool
validation_files_white_space::check_foreign_copyright()
const
{
return false;
}
bool
validation_files_white_space::check_binaries()
const
{
return false;
}
bool
validation_files_white_space::check(change::pointer cp, fstate_src_ty *src)
{
nstring path(cp->file_path(src));
assert(!path.empty());
if (path.empty())
return true;
os_become_orig();
int num_blank_lines = 0;
bool ok = true;
input::pointer ip = input_file::open_text(path);
int line_number = 0;
for (;;)
{
nstring line;
if (!ip->one_line(line))
break;
++line_number;
//
// check for white space on the end of the line
//
const char *dp = line.c_str();
const char *ep = dp + line.size();
if (dp < ep && isspace((unsigned char)ep[-1]))
{
sub_context_ty sc;
sc.var_set_format
(
"File_Name",
"%s: %d",
src->file_name->str_text,
line_number
);
change_error
(
cp,
&sc,
i18n("$filename: white space at end of line")
);
ok = false;
}
//
// check for a blank line
//
while (dp < ep)
{
if (!isspace((unsigned char)*dp))
break;
++dp;
}
if (dp == ep)
++num_blank_lines;
else
num_blank_lines = 0;
}
ip.reset();
os_become_undo();
if (num_blank_lines)
{
sub_context_ty sc;
sc.var_set_string("File_Name", src->file_name);
sc.var_set_long("Number", num_blank_lines);
sc.var_optional("Number");
change_error(cp, &sc, i18n("$filename: blank lines at end of file"));
ok = false;
}
return ok;
}
// vim: set ts=8 sw=4 et :