Mercurial > hg > octave-lojdl
changeset 12500:8f2056646dba
Improve docstrings for archive functions (gzip, bzip2, etc.)
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 03 Mar 2011 13:05:50 -0800 |
parents | a3019189ac51 |
children | 5454b687fd14 |
files | scripts/ChangeLog scripts/miscellaneous/bunzip2.m scripts/miscellaneous/bzip2.m scripts/miscellaneous/gunzip.m scripts/miscellaneous/gzip.m scripts/miscellaneous/tar.m scripts/miscellaneous/unpack.m scripts/miscellaneous/untar.m scripts/miscellaneous/unzip.m scripts/miscellaneous/zip.m |
diffstat | 10 files changed, 91 insertions(+), 97 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,12 @@ +2010-03-03 Rik <octave@nomad.inbox5.com> + + * miscellaneous/bunzip2.m, miscellaneous/bzip2.m, + miscellaneous/gunzip.m, miscellaneous/gzip.m, miscellaneous/unpack.m, + miscellaneous/untar.m, miscellaneous/unzip.m: Improve docstrings + + * miscellaneous/tar.m, miscellaneous/zip.m: Check for invalid arguments + at the top, rather than bottom, of code. + 2010-03-03 Rik <octave@nomad.inbox5.com> * miscellaneous/gzip.m: Use same functional form as bzip, zip, etc.
--- a/scripts/miscellaneous/bunzip2.m +++ b/scripts/miscellaneous/bunzip2.m @@ -17,10 +17,11 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} bunzip2 (@var{bzfile}, @var{dir}) +## @deftypefn {Function File} {} bunzip2 (@var{bzfile}) +## @deftypefnx {Function File} {} bunzip2 (@var{bzfile}, @var{dir}) ## Unpack the bzip2 archive @var{bzfile} to the directory @var{dir}. If ## @var{dir} is not specified, it defaults to the current directory. -## @seealso{unpack, bzip2, tar, untar, gzip, gunzip, zip, unzip} +## @seealso{bzip2, unpack, gunzip, unzip, untar} ## @end deftypefn ## Author: Bill Denney <denney@seas.upenn.edu>
--- a/scripts/miscellaneous/bzip2.m +++ b/scripts/miscellaneous/bzip2.m @@ -22,9 +22,9 @@ ## @deftypefnx {Function File} {@var{entries} =} bzip2 (@var{files}, @var{outdir}) ## Compress the list of files specified in @var{files}. ## Each file is compressed separately and a new file with a '.bz2' extension -## is created. The original files are not touched. Existing compressed files -## are silently overwritten.If @var{outdir} is defined the compressed versions -## of the files are placed in this directory. +## is created. The original files are not modified. Existing compressed files +## are silently overwritten. If @var{outdir} is defined the compressed +## files are placed in this directory. ## @seealso{bunzip2, gzip, zip, tar} ## @end deftypefn
--- a/scripts/miscellaneous/gunzip.m +++ b/scripts/miscellaneous/gunzip.m @@ -20,9 +20,9 @@ ## @deftypefn {Function File} {} gunzip (@var{gzfile}, @var{dir}) ## Unpack the gzip archive @var{gzfile} to the directory @var{dir}. If ## @var{dir} is not specified, it defaults to the current directory. If -## the @var{gzfile} is a directory, all gzfile in the directory will be +## @var{gzfile} is a directory, all gzfiles in the directory will be ## recursively gunzipped. -## @seealso{unpack, bunzip2, tar, untar, gzip, gunzip, zip, unzip} +## @seealso{gzip, unpack, bunzip2, unzip, untar} ## @end deftypefn ## Author: Bill Denney <denney@seas.upenn.edu>
--- a/scripts/miscellaneous/gzip.m +++ b/scripts/miscellaneous/gzip.m @@ -21,9 +21,9 @@ ## @deftypefnx {Function File} {@var{entries} =} gzip (@var{files}, @var{outdir}) ## Compress the list of files and/or directories specified in @var{files}. ## Each file is compressed separately and a new file with a '.gz' extension -## is created. The original files are not touched. Existing compressed +## is created. The original files are not modified. Existing compressed ## files are silently overwritten. If @var{outdir} is defined the compressed -## versions of the files are placed in this directory. +## files are placed in this directory. ## @seealso{gunzip, bzip2, zip, tar} ## @end deftypefn
--- a/scripts/miscellaneous/tar.m +++ b/scripts/miscellaneous/tar.m @@ -17,7 +17,8 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{entries} =} tar (@var{tarfile}, @var{files}, @var{root}) +## @deftypefn {Function File} {@var{entries} =} tar (@var{tarfile}, @var{files}) +## @deftypefnx {Function File} {@var{entries} =} tar (@var{tarfile}, @var{files}, @var{root}) ## Pack @var{files} @var{files} into the TAR archive @var{tarfile}. The ## list of files must be a string or a cell array of strings. ## @@ -26,49 +27,40 @@ ## ## If an output argument is requested the entries in the archive are ## returned in a cell array. -## @seealso{untar, gzip, gunzip, zip, unzip} +## @seealso{untar, bzip2, gzip, zip} ## @end deftypefn ## Author: Søren Hauberg <hauberg@gmail.com> -function entries = tar (tarfile, files, root) - - if (nargin == 2 || nargin == 3) +function entries = tar (tarfile, files, root = ".") - if (nargin == 2) - root = "."; - endif + if (nargin < 2 || nargin > 3) + print_usage (); + endif - ## Test type of input - if (ischar (files)) - files = cellstr (files); - endif + if (ischar (files)) + files = cellstr (files); + endif - if (ischar (tarfile) && iscellstr (files) && ischar (root)) - - cmd = sprintf ("tar cvf %s -C %s %s", tarfile, root, - sprintf (" %s", files{:})); + if (ischar (tarfile) && iscellstr (files) && ischar (root)) + error ("tar: all arguments must be character strings"); + endif - [status, output] = system (cmd); + cmd = sprintf ("tar cvf %s -C %s %s", tarfile, root, + sprintf (" %s", files{:})); + + [status, output] = system (cmd); - if (status == 0) - if (nargout > 0) - if (output(end) == "\n") - output(end) = []; - endif - entries = strsplit (output, "\n"); - entries = entries'; - endif - else - error ("tar: tar exited with status = %d", status); - endif + if (status) + error ("tar: tar exited with status = %d", status); + endif - else - error ("tar: expecting all arguments to be character strings"); + if (nargout > 0) + if (output(end) == "\n") + output(end) = []; endif - - else - print_usage("tar"); + entries = strsplit (output, "\n"); + entries = entries'; endif endfunction
--- a/scripts/miscellaneous/unpack.m +++ b/scripts/miscellaneous/unpack.m @@ -21,14 +21,13 @@ ## @deftypefnx {Function File} {@var{files} =} unpack (@var{file}, @var{dir}) ## @deftypefnx {Function File} {@var{files} =} unpack (@var{file}, @var{dir}, @var{filetype}) ## Unpack the archive @var{file} based on its extension to the directory -## @var{dir}. If @var{file} is a cellstr, then all files will be -## handled individually. If @var{dir} is not specified, it defaults to -## the current directory. It returns a list of @var{files} -## unpacked. If a directory is in the file list, then the -## @var{filetype} to unpack must also be specified. +## @var{dir}. If @var{file} is a list of strings, then each file is +## unpacked individually. If @var{dir} is not specified, it defaults to +## the current directory. If a directory is in the file list, then the +## @var{filetype} must also be specified. ## -## The @var{files} includes the entire path to the output files. -## @seealso{bunzip2, tar, untar, gzip, gunzip, zip, unzip} +## The optional return value is a list of @var{files} unpacked. +## @seealso{bzip2, gzip, zip, tar} ## @end deftypefn ## Author: Bill Denney <denney@seas.upenn.edu>
--- a/scripts/miscellaneous/untar.m +++ b/scripts/miscellaneous/untar.m @@ -17,10 +17,11 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} untar (@var{tarfile}, @var{dir}) +## @deftypefn {Function File} {} untar (@var{tarfile}) +## @deftypefnx {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{unpack, bunzip2, tar, gzip, gunzip, zip, unzip} +## @seealso{tar, unpack, bunzip2, gunzip, unzip} ## @end deftypefn ## Author: Søren Hauberg <hauberg@gmail.com>
--- a/scripts/miscellaneous/unzip.m +++ b/scripts/miscellaneous/unzip.m @@ -21,7 +21,7 @@ ## @deftypefnx {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{unpack, bunzip2, tar, untar, gzip, gunzip, zip} +## @seealso{zip, unpack, bunzip2, gunzip, untar} ## @end deftypefn ## Author: Søren Hauberg <hauberg@gmail.com>
--- a/scripts/miscellaneous/zip.m +++ b/scripts/miscellaneous/zip.m @@ -20,57 +20,49 @@ ## @deftypefn {Function File} {@var{entries} =} zip (@var{zipfile}, @var{files}) ## @deftypefnx {Function File} {@var{entries} =} zip (@var{zipfile}, @var{files}, @var{rootdir}) ## Compress the list of files and/or directories specified in @var{files} -## into the archive @var{zipfiles} in the same directory. If @var{rootdir} -## is defined the @var{files} is located relative to @var{rootdir} rather -## than the current directory -## @seealso{unzip,tar} +## into the archive @var{zipfile} in the same directory. If @var{rootdir} +## is defined the @var{files} are located relative to @var{rootdir} rather +## than the current directory. +## @seealso{unzip, bzip2, gzip, tar} ## @end deftypefn ## Author: Sylvain Pelissier <sylvain.pelissier@gmail.com> -function entries = zip (zipfile, files, rootdir) - - if (nargin != 3) - rootdir = "./"; - endif - - if (nargin == 2 || nargin == 3) - rootdir = tilde_expand (rootdir); - - if (ischar (files)) - files = cellstr (files); - endif - - if (ischar (zipfile) && iscellstr (files)) - - cmd = sprintf ("cd %s; zip -r %s/%s %s", rootdir, pwd (), zipfile, - sprintf (" %s", files{:})); - - [status, output] = system (cmd); +function entries = zip (zipfile, files, rootdir = ".") - if (status == 0) - if (nargout > 0) - cmd = sprintf ("unzip -Z -1 %s", zipfile); - [status, entries] = system (cmd); - if (status == 0) - if (entries(end) == "\n") - entries(end) = []; - endif - entries = strsplit (entries, "\n"); - else - error ("zip: zipinfo failed with exit status = %d", status); - endif - endif - else - error ("zip: zip failed with exit status = %d", status); - endif - - else - error ("zip: expecting all arguments to be character strings"); - endif - - else + if (nargin != 2 && nargin != 3) print_usage (); endif + rootdir = tilde_expand (rootdir); + + if (ischar (files)) + files = cellstr (files); + endif + + if (! ischar (zipfile) && ! iscellstr (files)) + error ("zip: expecting all arguments to be character strings"); + endif + + cmd = sprintf ("cd %s; zip -r %s/%s %s", rootdir, pwd (), zipfile, + sprintf (" %s", files{:})); + + [status, output] = system (cmd); + + if (status) + error ("zip: zip failed with exit status = %d", status); + endif + + if (nargout > 0) + cmd = sprintf ("unzip -Z -1 %s", zipfile); + [status, entries] = system (cmd); + if (status) + error ("zip: zipinfo failed with exit status = %d", status); + endif + if (entries(end) == "\n") + entries(end) = []; + endif + entries = strsplit (entries, "\n"); + endif + endfunction