]>
git.p6c8.net - devedit.git/blob - modules/Tool.pm
9e89e43e6ad71e0ad1e13cafe1c06bad5d428ef8
4 # Dev-Editor - Module Tool
6 # Some shared sub routines
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2003-10-03
21 use base
qw(Exporter);
23 @EXPORT = qw(check_path
30 # Check, if a virtual path is above a virtual root directory
31 # (currently no check if the path exists - check otherwise!)
33 # Params: 1. Virtual root directory
34 # 2. Virtual path to check
36 # Return: Array with the physical and the cleaned virtual path;
37 # false, if the submitted path is above the root directory
41 my ($root,$path) = @_;
45 $root = abs_path
($root);
46 $root = File
::Spec
->canonpath($root);
49 $path = $root."/".$path;
53 # The path points to a file
54 # We have to extract the directory name and create the absolute path
56 my $dir = upper_path
($path);
57 my $file = file_name
($path);
59 $dir = abs_path
($dir);
60 $path = $dir."/".$file;
64 $path = abs_path
($path);
67 $path = File
::Spec
->canonpath($path);
69 # Check if the path is above the root directory
71 return if(index($path,$root) == -1);
73 # Create short path name
75 my $short_path = substr($path,length($root));
76 $short_path =~ tr!\\!\/!;
77 $short_path = "/".$short_path unless($short_path =~ m
!^/!);
78 $short_path = $short_path."/" if($short_path !~ m
!/$! && -d
$path);
80 return ($path,$short_path);
85 # Clean up a path logically and replace backslashes with
90 # Return: Cleaned path
95 $path = File
::Spec
->canonpath($path);
103 # Returns the last path of a filename
107 # Return: Last part of the path
116 $path = substr($path,0,-1) if($path =~ m!/$!);
117 $path = substr($path,rindex($path,"/")+1);
125 # Truncate a path in one of the following ways:
127 # - If the path points to a directory, the upper directory
129 # - If the path points to a file, the directory containing
130 # the file will be returned.
134 # Return: Truncated path
143 $path = substr($path,0,-1) if($path =~ m!/$!);
144 $path = substr($path,0,rindex($path,"/"));
151 # it's true, baby ;-)
patrick-canterino.de