Menu

[r938]: / trunk / tools / checkyear.js  Maximize  Restore  History

Download this file

101 lines (90 with data), 2.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
/* This script is a local pre-commit hook script.
* It's used to check whether the copyright year of modified files has been
* bumped up to the current (2014) year.
*
* Only *.cpp, *.h and *.idl files are checked
*
* Set the local hook scripts like this (pre-commit hook):
* WScript path/to/this/script/file.js
* and set "Wait for the script to finish"
*/
var ForReading = 1;
var objArgs, num;
objArgs = WScript.Arguments;
num = objArgs.length;
if (num != 4 && num != 3)
{
WScript.Echo("Usage: [CScript | WScript] checkyear.js path/to/pathsfile depth path/to/messagefile path/to/CWD");
WScript.Quit(1);
}
var re = /^\/\/ Copyright.+(2014)(.*)/;
var basere = /^\/\/ Copyright(.*)/;
var filere = /(\.cpp$)|(\.h$)|(\.idl$)/;
var found = true;
var fs, a, rv, r;
fs = new ActiveXObject("Scripting.FileSystemObject");
// remove the quotes
var files = readPaths(objArgs(0));
// going backwards with while is believed to be faster
var fileindex = files.length;
var errormsg = "";
while (fileindex--)
{
var f = files[fileindex];
if (f.match(filere) !== null)
{
if (fs.FileExists(f))
{
a = fs.OpenTextFile(f, ForReading, false);
var copyrightFound = false;
var yearFound = false;
while (!a.AtEndOfStream && !yearFound)
{
r = a.ReadLine();
rv = r.match(basere);
if (rv !== null)
{
rv = r.match(re);
if (rv !== null)
{
yearFound = true;
}
copyrightFound = true;
}
}
a.Close();
if (copyrightFound && !yearFound)
{
if (errormsg !== "")
{
errormsg += "\n";
}
errormsg += f;
found = false;
}
}
}
}
if (found === false)
{
errormsg = "the file(s):\n" + errormsg + "\nhave not the correct copyright year!";
WScript.stderr.writeLine(errormsg);
}
WScript.Quit(!found);
// readFileLines
function readPaths(path)
{
var retPaths = [];
var fs = new ActiveXObject("Scripting.FileSystemObject");
if (fs.FileExists(path))
{
var a = fs.OpenTextFile(path, ForReading);
while (!a.AtEndOfStream)
{
var line = a.ReadLine();
retPaths.push(line);
}
a.Close();
}
return retPaths;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.