[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: untar.m on Solaris with non-GNU tar
From: |
John W. Eaton |
Subject: |
Re: untar.m on Solaris with non-GNU tar |
Date: |
Fri, 20 Oct 2006 22:51:31 -0400 |
On 20-Oct-2006, Bill Denney wrote:
| function files = bunzip2 (varargin)
|
| if ! (nargin == 1 || nargin == 2)
| print_usage ();
| endif
|
| args = varargin;
| if (nargin < 2)
| args{2} = ".";
| endif
| f = unpack (args{:}, "bunzip2");
| if nargout > 0
| files = f;
| endif
|
| endfunction
You don't really need varargin for a function like this. It might be
clearer to write
function filelist = bunzip2 (files, outputdir)
if (nargin == 1 || nargin == 2)
if (nargin == 1)
outputdir = ".";
endif
tmp = unpack (files, outputdir, "bunzip2");
if (nargout > 0)
filelist = tmp;
endif
else
print_usage ();
endif
endfunction
Also, it looks like we are always asking unpack to get and return the
file list, even if it is not requested. Should we maybe make it so
that step is avoided if we don't want it (omit the -v options in the
commands used by unpack and the output parsing if nargout is zero)?
Also, we could use mfilename to get the last arg for unpack. Then all
these functions could be identical except for the function names.
function varargout = bunzip2 (files, outputdir)
if (nargin == 1 || nargin == 2)
if (nargin == 1)
outputdir = ".";
endif
varargout = cell (1, nargout);
[varargout{:}] = unpack (files, outputdir, mfilename ());
else
print_usage ();
endif
endfunction
Hmm, don't see a way to push any of this duplication into the unpack
function given its current definition, but if print_usage accepted an
argument, then I suppose we could write
function varargout = bunzip2 (varargin)
varargout = cell (1, nargout);
[varargout{:}] = __unarchive_common__ (mfilename (), varargin{:})
endfunction
function varargout = gunzip (varargin)
varargout = cell (1, nargout);
[varargout{:}] = __unarchive_common__ (mfilename (), varargin{:})
endfunction
function varargout = untar (varargin)
varargout = cell (1, nargout);
[varargout{:}] = __unarchive_common__ (mfilename (), varargin{:})
endfunction
function varargout = unzip (varargin)
varargout = cell (1, nargout);
[varargout{:}] = __unarchive_common__ (mfilename (), varargin{:})
endfunction
function varargout = __unarchive_common__ (fcn_name, files, outputdir)
if (nargin == 2 || nargin == 3)
if (nargin == 2)
outputdir = ".";
endif
varargout = cell (1, nargout);
[varargout{:}] = unpack (files, outputdir, fcn_name);
else
print_usage (fcn_name);
endif
endfunction
OTOH, maybe that is going too far.
jwe
- untar.m on Solaris with non-GNU tar, John Swensen, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar, Bill Denney, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar, John W. Eaton, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar, Bill Denney, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar, Bill Denney, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar,
John W. Eaton <=
- Re: untar.m on Solaris with non-GNU tar, Bill Denney, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar, John W. Eaton, 2006/10/24
- Re: untar.m on Solaris with non-GNU tar, Bill Denney, 2006/10/24
- Re: untar.m on Solaris with non-GNU tar, John W. Eaton, 2006/10/24