@@ -12,19 +12,80 @@ if (file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
1212 );
1313}
1414
15+ $ version = <<<'EOF'
16+ Version: 0.2
17+
18+ Exuberant Ctags compatiable PHP enhancement, Copyright (C) 2012 Techlive Zheng
19+ Addresses: <techlivezheng@gmail.com>, https://github.com/techlivezheng/phpctags
20+ EOF;
21+
1522$ options = getopt ('af:Nno:RuV ' , array (
1623 'append:: ' ,
1724 'debug ' ,
1825 'exclude: ' ,
1926 'excmd:: ' ,
2027 'fields:: ' ,
2128 'format:: ' ,
29+ 'help ' ,
2230 'recurse:: ' ,
2331 'sort:: ' ,
2432 'version ' ,
2533 'memory:: ' ,
2634));
2735
36+ $ options_info = <<<'EOF'
37+ phpctags currently only supports a subset of the original ctags' options.
38+
39+ Usage: phpctags [options] [file(s)]
40+
41+ -a Append the tags to an existing tag file.
42+ -f <name>
43+ Write tags to specified file. Value of "-" writes tags to stdout
44+ ["tags"].
45+ -n Equivalent to --excmd=number.
46+ -N Equivalent to --excmd=pattern.
47+ -o Alternative for -f.
48+ -R Equivalent to --recurse.
49+ -u Equivalent to --sort=no.
50+ -V Equivalent to --verbose.
51+ --append=[yes|no]
52+ Should tags should be appended to existing tag file [no]?
53+ --debug
54+ phpctags only
55+ Repect PHP's error level configuration.
56+ --exclude=pattern
57+ Exclude files and directories matching 'pattern'.
58+ --excmd=number|pattern|mix
59+ Uses the specified type of EX command to locate tags [mix].
60+ --fields=[+|-]flags
61+ Include selected extension fields (flags: "afmikKlnsStz") [fks].
62+ --format=level
63+ Force output of specified tag file format [2].
64+ --help
65+ Print this option summary.
66+ --memory=[-1|bytes|KMG]
67+ phpctags only
68+ Set how many memories phpctags could use.
69+ --recurse=[yes|no]
70+ Recurse into directories supplied on command line [no].
71+ --sort=[yes|no|foldcase]
72+ Should tags be sorted (optionally ignoring case) [yes]?.
73+ --version
74+ Print version identifier to standard output.
75+ EOF;
76+
77+ // prune options and its value from the $argv array
78+ $ argv_ = array ();
79+ foreach ($ options as $ option => $ value ) {
80+ foreach ($ argv as $ key => $ chunk ) {
81+ $ regex = '/^ ' . (isset ($ option [1 ]) ? '-- ' : '- ' ) . $ option . '/ ' ;
82+ if ($ chunk == $ value && $ argv [$ key -1 ][0 ] == '- ' || preg_match ($ regex , $ chunk )) {
83+ array_push ($ argv_ , $ key );
84+ }
85+ }
86+ }
87+ while ($ key = array_pop ($ argv_ )) unset($ argv [$ key ]);
88+
2889// option -V is an alternative to --version
2990if (isset ($ options ['V ' ])) {
3091 $ options ['version ' ] = FALSE ;
@@ -34,21 +95,21 @@ if (!isset($options['debug'])) {
3495 error_reporting (0 );
3596}
3697
37- if (isset ($ options ['version ' ])) {
38- echo <<<'EOF'
39- Version: 0.2
40-
41- Exuberant Ctags compatiable PHP enhancement, Copyright (C) 2012 Techlive Zheng
42- Addresses: <techlivezheng@gmail.com>, https://github.com/techlivezheng/phpctags
98+ if (isset ($ options ['help ' ])) {
99+ echo $ version ;
100+ echo PHP_EOL ;
101+ echo PHP_EOL ;
102+ echo $ options_info ;
103+ exit ;
104+ }
43105
44- EOF;
106+ if (isset ($ options ['version ' ])) {
107+ echo $ version ;
45108 exit ;
46109}
47110
48111array_shift ($ argv );
49112
50- $ file = array_pop ($ argv );
51-
52113// option -o is an alternative to -f
53114if (isset ($ options ['o ' ]) && !isset ($ options ['f ' ])) {
54115 $ options ['f ' ] = $ options ['o ' ];
@@ -133,7 +194,8 @@ if (isset($options['recurse'])) {
133194
134195try {
135196 $ ctags = new PHPCtags ($ options );
136- $ result = $ ctags ->export ($ file );
197+ $ ctags ->addFiles ($ argv );
198+ $ result = $ ctags ->export ();
137199} catch (Exception $ e ) {
138200 die ("phpctags: {$ e ->getMessage ()}" );
139201}
0 commit comments