annotate scripts/miscellaneous/zip.m @ 14138:72c96de7a403 stable

maint: update copyright notices for 2012
author John W. Eaton <jwe@octave.org>
date Mon, 02 Jan 2012 14:25:41 -0500
parents 8f2056646dba
children 1de4ec2a856d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 12500
diff changeset
1 ## Copyright (C) 2006-2012 Sylvain Pelissier
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
2 ##
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
4 ##
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6065
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6065
diff changeset
8 ## your option) any later version.
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
9 ##
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
14 ##
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6065
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6065
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
18
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
20 ## @deftypefn {Function File} {@var{entries} =} zip (@var{zipfile}, @var{files})
6065
814f20da2cdb [project @ 2006-10-20 03:01:43 by jwe]
jwe
parents: 6049
diff changeset
21 ## @deftypefnx {Function File} {@var{entries} =} zip (@var{zipfile}, @var{files}, @var{rootdir})
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
22 ## Compress the list of files and/or directories specified in @var{files}
12500
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
23 ## into the archive @var{zipfile} in the same directory. If @var{rootdir}
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
24 ## is defined the @var{files} are located relative to @var{rootdir} rather
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
25 ## than the current directory.
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
26 ## @seealso{unzip, bzip2, gzip, tar}
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
27 ## @end deftypefn
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
28
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
29 ## Author: Sylvain Pelissier <sylvain.pelissier@gmail.com>
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
30
12500
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
31 function entries = zip (zipfile, files, rootdir = ".")
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
32
12500
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
33 if (nargin != 2 && nargin != 3)
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
34 print_usage ();
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
35 endif
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
36
12500
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
37 rootdir = tilde_expand (rootdir);
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
38
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
39 if (ischar (files))
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
40 files = cellstr (files);
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
41 endif
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
42
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
43 if (! ischar (zipfile) && ! iscellstr (files))
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
44 error ("zip: expecting all arguments to be character strings");
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
45 endif
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
46
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
47 cmd = sprintf ("cd %s; zip -r %s/%s %s", rootdir, pwd (), zipfile,
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
48 sprintf (" %s", files{:}));
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
49
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
50 [status, output] = system (cmd);
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
51
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
52 if (status)
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
53 error ("zip: zip failed with exit status = %d", status);
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
54 endif
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
55
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
56 if (nargout > 0)
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
57 cmd = sprintf ("unzip -Z -1 %s", zipfile);
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
58 [status, entries] = system (cmd);
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
59 if (status)
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
60 error ("zip: zipinfo failed with exit status = %d", status);
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
61 endif
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
62 if (entries(end) == "\n")
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
63 entries(end) = [];
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
64 endif
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
65 entries = strsplit (entries, "\n");
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
66 endif
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
67
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
68 endfunction