Skip to content

Commit d4ebfa2

Browse files
markwumr-russ
authored andcommitted
Fixed issues based on @mr-russ's PR.
1. Following ctags's behavior, use -V for verbose. 2. Use real path for file_get_contens and file_exists inside phar stub to avoid a weird PHP bug. Conflicts: PHPCtags.class.php bootstrap.php
1 parent 5bd29e3 commit d4ebfa2

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

PHPCtags.class.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ private function full_render() {
394394

395395
public function export()
396396
{
397+
$start = microtime(true);
398+
397399
if (empty($this->mFiles)) {
398400
throw new PHPCtagsException('No File specified.');
399401
}
@@ -402,17 +404,25 @@ public function export()
402404
$this->process($file);
403405
}
404406

405-
return $this->full_render();
407+
$content = $this->full_render();
408+
409+
$end = microtime(true);
410+
411+
if ($this->mOptions['V']) {
412+
echo "It tooks ".($end-$start)." seconds.\n";
413+
}
414+
415+
return $content;
406416
}
407417

408418
private function process($file)
409419
{
410420
// Load the tag md5 data to skip unchanged files.
411-
if (!isset($this->tagdata) && isset($this->cachefile) && file_exists($this->cachefile)) {
421+
if (!isset($this->tagdata) && isset($this->cachefile) && file_exists(realpath($this->cachefile))) {
412422
if ($this->mOptions['v']) {
413423
echo "Loaded cache file.".PHP_EOL;
414424
}
415-
$this->tagdata = unserialize(file_get_contents($this->cachefile));
425+
$this->tagdata = unserialize(file_get_contents(realpath($this->cachefile)));
416426
}
417427

418428
if (is_dir($file) && isset($this->mOptions['R'])) {
@@ -438,14 +448,14 @@ private function process($file)
438448
try {
439449
$this->process_single_file($filename);
440450
} catch(Exception $e) {
441-
echo "PHPParser: {$e->getMessage()} - {$filename}".PHP_EOL;
451+
echo "\nPHPParser: {$e->getMessage()} - {$filename}\n";
442452
}
443453
}
444454
} else {
445455
try {
446456
$this->process_single_file($filename);
447457
} catch(Exception $e) {
448-
echo "PHPParser: {$e->getMessage()} - {$file}".PHP_EOL;
458+
echo "PHPParser: {$e->getMessage()} - {$filename}".PHP_EOL;
449459
}
450460
}
451461
}
@@ -457,24 +467,20 @@ private function process_single_file($filename)
457467
}
458468
$this->filecount++;
459469

460-
$startfile = microtime(true);
461-
462470
$this->setMFile((string) $filename);
463471
$file = file_get_contents($this->mFile);
464472
$md5 = md5($file);
465473
if (isset($this->tagdata[$this->mFile][$md5])) {
466474
// The file is the same as the previous time we analyzed and saved.
467475
$this->mLines[$this->mFile] = $this->tagdata[$this->mFile][$md5];
468-
if ($this->mOptions['v']) {
476+
if ($this->mOptions['V']) {
469477
echo ".";
470478
}
471479
return;
472480
}
473481

474482
$struct = $this->struct($this->mParser->parse($file), TRUE);
475-
$finishfile = microtime(true);
476483
$this->mLines[$this->mFile] = $this->render($struct);
477-
$finishmerge = microtime(true);
478484
$this->tagdata[$this->mFile][$md5] = $this->mLines[$this->mFile];
479485
if ($this->mOptions['debug']) {
480486
echo "Parse: ".($finishfile - $startfile).", Merge: ".($finishmerge-$finishfile)."; (".$this->filecount.")".$this->mFile.PHP_EOL;
@@ -487,6 +493,6 @@ private function process_single_file($filename)
487493

488494
class PHPCtagsException extends Exception {
489495
public function __toString() {
490-
return "PHPCtags: {$this->message}\n";
496+
return "\nPHPCtags: {$this->message}\n";
491497
}
492498
}

bootstrap.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Addresses: <techlivezheng@gmail.com>, https://github.com/techlivezheng/phpctags
1919
EOF;
2020

21-
$options = getopt('aC:f:Nno:RuvV', array(
21+
$options = getopt('aC:f:Nno:RuV', array(
2222
'append::',
2323
'debug',
2424
'exclude:',
@@ -28,6 +28,7 @@
2828
'help',
2929
'recurse::',
3030
'sort::',
31+
'verbose::',
3132
'version',
3233
'memory::',
3334
));
@@ -48,8 +49,12 @@
4849
-o Alternative for -f.
4950
-R Equivalent to --recurse.
5051
-u Equivalent to --sort=no.
52+
<<<<<<< HEAD
5153
-v Equivalent to --verbose.
5254
-V Equivalent to --version.
55+
=======
56+
-V Equivalent to --verbose.
57+
>>>>>>> a86869b... Fixed issues based on @mr-russ's PR.
5358
--append=[yes|no]
5459
Should tags should be appended to existing tag file [no]?
5560
--debug
@@ -72,7 +77,13 @@
7277
Recurse into directories supplied on command line [no].
7378
--sort=[yes|no|foldcase]
7479
Should tags be sorted (optionally ignoring case) [yes]?.
80+
<<<<<<< HEAD
7581
--Version
82+
=======
83+
--verbose=[yes|no]
84+
Enable verbose messages describing actions on each source file.
85+
--version
86+
>>>>>>> a86869b... Fixed issues based on @mr-russ's PR.
7687
Print version identifier to standard output.
7788
EOF;
7889

@@ -89,9 +100,17 @@
89100
}
90101
while ($key = array_pop($argv_)) unset($argv[$key]);
91102

92-
// option -V is an alternative to --version
103+
// option -V is an alternative to --verbose
93104
if (isset($options['V'])) {
94-
$options['version'] = FALSE;
105+
$options['verbose'] = 'yes';
106+
}
107+
108+
if (isset($options['verbose'])) {
109+
if ($options['verbose'] === FALSE || yes_or_no($options['verbose']) == 'yes') {
110+
$options['V'] = 'yes';
111+
} else if (yes_or_no($options['verbose']) != 'no') {
112+
die('phpctags: Invalid value for "verbose" option'.PHP_EOL);
113+
}
95114
}
96115

97116
if (!isset($options['debug'])) {

0 commit comments

Comments
 (0)