Mercurial > hg > octave-lyh
changeset 6081:cd98c1e18d48
[project @ 2006-10-25 03:36:45 by jwe]
author | jwe |
---|---|
date | Wed, 25 Oct 2006 03:36:46 +0000 |
parents | 40ab35ab651c |
children | 588721ac2140 |
files | scripts/ChangeLog scripts/miscellaneous/untar.m scripts/miscellaneous/unzip.m |
diffstat | 3 files changed, 29 insertions(+), 95 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,10 @@ +2006-10-24 Bill Denney <denney@seas.upenn.edu> + + * miscellaneous/unpack.m, miscellaneous/bunzip2.m, + miscellaneous/gunzip.m: New files. + * miscellaneous/untar.m, miscellaneous/unzip.m: + Call unpack to do the real work. + 2006-10-24 John W. Eaton <jwe@octave.org> * plot/plot3.m: If we have a format string, then also pass using
--- a/scripts/miscellaneous/untar.m +++ b/scripts/miscellaneous/untar.m @@ -21,75 +21,22 @@ ## @deftypefn {Function File} untar (@var{tarfile}, @var{dir}) ## Unpack the TAR archive @var{tarfile} to the directory @var{dir}. ## If @var{dir} is not specified, it defaults to the current directory. -## @seealso{tar, gzip, gunzip, zip, unzip} +## @seealso{unpack, bzip2, bunzip2, tar, gzip, gunzip, zip, unzip} ## @end deftypefn ## Author: Søren Hauberg <hauberg@gmail.com> -## Adapted-By: jwe - -function files = untar (tarfile, directory) - - if (nargin == 1 || nargin == 2) - - if (nargin == 1) - directory = "."; - endif - - ## The file must exist (and be a file) and the directory must be a - ## string. - if (exist (tarfile, "file") && ischar (directory)) - - orig_dir = pwd (); - - tarfile = canonicalize_file_name (tarfile); - - s = stat (directory); - if (isempty (s)) - [status, msg] = mkdir (directory); - if (! status) - error ("untar: mkdir failed to create %s: %s", directory, msg); - endif - elseif (! S_ISDIR (s.mode)) - error ("untar: %s: not a directory", directory); - endif +## Adapted-By: jwe, Bill Denney - unwind_protect - chdir (directory); - [status, output] = system (sprintf ("tar -x -v -f %s", tarfile)); - unwind_protect_cleanup - chdir (orig_dir); - end_unwind_protect +function varargout = untar (files, outputdir) - if (status == 0) - if (nargout > 0) - fs = filesep (); - if (directory(end) != fs) - directory = strcat (directory, fs); - endif - ## Sadly not reliable if a filename contains a newline - ## character! - if (output(end) == "\n") - output(end) = []; - endif - files = cellstr (split (output, "\n")); - if (! strcmp (directory, ".")) - nf = length (files); - for i = 1:nf - files{i} = strcat (directory, files{i}); - endfor - endif - files = files'; - endif - else - error ("tar: tar exited with status = %s", status); - endif - - else - error ("untar: expecting arguments to be character strings"); - endif - - else - print_usage ("untar"); + if ! (nargin == 1 || nargin == 2) + print_usage (); endif + if (nargin == 1) + outputdir = "."; + endif + varargout = cell (1, nargout); + [varargout{:}] = unpack (files, outputdir, mfilename ()); + endfunction
--- a/scripts/miscellaneous/unzip.m +++ b/scripts/miscellaneous/unzip.m @@ -21,42 +21,22 @@ ## @deftypefn {Function File} unzip (@var{zipfile}, @var{dir}) ## Unpack the ZIP archive @var{zipfile} to the directory @var{dir}. ## If @var{dir} is not specified, it defaults to the current directory. -## @seealso{tar, untar, gzip, gunzip, zip} +## @seealso{unpack, bzip2, bunzip2, tar, untar, gzip, gunzip, zip} ## @end deftypefn ## Author: Søren Hauberg <hauberg@gmail.com> -## Adapted-By: jwe - -function files = unzip (zipfile, dir) - - if (nargin == 1 || nargin == 2) - - if (nargin == 1) - dir = "."; - endif - - if (ischar (zipfile) && ischar (dir)) - - [status, output] = system (sprintf ("unzip %s -d %s", zipfile, dir)); +## Adapted-By: jwe, Bill Denney - if (status == 0) - if (nargout > 0) - ## Create list of extracted files. It blows that there seems - ## to be no way to get unzip to print a simple list of file - ## names. - files = strrep (output, " inflating: ", ""); - files = cellstr (split (files, "\n")); - files = files(2:end-1,:); - files = files'; - endif - else - error ("unzip: unzip exited with status = %d", status); - endif - endif +function varargout = unzip (files, outputdir) - else - print_usage ("unzip"); + if ! (nargin == 1 || nargin == 2) + print_usage (); endif + if (nargin == 1) + outputdir = "."; + endif + varargout = cell (1, nargout); + [varargout{:}] = unpack (files, outputdir, mfilename ()); + endfunction -