]>
git.p6c8.net - devedit.git/blob - modules/Tool.pm
a37967ed5863c77caf877c59a025492209d25800
4 # Dev-Editor - Module Tool
6 # Some shared sub routines
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 10-03-2003
22 use base
qw(Exporter);
24 @EXPORT = qw(check_path
31 # Check, if a virtual path is above a virtual root directory
32 # (currently no check if the path exists - check otherwise!)
34 # Params: 1. Virtual root directory
35 # 2. Virtual path to check
37 # Return: Array with the physical and the cleaned virtual path;
38 # false, if the submitted path is above the root directory
42 my ($root,$path) = @_;
46 $root = abs_path
($root);
47 $root = File
::Spec
->canonpath($root);
50 $path = $root."/".$path;
54 # The path points to a file
55 # We have to extract the directory name and create the absolute path
57 my @pathinfo = fileparse
($path);
59 # This is only to avoid errors
61 my $basename = $pathinfo[0] || '';
62 my $dir = $pathinfo[1] || '';
63 my $ext = $pathinfo[2] || '';
65 $dir = abs_path
($dir);
67 $path = $dir."/".$basename.$ext;
71 $path = abs_path
($path);
74 $path = File
::Spec
->canonpath($path);
76 # Check if the path is above the root directory
78 return if(index($path,$root) == -1);
80 # Create short path name
82 my $short_path = substr($path,length($root));
83 $short_path =~ tr!\\!\/!;
84 $short_path = "/".$short_path unless($short_path =~ m
!^/!);
85 $short_path = $short_path."/" if($short_path !~ m
!/$! && -d
$path);
87 return ($path,$short_path);
92 # Clean up a path logically and replace backslashes with
97 # Return: Cleaned path
102 $path = File
::Spec
->canonpath($path);
110 # Returns the last path of a filename
114 # Return: Last part of the path
123 $path = substr($path,0,-1) if($path =~ m!/$!);
124 $path = substr($path,rindex($path,"/")+1);
132 # Truncate a path in one of the following ways:
134 # - If the path points to a directory, the upper directory
136 # - If the path points to a file, the directory containing
137 # the file will be returned.
141 # Return: Truncated path
150 $path = substr($path,0,-1) if($path =~ m!/$!);
151 $path = substr($path,0,rindex($path,"/"));
158 # it's true, baby ;-)
patrick-canterino.de