svn%xmlterm.org 877783f732 xmlterm changes only (not part of the default build).
Minor tweaks to handle input of control characters. Switched to double clicks, instead of single clicks, to activate XMLterm features (to protect the user).


git-svn-id: svn://10.0.0.236/trunk@62305 18797224-902f-48f8-a5cc-f745e15eee43
2000-03-07 15:45:16 +00:00

160 lines
4.8 KiB
Perl
Executable File

#!/usr/bin/perl
# xls: an XMLterm wrapper for the UNIX "ls" command
# Usage: xls [-c|--cols] [-h|help] [-i||--iconic] [-w|--window]
use Cwd;
use Getopt::Long;
Getopt::Long::config('bundling');
my $options = "@ARGV";
&GetOptions("cols|c=i", "help|h!", "iconic|i!", "window|w!");
if ($opt_help) {
print "Usage: xls [-c|--cols] [-i|--iconic] [-w|--window]\n";
exit;
}
# Icon details
#my $imgdir="chrome://xmlterm/skin/default/images"
my $imgdir = "file:///usr/share/pixmaps/mc";
my %img;
($img{'directory'}, $img{'executable'}, $img{'plainfile'}, $img{'urlfile'}) =
('i-directory.png', 'i-executable.png', 'i-regular.png', 'i-regular.png');
my $ncols = 5;
$ncols = $opt_cols if ($opt_cols);
my $cookie = $ENV{LTERM_COOKIE}; # XMLTerm cookie
print "\e{S$cookie\a"; # HTML stream escape sequence
print "<TABLE FRAME=none BORDER=0>";
print "<COLGROUP COLSPAN=$ncols WIDTH=1*>";
my $dir = cwd();
my $rowimg = "";
my $rowtxt = "";
my $nfile = 0;
foreach $file (glob("*")) { # for each file in current directory
$file =~ m%\A(.*?) (\.[^/.]*)?\Z%x # Deconstruct file name
or die "xls: Internal error; unable to deconstruct file name\n";
my ($filename, $extension) = ($1, $2);
my $sendcmd;
if ($opt_window) {
$sendcmd = "createln";
} else {
$sendcmd = "exec";
}
my ($filetype, $fileimg, $sendtxt1, $sendtxt2);
if (-d $file) { # directory
$filetype = "directory";
$fileimg = "$imgdir/$img{$filetype}";
$sendtxt1 = "cd $dir/$file; xls $options";
$sendtxt2 = "cd $file; xls $options";
} elsif (-x $file) { # executable
$filetype = "executable";
$fileimg = "$imgdir/$img{$filetype}";
$sendtxt1 = "$dir/$file";
$sendtxt2 = "./$file";
} elsif (($extension eq ".gif") ||
($extension eq ".png") ||
($extension eq ".jpg")) { # image
$filetype = "imagefile";
$fileimg = "file://$dir/$file";
$sendtxt1 = "xcat $dir/$file";
$sendtxt2 = "xcat $file";
} elsif ($extension eq ".ps") { # postscript
$filetype = "plainfile";
$fileimg = "$imgdir/$img{$filetype}";
$sendtxt1 = "ghostview $dir/$file &";
$sendtxt2 = "ghostview $file &";
} elsif ($extension eq ".url") { # URL
open INFILE, $file or next;
$_ = <INFILE>;
close INFILE;
# Extract content URL and the icon URL (if any)
my @urlvals;
my $nurl = 0;
while ( m%\b # URL word boundary
(http|file|mailto): # protocol
(//)? # slashpair
(?:([\w.]+)@)? # username
([\w\-]+(?:\.[\w\-]+)*)? # host
(?::(\d+))? # port
(/\S*?) # pathname
(?=>|\"|\'|\s|[.,!](?:\s|\Z)|\Z) # URL terminator (look ahead)
%x ) {
$urlvals[$nurl] = $&;
s%$&%%;
$nurl++;
}
s%\A\s*(\S.*?)?\s*\Z%$1%; # trim leading/trailing space
if ($nurl >= 1) {
my $urldesc = $_;
my $urlstr = $urlvals[0];
$urldesc = $urlstr if !$urldesc;
$sendcmd = "textlink"; # override send command
$filetype = "urlfile";
if ($nurl >= 2) {
$fileimg = "$urlvals[1]"; # use icon URL
} else {
$fileimg = "$imgdir/$img{$filetype}"; #default URL icon
}
$sendtxt1 = "$urlstr";
$sendtxt2 = "$urlstr";
} else {
$filetype = "plainfile";
$fileimg = "$imgdir/$img{$filetype}";
$sendtxt1 = "xcat $dir/$file";
$sendtxt2 = "xcat $file";
}
} else { # plain file
$filetype = "plainfile";
$fileimg = "$imgdir/$img{$filetype}";
$sendtxt1 = "xcat $dir/$file";
$sendtxt2 = "xcat $file";
}
my @comps = split(m./.,$file);
my $tail = $comps[$#comps]; # file name
my $clickcmd =
qq%onClick="return HandleEvent(event,'click','$sendcmd',-\#,'$sendtxt1','$sendtxt2')"%;
$rowimg .= "<TD><IMG HEIGHT=48 WIDTH=48 SRC='$fileimg' $clickcmd>";
$rowtxt .= "<TD><SPAN CLASS='$filetype' $clickcmd>";
$rowtxt .= "$tail</SPAN>";
$nfile++;
if (($nfile % $ncols) == 0) { # print complete table row
print "<TR>$rowimg" if ($opt_iconic) ;
print "<TR>$rowtxt";
$rowimg = "";
$rowtxt = "";
}
}
if ($rowtxt) {
print "<TR>$rowimg" if ($opt_iconic) ;
print "<TR>$rowtxt";
}
print "</TABLE>";
print "\000"; # Terminate HTML stream