Skip to content

Commit 39c29a8

Browse files
committed
Merge branch 'release/0.4'
2 parents 81e9d8f + fd09ecf commit 39c29a8

File tree

8 files changed

+209
-26
lines changed

8 files changed

+209
-26
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
vendor
2-
composer.lock
3-
composer.phar
41
tests/*.expect
52
tests/*.result
3+
build/
4+
vendor/
5+
phpctags

ChangeLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Version 0.4
2+
-----------
3+
4+
* add tagline support
5+
thanks to Mark Wu
6+
* add a Makefile to build stand-alone PHAR executable
7+
thanks to Mark Wu
8+
* update PHPParser dependency to version 0.9.3
9+
110
Version 0.3
211
-----------
312

Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
source := README.md \
2+
ChangeLog.md \
3+
composer.json \
4+
composer.lock \
5+
bootstrap.php \
6+
PHPCtags.class.php
7+
8+
.PHONY: all
9+
all: phpctags
10+
11+
.PHONY: clean
12+
clean:
13+
@echo "Cleaning executables ..."
14+
@rm -f ./phpctags
15+
@rm -f ./build/phpctags.phar
16+
@echo "Done!"
17+
18+
.PHONY: dist-clean
19+
dist-clean:
20+
@echo "Cleaning old build files and vendor libraries ..."
21+
@rm -rf ./build
22+
@rm -rf ./vendor
23+
@rm -f ./phpctags
24+
@echo "Done!"
25+
26+
.PHONY: install
27+
install: phpctags
28+
@echo "Sorry, you need to move phpctags to /usr/bin/phpctags or /usr/local/bin/phpctags or any place you want manually."
29+
30+
build:
31+
@if [ ! -x build ]; \
32+
then \
33+
mkdir build; \
34+
fi
35+
36+
build/composer.phar: | build
37+
@echo "Installing composer ..."
38+
@curl -s http://getcomposer.org/installer | php -- --install-dir=build
39+
40+
vendor: composer.lock build/composer.phar
41+
@echo "Installing vendor libraries ..."
42+
@php build/composer.phar install
43+
@touch vendor/
44+
45+
build/phpctags.phar: vendor $(source) | build
46+
@php -dphar.readonly=0 buildPHAR.php
47+
@chmod +x build/phpctags.phar
48+
49+
phpctags: build/phpctags.phar
50+
@echo "Building phpctags ..."
51+
@cp build/phpctags.phar phpctags
52+
@echo "Done!"

PHPCtags.class.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
class PHPCtags
33
{
4+
const VERSION = 0.4;
5+
46
private $mFile;
57

68
private $mFiles;
@@ -343,18 +345,26 @@ private function process($file)
343345
continue;
344346
}
345347

346-
$this->setMFile((string) $filename);
348+
try {
349+
$this->setMFile((string) $filename);
350+
$this->mStructs = array_merge(
351+
$this->mStructs,
352+
$this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE)
353+
);
354+
} catch(Exception $e) {
355+
echo "PHPParser: {$e->getMessage()} - {$filename}".PHP_EOL;
356+
}
357+
}
358+
} else {
359+
try {
360+
$this->setMFile($file);
347361
$this->mStructs = array_merge(
348362
$this->mStructs,
349363
$this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE)
350364
);
365+
} catch(Exception $e) {
366+
echo "PHPParser: {$e->getMessage()} - {$filename}".PHP_EOL;
351367
}
352-
} else {
353-
$this->setMFile($file);
354-
$this->mStructs = array_merge(
355-
$this->mStructs,
356-
$this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE)
357-
);
358368
}
359369
}
360370
}

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ Enjoy!
1818
Installation
1919
------------
2020

21-
We use [composer](http://getcomposer.org/) for dependency management, run the
22-
following commands under the project directory to get composer and install the
23-
dependency.
24-
25-
curl -s http://getcomposer.org/installer | php
26-
php composer.phar install
21+
Installation is simple, just run `make` in the root directory of the source,
22+
you will get a `phpctags` PHAR executable, add it to your `$PATH`, then you
23+
can invoke `phpcatgs` directly from anywhere.
2724

2825
See [phpctags on packagist](http://packagist.org/packages/techlivezheng/phpctags)
2926
for more details.
@@ -40,3 +37,4 @@ Acknowledgements
4037
* [Snapi](https://github.com/sanpii) for composer support.
4138
* [DeMarko](https://github.com/DeMarko) for memory limit support.
4239
* [Sander Marechal](https://github.com/sandermarechal) for improve console support
40+
* [Mark Wu](https://github.com/markwu) for building a stand-alone PHAR executable

phpctags renamed to bootstrap.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env php
21
<?php
32
if (file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
43
require($autoload);
@@ -12,9 +11,9 @@
1211
);
1312
}
1413

15-
$version = <<<'EOF'
16-
Version: 0.3
14+
$version = PHPCtags::VERSION;
1715

16+
$copyright = <<<'EOF'
1817
Exuberant Ctags compatiable PHP enhancement, Copyright (C) 2012 Techlive Zheng
1918
Addresses: <techlivezheng@gmail.com>, https://github.com/techlivezheng/phpctags
2019
EOF;
@@ -96,15 +95,17 @@
9695
}
9796

9897
if (isset($options['help'])) {
99-
echo $version;
98+
echo "Version: ".$version."\n\n".$copyright;
10099
echo PHP_EOL;
101100
echo PHP_EOL;
102101
echo $options_info;
102+
echo PHP_EOL;
103103
exit;
104104
}
105105

106106
if (isset($options['version'])) {
107-
echo $version;
107+
echo "Version: ".$version."\n\n".$copyright;
108+
echo PHP_EOL;
108109
exit;
109110
}
110111

@@ -158,7 +159,7 @@
158159
} else if ($options['sort'] == 'foldcase') {
159160
$options['sort'] = 'foldcase';
160161
} else {
161-
die('phpctags: Invalid value for "sort" option');
162+
die('phpctags: Invalid value for "sort" option'.PHP_EOL);
162163
}
163164
// option -n is equivalent to --sort=no
164165
} else if (isset($options['u'])) {
@@ -180,15 +181,15 @@
180181
if ($options['append'] === FALSE || yes_or_no($options['append']) == 'yes') {
181182
$options['a'] = FALSE;
182183
} else if (yes_or_no($options['append']) != 'no') {
183-
die('phpctags: Invalid value for "append" option');
184+
die('phpctags: Invalid value for "append" option'.PHP_EOL);
184185
}
185186
}
186187

187188
if (isset($options['recurse'])) {
188189
if ($options['recurse'] === FALSE || yes_or_no($options['recurse']) == 'yes') {
189190
$options['R'] = FALSE;
190191
} else if (yes_or_no($options['recurse']) != 'no') {
191-
die('phpctags: Invalid value for "recurse" option');
192+
die('phpctags: Invalid value for "recurse" option'.PHP_EOL);
192193
}
193194
}
194195

@@ -202,7 +203,7 @@
202203
$ctags->addFiles($argv);
203204
$result = $ctags->export();
204205
} catch (Exception $e) {
205-
die("phpctags: {$e->getMessage()}");
206+
die("phpctags: {$e->getMessage()}".PHP_EOL);
206207
}
207208

208209
// write to a specified file
@@ -215,7 +216,18 @@
215216
} else {
216217
$tagfile = fopen('tags', isset($options['a']) ? 'a' : 'w');
217218
}
218-
fwrite($tagfile, $result);
219+
220+
$mode = ($options['sort'] == 'yes' ? 1 : ($options['sort'] == 'foldcase' ? 2 : 0));
221+
$tagline = <<<EOF
222+
!_TAG_FILE_FORMAT\t2\t/extended format; --format=1 will not append ;" to lines/
223+
!_TAG_FILE_SORTED\t{$mode}\t/0=unsorted, 1=sorted, 2=foldcase/
224+
!_TAG_PROGRAM_AUTHOR\ttechlivezheng\t/techlivezheng@gmail.com/
225+
!_TAG_PROGRAM_NAME\tphpctags\t//
226+
!_TAG_PROGRAM_URL\thttps://github.com/techlivezheng/phpctags\t/official site/
227+
!_TAG_PROGRAM_VERSION\t${version}\t//\n
228+
EOF;
229+
230+
fwrite($tagfile, $tagline.$result);
219231
fclose($tagfile);
220232

221233
function yes_or_no($arg) {

buildPHAR.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
$phar = new Phar('build/phpctags.phar', 0, 'phpctags.phar');
4+
5+
$phar->buildFromIterator(
6+
new RecursiveIteratorIterator(
7+
new RecursiveCallbackFilterIterator(
8+
new RecursiveDirectoryIterator(
9+
getcwd(),
10+
FilesystemIterator::SKIP_DOTS
11+
),
12+
function ($current) {
13+
$excludes = array(
14+
'.*',
15+
'tags',
16+
'build/*',
17+
'tests/*',
18+
'Makefile',
19+
'phpctags.sh',
20+
'buildPHAR.php',
21+
);
22+
23+
foreach($excludes as $exclude) {
24+
if (fnmatch(getcwd().'/'.$exclude, $current->getPathName())) {
25+
return false;
26+
}
27+
}
28+
29+
return true;
30+
}
31+
)
32+
),
33+
getcwd()
34+
);
35+
36+
$phar->setStub(
37+
"#!/usr/bin/env php\n".$phar->createDefaultStub('bootstrap.php')
38+
);

composer.lock

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)