-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuildtags.php
131 lines (107 loc) · 3.29 KB
/
buildtags.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
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
<?php
define('API_DIR', '/Users/featherless/Sites/three20/api/');
define('API_SEARCH_DIR', API_DIR.'search/');
function read_dir($dir) {
$filenames = array();
$directory = opendir($dir);
while ($filename = readdir($directory)) {
if ($filename[0] != '.') {
$filenames[] = $filename;
}
}
closedir($directory);
return $filenames;
}
$searchFilenames = read_dir(API_SEARCH_DIR);
// Now that we have all of the search index files, let's split them apart by index type.
$indexFilenames = array();
foreach ($searchFilenames as $filename) {
$info = pathinfo($filename);
if ($info['extension'] == 'html' ) {
$underscorePosition = strpos($filename, '_');
if ($underscorePosition !== FALSE) {
$index = substr($filename, 0, $underscorePosition);
if (empty($indexFilenames[$index])) {
$indexFilenames[$index] = array();
}
$indexFilenames[$index] []= $filename;
}
}
}
$indices = array();
$active_index = null;
$in_scope_field = false;
function contents($parser, $data) {
global $indices;
global $active_index;
global $in_scope_field;
if ($in_scope_field) {
if ($active_index == 'classes') {
$indices[$active_index]['names'] []= $data;
$in_scope_field = false;
} else {
$indices[$active_index]['names'] []= $data;
$in_scope_field = false;
}
}
}
function startTag($parser, $name, $attribs) {
global $indices;
global $active_index;
global $in_scope_field;
if ($active_index == 'classes') {
if (isset($attribs['CLASS']) && $attribs['CLASS'] == 'SRSymbol') {
if (substr($attribs['HREF'], 0, 3) != 'jav') {
$indices[$active_index]['links'] []= $attribs['HREF'];
$in_scope_field = true;
}
}
} else {
if (isset($attribs['CLASS']) && $attribs['CLASS'] == 'SRSymbol') {
if (substr($attribs['HREF'], 0, 3) != 'jav') {
$indices[$active_index]['links'] []= $attribs['HREF'];
}
}
if (isset($attribs['CLASS']) && $attribs['CLASS'] == 'SRScope' &&
(!isset($attribs['ONKEYDOWN']) || strpos($attribs['ONKEYDOWN'], 'NavChild') === FALSE)) {
$in_scope_field = true;
} else {
$in_scope_field = false;
}
}
}
function endTag($parser, $name) {
$in_scope_field = false;
}
foreach ($indexFilenames as $index => $filenames) {
$indices[$index] = array(
'links' => array(),
'names' => array()
);
$active_index = $index;
foreach ($filenames as $filename) {
$data = file_get_contents(API_SEARCH_DIR.$filename);
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
if (!(xml_parse($xml_parser, $data, TRUE))) {
//echo $filename."\n";
//echo xml_error_string(xml_get_error_code($xml_parser))."\n";
//echo "Error on line ".xml_get_current_line_number($xml_parser)."\n";
}
xml_parser_free($xml_parser);
}
}
$class_lookup = array();
for ($ix = 0; $ix < count($indices['classes']['names']); ++$ix) {
$link = $indices['classes']['links'][$ix];
$link = substr($link, 3);
$class_lookup[$indices['classes']['names'][$ix]] = $link;
}
echo '$ttTags = array(\n';
$map = array();
foreach ($class_lookup as $name => $link) {
$map []= " '".$name."'";
}
echo implode(",\n", $map)."\n";
echo ");\n";