annotate scripts/miscellaneous/zip.m @ 6049:04c2ad6d1679

[project @ 2006-10-13 14:32:15 by jwe]
author jwe
date Fri, 13 Oct 2006 14:32:23 +0000
parents
children 814f20da2cdb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2006 Sylvain Pelissier
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
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 2, or (at your option)
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
8 ## any later version.
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
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
18 ## 02110-1301, USA.
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
19
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefn {Function File} {@var{entries} =} zip (@var{zipfile},@var{files})
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
22 ## @deftypefnx {Function File} {@var{entries} =} zip (@var{zipfile},@var{files},@var{rootdir})
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
23 ## Compress the list of files and/or directories specified in @var{files}
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
24 ## into the archive @var{zipfiles} in the same directory. If @var{rootdir}
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
25 ## is defined the @var{files} is located relative to @var{rootdir} rather
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
26 ## than the current directory
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
27 ## @seealso{unzip,tar}
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
28 ## @end deftypefn
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
29
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
30 ## Author: Sylvain Pelissier <sylvain.pelissier@gmail.com>
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
31
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
32 function entries = zip (zipfile, files, rootdir)
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
33
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
34 if (nargin != 3)
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
35 rootdir = "./";
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
36 endif
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
37
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
38 if (nargin == 2 || nargin == 3)
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
39 rootdir = tilde_expand (rootdir);
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
40
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
41 if (ischar (files))
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
42 files = cellstr (files);
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
43 endif
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
44
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
45 if (ischar (zipfile) && iscellstr (files))
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
46
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
47 cmd = sprintf ("cd %s; zip -r %s/%s %s", rootdir, pwd (), zipfile,
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
48 sprintf (" %s", files{:}));
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
49
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
50 [status, output] = system (cmd);
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
51
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
52 if (status == 0)
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
53 if (nargout > 0)
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
54 cmd = sprintf ("unzip -Z -1 %s", zipfile);
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
55 [status, entries] = system (cmd);
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
56 if (status == 0)
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
57 if (entries(end) == "\n")
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
58 entries(end) = [];
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
59 endif
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
60 entries = cellstr (split (entries, "\n"))';
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
61 else
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
62 error ("zip: zipinfo failed with exit status = %d", status);
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
63 endif
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
64 endif
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
65 else
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
66 error ("zip: zip failed with exit status = %d", status);
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
67 endif
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
68
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
69 else
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
70 error ("zip: expecting all arguments to be character strings");
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
71 endif
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
72
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
73 else
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
74 print_usage ();
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
75 endif
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
76
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents:
diff changeset
77 endfunction