Menu

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

Download this file

103 lines (86 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
101
102
/* 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 (2015) 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 = WScript.Arguments;
var 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.+(2018)(.*)/;
var basere = /^\/\/ Copyright(.*)/;
var filere = /(\.cpp$)|(\.h$)|(\.idl$)/;
// readFileLines
function readPaths(path)
{
var retPaths = [];
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
if (fileSystem.FileExists(path))
{
var textFile = fileSystem.OpenTextFile(path, forReading);
while (!textFile.AtEndOfStream)
{
var line = textFile.ReadLine();
retPaths.push(line);
}
textFile.Close();
}
return retPaths;
}
var found = true;
var files = readPaths(objArgs(0));
var fileIndex = files.length;
var errorMessage = "";
while (fileIndex--)
{
var f = files[fileIndex];
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (f.match(filere) !== null)
{
if (fso.FileExists(f))
{
var a = fso.OpenTextFile(f, forReading, false);
var copyrightFound = false;
var yearFound = false;
while (!a.AtEndOfStream && !yearFound)
{
var r = a.ReadLine();
var rv = r.match(basere);
if (rv !== null)
{
rv = r.match(re);
if (rv !== null)
{
yearFound = true;
}
copyrightFound = true;
}
}
a.Close();
if (copyrightFound && !yearFound)
{
if (errorMessage !== "")
{
errorMessage += "\n";
}
errorMessage += f;
found = false;
}
}
}
}
if (found === false)
{
errorMessage = "the file(s):\n" + errorMessage + "\nhave not the correct copyright year!";
WScript.stderr.writeLine(errorMessage);
}
WScript.Quit(!found);
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.