OSDN Git Service

Add Miss file
[tortoisegit/TortoiseGitJp.git] / contrib / hook-scripts / client-side / checkyear.js
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
4 //\r
5 // Only *.cpp and *.h files are checked\r
6 //\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
10 \r
11 var objArgs,num;\r
12 \r
13 objArgs = WScript.Arguments;\r
14 num = objArgs.length;\r
15 if (num != 4)\r
16 {\r
17     WScript.Echo("Usage: [CScript | WScript] checkyear.js path/to/pathsfile depth path/to/messagefile path/to/CWD");\r
18     WScript.Quit(1);\r
19 }\r
20 \r
21 var re = /^\/\/ Copyright.+(2008)(.*)/;\r
22 var basere = /^\/\/ Copyright(.*)/;\r
23 var filere = /(\.cpp$)|(\.h$)/;\r
24 var found = true;\r
25 var fs, a, ForAppending, rv, r;\r
26 ForReading = 1;\r
27 fs = new ActiveXObject("Scripting.FileSystemObject");\r
28 // remove the quotes\r
29 var files = readPaths(objArgs(0));\r
30 var fileindex=0;\r
31 var errormsg = "";\r
32 while (fileindex < files.length)\r
33 {\r
34         var f = files[fileindex];\r
35     if (f.match(filere) != null)\r
36     {\r
37                 if (fs.FileExists(f))\r
38                 {\r
39                         a = fs.OpenTextFile(f, ForReading, false);\r
40                         var currentfound = false;\r
41                         while ((!a.AtEndOfStream)&&(!currentfound))\r
42                         {\r
43                                 r =  a.ReadLine();\r
44                                 rv = r.match(basere);\r
45                                 if (rv != null)\r
46                                 {\r
47                                         rv = r.match(re);\r
48                                         if (rv == null)\r
49                                         {\r
50                                                 if (errormsg != "")\r
51                                                         errormsg += "\n";\r
52                                                 errormsg += f;\r
53                                                 found = false;\r
54                                         }\r
55                                         currentfound = true;\r
56                                 }\r
57                         }\r
58                         a.Close();\r
59                 }\r
60     }\r
61     fileindex+=1;\r
62 }\r
63 \r
64 if (found == false)\r
65 {\r
66         errormsg = "the file(s):\n" + errormsg + "\nhave not the correct copyright year!";\r
67         WScript.stderr.writeLine(errormsg);\r
68 }\r
69 \r
70 WScript.Quit(!found);\r
71 \r
72 \r
73 function readPaths(path)\r
74 {\r
75         var retPaths = new Array();\r
76         var fs = new ActiveXObject("Scripting.FileSystemObject");\r
77         if (fs.FileExists(path))\r
78         {\r
79                 var a = fs.OpenTextFile(path, 1, false);\r
80                 var i = 0;\r
81                 while (!a.AtEndOfStream)\r
82                 {\r
83                         var line = a.ReadLine();\r
84                         retPaths[i] = line;\r
85                         i = i + 1;\r
86                 }\r
87                 a.Close();\r
88         }\r
89         return retPaths;\r
90         \r
91 }