-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateFormatClass.php
executable file
·53 lines (43 loc) · 1.06 KB
/
generateFormatClass.php
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
#!/usr/bin/env php
<?php
exec("git log --help",$cmds);
$classPath="./Git-z/GitLogFormat.hpp";
function cb($m){
return strtoupper($m[1]);
}
$cnt=[];
$items=[];
foreach ($cmds as $cmd) {
if (preg_match_all('|^\s*·\s*%([@%\w]+):\s*([^\\.\\("%]*)|',$cmd,$m,PREG_SET_ORDER)) {
$msg = trim($m[0][2]);
$msg = str_replace(array(',','-'),'',$msg);
$msg = preg_replace_callback("| (\w)|","cb",$msg);
if (isset($cnt[$msg])){
$cnt[$msg]++;
$msg.=$cnt[$msg];
}else {
$cnt[$msg] = 1;
}
$items[]=["str"=>$m[0][1],"msg"=>$msg];
}
}
$output ="//Generated from ".pathinfo(__FILE__,PATHINFO_FILENAME)." ".date(DATE_RFC2822)."\n";
$output .= <<<HEAD
#ifndef GITLOGFORMAT_HPP
#define GITLOGFORMAT_HPP
namespace gitz{
class GitLogFormat
{
public:
HEAD;
foreach ($items as $item) {
$output.=str_pad("\t\tstatic const char* $item[msg]()",70," ")."{ return \"%$item[str]\"; }\n";
}
$output.= <<<FOOT
private: inline GitLogFormat() {} // make class static
};
}
#endif // GITLOGFORMAT_HPP
FOOT;
file_put_contents($classPath,$output);
//print_r($items);