5807
|
1 ## Copyright (C) 2005 S�ren Hauberg |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
|
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 ## -*- texinfo -*- |
5808
|
18 ## @deftypefn {Function File} {@var{entries} =} tar (@var{tarfile}, @var{files}, @var{root}) |
|
19 ## Pack @var{files} @var{files} into the TAR archive @var{tarfile}. The |
|
20 ## list of files must be a string or a cell array of strings. |
|
21 ## |
5807
|
22 ## The optional argument @var{root} changes the relative path of @var{files} |
|
23 ## from the current directory. |
|
24 ## |
5808
|
25 ## If an output argument is requested the entries in the archive are |
|
26 ## returned in a cell array. |
|
27 ## @seealso{untar, gzip, gunzip, zip, unzip} |
5807
|
28 ## @end deftypefn |
|
29 |
5808
|
30 ## Author: S�ren Hauberg <hauberg@gmail.com> |
5807
|
31 |
5808
|
32 function entries = tar (tarfile, files, root) |
|
33 |
|
34 if (nargin == 2 || nargin == 3) |
|
35 |
|
36 if (nargin == 2) |
|
37 root = "."; |
5807
|
38 endif |
|
39 |
|
40 ## Test type of input |
5808
|
41 if (ischar (files)) |
|
42 files = cellstr (files); |
5807
|
43 endif |
|
44 |
5808
|
45 if (ischar (tarfile) && iscellstr (files) && ischar (root)) |
|
46 |
|
47 cmd = sprintf ("tar -c -v -f %s -C %s %s", tarfile, root, |
|
48 sprintf (" %s", files{:})); |
|
49 |
|
50 [status, output] = system (cmd); |
5807
|
51 |
5808
|
52 if (status == 0) |
|
53 if (nargout > 0) |
|
54 if (output(end) == "\n") |
|
55 output(end) = []; |
|
56 endif |
|
57 entries = cellstr (split (output, "\n")); |
|
58 entries = entries'; |
|
59 endif |
|
60 else |
|
61 error ("tar: tar exited with status = %d", status); |
|
62 endif |
|
63 |
|
64 else |
|
65 error ("tar: expecting all arguments to be character strings"); |
5807
|
66 endif |
5808
|
67 |
|
68 else |
|
69 print_usage("tar"); |
|
70 endif |
|
71 |
5807
|
72 endfunction |