Skip to content

Commit 49b9f3d

Browse files
committed
Merge branch 'develop' into feature/improved-console-support
2 parents 158df35 + d4623fa commit 49b9f3d

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

PHPCtags.class.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ public function __construct()
2020
$this->mParser = new PHPParser_Parser(new PHPParser_Lexer);
2121
}
2222

23+
public function setMFile($file) {
24+
if(empty($file)) {
25+
throw new PHPCtagsException('No File specified.');
26+
}
27+
28+
if(!file_exists($file)) {
29+
throw new PHPCtagsException('Warning: cannot open source file "' . $file . '" : No such file');
30+
}
31+
32+
if(!is_readable($file)) {
33+
throw new PHPCtagsException('Warning: cannot open source file "' . $file . '" : File is not readable');
34+
}
35+
36+
$this->mFile = realpath($file);
37+
}
38+
2339
public static function getMKinds()
2440
{
2541
return self::$mKinds;
@@ -253,15 +269,19 @@ public function export($file, $options)
253269
continue;
254270
}
255271

256-
//@todo Check for existence
257-
$this->mFile = (string) $filename;
272+
$this->setMFile((string) $filename);
258273
$structs += $this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE);
259274
}
260275
} else {
261-
//@todo Check for existence
262-
$this->mFile = $file;
276+
$this->setMFile($file);
263277
$structs += $this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE);
264278
}
265279
return $this->render($structs, $options);
266280
}
267281
}
282+
283+
class PHPCtagsException extends Exception {
284+
public function __toString() {
285+
return "PHPCtags: {$this->message}\n";
286+
}
287+
}

phpctags

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ EOF;
3939
exit;
4040
}
4141

42-
$file = realpath(array_pop($argv));
42+
array_shift($argv);
43+
44+
$file = array_pop($argv);
4345

4446
if(!isset($options['excmd']))
4547
$options['excmd'] = 'pattern';
@@ -77,8 +79,12 @@ if(isset($options['recurse'])) {
7779
}
7880
}
7981

80-
$ctags = new PHPCtags();
81-
$result = $ctags->export($file, $options);
82+
try {
83+
$ctags = new PHPCtags();
84+
$result = $ctags->export($file, $options);
85+
} catch (Exception $e) {
86+
die("phpctags: {$e->getMessage()}");
87+
}
8288

8389
if (isset($options['f']) && $options['f'] !== '-') {
8490
$tagfile = fopen($options['f'], isset($options['a']) ? 'a' : 'w');

0 commit comments

Comments
 (0)