-
Notifications
You must be signed in to change notification settings - Fork 16
/
show_library_api
executable file
·144 lines (126 loc) · 3.32 KB
/
show_library_api
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/php
<?php
/* show_library_api
*
* Copyright (C) by Hugo Leisink <[email protected]>
* This file is part of the Banshee PHP framework
* http://www.banshee-php.org/
*/
chdir(dirname($argv[0]));
require("libraries/banshee.php");
require("libraries/helpers/console.php");
function show_directory_content($directory) {
$result = array();
if (($dp = opendir($directory)) !== false) {
while (($file = readdir($dp)) !== false) {
if ($file[0] == ".") {
continue;
} else if ($file == "helpers") {
continue;
}
$file = $directory."/".$file;
if (is_dir($file)) {
$files = show_directory_content($file);
$result = array_merge($result, $files);
} else if (substr($file, -4) == ".php") {
array_push($result, $file);
}
}
closedir($dp);
}
return $result;
}
error_reporting(E_ALL & ~E_NOTICE);
print "Show Banshee Library API\n\n";
if (count($argv) == 1) {
$files = show_directory_content("libraries");
sort($files);
$width = get_terminal_width();
$max = 0;
foreach ($files as &$file) {
$file = substr($file, 10);
$len = strlen($file);
if ($len > $max) {
$max = $len;
}
unset($file);
}
$cols = floor($width / ($max + 2));
$col = 0;
print "Usage: ".$argv[0]." <library>\n\n";
print "Available libaries:\n";
foreach ($files as $file) {
print " ".str_pad($file, $max);
if (++$col >= $cols) {
print "\n";
$col = 0;
}
}
print "\n";
return;
}
$directories = array("libraries", "libraries/database");
foreach ($directories as $directory) {
if (($fp = @fopen($directory."/".$argv[1], "r")) === false) {
$fp = @fopen($directory."/".$argv[1].".php", "r");
}
if ($fp !== false) {
break;
}
}
if ($fp === false) {
print "Library ".$argv[1]." not found.\n";
return;
}
$in_class = $in_get = $in_set = false;
while (($line = fgets($fp)) !== false) {
$line = chop($line);
if (preg_match("/^\tfunction /", $line) == 1) {
print substr(trim($line), 0, -2).";\n";
} else if (preg_match("/^\t\tpublic function __([a-z]*)/", $line, $matches) == 1) {
switch ($matches[1]) {
case "construct":
if (substr(trim($line), 28, -3) != "") {
print " constructor ".substr(trim($line), 16, -2).";\n";
}
break;
case "get":
$in_get = true;
break;
case "set":
$in_set = true;
break;
default:
if ($matches[1] != "destruct") {
print " magic method ".substr(trim($line), 16, -2).";\n";
}
}
} else if (preg_match("/\t*case /", $line) == 1) {
list(, $property) = explode("\"", $line, 3);
if ($in_get) {
$properties[$property] .= "r";
} else if ($in_set) {
$properties[$property] .= "w";
}
} else if (preg_match("/^\t(abstract |final )?class /", $line) == 1) {
print trim($line)."\n";
$in_class = true;
$properties = array();
} else if (preg_match("/^\t\tpublic function /", $line) == 1) {
foreach ($properties as $property => $type) {
print " property (".str_pad($type.")", 5).$property.";\n";
}
$properties = array();
print " method ".substr(trim($line), 16, -2).";\n";
} else if ($line == "\t\t\t}") {
if ($in_get) $in_get = false;
if ($in_set) $in_set = false;
} else if ($line == "\t}") {
if ($in_class) {
$in_class = false;
print "}\n\n";
}
}
}
fclose($fp);
?>