1- #!/usr/bin/php -q
1+ #!/usr/bin/env php
22<?php
33if (file_exists ($ autoload = __DIR__ . '/vendor/autoload.php ' )) {
44 require ($ autoload );
@@ -12,11 +12,14 @@ if (file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
1212 );
1313}
1414
15- $ options = getopt ('f: ' ,array (
15+ $ options = getopt ('af:R ' ,array (
16+ 'append:: ' ,
1617 'debug ' ,
18+ 'exclude: ' ,
1719 'excmd:: ' ,
1820 'fields:: ' ,
1921 'format:: ' ,
22+ 'recurse:: ' ,
2023 'version ' ,
2124 'memory:: ' ,
2225));
@@ -50,5 +53,64 @@ if(!isset($options['fields'])) {
5053 $ options ['fields ' ] = str_split ($ options ['fields ' ]);
5154}
5255
56+ if (isset ($ options ['append ' ])) {
57+ if ($ options ['append ' ] === FALSE || yes_or_no ($ options ['append ' ]) == 'yes ' ) {
58+ $ options ['a ' ] = FALSE ;
59+ } else if (yes_or_no ($ options ['append ' ]) != 'no ' ) {
60+ die ('phpctags: Invalid value for "append" option ' );
61+ }
62+ }
63+
64+ if (isset ($ options ['recurse ' ])) {
65+ if ($ options ['recurse ' ] === FALSE || yes_or_no ($ options ['recurse ' ]) == 'yes ' ) {
66+ $ options ['R ' ] = FALSE ;
67+ } else if (yes_or_no ($ options ['recurse ' ]) != 'no ' ) {
68+ die ('phpctags: Invalid value for "recurse" option ' );
69+ }
70+ }
71+
5372$ ctags = new PHPCtags ();
54- $ ctags ->export ($ file , $ options );
73+ $ result = '' ;
74+ if (isset ($ options ['R ' ])) {
75+ $ iterator = new RecursiveIteratorIterator (
76+ new RecursiveDirectoryIterator (
77+ $ file ,
78+ FilesystemIterator::SKIP_DOTS |
79+ FilesystemIterator::FOLLOW_SYMLINKS
80+ )
81+ );
82+
83+ $ extensions = array ('.php ' , '.php3 ' , '.php4 ' , '.php5 ' , '.phps ' );
84+
85+ foreach ($ iterator as $ filename ) {
86+ if (!in_array (substr ($ filename , strrpos ($ filename , '. ' )), $ extensions )) {
87+ continue ;
88+ }
89+
90+ if (isset ($ options ['exclude ' ]) && false !== strpos ($ filename , $ options ['exclude ' ])) {
91+ continue ;
92+ }
93+
94+ $ result .= $ ctags ->export ($ filename , $ options );
95+ }
96+ } else {
97+ $ result = $ ctags ->export ($ file , $ options );
98+ }
99+
100+ if (isset ($ options ['f ' ]) && $ options ['f ' ] !== '- ' ) {
101+ $ tagfile = fopen ($ options ['f ' ], isset ($ options ['a ' ]) ? 'a ' : 'w ' );
102+ } else {
103+ $ tagfile = fopen ('php://stdout ' , 'w ' );
104+ }
105+ fwrite ($ tagfile , $ result );
106+ fclose ($ tagfile );
107+
108+ function yes_or_no ($ arg ) {
109+ if (preg_match ('/\b[Y|y]([E|e][S|s])?\b/ ' , $ arg )) {
110+ return 'yes ' ;
111+ } else if (preg_match ('/\b[N|n]([O|o])?\b/ ' , $ arg )) {
112+ return 'no ' ;
113+ } else {
114+ return false ;
115+ }
116+ }
0 commit comments