1st release.

This commit is contained in:
hjp 2003-12-18 16:31:40 +00:00
parent 46f4512ed3
commit 3b37f9b952
4 changed files with 196 additions and 0 deletions

49
pathtools/GNUmakefile Normal file
View File

@ -0,0 +1,49 @@
include GNUmakevars
TARGETS = apppath preppath delpath apppath.1 preppath.1 delpath.1
CONFDIR=../../configure
CONFDIR_exists=$(shell [ -d $(CONFDIR) ] && echo ok)
all: configure $(TARGETS)
clean:
rm -f $(TARGETS) *.bak core foo bar baz *.ps
distclean: clean
rm -f customize
install: $(BINDIR) \
$(BINDIR)/apppath \
$(BINDIR)/preppath \
$(BINDIR)/delpath \
$(MAN1DIR)/apppath.1 \
$(MAN1DIR)/preppath.1 \
$(MAN1DIR)/delpath.1 \
%.1: %.pl
pod2man $< > $@
%: %.pl customize
sh ./customize < $< > $@
chmod +x $@
%: %.sh customize
sh ./customize < $< > $@
chmod +x $@
customize: configure
sh ./configure
$(BINDIR):
mkdir -p $@
ifeq ($(CONFDIR_exists),ok)
configure: $(CONFDIR)/start $(CONFDIR)/perl $(CONFDIR)/finish
cat $^ > $@
endif
include GNUmakerules

53
pathtools/apppath.pl Executable file
View File

@ -0,0 +1,53 @@
#!@@@perl@@@ -w
=head1 NAME
apppath - append directories to path
=head1 SYNOPSIS
apppath [-c] directory...
=head1 DESCRIPTION
apppath appends the directories given as arguments to the PATH and
prints the new path on stdout.
=head1 OPTIONS
=over 4
=item B<-c>
Check whether the directories exist before adding them. Nonexistent
directories are silently ignored.
=back
=head1 AUTHOR
Peter J. Holzer <hjp@hjp.at>.
=cut
use strict;
my $path = $ENV{PATH};
my @path = split(/:/, $path);
my $check;
if ($ARGV[0] eq '-c') {
$check = 1;
shift;
}
if ($#ARGV == 0 && $ARGV[0] =~ /:/) {
@ARGV = split(/:/, $ARGV[0]);
}
nd: for my $nd (@ARGV) {
for my $od (@path) {
next nd if ($nd eq $od);
}
push @path, $nd if (!$check || -d $nd);
}
print join(':', @path), "\n";

38
pathtools/delpath.pl Executable file
View File

@ -0,0 +1,38 @@
#!@@@perl@@@ -w
=head1 NAME
delpath - delete directories from path
=head1 SYNOPSIS
delpath directory...
=head1 DESCRIPTION
delpath deletes the directories given as arguments from the PATH and
prints the new path on stdout.
=head1 AUTHOR
Peter J. Holzer <hjp@hjp.at>.
=cut
use strict;
if ($#ARGV == 0 && $ARGV[0] =~ /:/) {
@ARGV = split(/:/, $ARGV[0]);
}
my $path = $ENV{PATH};
my @path = split(/:/, $path);
my %del;
for (@del{@ARGV}) {
$_ = 1;
}
@path = grep { !$del{$_} } @path;
print join(':', @path), "\n";

56
pathtools/preppath.pl Executable file
View File

@ -0,0 +1,56 @@
#!@@@perl@@@ -w
=head1 NAME
preppath - prepend directories to path
=head1 SYNOPSIS
preppath [-c] directory...
=head1 DESCRIPTION
apppath prepends the directories given as arguments to the PATH,
eliminates any duplicates prints the new path on stdout.
=head1 OPTIONS
=over 4
=item B<-c>
Check whether the directories exist before adding them. Nonexistent
directories are silently ignored.
=back
=head1 AUTHOR
Peter J. Holzer <hjp@hjp.at>.
=cut
use strict;
my $path = $ENV{PATH};
my @path = split(/:/, $path);
my $check;
if ($ARGV[0] eq '-c') {
$check = 1;
shift;
}
if ($#ARGV == 0 && $ARGV[0] =~ /:/) {
@ARGV = split(/:/, $ARGV[0]);
}
my %seen;
my @newpath;
for my $d (@ARGV, @path) {
if (!$seen{$d} && (!$check || -d $d)) {
push @newpath, $d;
$seen{$d} = 1;
}
}
print join(':', @newpath), "\n";