Mercurial > octave-antonio
annotate scripts/miscellaneous/gzip.m @ 8349:02beb5be5683
add bzip2 function
author | Thorsten Meyer <thorsten.meyier@gmx.de> |
---|---|
date | Sun, 02 Nov 2008 17:07:44 +0100 |
parents | a1dbe9d80eee |
children | 03b414516dd8 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 2007 David Bateman |
6869 | 2 ## |
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. | |
6869 | 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 ## | |
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/>. | |
6869 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {@var{entries} =} gzip (@var{files}) | |
21 ## @deftypefnx {Function File} {@var{entries} =} gzip (@var{files}, @var{outdir}) | |
22 ## Compress the list of files and/or directories specified in @var{files}. | |
23 ## Each file is compressed separately and a new file with a '.gz' extension | |
8349
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
24 ## is created. The original files are not touched. Existing compressed |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
25 ## files are silently overwritten. If @var{outdir} is defined the compressed |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
26 ## versions of the files are placed in this directory. |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
27 ## @seealso{gunzip, bzip2, zip, tar, __xzip__} |
6869 | 28 ## @end deftypefn |
29 | |
8349
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
30 function entries = gzip (varargin) |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
31 if (nargin == 1 || nargin == 2) && (nargout <= 1) |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
32 if nargout == 0 |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
33 __xzip__ ("gzip", "gz", "gzip -r %s", varargin{:}); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
34 else |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
35 entries = __xzip__ ("gzip", "gz", "gzip -r %s", varargin{:}); |
6869 | 36 endif |
37 else | |
38 print_usage (); | |
39 endif | |
40 endfunction | |
41 | |
8349
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
42 %!error <Invalid call to gzip. Correct usage is> gzip("1", "2", "3"); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
43 %!error <Invalid call to gzip. Correct usage is> gzip(); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
44 %!error <output directory does not exist> gzip("1", tmpnam); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
45 %!error <expecting all arguments to be character strings> gzip(1); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
46 %!xtest |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
47 %! unwind_protect |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
48 %! filename = tmpnam; |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
49 %! dummy = 1; |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
50 %! save(filename, "dummy"); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
51 %! dirname = tmpnam; |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
52 %! mkdir(dirname); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
53 %! entry = gzip(filename, dirname); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
54 %! [path, basename, extension] = fileparts(filename); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
55 %! if ! strcmp(entry, [dirname, "/", basename, extension, ".gz"]) |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
56 %! error("gzipped file does not match expected name!"); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
57 %! endif |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
58 %! if ! exist(entry, "file") |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
59 %! error("gzipped file cannot be found!"); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
60 %! endif |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
61 %! unwind_protect_cleanup |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
62 %! delete(filename); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
63 %! delete(entry{:}); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
64 %! rmdir(dirname); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
65 %! end_unwind_protect |