//
// 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
#include
validation_files_no_tabs::~validation_files_no_tabs()
{
}
validation_files_no_tabs::validation_files_no_tabs()
{
}
validation::pointer
validation_files_no_tabs::create(void)
{
return pointer(new validation_files_no_tabs());
}
bool
validation_files_no_tabs::check_branches()
const
{
return false;
}
bool
validation_files_no_tabs::check_downloaded()
const
{
return false;
}
bool
validation_files_no_tabs::check_foreign_copyright()
const
{
return false;
}
bool
validation_files_no_tabs::check_binaries()
const
{
return false;
}
bool
validation_files_no_tabs::check(change::pointer cp, fstate_src_ty *src)
{
//
// Don't perform this check for files marked as being allowed to
// have tabs.
//
if
(
attributes_list_find_boolean
(
src->attribute,
"aede-policy-tabs-allowed"
)
)
return true;
//
// Some files must have tabs,
// that's what the idiot format requires.
//
nstring t(src->file_name);
if (t.basename().downcase().starts_with("makefile"))
return true;
string_ty *path = cp->file_path(src);
assert(path);
if (!path)
return true;
os_become_orig();
bool ok = true;
input::pointer ip = input_file::open_text(nstring(path));
for (;;)
{
int c = ip->getch();
if (c < 0)
break;
if (c == 0)
{
// binary files are exempt from the check.
break;
}
if (c == '\t')
{
ok = false;
break;
}
}
ip.reset();
os_become_undo();
if (!ok)
{
sub_context_ty sc;
sc.var_set_string("File_Name", src->file_name);
change_error(cp, &sc, i18n("$filename: contains tab characters"));
}
return ok;
}
// vim: set ts=8 sw=4 et :