Mercurial > octave-antonio
annotate scripts/miscellaneous/bzip2.m @ 19697:4197fc428c7d
maint: Update copyright notices for 2015.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Feb 2015 14:19:08 -0500 |
parents | db92e7e28e1f |
children | df437a52bcaf |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19597
diff
changeset
|
1 ## Copyright (C) 2008-2015 Thorsten Meyer |
8349 | 2 ## (based on gzip.m by David Bateman) |
3 ## | |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
10 ## | |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
17 ## along with Octave; see the file COPYING. If not, see | |
18 ## <http://www.gnu.org/licenses/>. | |
19 | |
20 ## -*- texinfo -*- | |
19258
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
21 ## @deftypefn {Function File} {@var{filelist} =} bzip2 (@var{files}) |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{filelist} =} bzip2 (@var{files}, @var{dir}) |
8349 | 23 ## Compress the list of files specified in @var{files}. |
19258
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
24 ## |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
25 ## @var{files} is a character array or cell array of strings. Shell |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
26 ## wildcards in the filename such as @samp{*} or @samp{?} are accepted and |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
27 ## expanded. Each file is compressed separately and a new file with a |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
28 ## @file{".bz2"} extension is created. The original files are not modified, |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19258
diff
changeset
|
29 ## but existing compressed files will be silently overwritten. |
19258
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
30 ## |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
31 ## If @var{dir} is defined the compressed files are placed in this directory, |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
32 ## rather than the original directory where the uncompressed file resides. |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
33 ## If @var{dir} does not exist it is created. |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
34 ## |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
35 ## The optional output @var{filelist} is a list of the compressed files. |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
36 ## @seealso{bunzip2, unpack, gzip, zip, tar} |
8349 | 37 ## @end deftypefn |
38 | |
19258
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
39 function filelist = bzip2 (varargin) |
8349 | 40 |
19258
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
41 if (nargin < 1 || nargin > 2 || nargout > 1) |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
42 print_usage (); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
43 endif |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
44 |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
45 if (nargout == 0) |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
46 __xzip__ ("bzip2", "bz2", "bzip2 %s", varargin{:}); |
8349 | 47 else |
19258
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
48 filelist = __xzip__ ("bzip2", "bz2", "bzip2 %s", varargin{:}); |
8349 | 49 endif |
50 | |
51 endfunction | |
8362
03b414516dd8
clean up bzip2, gzip and __xzip__
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8349
diff
changeset
|
52 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
53 |
8362
03b414516dd8
clean up bzip2, gzip and __xzip__
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8349
diff
changeset
|
54 %!xtest |
19258
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
55 %! ## test bzip2 together with bunzip2 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
56 %! unwind_protect |
19258
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
57 %! filename = tempname; |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
58 %! dummy = pi; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
59 %! save (filename, "dummy"); |
19258
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
60 %! dirname = tempname; |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 %! mkdir (dirname); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 %! filelist = bzip2 (filename, dirname); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 %! filelist = filelist{1}; |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 %! [~, basename, extension] = fileparts (filename); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
65 %! if (! strcmp (filelist, [dirname, filesep, basename, extension, ".bz2"])) |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 %! error ("bzipped file does not match expected name!"); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 %! endif |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
68 %! if (! exist (filelist, "file")) |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
69 %! error ("bzipped file cannot be found!"); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
70 %! endif |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 %! bunzip2 (filelist); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
72 %! fid = fopen (filename, "rb"); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
73 %! assert (fid >= 0); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 %! orig_data = fread (fid); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 %! fclose (fid); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 %! fid = fopen ([dirname filesep basename extension], "rb"); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
77 %! assert (fid >= 0); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
78 %! new_data = fread (fid); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
79 %! fclose (fid); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
80 %! if (orig_data != new_data) |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 %! error ("bunzipped file not equal to original file!"); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
82 %! endif |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
83 %! unwind_protect_cleanup |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
84 %! delete (filename); |
19258
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
85 %! delete ([dirname, filesep, basename, extension]); |
a4e993343e93
Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
86 %! rmdir (dirname); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
87 %! end_unwind_protect |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
88 |