-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeanyrator.php
58 lines (56 loc) · 1.7 KB
/
geanyrator.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
<?php
/**
* @author
* Gerald Villorente, X-Team
*
* @description
* A PHP snippet to scan a given project (directory) recursively to generate
* tags for Geany's auto-complete functionality.
*
* @param
* Target project directory.
*
* @usage
* php geanyrator.php -d /path/to/drupal/module -e module -e inc -e php > /path/to/geany/tags/dir/project.php.tags
*
* Ex: php geanyrator.php -d /var/www/drupal/sites/all/modules/contrib/views/ -e module -e inc > ~/.config/geany/tags/views.php.tags
*/
// Get the user options.
$opt = getopt("d:e:");
// Flag to determine if the file is whitelisted.
$flag = FALSE;
// Flag to determine if the operation is successful.
$success = FALSE;
if (isset($opt['d']) && is_dir($opt['d']) && isset($opt['e'])) {
$scandir = new RecursiveDirectoryIterator($opt['d']);
$tags = NULL;
// Make sure that extensions is array.
(is_array($opt['e'])) ? $extensions = $opt['e'] : $extensions = array($opt['e']);
foreach (new RecursiveIteratorIterator($scandir) as $file) {
if (!is_dir($file)) {
if (in_array(strtolower(array_pop(explode('.', $file))), $extensions)) {
$success = TRUE;
$lines = file($file);
foreach ($lines as $line) {
if (preg_match_all('[function (.*)\((.*)\) ]U', $line, $matches)) {
$tags .= $matches[1][0] . '||' . $matches[2][0] . "|\n";
}
}
}
else {
$flag = TRUE;
}
}
}
if ($flag && !$success) {
print "Can't find the specified extensions.\n";
}
else {
$contents = "# format=pipe\n";
$contents .= $tags;
print $contents;
}
}
else {
print "Make sure that the directory is existing or the arguments you passed are correct.\n";
}