7017
|
1 ## Copyright (C) 2005, 2006, 2007 S�ren Hauberg |
5807
|
2 ## |
6049
|
3 ## This file is part of Octave. |
|
4 ## |
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
6049
|
9 ## |
|
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. |
|
14 ## |
5807
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
5807
|
18 |
|
19 ## -*- texinfo -*- |
5808
|
20 ## @deftypefn {Function File} {@var{entries} =} tar (@var{tarfile}, @var{files}, @var{root}) |
|
21 ## Pack @var{files} @var{files} into the TAR archive @var{tarfile}. The |
|
22 ## list of files must be a string or a cell array of strings. |
|
23 ## |
5807
|
24 ## The optional argument @var{root} changes the relative path of @var{files} |
|
25 ## from the current directory. |
|
26 ## |
5808
|
27 ## If an output argument is requested the entries in the archive are |
|
28 ## returned in a cell array. |
|
29 ## @seealso{untar, gzip, gunzip, zip, unzip} |
5807
|
30 ## @end deftypefn |
|
31 |
5808
|
32 ## Author: S�ren Hauberg <hauberg@gmail.com> |
5807
|
33 |
5808
|
34 function entries = tar (tarfile, files, root) |
|
35 |
|
36 if (nargin == 2 || nargin == 3) |
|
37 |
|
38 if (nargin == 2) |
|
39 root = "."; |
5807
|
40 endif |
|
41 |
|
42 ## Test type of input |
5808
|
43 if (ischar (files)) |
|
44 files = cellstr (files); |
5807
|
45 endif |
|
46 |
5808
|
47 if (ischar (tarfile) && iscellstr (files) && ischar (root)) |
|
48 |
|
49 cmd = sprintf ("tar -c -v -f %s -C %s %s", tarfile, root, |
|
50 sprintf (" %s", files{:})); |
|
51 |
|
52 [status, output] = system (cmd); |
5807
|
53 |
5808
|
54 if (status == 0) |
|
55 if (nargout > 0) |
|
56 if (output(end) == "\n") |
|
57 output(end) = []; |
|
58 endif |
|
59 entries = cellstr (split (output, "\n")); |
|
60 entries = entries'; |
|
61 endif |
|
62 else |
|
63 error ("tar: tar exited with status = %d", status); |
|
64 endif |
|
65 |
|
66 else |
|
67 error ("tar: expecting all arguments to be character strings"); |
5807
|
68 endif |
5808
|
69 |
|
70 else |
|
71 print_usage("tar"); |
|
72 endif |
|
73 |
5807
|
74 endfunction |