-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathparse_cpp.php
More file actions
121 lines (95 loc) · 2.89 KB
/
parse_cpp.php
File metadata and controls
121 lines (95 loc) · 2.89 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
require_once("_inc.php");
// loop through all of our files and create a class for them
$dir = "_headers";
if ($dh = opendir("$dir"))
{
while (($file = readdir($dh)) !== false)
if(preg_match("/\.h\$/", $file))
$headers[] = new CPP_Class(file_get_contents("$dir/$file"));
closedir($dh);
}
// build up our index html
$index = "";
// which headers had classes?
foreach($headers as $header)
if($header->getClassBlock())
$classes[] = $header;
// build up our patterns for replacement
foreach($classes as $class)
{
$patternsLength[] = strlen($class->getClassBlock()->name);
$patterns[] = "/\s(" . $class->getClassBlock()->name . ")/";
}
// sort by length (so we replace SceneLayer before Scene)
array_multisort($patternsLength, $patterns);
$patterns = array_reverse($patterns);
var_dump($patterns);
// callback for replacement
function linkNames_callback($matches)
{
$name = $matches[1];
return " <a href=\"$name.html\">$name</a>";
}
// automagically link names
function linkNames($text)
{
global $patterns;
return @preg_replace_callback($patterns, "linkNames_callback", $text);
}
// process each class
foreach($classes as $class)
{
$name = $class->getClassBlock()->name;
// open up the file for writing, save to index
$fp = fopen("_out/$name.html", "w+");
$index .= "<a href=\"$name.html\">$name</a><br />";
// start with name of class
fwrite($fp, "<h1>$name</h1>");
// process each code block
foreach($class->getBlocks() as $block)
{
// Only include interesting methods, avoid boilerplate stuff
if ($block->type != "Method" && $block->type != "Virtual method")
continue;
// Exclude boilerplate stuff that aren't bound to LUA
if ($block->name == "Create" ||
$block->name == "Destroy" ||
$block->name == "Save" ||
$block->name == "ReadProperty" ||
$block->name == "GetClass" ||
$block->name == "Update" ||
$block->name == "Draw" ||
$block->name == "DrawHUD")
continue;
// // type and name of block
// fwrite($fp, "<h2>$block->type - $block->name</h2>");
// Name of block
fwrite($fp, "<h2>$block->name</h2>");
// Declaration
fwrite($fp, "<p><em>$block->code</em></p>");
// output each field
foreach($block->fields as $key => $value)
{
// fwrite($fp, "<p><strong>$key</strong>" . nl2br(linkNames($value)) . "</p>");
// Description
if ($key == "Description")
fwrite($fp, "<p><strong>$key</strong>" . nl2br(linkNames($value)) . "</p>");
// Arguments
if ($key == "Arguments")
fwrite($fp, "<p><strong>$key</strong>" . nl2br(linkNames($value)) . "</p>");
// Return value
if ($key == "Return value")
fwrite($fp, "<p><strong>$key</strong>" . nl2br(linkNames($value)) . "</p>");
}
// end with declaration
// fwrite($fp, "<h3>Declaration</h3>");
// fwrite($fp, "<p><em>$block->code</em></p>");
}
fclose($fp);
}
// spit out our index file
$fp = fopen("_out/_index.html", "w+");
fwrite($fp, $index);
fclose($fp);
?>