diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/getopt.pl | 38 | ||||
-rw-r--r-- | lib/importenv.pl | 14 | ||||
-rw-r--r-- | lib/stat.pl | 27 |
3 files changed, 79 insertions, 0 deletions
diff --git a/lib/getopt.pl b/lib/getopt.pl new file mode 100644 index 0000000000..4832233ed2 --- /dev/null +++ b/lib/getopt.pl @@ -0,0 +1,38 @@ +;# $Header: getopt.pl,v 2.0 88/06/05 00:16:22 root Exp $ + +;# Process single-character switches with switch clustering. Pass one argument +;# which is a string containing all switches that take an argument. For each +;# switch found, sets $opt_x (where x is the switch name) to the value of the +;# argument, or 1 if no argument. Switches which take an argument don't care +;# whether there is a space between the switch and the argument. + +;# Usage: +;# do Getopt('oDI'); # -o, -D & -I take arg. Sets opt_* as a side effect. + +sub Getopt { + local($argumentative) = @_; + local($_,$first,$rest); + + while (($_ = $ARGV[0]) =~ /^-(.)(.*)/) { + ($first,$rest) = ($1,$2); + if (index($argumentative,$first) >= $[) { + if ($rest ne '') { + shift; + } + else { + shift; + $rest = shift; + } + eval "\$opt_$first = \$rest;"; + } + else { + eval "\$opt_$first = 1;"; + if ($rest ne '') { + $ARGV[0] = "-$rest"; + } + else { + shift; + } + } + } +} diff --git a/lib/importenv.pl b/lib/importenv.pl new file mode 100644 index 0000000000..c0c2be088e --- /dev/null +++ b/lib/importenv.pl @@ -0,0 +1,14 @@ +;# $Header: importenv.pl,v 2.0 88/06/05 00:16:17 root Exp $ + +;# This file, when interpreted, pulls the environment into normal variables. +;# Usage: +;# do 'importenv.pl'; +;# or +;# #include <importenv.pl> + +local($tmp,$key) = ''; + +foreach $key (keys(ENV)) { + $tmp .= "\$$key = \$ENV{'$key'};" if $key =~ /^[A-Za-z]\w*$/; +} +eval $tmp; diff --git a/lib/stat.pl b/lib/stat.pl new file mode 100644 index 0000000000..1895c58c19 --- /dev/null +++ b/lib/stat.pl @@ -0,0 +1,27 @@ +;# $Header: stat.pl,v 2.0 88/06/05 00:16:29 root Exp $ + +;# Usage: +;# @ary = stat(foo); +;# $st_dev = @ary[$ST_DEV]; +;# +$ST_DEV = 0 + $[; +$ST_INO = 1 + $[; +$ST_MODE = 2 + $[; +$ST_NLINK = 3 + $[; +$ST_UID = 4 + $[; +$ST_GID = 5 + $[; +$ST_RDEV = 6 + $[; +$ST_SIZE = 7 + $[; +$ST_ATIME = 8 + $[; +$ST_MTIME = 9 + $[; +$ST_CTIME = 10 + $[; +$ST_BLKSIZE = 11 + $[; +$ST_BLOCKS = 12 + $[; + +;# Usage: +;# do Stat('foo'); # sets st_* as a side effect +;# +sub Stat { + ($st_dev,$st_ino,$st_mode,$st_nlink,$st_uid,$st_gid,$st_rdev,$st_size, + $st_atime,$st_mtime,$st_ctime,$st_blksize,$st_blocks) = stat(shift(@_)); +} |