// // aegis - project change supervisor // Copyright (C) 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_authors::~validation_authors() { } validation_authors::validation_authors() { } validation::pointer validation_authors::create(void) { return pointer(new validation_authors()); } static nstring calc_year(void) { time_t when = now(); struct tm *tmp = localtime(&when); char buffer[10]; strftime(buffer, sizeof(buffer), "%Y", tmp); return nstring(buffer); } bool validation_authors::run(change::pointer cp) { // // Don't check branches, only individual changes have control over // the AUTHORS source file. // if (cp->was_a_branch()) return true; // // Don't perform this check for changes downloaded and applied by // aedist, because the original developer is no longer in control. // if (was_downloaded(cp)) return true; // // Don't perform this check for change sets marked as owning a // foreign copyright. // if (cp->attributes_get_boolean("foreign-copyright")) return true; // // Check each file in the change set. // fstate_src_ty *src = cp->file_find("AUTHORS", view_path_extreme); if (!src) { sub_context_ty sc; sc.var_set_charstar("File_Name", "AUTHORS"); change_error(cp, &sc, i18n("proj has no $filename file")); return false; } nstring path(cp->file_path(src)); assert(!path.empty()); if (path.empty()) return true; nstring year(calc_year()); nstring who(cp->pconf_copyright_owner_get()); nstring suggest("Copyright (C) " + year + " " + who); bool copyright_seen = false; bool public_domain_seen = false; os_become_orig(); input::pointer ip = input_file::open(path); for (;;) { nstring line; if (!ip->one_line(line)) break; const char *s = strstr(line.c_str(), "Copyright (C)"); if ( s && ( (strstr(s, year.c_str()) && strstr(s, who.c_str())) || strstr(s, "${date %Y}") ) ) copyright_seen = true; s = strstr(line.c_str(), "Public Domain"); if (s && strstr(s, who.c_str())) public_domain_seen = true; } ip.reset(); os_become_undo(); if (!copyright_seen && !public_domain_seen) { sub_context_ty sc; sc.var_set_string("File_Name", src->file_name); sc.var_set_string("Suggest", suggest); sc.var_optional("Suggest"); change_error(cp, &sc, i18n("$filename: no current copyright notice")); return false; } return true; } // vim: set ts=8 sw=4 et :