summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStig Bakken <ssb@php.net>2001-08-19 00:34:08 +0000
committerStig Bakken <ssb@php.net>2001-08-19 00:34:08 +0000
commitb96e13a99d82d053815513f420c0549e6e131c70 (patch)
treee169c10dbf2ddedcd608486d823ae8cd03a31395
parentf25c5f09f038f8c383b2b345d902441f0d746737 (diff)
downloadphp-git-b96e13a99d82d053815513f420c0549e6e131c70.tar.gz
Added "phptar" command as proof that the Archive_Tar class works.
# Great work, Vincent!
-rw-r--r--configure.in2
-rw-r--r--pear/Makefile.in5
-rwxr-xr-xpear/scripts/phptar.in236
3 files changed, 241 insertions, 2 deletions
diff --git a/configure.in b/configure.in
index 323512af3c..78810b51ed 100644
--- a/configure.in
+++ b/configure.in
@@ -923,7 +923,7 @@ PHP_GEN_CONFIG_VARS
$php_shtool mkdir -p pear/scripts
ALL_OUTPUT_FILES="php4.spec Zend/Makefile main/build-defs.h \
pear/scripts/pear pear/scripts/phpize pear/scripts/php-config \
-pear/scripts/pearize TSRM/Makefile $PHP_OUTPUT_FILES"
+pear/scripts/pearize pear/scripts/phptar TSRM/Makefile $PHP_OUTPUT_FILES"
AC_OUTPUT($ALL_OUTPUT_FILES, [], [
diff --git a/pear/Makefile.in b/pear/Makefile.in
index 251831244b..66a9bfa480 100644
--- a/pear/Makefile.in
+++ b/pear/Makefile.in
@@ -138,7 +138,7 @@ BUILD_FILES = \
dynlib.m4 \
acinclude.m4
-bin_SCRIPTS = phpize php-config pear pearize
+bin_SCRIPTS = phpize php-config pear pearize phptar
install-build:
$(mkinstalldirs) $(INSTALL_ROOT)$(phpbuilddir) $(INSTALL_ROOT)$(bindir) && \
@@ -183,6 +183,9 @@ scripts/pear: scripts/pear.in $(top_builddir)/config.status
scripts/phpize: scripts/phpize.in $(top_builddir)/config.status
(cd ..;CONFIG_FILES=pear/scripts/phpize CONFIG_HEADERS= $(top_builddir)/config.status)
+scripts/phptar: scripts/phptar.in $(top_builddir)/config.status
+ (cd ..;CONFIG_FILES=pear/scripts/phptar CONFIG_HEADERS= $(top_builddir)/config.status)
+
scripts/pearize: scripts/pearize.in $(top_builddir)/config.status
(cd ..;CONFIG_FILES=pear/scripts/pearize CONFIG_HEADERS= $(top_builddir)/config.status)
diff --git a/pear/scripts/phptar.in b/pear/scripts/phptar.in
new file mode 100755
index 0000000000..f0e336c2c0
--- /dev/null
+++ b/pear/scripts/phptar.in
@@ -0,0 +1,236 @@
+#!@prefix@/bin/php -Cq
+<?php // -*- PHP -*-
+
+// {{{ setup
+
+define('S_IFDIR', 0040000); // Directory
+define('S_IFCHR', 0020000); // Character device
+define('S_IFBLK', 0060000); // Block device
+define('S_IFREG', 0100000); // Regular file
+define('S_IFIFO', 0010000); // FIFO
+define('S_IFLNK', 0120000); // Symbolic link
+define('S_IFSOCK', 0140000); // Socket
+
+require_once "PEAR.php";
+require_once "Experimental/Archive/Tar.php";
+require_once "Console/Getopt.php";
+
+// }}}
+// {{{ options
+
+$verbose = false;
+$op_create = false;
+$op_list = false;
+$op_extract = false;
+$use_gzip = false;
+$file = '';
+
+$progname = basename(array_shift($argv));
+
+$options = Console_Getopt::getopt($argv, "h?ctxvzf:");
+if (PEAR::isError($options)) {
+ usage($options);
+}
+
+$opts = $options[0];
+foreach ($opts as $opt) {
+ switch ($opt[0]) {
+ case 'v': {
+ $verbose = true;
+ break;
+ }
+ case 'c': {
+ $op_create = true;
+ break;
+ }
+ case 't': {
+ $op_list = true;
+ break;
+ }
+ case 'x': {
+ $op_extract = true;
+ break;
+ }
+ case 'z': {
+ $use_gzip = true;
+ break;
+ }
+ case 'f': {
+ $file = $opt[1];
+ break;
+ }
+ case 'h':
+ case '?': {
+ usage();
+ break;
+ }
+ }
+}
+
+if ($op_create + $op_list + $op_extract > 1) {
+ usage("Only one of -c, -t and -x can be specified at once!");
+}
+
+if ($op_create + $op_list + $op_extract == 0) {
+ usage("Please specify either -c, -t or -x!");
+}
+
+if (empty($file)) {
+ if ($op_create) {
+ $file = "php://stdout";
+ } else {
+ $file = "php://stdin";
+ }
+}
+
+// }}}
+
+$tar = new Archive_Tar($file, $use_gzip);
+$tar->setErrorHandling(PEAR_ERROR_DIE, "$progname error: %s\n");
+
+if ($op_create) {
+ do_create($tar, $options[1]);
+ $tar->create($options[1]);
+} elseif ($op_list) {
+ do_list($tar, $verbose);
+} elseif ($op_extract) {
+ do_extract($tar);
+}
+
+// {{{ getrwx()
+
+function getrwx($bits) {
+ $str = '';
+ $str .= ($bits & 4) ? 'r' : '-';
+ $str .= ($bits & 2) ? 'w' : '-';
+ $str .= ($bits & 1) ? 'x' : '-';
+ return $str;
+}
+
+// }}}
+// {{{ getfiletype()
+
+function getfiletype($bits) {
+ static $map = array(
+ '-' => S_IFREG,
+ 'd' => S_IFDIR,
+ 'l' => S_IFLNK,
+ 'c' => S_IFCHR,
+ 'b' => S_IFBLK,
+ 'p' => S_IFIFO,
+ 's' => S_IFSOCK,
+ );
+ foreach ($map as $char => $mask) {
+ if ($bits & $mask) {
+ return $char;
+ }
+ }
+}
+
+// }}}
+// {{{ getuser()
+
+function getuser($uid) {
+ static $cache = array();
+ if (isset($cache[$uid])) {
+ return $cache[$uid];
+ }
+ if (function_exists("posix_getpwuid")) {
+ if (is_array($user = @posix_getpwuid($uid))) {
+ $cache[$uid] = $user['name'];
+ return $user['name'];
+ }
+ }
+ $cache[$uid] = $uid;
+ return $uid;
+}
+
+// }}}
+// {{{ getgroup()
+
+function getgroup($gid) {
+ static $cache = array();
+ if (isset($cache[$gid])) {
+ return $cache[$gid];
+ }
+ if (function_exists("posix_getgrgid")) {
+ if (is_array($group = @posix_getgrgid($gid))) {
+ $cache[$gid] = $group['name'];
+ return $group['name'];
+ }
+ }
+ $cache[$gid] = $gid;
+ return $gid;
+}
+
+// }}}
+// {{{ do_create()
+
+function do_create(&$tar, &$files)
+{
+ $tar->create($files);
+}
+
+// }}}
+// {{{ do_list()
+
+function do_list(&$tar, $verbose)
+{
+ static $rwx = array(4 => 'r', 2 => 'w', 1 => 'x');
+ $files = $tar->listContent();
+ if (is_array($files) && sizeof($files) > 0) {
+ foreach ($files as $file) {
+ if ($verbose) {
+ $fm = (int)$file['mode'];
+ $mode = sprintf('%s%s%s%s', getfiletype($fm),
+ getrwx(($fm >> 6) & 7), getrwx(($fm >> 3) & 7),
+ getrwx($fm & 7));
+ $owner = getuser($file['uid']) . '/' . getgroup($file['gid']);
+ printf("%10s %-11s %7d %s %s\n", $mode, $owner, $file['size'],
+ date('Y-m-d H:i:s', $file['mtime']), $file['filename']);
+ } else {
+ printf("%s\n", $file['filename']);
+ }
+ }
+ }
+}
+
+// }}}
+// {{{ do_extract()
+
+function do_extract(&$tar, $destdir = ".")
+{
+ $tar->extract($destdir);
+}
+
+// }}}
+// {{{ usage()
+
+function usage($errormsg = '')
+{
+ global $progname;
+ $fp = fopen("php://stderr", "w");
+ if ($errormsg) {
+ if (PEAR::isError($errormsg)) {
+ fwrite($fp, $errormsg->getMessage() . "\n");
+ } else {
+ fwrite($fp, "$errormsg\n");
+ }
+ }
+ fwrite($fp, "$progname [-h|-?] {-c|-t|-x} [-z] [-v] [-f file] [file(s)...]
+Options:
+ -h, -? Show this screen
+ -c Create archive
+ -t List archive
+ -x Extract archive
+ -z Run input/output through gzip
+ -f file Use <file> as input or output (default is stdin/stdout)
+
+");
+ fclose($fp);
+ exit;
+}
+
+// }}}
+
+?> \ No newline at end of file