1 ## Copyright (C) 2005-2012 Søren Hauberg
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {@var{entries} =} tar (@var{tarfile}, @var{files})
21 ## @deftypefnx {Function File} {@var{entries} =} tar (@var{tarfile}, @var{files}, @var{root})
22 ## Pack @var{files} @var{files} into the TAR archive @var{tarfile}. The
23 ## list of files must be a string or a cell array of strings.
25 ## The optional argument @var{root} changes the relative path of @var{files}
26 ## from the current directory.
28 ## If an output argument is requested the entries in the archive are
29 ## returned in a cell array.
30 ## @seealso{untar, bzip2, gzip, zip}
33 ## Author: Søren Hauberg <hauberg@gmail.com>
35 function entries = tar (tarfile, files, root = ".")
37 if (nargin < 2 || nargin > 3)
42 files = cellstr (files);
45 if (! (ischar (tarfile) && iscellstr (files) && ischar (root)))
46 error ("tar: all arguments must be character strings");
49 cmd = sprintf ("tar cvf %s -C %s %s", tarfile, root,
50 sprintf (" %s", files{:}));
52 [status, output] = system (cmd);
55 error ("tar: tar exited with status = %d", status);
59 if (output(end) == "\n")
62 entries = strsplit (output, "\n");