1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
|
# -*- perl -*-
###############################################################################
# $Id: OS2.pm,v 1.9 1999/10/25 21:18:22 MRO Exp $
#
# OS2.pm
#
# Contains OS/2 specific wrappers for system commands.
#
# NOTE: These subs do proper error catching. They return 1 on success
# and 0 on failure. In the latter case an error message is
# printed.
#
# Author: Marek Rouchal <marek@saftsack.fs.uni-bayreuth.de>
# using stuff from the former Override.pm and from the File::Spec modules.
#
# This software is part of LaTeX2HTML, originally by Nikos Drakos
# It is published under the GNU Public License and comes without any
# warranty.
#
# You aren't supposed to edit this script.
#
###############################################################################
# Changes History
#
# $Log: OS2.pm,v $
# Revision 1.9 1999/10/25 21:18:22 MRO
#
# -- added more configure options (Jens' suggestions)
# -- fixed bug in regexp range reported by Achim Haertel
# -- fixed old references in documentation (related to mail list/archive)
#
# Revision 1.8 1999/08/30 22:45:09 MRO
#
# -- perl now reports line numbers respective to .pin file - eases
# code development!
# -- l2hcfg.pm is installed, too for furtjer reference
# -- some minor bugs (hopefully) fixed.
#
# Revision 1.7 1999/06/06 14:24:54 MRO
#
#
# -- many cleanups wrt. to TeXlive
# -- changed $* to /m as far as possible. $* is deprecated in perl5, all
# occurrences should be removed.
#
# Revision 1.6 1999/06/04 15:30:17 MRO
#
#
# -- fixed errors introduced by cleaning up TMP*
# -- made pstoimg -quiet really quiet
# -- pstoimg -debug now saves intermediate result files
# -- several fixes for OS/2
#
# Revision 1.5 1999/06/03 12:15:45 MRO
#
#
# - cleaned up the TMP / TMPDIR / TMP_ mechansim. Should work much the
# same now, but the code should be easier to understand.
#
# - cleaned up L2hos, added an INSTALLation FAQ, beautified the test
# document a little bit
#
# Revision 1.4 1999/06/01 06:55:38 MRO
#
#
# - fixed small bug in L2hos/*
# - added some test_mode related output to latex2html
# - improved documentation
# - fixed small bug in pstoimg wrt. OS2
#
# Revision 1.3 1999/05/31 07:49:08 MRO
#
#
# - a lot of cleanups wrt. OS/2
# - make test now available (TEST.BAT on Win32, TEST.CMD on OS/2)
# - re-inserted L2HCONFIG environment
# - added some new subs to L2hos (path2os, path2URL, Cwd)
#
# Revision 1.2 1999/05/19 23:54:03 MRO
#
#
# -- uniquified icons - some of them look a little bit strange, might
# need to be fixed.
# -- got rid of unlink errors, cleaned up some cosmetics
#
# Revision 1.1 1999/05/11 06:10:02 MRO
#
#
# - merged config stuff, did first tries on Linux. Simple document
# passes! More test required, have to ger rid of Warnings in texexpand
#
# Revision 1.2 1999/05/05 19:47:07 MRO
#
#
# - many cosmetic changes
# - final backup before merge
#
# Revision 1.1 1999/03/15 23:00:54 MRO
#
#
# - moved L2hos modules to top level directory, so that no dir-
# delimiter is necessary in the @INC-statement.
# - changed strategy for "shave": Do not rely on STDERR redirection any
# more (caused problems on at least Win32)
#
# Revision 1.1 1999/02/10 01:37:16 MRO
#
#
# -- changed os-dependency structure again - now neat OO modules are
# used: portable, extensible, neat!
# -- some minor cleanups and bugfixes
#
#
###############################################################################
package L2hos::OS2;
use Exporter ();
use Carp;
use Cwd;
use File::Copy;
use strict;
use L2hos qw($Verbose);
my $dd = '\\';
# Platform identifier (configure internal)
sub plat {
my ($self) = @_;
'os2';
}
# Directory delimiter
sub dd {
my ($self) = @_;
$dd;
}
# Path delimiter in PATH environment
sub pathd {
my ($self) = @_;
';';
}
# current working directory in platform-specific format
sub Cwd {
my ($self) = @_;
path2os($self,cwd());
}
# The home directory
sub home {
my ($self,$user) = @_;
croak "Error (home): Cannot expand other user's home directory\n"
if($user);
$ENV{'HOME'} || Cwd() || '.';
}
# The shell the current user is running
sub shell {
my ($self) = @_;
$ENV{'COMSPEC'} || '',
}
# The user's login name
sub user {
my ($self) = @_;
$ENV{'USER'} || 'unknown',
}
# The user's full name
sub fullname {
my ($self) = @_;
$ENV{'USER'} || 'unknown',
}
# The hostname we're running on
sub host {
my ($self) = @_;
use Sys::Hostname;
my $host = hostname() || '';
$host;
}
# The null device to redirect garbage to
sub nulldev {
my ($self) = @_;
# Uli Wortmann: '/dev/nul' (one "l")
'/dev/null'; #'nul:';
}
# internal copy routine
sub os2_copy {
my ($str,$from,$to) = @_;
unless(-r $from) {
carp qq{Error ($str): Cannot read source "$from"\n};
return 0;
}
if(-e $to && !unlink($to)) {
carp qq{Error ($str): Cannot remove already existing destination "$to": $!\n};
return 0;
}
unless(copy($from,$to)) {
carp qq{Error ($str): Copy "$from" to "$to" failed: $!\n};
return 0;
}
1;
}
# A copy method
sub Copy {
my ($self,$from,$to) = @_;
os2_copy('Copy',$from,$to);
}
# A delete/remove/unlink method
sub Unlink {
my ($self,@files) = @_;
my @items;
if(@items = grep(-e, @files)) {
unless(unlink(@items)) {
carp 'Error (Unlink): Unlink "' . join(' ', @items) . "\" failed: $!\n";
return 0;
}
}
1;
}
# A rename/move method
sub Rename {
my ($self,$from,$to) = @_;
# return here if source does not exist
unless(-e $from) {
carp qq{Error (Rename): "$from" does not exist.\n};
return 0;
}
# delete destination if it exists
if(-e $to && !unlink($to)) {
carp qq{Error (Rename): Could not delete existing "$to": $!\n};
return 0;
}
unless(rename($from,$to)) {
carp qq{Error (Rename): Rename "$from" to "$to" failed: $!\n};
return 0;
}
1;
}
# A (hard) link method
sub Link {
my ($self,$from,$to) = @_;
# No hard links, so copy
os2_copy('Link',$from,$to);
1;
}
# A symbolic link method
sub Symlink {
my ($self,$from,$to) = @_;
# No symlinks, so copy
os2_copy('Symlink',$from,$to);
1;
}
# Given a directory name in either relative or absolute form, returns
# the absolute form.
# Note: The argument *must* be a directory name.
sub Make_directory_absolute {
my ($self,$path) = @_;
unless($path =~ /^([A-Z]:)?\Q$dd/i) { # path doesn't start with 'x:\'
my $orig_cwd;
unless($orig_cwd = cwd()) {
carp qq{Error (Make_directory_absolute): Could not determine current directory: $!\n};
return '';
}
unless(chdir $path) {
carp qq{Error (Make_directory_absolute): chdir "$path" failed: $!\n};
return '';
}
$path = cwd();
chdir $orig_cwd;
}
path2os($self,$path);
}
# Call external tools
sub syswait {
my ($self,$cmd,$in,$out,$err) = @_;
carp qq{Debug (syswait): Running "$cmd"\n} if($Verbose);
# it seems that no command is using specific redirections ...
system("cmd.exe", "/c", $cmd);
}
# check if path is absolute
sub is_absolute_path {
my ($self,$path) = @_;
$path =~ /^([A-Z]:)?\Q$dd\E/i;
}
# Convert a path to OS-specific
sub path2os {
my ($self,$path) = @_;
$path =~ s:/+:$dd:g;
$path;
}
# convert a path to an URL
sub path2URL {
my ($self,$path) = @_;
$path =~ s:[$dd$dd]+:/:g;
$path =~ s#^([a-z]):#$1|#i;
"file:///" . $path;
}
# convert a path so that LaTeX can use it
sub path2latex {
my ($self,$path) = @_;
$path =~ s:[$dd$dd]+:/:go;
$path;
}
# run perldoc the right way
sub perldoc {
my ($self,$script) = @_;
use vars qw(%Config);
eval 'use Config qw(%Config)'; # load perl's configuration
my $perldoc = $Config{scriptdir}.$dd."perldoc";
$script ||= $0;
# no nroff here
system("$perldoc -t $script");
}
# quote a command line argument
sub quote {
my ($self,$str) = @_;
"'$str'";
}
1; # must be last line
__END__
|