annotate scripts/miscellaneous/unpack.m @ 20164:df437a52bcaf stable

doc: Update more docstrings to have one sentence summary as first line. Reviewed miscellaneous, sparse, strings in scripts directory. * scripts/miscellaneous/bzip2.m, scripts/miscellaneous/citation.m, scripts/miscellaneous/compare_versions.m, scripts/miscellaneous/computer.m, scripts/miscellaneous/debug.m, scripts/miscellaneous/dir.m, scripts/miscellaneous/edit.m, scripts/miscellaneous/error_ids.m, scripts/miscellaneous/fileattrib.m, scripts/miscellaneous/fullfile.m, scripts/miscellaneous/genvarname.m, scripts/miscellaneous/gzip.m, scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/news.m, scripts/miscellaneous/open.m, scripts/miscellaneous/parseparams.m, scripts/miscellaneous/recycle.m, scripts/miscellaneous/run.m, scripts/miscellaneous/swapbytes.m, scripts/miscellaneous/tar.m, scripts/miscellaneous/tmpnam.m, scripts/miscellaneous/unpack.m, scripts/miscellaneous/what.m, scripts/sparse/bicg.m, scripts/sparse/bicgstab.m, scripts/sparse/cgs.m, scripts/sparse/colperm.m, scripts/sparse/eigs.m, scripts/sparse/etreeplot.m, scripts/sparse/gmres.m, scripts/sparse/gplot.m, scripts/sparse/ichol.m, scripts/sparse/ilu.m, scripts/sparse/pcg.m, scripts/sparse/pcr.m, scripts/sparse/qmr.m, scripts/sparse/spaugment.m, scripts/sparse/spconvert.m, scripts/sparse/spdiags.m, scripts/sparse/spfun.m, scripts/sparse/spones.m, scripts/sparse/sprandsym.m, scripts/sparse/spstats.m, scripts/sparse/spy.m, scripts/sparse/svds.m, scripts/sparse/treelayout.m, scripts/sparse/treeplot.m, scripts/strings/base2dec.m, scripts/strings/bin2dec.m, scripts/strings/blanks.m, scripts/strings/cstrcat.m, scripts/strings/deblank.m, scripts/strings/dec2base.m, scripts/strings/dec2bin.m, scripts/strings/dec2hex.m, scripts/strings/findstr.m, scripts/strings/hex2dec.m, scripts/strings/index.m, scripts/strings/isletter.m, scripts/strings/isstrprop.m, scripts/strings/mat2str.m, scripts/strings/ostrsplit.m, scripts/strings/regexptranslate.m, scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m, scripts/strings/strchr.m, scripts/strings/strjoin.m, scripts/strings/strjust.m, scripts/strings/strmatch.m, scripts/strings/strsplit.m, scripts/strings/strtok.m, scripts/strings/strtrim.m, scripts/strings/strtrunc.m, scripts/strings/substr.m, scripts/strings/untabify.m, scripts/time/datenum.m: Update more docstrings to have one sentence summary as first line.
author Rik <rik@octave.org>
date Mon, 04 May 2015 14:22:02 -0700
parents 8c20fb6caa16
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19597
diff changeset
1 ## Copyright (C) 2006-2015 Bill Denney
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
2 ##
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
4 ##
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
588721ac2140 [project @ 2006-10-25 03:46:17 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: 6546
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: 6546
diff changeset
8 ## your option) any later version.
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
9 ##
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
14 ##
588721ac2140 [project @ 2006-10-25 03:46:17 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: 6546
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: 6546
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
18
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
20 ## @deftypefn {Function File} {@var{files} =} unpack (@var{file})
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
21 ## @deftypefnx {Function File} {@var{files} =} unpack (@var{file}, @var{dir})
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
22 ## @deftypefnx {Function File} {@var{files} =} unpack (@var{file}, @var{dir}, @var{filetype})
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
23 ## Unpack the archive @var{file} based on its extension to the directory
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
24 ## @var{dir}.
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
25 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
26 ## If @var{file} is a list of strings, then each file is unpacked
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19951
diff changeset
27 ## individually. Shell wildcards in the filename such as @samp{*} or
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19951
diff changeset
28 ## @samp{?} are accepted and expanded.
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
29 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
30 ## If @var{dir} is not specified or is empty (@code{[]}), it defaults to the
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
31 ## current directory. If a directory is in the file list, then @var{filetype}
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
32 ## must also be specified.
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
33 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
34 ## The specific archive filetype is inferred from the extension of the file.
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
35 ## The @var{filetype} may also be specified directly using a string which
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
36 ## corresponds to a known extension.
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
37 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
38 ## Valid filetype extensions:
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
39 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
40 ## @table @code
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
41 ## @item bz
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
42 ## @itemx bz2
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
43 ## bzip archive
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
44 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
45 ## @item gz
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
46 ## gzip archive
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
47 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
48 ## @item tar
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
49 ## tar archive
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
50 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
51 ## @item tarbz
19235
cac9d4c49522 unpack.m: Fix Texinfo error in docstring.
Rik <rik@octave.org>
parents: 19234
diff changeset
52 ## @itemx tarbz2
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
53 ## @itemx tbz
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
54 ## @itemx tbz2
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
55 ## tar + bzip archive
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
56 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
57 ## @item targz
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
58 ## @itemx tgz
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
59 ## tar + gzip archive
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
60 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
61 ## @item z
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
62 ## compress archive
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
63 ##
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
64 ## @item zip
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
65 ## zip archive
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
66 ## @end table
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
67 ##
12642
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12500
diff changeset
68 ## The optional return value is a list of @var{files} unpacked.
19243
91a6f06c5052 Overhaul gzip.m and gunzip.m
Rik <rik@octave.org>
parents: 19235
diff changeset
69 ## @seealso{bunzip2, gunzip, unzip, untar, bzip2, gzip, zip, tar}
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
70 ## @end deftypefn
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
71
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
72 ## Author: Bill Denney <denney@seas.upenn.edu>
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
73
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
74 function filelist = unpack (file, dir = ".", filetype = "")
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
75
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
76 if (nargin < 1 || nargin > 3)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
77 print_usage ();
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
78 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
79
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
80 if (! ischar (file) && ! iscellstr (file))
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
81 error ("unpack: FILE must be a string or cell array of strings");
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
82 endif
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
83
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
84 ## Convert char arrays to cell strings to simplify further processing
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
85 if (ischar (file))
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
86 file = cellstr (file);
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
87 endif
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
88 if (numel (file) == 1)
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
89 gfile = glob (file);
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
90 if (isempty (gfile))
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
91 error ('unpack: file "%s" not found', file{1});
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
92 else
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
93 file = gfile;
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
94 endif
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
95 endif
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
96
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
97 ## Recursively unpack cellstr arrays one file at a time
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
98 if (numel (file) > 1)
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
99 files = {};
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
100 for i = 1:numel (file)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
101 tmpfiles = unpack (file{i}, dir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
102 files = {files{:} tmpfiles{:}};
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
103 endfor
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
104
8352
33337f1aca75 fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8297
diff changeset
105 ## Return output if requested.
33337f1aca75 fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8297
diff changeset
106 if (nargout > 0)
33337f1aca75 fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8297
diff changeset
107 filelist = files;
33337f1aca75 fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8297
diff changeset
108 endif
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
109 return;
8352
33337f1aca75 fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8297
diff changeset
110
19233
0ded8964c13a Added wildcard * support to archive-related routines (bug #43211).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents: 18857
diff changeset
111 else
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
112 file = file{1};
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
113 endif
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
114
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
115 if (isdir (file))
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
116 if (isempty (filetype))
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
117 error ("unpack: FILETYPE must be given for a directory");
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
118 elseif (! any (strcmpi (filetype, "gunzip")))
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
119 error ('unpack: FILETYPE must be "gunzip" for a directory');
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
120 endif
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
121 ext = ".gz";
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
122 else
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
123 [pathstr, name, ext] = fileparts (file);
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
124
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
125 ## Check to see if it's .tar.gz, .tar.Z, etc.
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
126 if (any (strcmpi ({".gz" ".Z" ".bz2" ".bz"}, ext)))
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
127 [~, tmpname, tmpext] = fileparts (name);
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
128 if (strcmpi (tmpext, ".tar"))
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
129 name = tmpname;
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 16724
diff changeset
130 ext = [tmpext ext];
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
131 endif
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
132 endif
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
133
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
134 ## If the file is a URL, download it and then work with that file.
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
135 if (! isempty (strfind (file, "://")))
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
136 ## FIXME: The above code is not a perfect test for a URL
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
137 urlfile = file;
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 19259
diff changeset
138 tmpfile = [tempname ext];
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
139 [file, success, msg] = urlwrite (urlfile, tmpfile);
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
140 if (! success)
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
141 error ('unpack: could not fetch "%s": %s', urlfile, msg);
12499
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
142 endif
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
143 endif
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
144
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
145 endif
a3019189ac51 Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents: 11588
diff changeset
146
19579
0cc52d752f99 unpack.m: replace canonicalize_file_name by make_absolute_filename (bug #43979)
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19278
diff changeset
147 file = make_absolute_filename (file);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
148
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
149 ## Instructions on what to do for any extension.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
150 ##
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
151 ## The field names are the file extension without periods.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
152 ## The first cell is what is executed to unpack an archive verbosely.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
153 ## The second cell is what is executed to unpack an archive quietly.
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
154 ## The third cell is the function to execute on output to get the files list.
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
155 ## The fourth cell indicates if the files may need to be manually moved
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
156 ## (i.e., tar and unzip decompress into the current directory while
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
157 ## bzip2 and gzip decompress the file at its location).
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
158 persistent commandlist;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
159 if (isempty (commandlist))
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
160 commandlist.gz = {'gzip -d -v -r "%s"', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
161 'gzip -d -r "%s"', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
162 @__parse_gzip__, true};
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
163 commandlist.z = commandlist.gz;
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
164 commandlist.bz2 = {'bzip2 -d -v "%s"', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
165 'bzip2 -d "%s"', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
166 @__parse_bzip2__, true};
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
167 commandlist.bz = commandlist.bz2;
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
168 commandlist.tar = {'tar xvf "%s"', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
169 'tar xf "%s"', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
170 @__parse_tar__, false};
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
171 commandlist.targz = {'gzip -d -c "%s" | tar xvf -', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
172 'gzip -d -c "%s" | tar xf -', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
173 @__parse_tar__, false};
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
174 commandlist.tgz = commandlist.targz;
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
175 commandlist.tarbz2 = {'bzip2 -d -c "%s" | tar xvf -', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
176 'bzip2 -d -c "%s" | tar xf -', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
177 @__parse_tar__, false};
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
178 commandlist.tarbz = commandlist.tarbz2;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
179 commandlist.tbz2 = commandlist.tarbz2;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
180 commandlist.tbz = commandlist.tarbz2;
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
181 commandlist.zip = {'unzip -n "%s"', ...
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
182 'unzip -nq "%s"', ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
183 @__parse_zip__, false};
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
184 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
185
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
186 ## Unzip doesn't actually care about the extension
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
187 if (strcmpi (filetype, "unzip"))
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
188 nodotext = "zip";
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
189 else
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
190 nodotext = ext(ext != '.');
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
191 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
192
19951
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
193 if (ispc && strcmp (nodotext, "tar"))
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
194 ## Change file pathname into a mingw style acceptable for tar
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
195 file = __w2mpth__ (file);
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
196 endif
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
197
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
198 if (isfield (commandlist, tolower (nodotext)))
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
199 [commandv, commandq, parsefcn, move] = deal (commandlist.(nodotext){:});
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
200 origdir = pwd ();
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
201 if (move)
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19579
diff changeset
202 startdir = fileparts (file);
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
203 else
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
204 startdir = origdir;
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
205 endif
19951
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
206 cstartdir = make_absolute_filename (startdir);
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
207 cenddir = make_absolute_filename (dir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
208 needmove = move && ! strcmp (cstartdir, cenddir);
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
209 if (nargout > 0 || needmove)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
210 command = commandv;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
211 else
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
212 command = commandq;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
213 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
214 else
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
215 warning ("unpack: unrecognized FILETYPE <%s>", ext);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
216 files = file;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
217 return;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
218 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
219
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
220 ## Create the directory if necessary.
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
221 s = stat (dir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
222 if (isempty (s))
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
223 [status, msg] = mkdir (dir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
224 if (! status)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
225 error ("unpack: mkdir failed to create %s: %s", dir, msg);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
226 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
227 elseif (! S_ISDIR (s.mode))
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
228 error ("unpack: %s: not a directory", dir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
229 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
230
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
231 unwind_protect
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
232 cd (dir);
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 16724
diff changeset
233 [status, output] = system (sprintf ([command " 2>&1"], file));
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
234 unwind_protect_cleanup
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
235 cd (origdir);
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
236 end_unwind_protect
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
237
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
238 if (status)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
239 error ("unpack: unarchiving program exited with status: %d\n%s",
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9170
diff changeset
240 status, output);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
241 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
242
6084
38114c34b44a [project @ 2006-10-25 03:52:48 by jwe]
jwe
parents: 6083
diff changeset
243 if (nargout > 0 || needmove)
19927
0cc365dada52 Allow tar, unpack, and zip to run on Windows with CR/NL EOL.
Rik <rik@octave.org>
parents: 19697
diff changeset
244 ## Trim the last CR or NL if needed.
0cc365dada52 Allow tar, unpack, and zip to run on Windows with CR/NL EOL.
Rik <rik@octave.org>
parents: 19697
diff changeset
245 files = parsefcn (ostrsplit (output, "\r\n", true))';
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
246
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
247 ## Move files if necessary.
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
248 if (needmove)
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
249 [st, msg] = movefile (files, cenddir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
250 if (! st)
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
251 error ('unpack: unable to move files to "%s": %s', dir, msg);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
252 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
253
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
254 ## Fix the names of the files since they were moved.
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
255 files = strrep (files, cstartdir, cenddir);
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
256 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
257
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
258 ## Return output if requested.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
259 if (nargout > 0)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
260 filelist = files;
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
261 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
262 endif
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
263
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
264 endfunction
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
265
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
266 function files = __parse_zip__ (output)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
267 ## Parse the output from zip and unzip.
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
268
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
269 ## Skip first line which is Archive header.
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
270 files = char (output(2:end));
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
271 ## Trim constant width prefix and return cell array.
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
272 files = cellstr (files(:,14:end))
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
273 endfunction
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
274
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
275 function output = __parse_tar__ (output)
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
276 ## This is a no-op, but it makes things simpler for other cases.
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
277 endfunction
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
278
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
279 function files = __parse_gzip__ (output)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
280 ## Parse the output from gzip and gunzip returning the files
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
281 ## commpressed (or decompressed).
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
282
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
283 files = regexprep (output, '^.+ with (.*)$', '$1');
6082
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
284 endfunction
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
285
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
286 function files = __parse_bzip2__ (output)
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
287 ## Parse the output from bzip2 and bunzip2 returning the files
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
288 ## commpressed (or decompressed).
588721ac2140 [project @ 2006-10-25 03:46:17 by jwe]
jwe
parents:
diff changeset
289
17000
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
290 ## Strip leading blanks and .bz2 extension from file name
45165d6c4738 unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents: 16994
diff changeset
291 files = regexprep (output, '^\s+(.*)\.bz2: .*', '$1');
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
292 endfunction
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
293
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
294
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
295 %!test
19259
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
296 %! ## Create temporary directory and file for packing and unpacking
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
297 %! dirname = tempname ();
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
298 %! assert (mkdir (dirname));
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
299 %! filename = tempname ();
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
300 %! fid = fopen (filename, "wt");
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
301 %! assert (fid >= 0);
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
302 %! fprintf (fid, "Hello World\n");
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
303 %! fprintf (fid, "123 456 789\n");
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
304 %! fclose (fid);
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
305 %! unwind_protect
19259
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
306 %! copyfile (filename, [filename ".orig"]);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
307 %! gzip (filename, dirname);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
308 %! [~, f] = fileparts (filename);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
309 %! filelist = unpack (fullfile (dirname, [f ".gz"]), P_tmpdir);
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19579
diff changeset
310 %! assert (filelist{1}, filename);
19259
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
311 %! fid = fopen ([filename ".orig"], "rb");
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
312 %! assert (fid >= 0);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
313 %! orig_data = fread (fid);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
314 %! fclose (fid);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
315 %! fid = fopen (filename, "rb");
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
316 %! assert (fid >= 0);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
317 %! new_data = fread (fid);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
318 %! fclose (fid);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
319 %! if (orig_data != new_data)
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
320 %! error ("unpack: Unpacked file does not equal original");
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
321 %! endif
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
322 %! unwind_protect_cleanup
19259
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
323 %! unlink (filename);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
324 %! unlink ([filename ".orig"]);
f8552bd35180 unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents: 19243
diff changeset
325 %! rmdir (dirname);
19234
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
326 %! end_unwind_protect
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
327
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
328 ## Test input validation
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
329 %!error unpack ()
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
330 %!error unpack (1,2,3,4)
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
331 %!error <FILE must be a string or cell array of strings> unpack (1)
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
332 %!error <file "_%NOT_A_FILENAME%_" not found> unpack ("_%NOT_A_FILENAME%_")
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
333 %!error <file "_%NOT_A_FILENAME%_" not found> unpack ({"_%NOT_A_FILENAME%_"})
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
334 %!error <file "_%NOT_A_FILENAME%_" not found> unpack ({"_%NOT_A_FILENAME%_", "2nd_filename"})
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
335 %!error <FILETYPE must be given for a directory>
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
336 %! if (isunix || ismac)
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
337 %! unpack ("/");
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
338 %! else
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
339 %! unpack ('C:\');
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
340 %! endif
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
341 %!error <FILETYPE must be "gunzip" for a directory>
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
342 %! if (isunix || ismac)
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
343 %! unpack ("/", [], "foobar");
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
344 %! else
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
345 %! unpack ('C:\', [], "foobar");
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
346 %! endif
6ebc2ca01c76 unpack.m: Overhaul function.
Rik <rik@octave.org>
parents: 19233
diff changeset
347