]>
git.p6c8.net - devedit.git/blob - modules/Tool.pm
4 # Dev-Editor - Module Tool
6 # Some shared sub routines
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 09-22-2003
24 use base
qw(Exporter);
26 @EXPORT = qw(check_path
33 # Check, if a virtual path is above a virtual root directory
34 # (currently no check if the path exists - check otherwise!)
36 # Params: 1. Virtual root directory
37 # 2. Virtual path to check
39 # Return: Array with the physical and the cleaned virtual path;
40 # false, if the submitted path is above the root directory
44 my ($root,$path) = @_;
48 $root = abs_path
($root);
49 $root = File
::Spec
->canonpath($root);
52 $path = $root."/".$path;
56 # The path points to a file
57 # We have to extract the directory name and create the absolute path
59 my @pathinfo = fileparse
($path);
61 # This is only to avoid errors
63 my $basename = $pathinfo[0] || '';
64 my $dir = $pathinfo[1] || '';
65 my $ext = $pathinfo[2] || '';
67 $dir = abs_path
($dir);
69 $path = $dir."/".$basename.$ext;
73 $path = abs_path
($path);
76 $path = File
::Spec
->canonpath($path);
78 # Check if the path is above the root directory
80 return if(index($path,$root) == -1);
82 # Create short path name
84 my $short_path = substr($path,length($root));
85 $short_path =~ tr!\\!\/!;
86 $short_path = "/".$short_path unless($short_path =~ m
!^/!);
87 $short_path = $short_path."/" if($short_path !~ m
!/$! && -d
$path);
89 return ($path,$short_path);
94 # Clean up a path logically and replace backslashes with
99 # Return: Cleaned path
104 $path = File
::Spec
->canonpath($path);
112 # Creates a readable string of a UNIX filemode number
113 # (copied from Tool.pm of Dev-Editor 0.1.4)
115 # Params: Filemode as number
117 # Return: Filemode as readable string
121 my ($modestring, $ur, $uw, $ux, $gr, $gw, $gx, $or, $ow, $ox);
124 $ur = ($mode & 0400) ?
"r" : "-"; # User Read
125 $uw = ($mode & 0200) ?
"w" : "-"; # User Write
126 $ux = ($mode & 0100) ?
"x" : "-"; # User eXecute
127 $gr = ($mode & 0040) ?
"r" : "-"; # Group Read
128 $gw = ($mode & 0020) ?
"w" : "-"; # Group Write
129 $gx = ($mode & 0010) ?
"x" : "-"; # Group eXecute
130 $or = ($mode & 0004) ?
"r" : "-"; # Other Read
131 $ow = ($mode & 0002) ?
"w" : "-"; # Other Write
132 $ox = ($mode & 0001) ?
"x" : "-"; # Other eXecute
134 # build a readable mode string (rwxrwxrwx)
135 return $ur . $uw . $ux . $gr . $gw . $gx . $or . $ow . $ox;
140 # Truncate a path in one of the following ways:
142 # - If the path points to a directory, the upper directory
144 # - If the path points to a file, the directory containing
145 # the file will be returned.
149 # Return: Truncated path
158 $path = substr($path,0,-1) if($path =~ m!/$!);
159 $path = substr($path,0,rindex($path,"/"));
166 # it's true, baby ;-)
patrick-canterino.de