Mercurial > octave-antonio
annotate scripts/miscellaneous/gzip.m @ 12499:a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 03 Mar 2011 11:59:05 -0800 |
parents | c792872f8942 |
children | 8f2056646dba |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2007-2011 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 -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9051
diff
changeset
|
20 ## @deftypefn {Function File} {@var{entries} =} gzip (@var{files}) |
6869 | 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 | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
24 ## is created. The original files are not touched. Existing compressed |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
25 ## files are silently overwritten. If @var{outdir} is defined the compressed |
8349
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
26 ## versions of the files are placed in this directory. |
8362
03b414516dd8
clean up bzip2, gzip and __xzip__
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8349
diff
changeset
|
27 ## @seealso{gunzip, bzip2, zip, tar} |
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) |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
31 if (nargin != 1 && nargin != 2) || (nargout > 1) |
6869 | 32 print_usage (); |
33 endif | |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
34 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
35 if (nargout == 0) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
36 __xzip__ ("gzip", "gz", "gzip -r %s", varargin{:}); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
37 else |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
38 entries = __xzip__ ("gzip", "gz", "gzip -r %s", varargin{:}); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
39 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
40 |
6869 | 41 endfunction |
42 | |
8349
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
43 %!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
|
44 %!error <Invalid call to gzip. Correct usage is> gzip(); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
45 %!error <output directory does not exist> gzip("1", tmpnam); |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
46 %!error <FILES must be a character array or cellstr> gzip(1); |
8349
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
47 %!xtest |
8362
03b414516dd8
clean up bzip2, gzip and __xzip__
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8349
diff
changeset
|
48 %! # test gzip together with gunzip |
8349
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
49 %! unwind_protect |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
50 %! filename = tmpnam; |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
51 %! dummy = 1; |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
52 %! save(filename, "dummy"); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
53 %! dirname = tmpnam; |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
54 %! mkdir(dirname); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
55 %! entry = gzip(filename, dirname); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
56 %! [path, basename, extension] = fileparts(filename); |
8640
34b9a5743388
fix gzip test code - use filesep()
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8362
diff
changeset
|
57 %! if ! strcmp(entry, [dirname, filesep, basename, extension, ".gz"]) |
8349
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
58 %! error("gzipped file does not match expected name!"); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
59 %! endif |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
60 %! if ! exist(entry, "file") |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
61 %! error("gzipped file cannot be found!"); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
62 %! endif |
8362
03b414516dd8
clean up bzip2, gzip and __xzip__
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8349
diff
changeset
|
63 %! gunzip(entry); |
8640
34b9a5743388
fix gzip test code - use filesep()
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8362
diff
changeset
|
64 %! if (system(sprintf("diff %s %s%c%s%s", filename, dirname, filesep, |
8362
03b414516dd8
clean up bzip2, gzip and __xzip__
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8349
diff
changeset
|
65 %! basename, extension))) |
03b414516dd8
clean up bzip2, gzip and __xzip__
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8349
diff
changeset
|
66 %! error("unzipped file not equal to original file!"); |
03b414516dd8
clean up bzip2, gzip and __xzip__
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8349
diff
changeset
|
67 %! end |
8349
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
68 %! unwind_protect_cleanup |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
69 %! delete(filename); |
8640
34b9a5743388
fix gzip test code - use filesep()
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8362
diff
changeset
|
70 %! delete([dirname, filesep, basename, extension]); |
8349
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
71 %! rmdir(dirname); |
02beb5be5683
add bzip2 function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
72 %! end_unwind_protect |