-
Notifications
You must be signed in to change notification settings - Fork 595
/
create_php_tags.php
executable file
·70 lines (54 loc) · 2.15 KB
/
create_php_tags.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
#!/usr/bin/php
<?php
// Author: Matti Mårds
// License: GPL V2 or later
// Script to generate a new php.tags file from a downloaded PHP function summary list from
// http://cvs.php.net/viewvc.cgi/phpdoc/funcsummary.txt?view=co
// The script expects a file funcsummary.txt in /tmp and will write the parsed tags into
// data/php.tags.
//
// wget -O funcsummary.txt "http://cvs.php.net/viewvc.cgi/phpdoc/funcsummary.txt?view=co"
//
// (the script should be run in the top source directory)
# (from tagmanager/tm_tag.c:32)
define("TA_NAME", 200);
define("TA_TYPE", 204);
define("TA_ARGLIST", 205);
define("TA_VARTYPE", 207);
# TMTagType (tagmanager/tm_tag.h:47)
define("TYPE_FUNCTION", 128);
// Create an array of the lines in the file
$file = file('funcsummary.txt');
// Create template for a tag (tagmanager format)
$tagTpl = "%s%c%d%c%s%c%s";
// String to store the output
$tagsOutput = array();
// Iterate through each line of the file
for($line = 0, $lineCount = count($file); $line < $lineCount; ++$line) {
// If the line isn't a function definition, skip it
if(!preg_match('/^(?P<retType>\w+) (?P<funcName>[\w:]+)(?P<params>\(.*?\))/', $file[$line], $funcDefMatch)) {
continue;
}
// Skip methods as they aren't used for now
if (strpos($funcDefMatch['funcName'], '::') !== false) {
continue;
}
// Get the function description
//$funcDesc = trim($file[$line + 1]);
// Geany doesn't use the function description (yet?), so use an empty string to save space
$funcDesc = '';
// Remove the void parameter, it will only confuse some people
if($funcDefMatch['params'] === '(void)') {
$funcDefMatch['params'] = '()';
}
// $funcDefMatch['funcName'] = str_replace('::', '->', $funcDefMatch['funcName']);
$tagsOutput[] = sprintf($tagTpl, $funcDefMatch['funcName'], TA_TYPE, TYPE_FUNCTION,
TA_ARGLIST, $funcDefMatch['params'], TA_VARTYPE, $funcDefMatch['retType']);
}
$tagsOutput[] = sprintf(
'# format=tagmanager - Automatically generated file - do not edit (created on %s)',
date('r'));
// Sort the output
sort($tagsOutput);
file_put_contents('data/php.tags', join("\n", $tagsOutput));
?>