Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/tar.m @ 11233:1dfbcc9eee92
eliminate special cases for __DECCXX
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Nov 2010 21:11:43 -0500 |
parents | 95c3e38098bf |
children | fd0a3ac60b0e |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2005, 2006, 2007, 2009 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 | |
9170
81a755db4db4
pass xvf to tar instead of -x -v -f
Peter O'Gorman <pogma@thewrittenword.com>
parents:
8920
diff
changeset
|
49 cmd = sprintf ("tar cvf %s -C %s %s", tarfile, root, |
10549 | 50 sprintf (" %s", files{:})); |
5808 | 51 |
52 [status, output] = system (cmd); | |
5807 | 53 |
5808 | 54 if (status == 0) |
10549 | 55 if (nargout > 0) |
56 if (output(end) == "\n") | |
57 output(end) = []; | |
58 endif | |
8877
2c8b2399247b
implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
59 entries = strsplit (output, "\n"); |
10549 | 60 entries = entries'; |
61 endif | |
5808 | 62 else |
10549 | 63 error ("tar: tar exited with status = %d", status); |
5808 | 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 |