1 // this script is a local pre-commit hook script.
\r
2 // Used to check whether the copyright year of modified files has been bumped
\r
3 // up to the current (2007) year.
\r
5 // Only *.cpp and *.h files are checked
\r
7 // Set the local hook scripts like this (pre-commit hook):
\r
8 // WScript path/to/this/script/file.js
\r
9 // and set "Wait for the script to finish"
\r
13 objArgs = WScript.Arguments;
\r
14 num = objArgs.length;
\r
17 WScript.Echo("Usage: [CScript | WScript] checkyear.js path/to/pathsfile depth path/to/messagefile path/to/CWD");
\r
21 var re = /^\/\/ Copyright.+(2008)(.*)/;
\r
22 var basere = /^\/\/ Copyright(.*)/;
\r
23 var filere = /(\.cpp$)|(\.h$)/;
\r
25 var fs, a, ForAppending, rv, r;
\r
27 fs = new ActiveXObject("Scripting.FileSystemObject");
\r
28 // remove the quotes
\r
29 var files = readPaths(objArgs(0));
\r
32 while (fileindex < files.length)
\r
34 var f = files[fileindex];
\r
35 if (f.match(filere) != null)
\r
37 if (fs.FileExists(f))
\r
39 a = fs.OpenTextFile(f, ForReading, false);
\r
40 var currentfound = false;
\r
41 while ((!a.AtEndOfStream)&&(!currentfound))
\r
44 rv = r.match(basere);
\r
55 currentfound = true;
\r
66 errormsg = "the file(s):\n" + errormsg + "\nhave not the correct copyright year!";
\r
67 WScript.stderr.writeLine(errormsg);
\r
70 WScript.Quit(!found);
\r
73 function readPaths(path)
\r
75 var retPaths = new Array();
\r
76 var fs = new ActiveXObject("Scripting.FileSystemObject");
\r
77 if (fs.FileExists(path))
\r
79 var a = fs.OpenTextFile(path, 1, false);
\r
81 while (!a.AtEndOfStream)
\r
83 var line = a.ReadLine();
\r